//var container = YMaps.jQuery("#YMapsID"),
//var map = new YMaps.Map(container[0]);
//var map.setCenter(new YMaps.GeoPoint(37.64, 55.76), 10);
// —оздает обработчик событи€ window.onLoad


$(document).ready(function(){


	$(".anythingSlider .wrapper li").hover(
		function(){
			$(this).find(".ptext").fadeIn("slow");
		},
		function(){
			$(this).find(".ptext").fadeOut("slow");
		}
	);
w = (window.innerWidth ? window.innerWidth : (document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.offsetWidth));
h = (window.innerHeight ? window.innerHeight : (document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.offsetHeight));

	//$('body').addClass($.os.name).addClass($.browser.name).addClass($.browser.className);
	
	 $('.anythingSlider').anythingSlider({
		easing: "easeInOutExpo",        // Anything other than "linear" or "swing" requires the easing plugin
		autoPlay: false,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
		delay: 3000,                    // How long between slide transitions in AutoPlay mode
		startStopped: false,            // If autoPlay is on, this can force it to start stopped
		animationTime: 600,             // How long the slide transition takes
		hashTags: true,                 // Should links change the hashtag in the URL?
		buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
		pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
		startText: "Go",             // Start text
		stopText: "Stop",               // Stop text
		navigationFormatter: false       // Details at the top of the file on this use (advanced use)
    });
	//$('div.thumbNav a.cur').text();
	var stop = $('div.thumbNav a.cur').text();
	var lft = parseInt($('#thumbNav').find('a:first').text());
	var rft = parseInt($('#thumbNav').find('a:last').text());
	$('#thumbNav').hide(0);
	if(stop == lft)
	{
		$('a.forward').hide(0);
		$('a.back').hide(0);
	}
	//alert(stop + '+++' + start);
	function show_hide_arrows()
	{
		var cur = parseInt($('#thumbNav').find('a.cur').text());
		if(cur == lft)
			$('a.back').hide(0);
		else
			$('a.back').show(0);
		if(cur == rft)
			$('a.forward').hide(0);
		else
			$('a.forward').show(0);
	}
	show_hide_arrows();
	$('a.forward').live('click',function(){
		setTimeout(function(){show_hide_arrows();},610);
	});
	$('a.back').live('click',function(){
		setTimeout(function(){show_hide_arrows();},610);
	});
	//alert(a);
	
	
	if($.browser.name == 'msie')
	{
		function minH()
		{
			if($('body').width() <= 1000)
				$('#container').width('1000px');
			else
				if($('body').width() >= 1240)
					$('#container').width('1240px');
				else
					$('#container').width('100%');
		};
		minH();
		$(window).resize(function(){
			minH();
		});
	}
	var cnt = parseInt($('#menu a:last').attr('rel')) + 1;
	var size = new Array(cnt);
	for(var i=0;i<cnt;i++)
	{
		size[i] = $('#item' + i).width();
	}
	var colcnt = 5;
	var colors = new Array(colcnt);
	colors[0] = '#f7931e';
	colors[1] = '#bf232e';
	colors[2] = '#f55e23';
	colors[3] = '#ffec1e';
	colors[4] = '#ea0d24';
	function anim(cur)
	{
		var left = 0;
		for(var i=0;i<cur;i++)
			left += (size[i] + 40);
		$('#line').animate({'left':left,'width':size[cur],'backgroundColor':colors[Math.floor(Math.random()*colcnt)]},1000);
	}
	anim(parseInt($('#menu a.hover').attr('rel')));
	$(window).resize(function(){$('#ajax').css({'height':$('#content').height()});});
	$('#ajax').css({'height':$('#content').height()});
	$('#about_b').css({'height':$('#content').height()});
	
	$('#about_b_logos a').live('mouseover',function(){
		$(this).find('img.nh').animate({'opacity':'1'},300);
		$(this).find('img.h').animate({'opacity':'0'},300);
	}).live('mouseleave',function(){
		$(this).find('img.nh').animate({'opacity':'0'},300);
		$(this).find('img.h').animate({'opacity':'1'},300);
	});
	$('#we_can_cat div.item').live('mouseover',function(){
		$(this).css({'background':'black'});
		$(this).find('div.title').addClass('titleh');
	}).live('mouseleave',function(){
		$(this).css({'background':'none'});
		$(this).find('div.title').removeClass('titleh');
	});
	$('#peoplaes img').live('mouseover',function(){
		$(this).parent().parent().css({'overflow':'visible'});
		$(this).parent().parent().find('div.more').show();
		$(this).parent().css({'background':'url(/tpl/img/007.png)'});
	}).live('mouseleave',function(){
		$(this).parent().parent().css({'overflow':'hidden'});
		$(this).parent().parent().find('div.more').hide();
		$(this).parent().css({'background':'url(/tpl/img/blank.gif)'});
	});
	function menu_ajax(){
		$('#menu a').click(function(){
			if($(this).attr('href') == 'http://cakelabs.ru/blog/')return true;
			var curElem = parseInt($('#menu a.hover').attr('rel'));
			var thisRel = $(this).attr('rel');
			var lnk=$(this).attr('href');
			if(curElem != thisRel)
			{
				function resetContent()
				{
					$('#content').animate({'left':'0px'},500,function(){
						$('#ajax').animate({'height':$('#content').height()},500);
						$('#about_b').animate({'height':$('#content').height()},500);
						
						//init_cmap();
						if($("#BX_YMAP_cmap").length>0) {
   							// функци€ существует, ее можно вызывать
   							//alert("1");
   							init_cmap();
						}
					});
				}
				$('#menu a.hover').removeClass('hover');
				$(this).addClass('hover');
				anim(thisRel);
				if(curElem>thisRel)
					$('#content').animate({'left':'-1280px'},500).animate({'left':'1280px'},0).load($(this).attr('href') + '?ajax=yes',resetContent());
				else
					$('#content').animate({'left':'1280px'},500).animate({'left':'-1280px'},0).load($(this).attr('href') + '?ajax=yes',resetContent());
						
					
			}else{
				//alert("111");
				//ѕереходим по ссылке
				window.location.href=(lnk);
			}
			return false;
		});
	}
	menu_ajax();
	function brainstorm(){
		$('body').animate({'opacity':'0','backgroundColor':'#FF0000'},100).animate({'opacity':'1','backgroundColor':'#00FF00'},100).animate({'opacity':'0','backgroundColor':'#0000FF'},100).animate({'opacity':'1','backgroundColor':'#FF00FF'},100).animate({'opacity':'0','backgroundColor':'#FFFF00'},100).animate({'opacity':'1','backgroundColor':'#282828'},100);
	}
	//$('#logo').live('click',function(){brainstorm();brainstorm();brainstorm(); return false;});
	$('.back_link').hover(function(){$(this).animate({'backgroundColor':'#000000'},100);},function(){$(this).animate({'backgroundColor':'#345466'},100);})
	$('.pr_ar').hover(function(){$(this).animate({'backgroundColor':'#F7931E'},100);},function(){$(this).animate({'backgroundColor':'#000000'},100);})
	
	$('.aboutcompclk').live('click',function(){
		$('#about_b_rmenu a').removeClass('hhh');
		$(this).addClass('hhh');
		if($(this).attr('rel') != '0'){
			$('#aitem1').css({'background':'#345466'});
			$('#aitem0').css({'background':'#000'});
		}else{
			$('#aitem0').css({'background':'#345466'});$('#aitem1').css({'background':'#000'});
		
		}
		if($(this).attr('rel') != '1'){
			$('#about_b_text div.tab').slideUp("normal");
			$('#about_b_text div.tab' + $(this).attr('rel')).slideDown("normal");
		}
		return false;
	});
	
	$('.pr_ar_m a').hover(function(){
		if($(this).attr('class') == 'rig')
		{
			$(this).css({'backgroundPosition':'115px 34px'});
		}else
		{
			$(this).css({'backgroundPosition':'0px 34px'});
		}
	},function(){
		if($(this).attr('class') == 'rig')
		{
			$(this).css({'backgroundPosition':'115px 0px'});
		}else
		{
			$(this).css({'backgroundPosition':'0px 0px'});
		}
	});
	//$('#about_b .stext p:not(:eq(0))').slideUp(0);
	/*$('#about_b .stext p').slideUp(0);
	var sblck = $('#about_b .stext');
	$.each(sblck,function(k,v){
		//alert($(v).html());
		$(v).find('p:first').slideDown(0);
	});*/
	/*$('#about_b .sopenp').toggle(function(){
		$(this).parent().find('p').slideDown(100);
	},function(){
		$(this).parent().find('p:not(:eq(0))').slideUp(100);
		//$(this).parent().find('p').slideDown(0);
	});*/
	$('#about_b .sopenp').live('click',function(){
		$('<div id="about_b_det"><div id="about_b_det_txt"><div id="asdasd11close"></div>' + $(this).parent().html() + '</div></div>').insertBefore('#container');
		$('#about_b_det').animate({'opacity':'0'},0);
		$('#about_b_det').animate({'opacity':'1'},700);
		$('#about_b_det a.sopenp').hide(0);
		$('#about_b_det div.title').hide(0);
		$('#about_b_det img').hide(0);
		$('#about_b_det').height($('#container').height());
		return false;
	});
	$('#about_b_det').live('click',function(){
		$('#about_b_det').remove();
	});
	
	/*
	var servcolcnt = 11;
	var servcol = new Array(servcolcnt);
	var rndArr = new Array(servcolcnt);
	servcol[0] = '#f7931e';
	servcol[1] = '#bf232e';
	servcol[2] = '#f55e23';
	servcol[3] = '#ffec1e';
	servcol[4] = '#ea0d24';
	servcol[5] = '#3f6376';
	servcol[6] = '#00766f';
	servcol[7] = '#59763f';
	servcol[8] = '#76713f';
	servcol[9] = '#765d3f';
	servcol[10] = '#76423f';
	i = 0;
	for(i=0;i<servcolcnt;i++)
	{
		rndArr[i] = i;
	}
	i = 0;
	for(i=0;i<servcolcnt;i++)
	{
		n = Math.floor(Math.random() * servcolcnt);
		m = Math.floor(Math.random() * servcolcnt);
		z = rndArr[m];
		rndArr[m] = rndArr[n];
		rndArr[n] = z;
	}
	*/
	var scol = new Array(5);
	/*scol[0] = '#3f6376';
	scol[1] = '#00766f';
	scol[2] = '#59763f';
	scol[3] = '#76713f';
	scol[4] = '#765d3f';
	scol[5] = '#76423f';*/
	/*scol[0] = '#f7931e';
	scol[1] = '#bf232e';
	scol[2] = '#f55e23';
	scol[3] = '#ffec1e';
	scol[4] = '#ea0d24';*/
	function colorizeserv()
	{
		/*for(i=0;i<6;i++)
		{
			r = Math.floor(Math.random() * 100) + 155;
			g = Math.floor(Math.random() * 100) + 155;
			b = Math.floor(Math.random() * 100) + 155;
			rgb = 'rgb('+r+','+g+','+b+')';
			$('div.servitem:eq(' + i + ') div.servtitle').animate({'borderBottomColor':rgb},5000);
			$('div.servitem:eq(' + i + ') a').animate({'borderBottomColor':rgb,'color':rgb},5000);
		}*/
		for(i=0;i<6;i++)
		{
			$('div.servitem:eq(' + i + ') div.servtitle').animate({'borderBottomColor':colors[Math.floor(Math.random() * 5)]},3000);
		}
	}
	//setInterval(colorizeserv,3000);
	
	$('a.servupsrc').live('click',function(){
		$('<div id="about_b_det"><div id="about_b_det_txt"><div id="asdasd11close"></div>' + $(this).find('div.servupdiv').html() + '</div></div>').insertBefore('#container');
		$('#about_b_det').animate({'opacity':'0'},0);
		$('#about_b_det').animate({'opacity':'1'},700);
		//$('#about_b_det a.sopenp').hide(0);
		//$('#about_b_det div.title').hide(0);
		//$('#about_b_det img').hide(0);
		$('#about_b_det').height(h);
		return false;
	});
});