function TNCom_getDocumentSize(val)
{	
	var xScroll,yScroll,value;	
	if(window.innerHeight&&window.scrollMaxY)
	{
		xScroll=window.innerWidth+window.scrollMaxX;
		yScroll=window.innerHeight+window.scrollMaxY;
	}
	else if(document.body.scrollHeight>document.body.offsetHeight)
	{
		xScroll=document.body.scrollWidth;
		yScroll=document.body.scrollHeight;
	}
	else{
		xScroll=document.body.offsetWidth;
		yScroll=document.body.offsetHeight;
	}
	
	var windowWidth,windowHeight;
	
	if(self.innerHeight)
	{
		if(document.documentElement.clientWidth){
			windowWidth=document.documentElement.clientWidth;
		}
		else{
			windowWidth=self.innerWidth;
		}
		windowHeight=self.innerHeight;
	}
	else if(document.documentElement&&document.documentElement.clientHeight)
	{
		windowWidth=document.documentElement.clientWidth;
		windowHeight=document.documentElement.clientHeight;
	}
	else if(document.body)
	{
		windowWidth=document.body.clientWidth;		
		windowHeight=document.body.clientHeight;
	}
	
	if(yScroll<windowHeight){
		pageHeight=windowHeight;
	}
	else{
		pageHeight=yScroll
	}
	
	if(xScroll<windowWidth){
		pageWidth=xScroll
	}
	else{
		pageWidth=windowWidth
	}
	
	arrayPageSize=new Array(pageWidth,pageHeight,windowWidth,windowHeight)	
	return arrayPageSize[val]
}// end function

function TNActiveTab(obj, num){		
		var curentTab=obj.id;
		var curentContent=curentTab.replace("tab","cont");

		curentContent_1=curentTab.replace("tab","cont");		
		var tabs=$('#' + curentTab).parent().children();
		var contents=$('#' + curentContent).parent().children();

		$(tabs).each( function(){								
				$(this).attr('class','');
		});		
		
		$(contents).each( function(){								
				$(this).hide();
		});	
		
		$('#' + curentTab).addClass('act');
		$('#' + curentContent).fadeIn('slow');	
}//end function

var g_obj;
var g_tout;
(function($) {
	$.fn.TNActiveMenu = function() 
	{	
		var intDis=$(this).offset().left-$("#div_down").offset().left+$(this).width()/2;
		//alert(intDis);
		var intsubw=itemW($(this).children(".submenu"));
		var intmargin=Math.round(intDis - intsubw/2);
		if((intmargin+intsubw)>977) intmargin=977-intsubw-5;
		if(intmargin<0) intmargin=5;
		$(this).children(".submenu").css("padding-left",intmargin);
		$(this).children(".submenu").width(977);
		if($(this).hasClass("active")){
			$(this).addClass("li_act");
		}
		$(this).mouseover(function(){
			$(g_obj,".menu_main .active").removeClass("li_act");
			clearTimeout(g_tout);
			$(this).addClass("li_act");
		});
		$(this).mouseout(function(){
			g_obj=this;
			clearTimeout(g_tout);
			g_tout=setTimeout(function(){
				$(g_obj).removeClass("li_act");
				$(".menu_main .active").addClass("li_act");
			},800);
		});
		function itemW(objitem){
			var w=0;
			var ratio=12;
			$(objitem).children('li').each(function(index){
				w+=0+$(this).text().length*ratio;
			})
			return Math.round(w);
		}
	};
})(jQuery);
$('.menu_main .item').each(function(){
     $(this).TNActiveMenu();
 });

