﻿/* Menu
======================================= */
$q(function menu()
{
	var last=null;
	var showed=false;
	var time=null;
	var time2=null;
	var self;
	
	var timeHide=function()
	{
		time2=null;
		
		if(!self) return;
		
		$q(self).removeClass("hover");
		$q(self).removeAttr("id");
		self=null;
		
		$q("#header .podmenu").animate({height: "hide", opacity: "hide"}, "fast", function()
		{
			if(this.parentNode.className != 'main_menu selected')
			return;
			
			if(last)
			{
				$q(last).children("div.podmenu").css({opacity:'',width:'',height:'',display:'',overflow:''});
				$q(last).removeClass("selected");
				$q(last).children("div.podmenu").children('table').css({visibility:''});
				$q("#header ul li td div").css({display:''});
				
				if(prev_a)
				$q(prev_a).removeClass("selected");
				
				prev_a=null;
			}
				
			last=null;
			showed=false;
			$q(".menushadow").hide();
			//$q(".menushadow").animate({opacity: "hide"}, "fast");
		});
	}
	
	$q("#header ul").bind('mouseleave', function (event)
	{
		$q("#header .podmenu").stop();
		
		if(time)
		clearTimeout(time);
		
		if(time2)
		return;
		
		if(!showed)
		{
			if(self)
			{
				$q(self).removeClass("selected");
			}
			$q(".menushadow").hide();
			$q(this).removeClass("hover");
			$q(this).removeAttr("id");
			$q("#header .podmenu").animate({height: "hide", opacity: "hide"});
			self=null;
			last=null;
			return;
		}
		
		self=this;
		
		time2=setTimeout(timeHide,200);
	});
	
	
	var timeShow=function()
	{
		$q(".menushadow").show();
		$q(self).children("div.podmenu").find('span.banner').css({display:''});
		$q(self).children("div.podmenu").animate({height: "show", opacity: "show"}, "fast", function()
		{
			last=self;
			showed=true;
		});

	}
	$q("#header li.main_menu").bind('mouseenter', function (event)
	{
		if(time2)
		{
			clearTimeout(time2);
			time2=null;
		}
		
		if(time)
		clearTimeout(time);
		
		if($q(this).parent().attr("id") == "navigation" && this==last)
		return;
		
		$q(this).parent().attr({id: "navigation"});
		
		$q("#header .podmenu").stop();
		$q(this).children("div.podmenu").css({width:'',height:'',display:'',overflow:'',opacity:''},true);
		
		$q(this).addClass("selected");
		$q("#header ul").addClass("hover");
		
		if(last)
		{
			//console.log(1);
			if(this==last)
			{
				$q(this).children("div.podmenu").children('table').css({opacity:'',width:'',height:'',display:'',overflow:''});
				$q(this).children("div.podmenu").css({display:'block',overflow:'',width:'',height:'',opacity:''});
				//console.log([this,1]);
				return;
			}
			
			
			$q(last).removeClass("selected");
			$q(last).children("div.podmenu").css({opacity:'',width:'',height:'',display:'',overflow:''});
			$q(last).children("div.podmenu").children('table').css({visibility:''});
		
			$q(this).children("div.podmenu").find('td div').css({display:''});
			$q(this).children("div.podmenu").children('table').css({visibility:'hidden'});
			//баннер показать
			$q(this).children("div.podmenu").find('span.banner').css({display:''});
			
			if(prev_a)
			$q(prev_a).removeClass("selected");
			
			prev_a=null;
			
			last=this;
			
			$q(this).children("div.podmenu").animate({width: "show"}, "fast", function()
			{
				$q(this).children("table").css({visibility:''});
			});
			
			return;
		}
		
		if(self)
		{
			$q(self).removeClass("selected");
			$q(self).children("div.podmenu").css({opacity:'',width:'',height:'',display:'',overflow:''});
			$q(self).children("div.podmenu").children('table').css({visibility:''});
		}
		
		self=this;
		
		time = setTimeout(timeShow,50);
	});
	
	/*$q("#header li a.attention").bind('click', function (event)
	{
console.log(-1);
		$q("#header .podmenu").animate({height: "hide", opacity: "hide"}, "fast");
				
		$q(".attention_block").fadeIn("fast");

		if(!$q.browser.msie || $q.browser.version > 6)
		{
			if ($q.browser.msie && $q.browser.version >= 7)
			$q(".menushadow").show();
			else
			$q(".menushadow").fadeIn("fast");
		}

	});*/
	var prev_a;
	$q("#header li td a").bind('click', function (event)
	{
		$q(this).parents().find('div.podmenu td div.menu_3').css({display:''});
		
		if(prev_a)
		{
			$q(prev_a).removeClass("selected");
			
			if(prev_a==this)
			{
				$q(this).parents().find('div.podmenu span.banner').css({display:''});
				event.preventDefault();
				prev_a=null;
				return;
			}
		}
		
		if(!$q(this).next().length)
		{
			$q(this).parents().find('div.podmenu span.banner').css({display:''});
			prev_a=null;
			return;
		}
		
		event.preventDefault();
		
		if(prev_a)
		$q(this).next().show();
		else
		$q(this).next().fadeIn("fast");
		
		$q(this).addClass("selected");
		$q(this).parents().find('div.podmenu span.banner').css({display:'none'});
		
		prev_a=this;
		
		if ( $q.browser.msie )
		{
			if( $q.browser.version < 7 )
			{
				$q(this).next().css({ visibility:"visible" });
			}
		}
		
		event.stopPropagation();
	});
	
	
	
	
	
	//
		
	$q("#header ul li.main_menu a.podmenu_a").bind('click', function (event)
	{
		event.preventDefault();
		event.stopPropagation();
		return;
		
		if( $q(this).parent().attr("id") != "navigation" )
		return;
		
		var endwidth	= $q(this).children(".podmenu").width();
		var startwidth	= $q(".selected").children(".podmenu").width();
		
		$q(this).children(".podmenu").width(startwidth);

		$q("#header ul li.main_menu").removeClass("selected");
		$q("#header .podmenu").hide();
		$q("#header ul li td div").css({display:''});
		
		if ( $q.browser.msie )
		{
			if( $q.browser.version < 7 )
			{
				$q("#header ul li td div").css({ visibility:"hidden" });
			}
		}
		
		$q(this).addClass("selected");

		$q(this).children(".podmenu").animate({ width: endwidth + "px", display: "block" }, 200 );
	});
})

/* Calc
======================================= */
$q(function menu()
{
	$q("#button").bind('click', function (event) {
		event.preventDefault();
		$q(".calc_result").show();
		event.stopPropagation();
	});
	
/*
	$q(".graphic").bind('click', function (event) {
		event.preventDefault();
		if ( ($q.browser.msie) && ($q.browser.version < 7) ) {
			$q(".hiddenshadow").show();
		} else {
			$q(".hiddenshadow").fadeIn("fast");
		}
		$q(".baloon").slideDown("slow");
		
		if ( $q.browser.msie ) {
			if( $q.browser.version < 7 ) {
				$q(".content select").hide();
			}
		}
		event.stopPropagation();
	});
*/		
	
	$q(".hiddenshadow").bind('click', function (event) {
		event.preventDefault();
		/*if ( ($q.browser.msie) && ($q.browser.version < 7) ) {
			$q(".hiddenshadow").hide();
		} else {
			$q(".hiddenshadow").fadeOut("fast");
		}*/
		$q(".baloon").fadeOut("fast");
		if ( $q.browser.msie ) {
			if( $q.browser.version < 7 ) {
				$q(".content select").show();
			}
		}
		event.stopPropagation();
	});
});


/* Main
======================================= */
(function()
{
	if(!$q(".main_title div").length)
	return $q('main_png_view').css({display:'block'});
	
	$q(".main_title div").animate({opacity: "show"}, "slow", function()
	{
		//fix animate hover ie 6-7
		//только нельзя вообще где-либо упоминать позицию тэга с бакграундом
		$q(this).find('span').css({position:''});
	});
	
}).attach('load');

$q(function main_title()
{
	$q(".main_title div a.main_title_a").bind('click', function(ev)
	{
		ev.stopPropagation();
		ev.preventDefault();
		$q(".center_shadow").css({zIndex:100});
		$q(".center_shadow").animate({opacity: "show"}, "fast",function(){$q("#open_banner").css({display:''});});
	});
	
	$q("#open_banner input").bind('click', window.banner_hide=function()
	{
		$q("#open_banner").css({display:'none'});
		
		if ($q.browser.msie)// && $q.browser.version < 7 )
		{
			$q("#op_ban")[0].innerHTML='';
			op_ban.write("op_ban");
		}
		
		$q(".center_shadow").css({zIndex:''});
		
		if ( $q.browser.msie )
		$q(".center_shadow").hide();
		else
		$q(".center_shadow").fadeOut("fast");
	})
})

/* ie hide select onload
======================================= */
$q(function ieselect() {
	 if ($q.browser.msie ) {
		if( $q.browser.version < 7 ) {
			if( $q(".shadow").css("display") != "none" ) {
				$q(".content select").hide();
			}
		}
	}
})


$q(function showpodmenu() {
	$q("#fondpodmenu").bind('mouseenter', function (event) {
		$q(".fond_podmenu").show();
	});
	$q(".fond_podmenu").bind('mouseleave', function (event) {
		$q(".fond_podmenu").hide();
	});
})




function fondswitch(container, b_open) {

	$(container).style.height = (b_open == '1' ? '410px' : '230px');
	$("flash_" + container).style.height = (b_open == '1' ? '410px' : '230px');
		
	//setTimeout(function() { $q("#" + container).css({zIndex : 1 }); $q("#flash_" + container).css({zIndex : 1 }); }, 1);	
}
