

$(document).ready(function () {

	// SHOW_POPUP_IMG
	$('a.show_popup').click(function(){
		var galery_set = new Array();
		galery_set[0]={'caption':$(this).find('img').attr('alt'), 'url':$(this).attr('href')}
		GB_showImageSet(galery_set, 1);
		return false;
	});
	
	
	$('a.highslide').click(function(){return hs.expand(this);});
	
	/*$(function() {
		$("div#news_line").jCarouselLite({
			vertical: true,
			hoverPause:false,
			visible: 1,		
			scroll: 1,		
			auto:1,
			speed:12000,
			divHeight:370,
			easing:'linear'
		});
	});*/
	$("div#news_line").css('display', 'block');

	
	

	
	var imgs = $('ul.catalog_tree li img').get();
	if(imgs!=null && imgs.length>0)
	{
		//alert(imgs.length);
		for(var i=0; i < imgs.length; i++)
		{
			if(getCookie($(imgs[i]).attr('id'))!=null)
			{
				showhide_tree(imgs[i],1);
			}
		}
	}
	
	$('ul.catalog_tree li img').click(function()
	{
		showhide_tree(this);
		return false;
	});
});




function showhide_tree(obj, nohide)
{
	if(nohide==null) nohide = 0;
	if($(obj).parent().attr('class')=='child_none' || $(obj).parent().attr('class')=='lev1_childs_none') return false;
	
	if($(obj).parent().attr('class')=='child' || $(obj).parent().attr('class')=='child_act')
	{
		if($(obj).parent().find('ul:first').attr('class')=='childs') 
		{			
			$(obj).parent().find('ul:first').attr('class', 'childs_act');
			$(obj).parent().attr('class', 'child_act');
			setCookie($(obj).attr('id'), 1);
		}
		else
		{
			if(nohide==0)
			{
				$(obj).parent().find('ul:first').attr('class', 'childs');
				$(obj).parent().attr('class', 'child');
				deleteCookie($(obj).attr('id'));
			}
		}
	}
	else
	{
		if($(obj).parent().find('ul:first').attr('class')=='childs') 
		{			
			$(obj).parent().find('ul:first').attr('class', 'childs_act');
			$(obj).parent().attr('class', 'lev1_childs_act');
			setCookie($(obj).attr('id'), 1);
		}
		else
		{		
			if(nohide==0)
			{
				$(obj).parent().find('ul:first').attr('class', 'childs');
				$(obj).parent().attr('class', 'lev1_childs');
				deleteCookie($(obj).attr('id'));
			}
		}
	}

}













function is_numeric(str)
{
	for(var i=0; i<str.length; i++)
	{
		flag=false;
		var ss = str.substr(i,1);
		//alert(ss);
		for(var num=0; num<10; num++)
		{
			//alert(parseInt(ss)!=num);
			if(isNaN(parseInt(ss))) return false;
			if(parseInt(ss)==num) flag = true;
		}
		if(!flag) return false;
	}
	return true;
}


function setCookie (name, value, expires, path, domain, secure) 
{
      document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "; path=/") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function getCookie(name) 
{
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	return(setStr);
}

function deleteCookie(name, path, domain) {
	document.cookie = name + "=" +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	"; expires=Thu, 01-Jan-70 00:00:01 GMT";
};



function ajax_loader()
{
	//alert('ddd');
	if($('div#ajax_loader').attr('id')==null)
	{
		$('body').append('<div id="ajax_loader" style="display:none"></div>');
	}
	if($('div#ajax_loader').css('display')!='none')
	$('div#ajax_loader').hide(300);	
	else	
	$('div#ajax_loader').show(300);	
}

function migalka(obj)
{
	if($('div#ajax_loader').css('display')!='none')
	{
		$(obj).attr('disabled', 'true');
		$(obj).fadeOut(350, function (){
			$(this).fadeIn(350, function (){
				migalka(this);
				})
			});
	}
	else
	$(obj).attr('disabled', '');
}

function getElementPosition(elemId)
{
    var elem = document.getElementById(elemId);
    
    var w = elem.offsetWidth;
    var h = elem.offsetHeight;
    
    var l = 0;
    var t = 0;
    
    while (elem)
    {
        l += elem.offsetLeft;
        t += elem.offsetTop;
        elem = elem.offsetParent;
    }	
    return {"left":l, "top":t, "width": w, "height":h};
}
function getElementPosition(obj)
{
    var elem = obj;
    
    var w = elem.offsetWidth;
    var h = elem.offsetHeight;
    
    var l = 0;
    var t = 0;
    
    while (elem)
    {
        l += elem.offsetLeft;
        t += elem.offsetTop;
        elem = elem.offsetParent;
    }	
    return {"left":l, "top":t, "width": w, "height":h};
}


function init_menu() 
{
	var dd_menu_offsetL=-1;
	var dd_menu_offsetT=39;
	var dd_menu_opacity='0.93';

	//$("ul.subnav").parent().append("<span></span>"); 
	$("div.nav ul").css('display','none');
	$("div.nav a.bt, a.bt1").mouseover( function() 
	{		
		pos=getElementPosition(this);
		vm=dd_menu_offsetT;
		var h=0;
		
		if($(this).attr('class')=='bt') $(this).attr('class', 'bt_act');
		if($(this).attr('class')=='bt1') $(this).attr('class', 'bt_act1');
		var width = 100;
		var a = $(this).parent().find("ul.subnav li a").get();
		for(var i=0; i<a.length; i++)
		{
			if($(a[i]).text().length*5>width) width = $(a[i]).text().length*5;
		}
		
		$(this).parent().find("ul.subnav").width(width);		
		$(this).parent().find("ul.subnav").css("left", dd_menu_offsetL+pos.left+'px');
		$(this).parent().find("ul.subnav").css("top", (pos.top+vm+h)+'px');
		$(this).parent().find("ul.subnav").css("opacity", dd_menu_opacity);
		
		if($(this).attr('rel')=='') {$(this).attr('rel', 1)};

		//if($(this).attr('rel')==1) 
		$(this).parent().find("ul.subnav").show('fast', function(){$(this).parent().find('a').attr('rel', 0)});		
		
		
		$(this).parent().hover(function(){	},function()
											{
												$(this).parent().find("ul.subnav").hide('slow', function(){
													$(this).parent().find('a').attr('rel', 1); 
													}); 

												$(this).parent().find('a.bt_act').attr('class', 'bt');
												$(this).parent().find('a.bt_act1').attr('class', 'bt1');

											});
	}
	).hover(function() {});
}

