﻿var gogo = new Array(5);
gogo = [true, true, true, true, true];

$(document).ready(function(){
	resizing();
	window.setTimeout(function(){
		menu_enable();						   
		sifr_enable();							   
	}, 500)
	
	window.setTimeout(function(){
		$(window).resize(function(){
			resizing();
			$("div.flash_res").height( ($("div.flash_res").width() - 1)/koef );				
		});
	}, 2000);
	
	var koef = 600/400;
	$("div.flash_res").height( ($("div.flash_res").width() - 1)/koef );	
	
	noflash();	
	//letitsnow();
});


function menu_enable(){

	$("div.menu ul li p.blue").each(function(){
		$(this).after("<p class='white'>" + $(this).text() + "</p>");
	});
	$("div.menu ul li p.white").css("opacity", "0");	
	
	$("div.menu ul li").not("div.menu ul li ul li").bind("mouseover", function(){
		var num1 = num($(this));																			   
		if (gogo[num1]) {
			$(this).find("ul").css("left", ($(this).width()-180)/2).slideDown(250);
			$(this).find("p.white").css("opacity", "1");		
			$(this).find("p.blue").css("opacity", "0");
		}
	}).bind("mouseleave", function(){
		var num1 = num($(this));
		gogo[num1] = false;
		$(this).stop();			
		$(this).find("ul").slideUp(250, function(){gogo[num1] = true});
		$(this).find("p.blue").css("opacity", "1");		
		$(this).find("p.white").css("opacity", "0");
	});
	
	/*$("div.menu ul li a").not("div.menu ul li ul li a").each(function(){
		if ($(this).parents("li:first").find("ul").length) $(this).bind("click", function(){
			return false;
		});
	});*/
	
	$(window).resize(function(){
		$("div.menu ul li").not("div.menu ul li ul li").find("ul").css("left", ($(this).width()-180)/2);					  
	});
}

function num(el){
	var href_now = el.find(">a").attr("href");
	
	var a_all = $("div.menu ul li").not("div.menu ul li ul li").find(">a");
	for (var i = 0; i < a_all.length; i++){
		if (a_all.eq(i).attr("href") == href_now) return i;
	}
	return false;
}


function sifr_enable(){
	if(typeof sIFR == "function"){
		
		menu_sifr();
		
		sIFR.replaceElement(named({
			sSelector:"h1, h2, h4",
			sFlashSrc:"img/swift.swf",
			sColor:"#FFFFFF",
			sLinkColor:"#FFFFFF",
			sBgColor:"#FFFFFF",
			sHoverColor:"#FFFFFF",
			nPaddingTop:0,
			nPaddingBottom:0,
			sWmode:"transparent",
			sFlashVars:"textalign=left&offsetTop=0"
		}));

	}
}

function resizing(){
	if ($(window).width() > 1200) {
		$("div.main").width(1200);
	}
	else $("div.main").css("width", "auto");
}

function menu_sifr(){
		sIFR.replaceElement(named({
			sSelector:"div.menu ul li p.blue",
			sFlashSrc:"img/swift.swf",
			sColor:"#00b9ff",
			sLinkColor:"#00b9ff",
			sBgColor:"#00b9ff",
			sHoverColor:"#00b9ff",
			nPaddingTop:0,
			nPaddingBottom:0,
			sWmode:"transparent",
			sFlashVars:"textalign=center&offsetTop=0"
		}));
		
		sIFR.replaceElement(named({
			sSelector:"div.menu ul li p.white",
			sFlashSrc:"img/swift.swf",
			sColor:"#ffffff",
			sLinkColor:"#ffffff",
			sBgColor:"#ffffff",
			sHoverColor:"#ffffff",
			nPaddingTop:0,
			nPaddingBottom:0,
			sWmode:"transparent",
			sFlashVars:"textalign=center&offsetTop=0"
		}));	
}


function callei() {
	thisMovie("map").print_map();
}

function thisMovie(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) return window[movieName]; else return document[movieName]
}

function li() {
document.write("<a href='http://www.liveinternet.ru/click' "+
"target=_blank><img style='visibility:hidden;' src='//counter.yadro.ru/hit?t11.6;r"+
escape(document.referrer)+((typeof(screen)=="undefined")?"":
";s"+screen.width+"*"+screen.height+"*"+(screen.colorDepth?
screen.colorDepth:screen.pixelDepth))+";u"+escape(document.URL)+
";"+Math.random()+
"' alt='' title='LiveInternet: показано число просмотров за 24"+
" часа, посетителей за 24 часа и за сегодня' "+
"border='0' width='88' height='31'><\/a>");
}

function flashVersion() {
      var ua = navigator.userAgent.toLowerCase();
      var isIE = (ua.indexOf("msie") != -1 && ua.indexOf("opera") == -1 && ua.indexOf("webtv") == -1);
      var version = 0;
      var lastVersion = 11;
      var i;
      if (isIE) {
            try {
                  for (i = 3; i <= lastVersion; i++) {
                        if (eval('new ActiveXObject("ShockwaveFlash.ShockwaveFlash.'+i+'")')) {
                              version = i;
                        }
                  }
            } catch(e) {}
      } else {
            for (i = 0; i < navigator.plugins.length; i++) {
                  if (navigator.plugins[i].name.indexOf('Flash') > -1) {
                        version = (parseInt(navigator.plugins[i].description.charAt(16)) > version) ? parseInt(navigator.plugins[i].description.charAt(16)) : version;
                  }
            }
      }
      return version;
}

function noflash(){
	if (flashVersion() == 0){
		$("div.flash").children().remove().end().html("<img src='/img/mainpic_noflash.jpg' alt='' />");
		$("div.logo").children().remove().end().html("<a href='/'><img src='/img/logo.gif' alt='' /></a>");
		$("div.flash_res").children().remove().end().html("<p><img src='/img/nofla/censored.gif' style='margin-top: -11px;'></img></p>");
	}
	else return false;
}
function letitsnow() {
	var snow_intensive=500;
	var snow_speed=5000;
	var ww = 1120; // w - 80
	var wh = 210;
	var count = 20;
	var wplase = [];
	for(var i=0;i<1200;i++){
		wplase[i]=0;
	}
	setInterval(function() {
		var x = Math.floor(Math.random()*ww);
		var w = Math.floor(Math.random()*4)+3;
		var snow = "<div class='letitsnow' style='position:absolute; width:"+w+"px; height:"+w+"px; background-color:#eef;top:0;left:"+x+"px'/>";
		var new_x = (Math.floor(Math.random()*80))+x;
		$(snow).insertBefore("div.logo").animate({top:wh-wplase[new_x]-w,left:new_x},snow_speed-w*100,function(){
			$(this).css({
				"border-bottom-right-radius": "0px",
				"border-bottom-left-radius": "0px",
				"z-index": "900",
			});
			if(wplase[new_x]<2){
				$(this).css({
					"height":w/2,
					"top":wh-wplase[new_x]-w/2
				});
			}

			$(this).bind("mouseover",function(){
				$(this).remove();
			})
			wplase[new_x]++;
			wplase[new_x+1]++;
			wplase[new_x+2]++;
		});


},snow_intensive);
}

