$(document).ready(function(){
	// hack for menu items
	$("ul#rMainMenu li a img").css({ height:"12px" });


	$(".top-bc-icons img").hover(function(){
		$(this).stop().animate({ width:"95px" }, 300);	
	}, function(){
		$(this).stop().animate({ width:"88px" }, 300);	
	});


	// thickbox prepare
	$.each($("td.rMenuText a.newwin"), function(i){
		var parentA = $(this).parent().prev();
		var href = $(this).attr("href");
		if(href.indexOf('/panoramic') > -1){
			$(this).attr("href", href + "?KeepThis=true&TB_iframe=true&height=480&width=640");
			$("a", $(parentA)).attr("href", href + "?KeepThis=true&TB_iframe=true&height=480&width=640");
		} else if(href.indexOf('/images/') > -1){
			$(this).attr("href", href + "?height=600&width=600");
			$("a", $(parentA)).attr("href", href + "?height=600&width=600");
		} else if(href.indexOf('/floorplan') > -1){
			$(this).attr("href", href + "?height=594&width=978");
			$("a", $(parentA)).attr("href", href + "?height=594&width=978");
		}
	});

	$.each($(".clientlogo"), function(){
		if($("#descr"+$(this).attr("rel")).html() != ""){
			$(this).attr("href","#TB_inline?inlineId=descr"+$(this).attr("rel")+"&height=280&width=450");
		}
	});

	var backs = {
		'right-side-bg1':'-505px -0px',
		'left-side-bg1':'-184px -245px'
	};
	// size of resized block cut by 50px
	var backsMoveLeft = {
		'right-side-bg1':'-465px -0px',
		'left-side-bg1':'-213px -0px'
	};
	// resize of resizeblock
	var resizeBlock = {
		'right':{ back:'-225px -0px', width:'240px' }
	};
	
	$.each(backs, function(name, value){
		$("#"+name).css({ backgroundPosition:value });
	});

	// move block right
	$("#acc1").hover(function(){
		var el = $(this);
			$("img.head", el).stop().animate({ left:"-600px" });
			$("img.full", el).stop().css({ left:"-500px" }).show().animate({ left:"40px" });
		$("#acc3").stop().animate({ left:"390px", width:"404px" }, 500, "linear"); // was 235 & 444
		$("#acc2 img.head").stop().animate({ left:"295px" }, 700, "easeInOutCubic");
		
		// blocks			
			$("#acc3 td#resizeblock").stop().animate({ width:resizeBlock.right.width, backgroundPosition:resizeBlock.right.back }, 500, "linear"); // was 210px & -225px 
			$("#acc3 #magnus-head").stop().animate({ left:"115px", top:"200px" }, 500, "linear");
			$("#right-side-bg1").stop().animate({ backgroundPosition:backsMoveLeft['right-side-bg1'] }, 500, "linear");
			
	}, function(){
		var el = $(this);
		$("img.head", el).stop().animate({ left:"75px" });
		$("img.full", el).stop().animate({ left:"-600px" });
		
		$("#acc3").stop().animate({ left:"235px", width:"444px" }, 500, "linear"); // was 235 & 444
		$("#acc2 img.head").stop().animate({ left:"250px" }, 700, "easeInOutCubic");
				
		// blocks			
			$("#acc3 td#resizeblock").stop().animate({ width:"280px", backgroundPosition:"-225px 0px" }, 500, "linear"); // was 210px & -225px 
			$("#acc3 #magnus-head").stop().animate({ left:"135px", top:"200px" }, 500, "linear");
			$("#right-side-bg1").stop().animate({ backgroundPosition:backs['right-side-bg1'] }, 500, "linear");
	});

	// move block left
	$("#acc2").hover(function(){
		var el = $(this);
		$("#acc3").stop().animate({ left:"140px", width:"404px" }, 500, "linear");
		$("#acc1 img.head").stop().animate({ left:"20px" }, 700, "easeInOutCubic");
		
			$("img.head", el).stop().animate({ left:"500px" });
			$("img.full", el).stop().css({ left:"800px" }).show().animate({ left:"60px" });
			
			$("#acc3 td#resizeblock").stop().animate({ width:"240px", backgroundPosition:"-225px -0px" }, 500, "linear")
			$("#acc3 #magnus-head").stop().animate({ left:"115px", top:"200px" }, 500, "linear")
			$("#right-side-bg1").stop().animate({ backgroundPosition:backsMoveLeft['right-side-bg1'] }, 500, "linear");
		
	}, function(){
		var el = $(this);
		$("#acc3").stop().animate({ left:"235px", width:"444px" }, 500, "linear");
		$("#acc1 img.head").stop().animate({ left:"75px" }, 700, "easeInOutCubic");
		
		$("img.full", el).stop().animate({ left:"800px" });
		$("img.head", el).stop().animate({ left:"250px" });

			$("#acc3 td#resizeblock").stop().animate({ width:"280px", backgroundPosition:"-225px 0px" }, 500, "linear")
			$("#acc3 #magnus-head").stop().animate({ left:"135px", top:"200px" }, 500, "linear")
			$("#right-side-bg1").stop().animate({ backgroundPosition:backs['right-side-bg1'] }, 500, "linear");
	});
		
	// sho central block
	$("#acc3").hover(function(){
		var el = $(this);
		$(this).stop().animate({ left:"135px", width:"674px" }, 500, "linear");
		$("#acc1 img.head").stop().animate({ left:"20px", top:"200px" }, 200, "easeInOutCubic");
		$("#acc2 img.head").stop().animate({ left:"305px", top:"200px" }, 700, "easeInOutCubic");

		$("img.head", el).stop().animate({ left:"250px" });
		$("#acc3 td#resizeblock").stop().animate({ width:"508px", backgroundPosition:"-123px 0px" }, 500, "linear", function(){
			$("img.head", el).stop().animate({ top:"1000px" });
			$("img.full", el).stop().css({ top:"-500px", left:"170px" }).show().animate({ top:"100px" });
		});
			$("#left-side-bg1").stop().animate({ backgroundPosition:"-84px -245px" }, 500, "linear");
			$("#right-side-bg1").stop().animate({ backgroundPosition:"-610px -0px" }, 500, "linear");
	}, function(){
		var el = $(this);
		$(this).stop().animate({ left:"235px", width:"444px" }, 500, "linear");
		$("#acc1 img.head").stop().animate({ left:"75px", top:"200px" }, 700, "easeInOutCubic");
		$("#acc2 img.head").stop().animate({ left:"250px", top:"200px" }, 700, "easeInOutCubic");

		$("#acc3 td#resizeblock").stop().animate({ width:"280px", backgroundPosition:"-225px -0px" }, 500, "linear");
			$("#left-side-bg1").stop().animate({ backgroundPosition:backs['left-side-bg1'] }, 500, "linear");		
			$("#right-side-bg1").stop().animate({ backgroundPosition:backs['right-side-bg1'] }, 500, "linear");					
			
		$("img.full", el).stop().animate({ top:"-500px" });
		$("img.head", el).stop().animate({ top:"200px", left:"135px" });
	});

	if($(".rIndexContent").length && globLang.lang == "ru"){
		$("#rSubAccordion").append('<a id="indexMoreSpoil" href="javascript:void(0);" style="margin-left:'+globLang.morepos+'"><img src="/images/facility/index/'+ globLang.lang +'/more.gif" alt="'+ globLang.more +'" /></a>');
		$(".rIndexContent").hide();
		$("#indexMoreSpoil").live("click", function(){
			if($(".rIndexContent").is(":hidden")){
				$("img", this).replaceWith('<img src="/images/facility/index/'+ globLang.lang +'/hide.gif" alt="'+ globLang.hide +'" />'); //attr("src", "/images/facility/index/"+ globLang.lang +"/hide.gif").attr("alt", globLang.hide);
				$(".rIndexContent").slideDown();
			} else {
				$("img", this).replaceWith('<img src="/images/facility/index/'+ globLang.lang +'/more.gif" alt="'+ globLang.more +'" />'); //.attr("src", "/images/facility/index/"+ globLang.lang +"/more.gif").attr("alt", globLang.more);
				$(".rIndexContent").slideUp();			
			}
					
		});
	}
	
	if($(".googleLoad").length){
		$(".googleLoad").ready(function(){
			var gCanvas = $(".googleLoad").attr("id");
			var gLat = $(".googleLoad").attr("lat");
			var gLng = $(".googleLoad").attr("lng");
			var gText = '';
			if($(".googleLoad").attr("gtext") != ""){
				var gText = $(".googleLoad").attr("gtext");
			}
			gminitialize(gCanvas, gLat, gLng, gText);
			//initialize(gCanvas, gLat, gLng, gText);
		});
	}
	
});



function gminitialize(gCanvas, gLat, gLng, gText) {
	if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById(gCanvas));
		map.addControl(new GSmallMapControl());
		map.setCenter(new GLatLng(gLat,gLng), 16);
		if(gText != ""){
			map.openInfoWindowHtml( map.getCenter(), gText );
		}
		var point = new GLatLng(gLat,gLng);
		map.addOverlay(createMarker(point, 1));
	}
}
function createMarker(point, index) {
	var baseIcon = new GIcon();
	baseIcon.image = "/images/icons/google.png";
	baseIcon.iconSize = new GSize(57, 50);
	baseIcon.iconAnchor = new GPoint(30, 5);
	var letteredIcon = new GIcon(baseIcon);
	markerOptions = { icon:letteredIcon };
	var marker = new GMarker(point, markerOptions);
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml("Marker <b>" + letter + "</b>");
	});
	return marker;
}