$(function () {
	//	alert($.cookie("myPlato"));
	var putt=window.location.href;
	if(putt.indexOf('partners')>0){
		putt=putt.substr(putt.indexOf('partners')+9,putt.indexOf('.html')-putt.indexOf('partners')-9);
	}else{
		putt=putt.substr(putt.indexOf('partners')+9,putt.indexOf('.html')-putt.indexOf('partners')-9);
	}
	if($.cookie("myPlato"+putt)!=null){
		var nm="#"+$.cookie("myPlato"+putt).substr(2,3);
		$(nm).blur();
		$("ul.zakladki li.active").removeClass("active");
		$(nm).addClass("active");

		$("div.bm_block div.list div.active").removeClass("active").hide();
		$($.cookie("myPlato"+putt)).addClass("active").show();
	}
	
	$("ul.zakladki li").click(function () {				
		$(this).blur();
		/*$(this).children("a").css("background", "url(/i/zakladka_white.png)");
		alert("dddd");
		$("ul.zakladki li.active a").css("background", "url(/i/zakladka_navy.png)");*/	
		$("ul.zakladki li.active").removeClass("active");
		$(this).addClass("active");
		
		var putt=window.location.href;
		if(putt.indexOf('partners')>0){
			putt=putt.substr(putt.indexOf('partners')+9,putt.indexOf('.html')-putt.indexOf('partners')-9);
		}else{
			putt=putt.substr(putt.indexOf('holding/business_projects')+25,putt.indexOf('.html')-putt.indexOf('holding/business_projects')-25);
		}
		
		var iid = $(this).attr("id");
		$("div.bm_block div.list div.active").removeClass("active").fadeOut("normal", function () {
			$("#i" + iid).addClass("active").fadeIn("normal");
			$.cookie("myPlato"+putt, "#i" + iid, window.location.href);
		});
		
		return false;
	});
	$("ul.zakladki4 li").click(function () {
		$(this).blur();
		$("ul.zakladki4 li.active").removeClass("active");
		$(this).addClass("active");
		
		var iid = $(this).attr("id");
		$("div.bm_block div.list div.active").removeClass("active").fadeOut("normal", function () {
			$("#i" + iid).addClass("active").fadeIn("normal");
		});
		
		return false;
	});
	/*
	var animate_lenta = true;
	$(".galary .next").click(function () {
		if (parseFloat($(".galary .lenta").width()) + parseFloat($(".galary .lenta").css("left")) > parseFloat($(".galary .widediv").width()) && animate_lenta) {
			animate_lenta = false;
			
			$(".galary .lenta").animate({
				"left": parseFloat($(".galary .lenta").css("left")) - 163 * 5
			}, 500, "swing", function () {
				animate_lenta = true;
				
				if (parseFloat($(".galary .lenta").width()) + parseFloat($(".galary .lenta").css("left")) < parseFloat($(".galary .widediv").width()) && animate_lenta) {
					//alert(1212);
					addOne();
				}
				
			});
		}
	
		return false;
	});
	
	var animate_lenta = true;
	$(".galary .previous").click(function () {
		if (parseFloat($(".galary .lenta").css("left")) < 0 && animate_lenta) {
			animate_lenta = false;
			
			$(".galary .lenta").animate({
				"left": parseFloat($(".galary .lenta").css("left")) + 163 * 5
			}, 500, "swing", function () {
				if (parseFloat($(".galary .lenta").css("left")) > 0) {
				//alert(121);
					addOne2();
				}
				animate_lenta = true;
			});
		}
	
		return false;
	});
	*/
	var anketa_opened = false;
	var last_id = 0;
	$("a.styled_a_1").click(function () {
		var asd = $(this);
		
		if (last_id == asd.attr("id")) {
			$("#anketa_close").click();
			return false;
		}
		
		last_id = asd.attr("id");
		$("#vacancy_id").val(last_id);
		
		if (anketa_opened)
			$("#anketa").hide( function () {
				asd.after($("#anketa"));
				$("#anketa").show();
			});
		else {
			asd.after($("#anketa"));
			$("#anketa").show();
			anketa_opened = true;
		}
		
		return false;
	});
	
	$("#anketa_close").click(function () {
		$("#anketa").hide();
		anketa_opened = false;
		last_id = 0;
		
		return false;
	});
	
	$(".add_this").live("click", function () {
		$(".workit").last().clone()	.appendTo(".make_it").find(".to_show").show();
		
		return false;
	});
	
	$(".delete_this").live("click", function () {
		$(this).parent().parent().parent().detach();
		
		return false;
	});
	
	$(".add_this2").live("click", function () {
		$(".workit2").last().clone()	.appendTo(".make_it2").find(".to_show2").show();
		
		return false;
	});
	
	$(".delete_this2").live("click", function () {
		$(this).parent().parent().parent().detach();
		
		return false;
	});
	/*$("a.styled_a_1").click(function () {
		var asd = $(this);
		
		if (last_id == asd.attr("id")) {
			$("#anketa_close").click();
			return false;
		}
		
		last_id = asd.attr("id");
		$("#vacancy_id").val(last_id);
		
		if (anketa_opened)
			$("#anketa").slideUp("normal", function () {
				asd.after($("#anketa"));
				$("#anketa").slideDown("normal");
			});
		else {
			asd.after($("#anketa"));
			$("#anketa").slideDown("normal");
			anketa_opened = true;
		}
		
		return false;
	});
	
	$("#anketa_close").click(function () {
		$("#anketa").slideUp();
		anketa_opened = false;
		last_id = 0;
		
		return false;
	});
	
	$(".add_this").live("click", function () {
		$(".workit").last().clone()	.appendTo(".make_it").find(".to_show").show();
		
		return false;
	});
	
	$(".delete_this").live("click", function () {
		$(this).parent().parent().parent().detach();
		
		return false;
	});
	
	$(".add_this2").live("click", function () {
		$(".workit2").last().clone()	.appendTo(".make_it2").find(".to_show2").show();
		
		return false;
	});
	
	$(".delete_this2").live("click", function () {
		$(this).parent().parent().parent().detach();
		
		return false;
	});*/
});

	function addOne(){
		$(".galary .lenta").css("width", parseFloat($(".galary .lenta")[0].style.width)*2);
		$(".galary .lenta").html($(".galary .lenta").html()+$(".galary .lenta").html());
	
	}


	function addOne2(){
		w=parseFloat($(".galary .lenta")[0].style.width);
		$(".galary .lenta").css("left", -1*w+816);
		$(".galary .lenta").css("width", w*2);
		$(".galary .lenta").html($(".galary .lenta").html()+$(".galary .lenta").html());
	
	}

	$(document).ready(function(){
		
		$('.companies .block').mouseover(function(){
			id=this.id.replace('city','');
			for(city in comps[id]){
				$('#round'+city).css('backgroundPosition', 'left top');
			}
		});
		
		
		$('.companies .block').mouseout(function(){
			id=this.id.replace('city','');
			for(city in comps[id]){
				$('#round'+city).css('backgroundPosition', 'left -13px');
			}
		});
		
		
		$('.city_icon').mouseover(function(){
			id=this.id.replace('round','');
			$('.popup_map').css("display", "none");
			
			$('#popka'+id).fadeIn();
			$('#popka'+id)[0].style.left=(parseInt(this.style.left)+5)+"px";
			$('#popka'+id)[0].style.top=(parseInt(this.style.top))+"px";
			
			//$('#popka'+id).mouseout(function(){$('#popka'+id).fadeOut();}).mouseover();

			
			
		});
		
		//$('.popup_map').mouseout(function(){$('.popup_map').fadeOut();});
		//$('.popup_map').click(function(){return false;});
		$('.our_geography').click(function(){$('.popup_map').fadeOut();});
		//$('.our_geography').mouseout(function(){$('.popup_map').fadeOut();});
		
		
	});
