/*
   name - name of the cookie
   value - value of the cookie
   [expires] - expiration date of the cookie
     (defaults to end of current session)
   [path] - path for which the cookie is valid
     (defaults to path of calling document)
   [domain] - domain for which the cookie is valid
     (defaults to domain of calling document)
   [secure] - Boolean value indicating if the cookie transmission requires
     a secure transmission
   * an argument defaults when it is assigned null as a placeholder
   * a null placeholder is not required for trailing omitted arguments
*/

function setCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
	document.cookie = curCookie;
}


/*
  name - name of the desired cookie
  return string containing value of specified cookie or null
  if cookie does not exist
*/

function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
	if (begin != 0) return null;
	}
	else
		begin += 2;
	var end = document.cookie.indexOf(";", begin);
	if (end == -1)
		end = dc.length;
	return unescape(dc.substring(begin + prefix.length, end));
}


/*
   name - name of the cookie
   [path] - path of the cookie (must be same as path used to create cookie)
   [domain] - domain of the cookie (must be same as domain used to
     create cookie)
   path and domain default if assigned null or omitted if no explicit
     argument proceeds
*/

function deleteCookie(name, path, domain) {
	if (getCookie(name)) {
		document.cookie = name + "=" +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"

function fixDate(date) {
	var base = new Date(0);
	var skew = base.getTime();
	if (skew > 0)
		date.setTime(date.getTime() - skew);
}

//fancy box
$(document).ready(function() { 
	$("a.fancy").fancybox({
		'overlayShow' : true,
		'hideOnContentClick': true
	});
	

	
	$("a.fancy2").click(function () { 
      var link = $(this).attr("href"); 
	  var title = $(this).attr("alt"); 
	  var img = "<img style=\"height:500px; \" src='" + link + "' /><br /><p>" + title + "</p>";
	  $(".big_img").empty();
	  $(".big_img").css("height","550px");
	  $(".big_img").html(img);
	  return false;
    });
   
   $(".img_down").hide();
   var down_off = $(".down").offset();
   //$(".img_down").css("left",down_off.left - 20);
   $(".img_down").css("left",down_off.left - 130);
   
   $(".img_left").hide();
   var down_left = $("img.photo-left").offset();
   //$(".img_left").css("left",down_left.left - 20);
   $(".img_left").css("left",down_left.left - 130);
   
   $(".img_right").hide();
   var down_right = $("img.photo-right").offset();
   //$(".img_right").css("left",down_right.left - 40);
   $(".img_right").css("left",down_right.left - 150);
	
   
	$(".down").hover(
      function () {
		$(".img_down").show();
		$(".img_right").hide();
		$(".img_left").hide();
      }, 
      function () {}
    );
	
	$("img.photo-right").hover(
      function () {
		$(".img_right").show();
		$(".img_down").hide();
		$(".img_left").hide();
      }, 
      function () {}
    );
	
	$("img.photo-left").hover(
      function () {
		$(".img_left").show();
		$(".img_right").hide();
		$(".img_down").hide();
      }, 
      function () {}
    );
	
	$(".img_down").mouseover(function(){
      $(".img_down").show();
    });

	
	$("#stage1 img").css("opacity","0.01");
	$("#stage2 img").css("opacity","0.01");
	$("#stage3 img").css("opacity","0.01");
	$("#stage3").css("filter","alpha(opacity=1)");
	$("#stage2").css("filter","alpha(opacity=1)");
	$("#stage1").css("filter","alpha(opacity=1)");
	
	$("#tooltip1").hide();
	$("#tooltip2").hide();
	$("#tooltip3").hide();
	
	
	
	var offset1 = $("#stage1").offset();
	var offset2 = $("#stage1").offset();
	var offset3 = $("#stage1").offset();
	
	
	
	var left1 = offset1.left - $("#tooltip1").width() - 50;
	var left2 = offset2.left - $("#tooltip2").width() - 50;
	var left3 = offset3.left - $("#tooltip3").width() - 50;
	
	
	
	$("#tooltip1").css("left",left1);
	$("#tooltip2").css("left",left2);
	$("#tooltip3").css("left",left3);
	
	var bg = $("#map").offset();
	var bg_t = bg.top - 143;
	$("#mainconteiner").css("background-position","50% " + bg_t + "px");
	
	var ht1 = bg_t + 400 - $("#tooltip1").height();
	var ht2 = bg_t + 400 - $("#tooltip2").height();
	var ht3 = bg_t + 400 - $("#tooltip3").height();
	
	$("#tooltip1").css("top",ht1);
	$("#tooltip2").css("top",ht2);
	$("#tooltip3").css("top",ht3);
	
	$("#stage1").hover(
      function () {
        $("#stage1 img").css("opacity","1");
		$("#stage1").css("filter","alpha(opacity=100)");
		$("#stage3 img").css("opacity","0.01");
		$("#stage3").css("filter","alpha(opacity=1)");
		$("#stage2 img").css("opacity","0.01");
		$("#stage2").css("filter","alpha(opacity=1)");
		
		$("#tooltip1").show();
		$("#tooltip2").hide();
		$("#tooltip3").hide();
      }, 
      function () {
        
		
      }
    );
	$("#stage2").hover(
      function () {
        $("#stage2 img").css("opacity","1");
		$("#stage2").css("filter","alpha(opacity=100)");
		$("#stage3 img").css("opacity","0.01");
		$("#stage3").css("filter","alpha(opacity=1)");
		$("#stage1 img").css("opacity","0.01");
		$("#stage1").css("filter","alpha(opacity=1)");
		
		$("#tooltip2").show();
		$("#tooltip1").hide();
		$("#tooltip3").hide();
      }, 
      function () {
 
      }
    );
	$("#stage3").hover(
      function () {
		$("#stage3 img").css("opacity","1");
		$("#stage3").css("filter","alpha(opacity=100)");
		$("#stage2 img").css("opacity","0.01");
		$("#stage2").css("filter","alpha(opacity=1)");
		$("#stage1 img").css("opacity","0.01");
		$("#stage1").css("filter","alpha(opacity=1)");
      
		$("#tooltip3").show();
		$("#tooltip2").hide();
		$("#tooltip1").hide();
      }, 
      function () {
  
      }
    );



	

});

//Исправляем PNG в IE6
var arVersion = navigator.appVersion.split("MSIE");
var version = parseFloat(arVersion[1]);
function fixPNG(myImage) {
	if ((version >= 5.5) && (version < 7) && (document.body.filters)) {
		var imgID = (myImage.id) ? "id='" + myImage.id + "' " : "";
		var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : "";
		var imgTitle = (myImage.title) ? "title='" + myImage.title + "' " : "title='" + myImage.alt + "' ";
		var imgStyle = "display:inline-block;" + myImage.style.cssText;
		var strNewHTML = "<span " + imgID + imgClass + imgTitle
			+ " style=\"" + "width:" + myImage.width + "px; height:" + myImage.height + "px;" + imgStyle + ";"
			+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			+ "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>";
		myImage.outerHTML = strNewHTML;
	}
}
