$(window).load(function(){
	if(typeof(home_eZGmapLocation_MapView)!='undefined'){
                    initGMap();
	}
});

$( function()
	{
		Cufon.replace('.central-title-inner', { fontFamily: 'gotham-black', hover: true });
		$('.move_left' ).mouseenter(function(){ moveControl($(this), 'left' ); });
		$('.move_right').mouseenter(function(){ moveControl($(this), 'right'); });
		$('.move_up'   ).mouseenter(function(){ moveControl($(this), 'up'   ); });
		$('.move_down' ).mouseenter(function(){ moveControl($(this), 'down' ); });
		$('.move_dl'   ).mouseenter(function(){ moveControl($(this), 'dl'   ); });
		$('.move_dr'   ).mouseenter(function(){ moveControl($(this), 'dr'   ); });
		$('.move_ul'   ).mouseenter(function(){ moveControl($(this), 'ul'   ); });
		$('.move_ur'   ).mouseenter(function(){ moveControl($(this), 'ur'   ); });
		$('.move_left, .move_right, .move_up, .move_down, .move_dl, .move_dr, .move_ul, .move_ur')
				.mouseleave(function(){ moveControl($(this), 'back' ); });
		
		pageWidth = 957;
		iW = 1389; // image width
		iH = 467;
		
		// set piece width and load the front image
		expOffset = Math.ceil((iW - pageWidth)/2)
		expWidth = pageWidth + expOffset + Math.floor(($(document).width()-pageWidth)/2);
		if(expWidth>iW)
			expWidth=iW;
		
		$('.exp_images')
			.css({
				left: -expOffset,
				width: expWidth,
				height: iH
			})
			.fadeIn();
    
    $(".exp_images img").one('load', function()
      {
        $('.exp_controls .expc').css('display','block');
      }).each(function()
          {
            if(this.complete) $(this).load();
          });
		
		// controls click
		$('.expa1').click(function(){ moveStage( this ); });
		$('.expa2').click(function(){ moveStage( this ); });
		$('.expa3').click(function(){ moveStage( this ); }); // fix - in
		$('.expa4').click(function(){ moveStage( this ); });
		$('.expa5').click(function(){ moveStage( this ); });
		$('.expa6').click(function(){ moveStage( this ); });
		$('.expb0').click(function(){ moveStage( this ); });
		$('.expb6').click(function(){ moveStage( this ); });
		$('.expc0').click(function(){ moveStage( this ); });
		$('.expc5').click(function(){ moveStage( this ); });
		$('.expd5').click(function(){ moveStage( this ); });
		$('.expe0').click(function(){ moveStage( this ); }); // fix - out
		$('.expe7').click(function(){ moveStage( this ); });
		$('.expf7').click(function(){ moveStage( this ); });
		$('.expd6').click(function(){ moveStage( this ); });
		$('.exph0').click(function(){ moveStage( this ); });
		$('.expb7').click(function(){ moveStage( this ); });
		$('.expc7').click(function(){ moveStage( this ); });

		//west
		$('.expb1').click(function(){ moveStage( this ); });
		$('.expd8').click(function(){ moveStage( this ); });
		$('.expb2').click(function(){ moveStage( this ); });
		$('.expd9').click(function(){ moveStage( this ); });
		$('.expb3').click(function(){ moveStage( this ); });
		$('.expd10').click(function(){ moveStage( this ); });
		$('.expb4').click(function(){ moveStage( this ); });
		$('.expd11').click(function(){ moveStage( this ); });
		$('.expb5').click(function(){ moveStage( this ); });
		$('.expd12').click(function(){ moveStage( this ); });
		$('.expb12').click(function(){ moveStage( this ); });
		$('.expd13').click(function(){ moveStage( this ); });

		//east
		$('.expc1').click(function(){ moveStage( this ); });
		$('.expd14').click(function(){ moveStage( this ); });
		$('.expc2').click(function(){ moveStage( this ); });
		$('.expd15').click(function(){ moveStage( this ); });
		//$('.expc3').click(function(){ moveStage( this ); });
		$('.expd16').click(function(){ moveStage( this ); });
		$('.expc4').click(function(){ moveStage( this ); });
		$('.expd17').click(function(){ moveStage( this ); });
		$('.expc6').click(function(){ moveStage( this ); });
		$('.expd18').click(function(){ moveStage( this ); });
		$('.expc8').click(function(){ moveStage( this ); });
		$('.expd19').click(function(){ moveStage( this ); });
		$('.expc9').click(function(){ moveStage( this ); });
		$('.expd20').click(function(){ moveStage( this ); });

		$('.expe3').click(function(){ moveStage( this ); });
		$('.expf21').click(function(){ moveStage( this ); });

		//north
        //$('.extr1').click(function(){ moveStage( this ); });
        $('.extr2').click(function(){ moveStage( this ); });
        $('.expd1').click(function(){ moveStage( this ); });
        //$('.expd2').click(function(){ moveStage( this ); });
        $('.expd3').click(function(){ moveStage( this ); });
        $('.expcr1').click(function(){ moveStage( this ); });
        $('.expcr2').click(function(){ moveStage( this ); });
        $('.expe15').click(function(){ moveStage( this ); });
        $('.expe1').click(function(){ moveStage( this ); });
        $('.expf24').click(function(){ moveStage( this ); });
        $('.exts1').click(function(){ moveStage( this ); });
        $('.exts2').click(function(){ moveStage( this ); });
        //$('.exts3').click(function(){ moveStage( this ); });
        //$('.exts4').click(function(){ moveStage( this ); });
        $('.exts5').click(function(){ moveStage( this ); });
        //$('.exts6').click(function(){ moveStage( this ); });

		$('.exp_back_r')
			.click(function(){ moveStage( this ); })
			.mouseleave(function(){ $(this).animate({left: 328}, 200) });
		$('.exp_back_l')
			.click(function(){ moveStage( this ); })
			.mouseleave(function(){ $(this).animate({left: 327}, 200) });
		
		// show/hide specials
		$('.exp_specials').click(function()
		{
		    bar = $(this).parent();
		    specs = bar.siblings('.ts_spec');
		    dH = Math.floor(specs.height()/2);
		    gallery = bar.siblings('.gallery-full-width');
		    movables = specs.add(bar).add(bar.siblings('.exp_movable'));

		    if ($(this).hasClass('photo'))
		    {
		        if ($('.special.on',this).length == 0)
		        {
		            $(this).toggleClass('on');
		            gallery.slideToggle();   
		        }
		        else
		            return false;
		    }
		    else if ($(this).hasClass('special'))
		         {
		            if ($(this).hasClass('on'))
		            {
		                $(this).removeClass('on')
		                specs.slideUp()
		                movables.animate({top: '+='+dH}, {queue: false})
		            }
		            else
		            {
		                $(this).addClass('on');
		                specs.data('dH', dH);
		                specs.slideDown();
		                movables.animate({top: '-='+dH}, {queue: false})
		            }
		         }
			return false;
		})
		
		$('.ts_close').click(function(){
			specs = $(this).parent();
			bar = specs.siblings('.sp_moreinf');
			movables = specs.add(bar).add(bar.siblings('.exp_movable'));
			bar.children('.exp_specials').removeClass('on')
			specs.slideUp()
			movables.animate({top: '+='+dH}, {queue: false})
		})
		
		function moveStage( target )
		{
			window.open( $( target ).attr( 'rel' ), '_self');
		}
		
		// controls movement
		function moveControl(elem, dir) {
			if(elem.hasClass('exp_load')) return false;
			t1= 80; t2= 40;
			if(!elem.data('set')) {
				elem.data('set', 'true');
				elem.data('orig', elem.css('backgroundPosition'));
				bPos = elem.css('backgroundPosition').split('px ');
				if(bPos.length == 2) {
						bPos[0] *= 1;
						bPos[1] = bPos[1].replace('px', '')*1;
				}
				switch(dir) {
					case 'up'   : pos =  bPos[0]   +'px '+ (bPos[1]-5)+'px'; posM =  bPos[0]    +'px '+(bPos[1]-10)+'px'; break;
					case 'down' : pos =  bPos[0]   +'px '+ (bPos[1]+5)+'px'; posM =  bPos[0]    +'px '+(bPos[1]+10)+'px'; break;
					case 'left' : pos = (bPos[0]-5)+'px '+  bPos[1]   +'px'; posM = (bPos[0]-10)+'px '+ bPos[1]    +'px'; break;
					case 'right': pos = (bPos[0]+5)+'px '+  bPos[1]   +'px'; posM = (bPos[0]+10)+'px '+ bPos[1]    +'px'; break;
					case 'dl'   : pos = (bPos[0]-5)+'px '+ (bPos[1]+3)+'px'; posM = (bPos[0]-10)+'px '+(bPos[1]+ 6)+'px'; break;
					case 'dr'   : pos = (bPos[0]+5)+'px '+ (bPos[1]+3)+'px'; posM = (bPos[0]+10)+'px '+(bPos[1]+ 6)+'px'; break;
					case 'ul'   : pos = (bPos[0]-5)+'px '+ (bPos[1]-3)+'px'; posM = (bPos[0]-10)+'px '+(bPos[1]- 6)+'px'; break;
					case 'ur'   : pos = (bPos[0]+5)+'px '+ (bPos[1]-3)+'px'; posM = (bPos[0]+10)+'px '+(bPos[1]- 6)+'px'; break;
					default     : pos = elem.css('backgroundPosition');
				}
				elem.data('newPos', pos);
				elem.data('newPosM', posM);
			}
			if(dir == 'back') {
				posM = elem.data('orig');
			} else {
				posM = elem.data('newPosM');
			}
			elem.stop().animate({backgroundPosition: posM}, t1, 'linear', function(){
				if(dir == 'back') {
					pos = elem.data('orig');
				} else {
					pos = elem.data('newPos');
				}
				elem.animate({backgroundPosition: pos}, t2, 'linear')
			})
		}
	}
);

