var ie=false;

$(document).ready(function(){
	if ( $.browser.msie ) {
		if ($.browser.version < 9) ie = true;
	}

	dinamicMenu();

	$("#block .slide").click(function(){
		$(this).parent().parent().children('div.spl').slideToggle("fast");
		$(this).toggleClass("active");
		
		return false;
	});
	
	$("#tm2 .slide").click(function(){
		$(this).parent().parent().children('div.subtm2').slideToggle(0);
		$(this).toggleClass("active");
		$(this).parent().toggleClass("hover");
		return false;
	});
	
	/* Colorbox */
	$("a[rel='gal']").colorbox({opacity:0.5, scalePhotos:true, maxWidth:"90%", maxHeight:"90%"});
	$("a.gal").colorbox({opacity:0.5, scalePhotos:true, maxWidth:"90%", maxHeight:"90%" });
	
	/* onFocus */
	$('#search .s').focus(function(){
		if($(this).val() == 'Поиск по сайту'){$(this).val('').addClass('focus');}
	});
	$('#search .s').blur(function(){
		if($(this).val() == ''){$(this).val('Поиск по сайту').removeClass('focus');}
	});
	
	/*Визуал*/
	var lastRel = 1;
	
	var curRel  = 1;
	$('#visual .visMenu .btn').click(function(){
		var rel = $(this).attr('rel');
		curRel = rel;
		showVisPage(rel);
	});
	
	
	$('#visual').everyTime(5000, function(){
		curRel++;
		if(curRel > 3){curRel = 1;}
		showVisPage(curRel);
	});
	
	$('#visual').hover(function(){
		$('#visual').stopTime();
	}, function(){
		$('#visual').everyTime(5000, function(){
			curRel++;
			if(curRel > 3){curRel = 1;}
			showVisPage(curRel);
		});
	});
	
	function stopTimeAll(){
		$('.cl1').stopTime();
		$('.cl2').stopTime();
		$('.cl3').stopTime();
		$('vis1img').stopTime();
		$('vis2img').stopTime();
		$('vis3img').stopTime();
		$('vis1i').stopTime();
		$('vis2i').stopTime();
		$('vis3i').stopTime();
		$('.btn[rel=1]').stopTime();
	}
	
	function showVisPage(rel){
		if(!$('.btn[rel='+rel+']').hasClass('active')){
			stopTimeAll();
			$('.visMenu .btn').removeClass('active');
			$('.visMenu .btn[rel='+rel+']').addClass('active');
			$('.visLeft').hide();
			$('.visLeft[rel='+rel+']').fadeIn('fast');
			hidePrev(lastRel);
			$('.btn[rel=1]').oneTime(100, function(){
				lastRel = rel;
				
				//$('.visual-container').hide();
				var vC = $('.visual-container[rel='+rel+']');
				//$('.cl1').stop(true,true);
				//$('.cl2').stop(true,true);
				//$('.cl3').stop(true,true);
				$('.visLeft').stop(true,true);
				$('vis1img').stop(true,true);
				$('vis2img').stop(true,true);
				$('vis3img').stop(true,true);
				$('vis1i').stop(true,true);
				$('vis2i').stop(true,true);
				$('vis3i').stop(true,true);
				
				

				var l1 = 375;
				vC.find('.cl1').css('left', 1050);
				vC.find('.cl1').stop(true,true);
				vC.find('.cl1').animate({left:l1},1600);
				
				var l2 = 230;
				vC.find('.cl2').css('right', -350);
				vC.find('.cl2').stop(true,true);
				vC.find('.cl2').oneTime(400, function(){
					vC.find('.cl2').animate({right:l2},1200);
				});
				

				var l3 = 20;
				vC.find('.cl3').css('right', -350);
				vC.find('.cl3').stop(true,true);
				vC.find('.cl3').oneTime(800, function(){
					vC.find('.cl3').animate({right:l3},800);
				});
				vC.show();
				
				vC.find('.vis'+rel+'i').stop(true,true);
				var l4 = parseInt(vC.find('.vis'+rel+'i').css('right'),10);
				vC.find('.vis'+rel+'i').css('right', -300);
				vC.find('.vis'+rel+'i').show();
				vC.find('.vis'+rel+'i').oneTime(1000, function(){
					vC.find('.vis'+rel+'i').stop(true,true);
					vC.find('.vis'+rel+'i').animate({right:l4},600);
				});
				
				vC.find('.vis'+rel+'img').stop(true,true);
				var l5 = parseInt(vC.find('.vis'+rel+'img').css('right'),10);
				vC.find('.vis'+rel+'img').css('right', -300);
				vC.find('.vis'+rel+'img').show();
				vC.find('.vis'+rel+'img').stop(true,true);
				vC.find('.vis'+rel+'img').oneTime(1000, function(){
					vC.find('.vis'+rel+'img').stop(true,true);
					vC.find('.vis'+rel+'img').animate({right:l5},600);
				});
			});
		}
	}
	
	function hidePrev(lastRel){
		//$('.cl1').stop(true,true);
		//$('.cl2').stop(true,true);
		//$('.cl3').stop(true,true);
		//$('vis1img').stop(true,true);
		//$('vis2img').stop(true,true);
		//$('vis3img').stop(true,true);
		//$('vis1i').stop(true,true);
		//$('vis2i').stop(true,true);
		//$('vis3i').stop(true,true);
		stopTimeAll();
		
		var vC = $('.visual-container[rel='+lastRel+']');

		
		var l1 = -375;
		vC.find('.cl1').css('left', l1);
		vC.find('.cl1').stop(true,true);
		vC.find('.cl1').animate({left:-350},2200);
		
		
		var l2 = 230;
		vC.find('.cl2').css('right', l2);
		vC.find('.cl2').stop(true,true);
		vC.find('.cl2').oneTime(0, function(){
			vC.find('.cl2').animate({right:1350},1800);
		});
		

		var l3 = 20;
		vC.find('.cl3').css('right', l3);
		vC.find('.cl3').stop(true,true);
		vC.find('.cl3').oneTime(0, function(){
			vC.find('.cl3').animate({right:1350},1200);
		});
		vC.find('.vis'+lastRel+'i').stop(true,true);
		var l4 = parseInt(vC.find('.vis'+lastRel+'i').css('right'),10);
		vC.find('.vis'+lastRel+'i').css('right',l4);
		vC.find('.vis'+lastRel+'i').oneTime(0, function(){
			vC.find('.vis'+lastRel+'i').animate({right:1150},600, function(){
				vC.find('.vis'+lastRel+'i').hide();
				vC.find('.vis'+lastRel+'i').css('right',l4);
			});
		});
		
		vC.find('.vis'+lastRel+'img').stop(true,true);
		var l5 = parseInt(vC.find('.vis'+lastRel+'img').css('right'),10);
		vC.find('.vis'+lastRel+'img').css('right', l5);
		vC.find('.vis'+lastRel+'img').oneTime(0, function(){
			vC.find('.vis'+lastRel+'img').animate({right:1350},800, function(){
				vC.find('.vis'+lastRel+'img').hide();
				vC.find('.vis'+lastRel+'img').css('right', l5);
			});
		});
	}
	
}); // end ready

if (window.addEventListener)
window.addEventListener("load", createcssmenu, false)
else if (window.attachEvent)
window.attachEvent("onload", createcssmenu)

var ShowReaktiveFlag = false;

function ShowReaktiveStart(){ ShowReaktiveFlag = true; setTimeout("ShowReaktive()",50); }
function ShowReaktive(){
	if ((ShowReaktiveFlag) && ($("#reaktive_block").css('display')=='none')){
		$("#reaktive_block").css({display: "block"});
		$("#reaktive_block IMG").css({width: 0, height: 0, left: 205, top: 0});
		$("#reaktive_block IMG").animate({width: 274, height: 131, left:0, top: -110}, 300);
	}
}

function HideReaktiveStart(){ ShowReaktiveFlag = false; setTimeout("HideReaktive()",50); }
function HideReaktive(){
	if ((!ShowReaktiveFlag) && ($("#reaktive_block").css('display')!='none')){
		if ($.browser.msie) $("#reaktive_block").css('display','none');
		else $("#reaktive_block").fadeOut(300);
	}
}

function dinamicMenu(){
	$('.dinmenu').hover(function(){
		var ob = $(this);
		
			$('.sub, .sub2, .sub3').clearQueue();
			$('.sub:animated, .sub2:animated, .sub3:animated').css({
				display: 'none',
				width: 'auto'
			});
			
			
			$('.dinmenu').removeClass('active withsub').children('.sub').css('display', 'none');
		if (ob.children('.sub, .sub2, .sub3').children('.cs').children('.gradient').children('ul.glossymenu').length > 0) {	
			ob.addClass('active withsub');
			var width = ob.children('.sub, .sub2, .sub3').eq(0).width();
			if (!ie) {
				ob.children('.sub, .sub2, .sub3').css({
					//width: '0px',
					display: 'block',
					opacity: 0
				}).animate({
					//width: width + 'px',
					opacity: 1
				}, 150); //.width('auto');
			} else {
				ob.children('.sub, .sub2, .sub3').show();
			}
		}
		
	}, function(){
			$(this).find('.sub, .sub2, .sub3').hide();
			$(this).removeClass('active');	
			$(this).removeClass('withsub');
	});
}

var menuids=new Array('verticalmenu105', 'verticalmenu109') //Enter id(s) of UL menus, separated by commas
var submenuoffset=0 //Offset of submenus from main menu. Default is -2 pixels.

function createcssmenu(){
for (var i=0; i<menuids.length; i++){
  var ultags=document.getElementById(menuids[i]).getElementsByTagName("ul")
    for (var t=0; t<ultags.length; t++){
		var spanref=document.createElement("span")
			spanref.className="arrowdiv"
			spanref.innerHTML=""
			ultags[t].parentNode.getElementsByTagName("a")[0].appendChild(spanref)
		ultags[t].parentNode.onmouseover=function(){
			//$(ultags[t].parentNode).parent().display('none');
			this.className += " subActive ";

			//alert(submenuoffset);
			if($(this).parent().parent().parent().find('img').length){
				this.getElementsByTagName("ul")[0].style.left=this.parentNode.offsetWidth-86+"px";/*submenuoffset*/
			}else{
				this.getElementsByTagName("ul")[0].style.left=this.parentNode.offsetWidth+"px";/*submenuoffset*/
			}
			this.getElementsByTagName("ul")[0].style.display="block"
		}
		ultags[t].parentNode.onmouseout=function(){
			this.getElementsByTagName("ul")[0].style.display="none"
			$(this).removeClass('subActive');
		}
    }
  }
}

/* ИЕ6 */
$(document).ready(function(){
	if($.browser.msie && $.browser.version.substr(0,1)<7){
		showIe6Alert();
	}
});

function showIe6Alert(){
	$('body').append('<div id="dark2"></div>');
	$('body').append('<div class="popupIE6"><div class="pad"><h2>Внимание! Вы используйте устаревший браузер Internet&nbsp;Explorer&nbsp;6</h2><p>Данный сайт построен на передовых, современных технологиях и не поддерживает Internet Explorer 6-ой версии.</p> <p>Настоятельно Вам рекомендуем выбрать и установить любой из современных браузеров. Это бесплатно и займет всего несколько минут.</p><ul><li><a href="http://www.microsoft.com/windows/Internet-explorer/default.aspx">Internet Explorer</a></li><li><a href="http://www.opera.com/download/">Opera Browser</a></li><li><a href="http://www.mozilla.com/firefox/">Mozilla Firefox</a></li><li><a href="http://www.google.com/chrome">Google Chrome</a></li></ul></div><div class="close"><img src="/pics/i/close.gif" alt="Закрыть" /></div></div>');
	$('#dark2').show();
	$('#dark2').click(function(){
		$('.popupIE6').hide();
		$('#dark2').hide();
	});
	$('.popupIE6 .close').click(function(){
		$('.popupIE6').hide();
		$('#dark2').hide();
	});
}

/* swf */
$(document).ready(function(){
	var flashvars = {};
	var params = {wmode: "opaque", bgcolor: "#FFF", scale:"noscale"};
	var attributes = {};
	swfobject.embedSWF("/swf/1000.swf", "b1", "210px", "50px", "9.0.0" ,"/swf/expressInstall.swf", flashvars, params, attributes);
});

$(document).ready(function(){
	var flashvars = {};
	var params = {wmode: "opaque", bgcolor: "#FFF", scale:"noscale"};
	var attributes = {};
	swfobject.embedSWF("/swf/pr1.swf", "b3", "227px", "123px", "9.0.0" ,"/swf/expressInstall.swf", flashvars, params, attributes);
});

$(document).ready(function(){
	var flashvars = {};
	var params = {wmode: "opaque", bgcolor: "#FFF", scale:"noscale"};
	var attributes = {};
	swfobject.embedSWF("/swf/city.swf", "b2", "210px", "50px", "9.0.0" ,"/swf/expressInstall.swf", flashvars, params, attributes);
});
