	var firstSelectedCss = "firstTitle";
	var secondSelectedCss = "secondTitle";
	var thirdSelectedCss = "threeTitle";
  var menuSelectedCss = "menuSelectCss";

$(document).ready(function() {
	//$("#sideBar").ready(function() {
		
		$("#sideBar>ul>li>ul").hide(); //隐藏一级频道
		$("#sideBar>ul>li>ul>li>ul").hide();//隐藏二级频道
        $("#"+firstChannelID).addClass(menuSelectedCss);
		//$("#"+redName).addClass(menuSelectedCss);
		Select(currentID);
		RemoveUlWhenNotLi();
		NotExpand();
		ModifyProCategory()
	});

	function Select(index)
	{
		if(!isInteger(index))
		{
			$("#sideBar>ul>li>ul").hide();			//隐藏一级频道
			$("#sideBar>ul>li>ul>li>ul").hide();	//隐藏二级频道
			var channelArray = new Array();
			channelArray = index.split(',');
			for(i=0;i<channelArray.length;i++)
			{
				var currentLi = $("#tab_"+channelArray[i]);
				if($("#tab_"+channelArray[i]).children(".subNav").html() != null)//表示选中一级频道
				{
					currentLi.addClass(firstSelectedCss);
				}
				if($("#tab_"+channelArray[i]).parent(".subNav").html() != null)//表示选中二级频道
				{
					currentLi.parents(".treeNavTitle").addClass(firstSelectedCss); //设置一级导航样式
					currentLi.addClass(secondSelectedCss); //设置二级导航样式
				}
				
				if($("#tab_"+channelArray[i]).children("ul").html() == null)//表示选中三级频道
				{
					currentLi.parents(".treeNavTitle").addClass(firstSelectedCss); //设置一级导航样式
					currentLi.parent().parent("li").addClass(secondSelectedCss); //设置二级导航样式
					currentLi.addClass(thirdSelectedCss);  //设置三级导航样式
				}
				currentLi.children("ul").show();	//显示子频道
				currentLi.parents(".subNav").show();//显示父的顶级频道
				currentLi.parent("ul").show();//显示父二级频道
				new loadIframe();//开始载入iframe
			}
		}
		else
		{
			var currentLi = $("#tab_"+index);
			
			if($("#tab_"+index).children(".subNav").html() != null)//表示选中一级频道
			{
				currentLi.addClass(firstSelectedCss);
			}
			
			if($("#tab_"+index).parent(".subNav").html() != null)//表示选中二级频道
			{
				currentLi.parents(".treeNavTitle").addClass(firstSelectedCss); //设置一级导航样式
				currentLi.addClass(secondSelectedCss); //设置二级导航样式
			}
			if($("#tab_"+index).children("ul").html() == null)//表示选中三级频道
			{
				currentLi.parents(".treeNavTitle").addClass(firstSelectedCss); //设置一级导航样式
				currentLi.parent().parent("li").addClass(secondSelectedCss); //设置二级导航样式
				currentLi.addClass(thirdSelectedCss);  //设置三级导航样式
			}
			
			$("#sideBar>ul>li>ul").hide();			//隐藏一级频道
			$("#sideBar>ul>li>ul>li>ul").hide();	//隐藏二级频道
			currentLi.children("ul").show();	//显示子频道
			currentLi.parents(".subNav").show();//显示父的顶级频道
			currentLi.parent("ul").show();//显示父二级频道
			
			new loadIframe();//开始载入iframe
		}
	}		

	iframeUrl = {};
	function loadIframe() {
		if(iframeUrl.url1 != null) {
			if(iframeUrl.url1[0].type == "1")
			{
				$('#' +iframeUrl.url1[0].id).html('<iframe src="' + iframeUrl.url1[0].url + '" align="MIDDLE" width="' + iframeUrl.url1[0].width + '" height="' + iframeUrl.url1[0].height + '" marginwidth="0" marginheight="0" frameborder="0" scrolling="No"></iframe>');
			}
			else if(iframeUrl.url1[0].type == "2") 
			{
				 $('#' +iframeUrl.url1[0].id).html(iframeUrl.url1[0].url);
			}
		}
		if(iframeUrl.url2 != null) {
			if(iframeUrl.url2[0].type == "1")
			{
				$('#' +iframeUrl.url2[0].id).html('<iframe src="' + iframeUrl.url2[0].url + '" align="MIDDLE" width="' + iframeUrl.url2[0].width + '" height="' + iframeUrl.url2[0].height + '" marginwidth="0" marginheight="0" frameborder="0" scrolling="No"></iframe>');
			}
			else if(iframeUrl.url2[0].type == "2") 
			{
				 $('#' +iframeUrl.url2[0].id).html(iframeUrl.url2[0].url);
			}
		}
		if(iframeUrl.url3 != null) {
			if(iframeUrl.url13[0].type == "1")
			{
				$('#' +iframeUrl.url3[0].id).html('<iframe src="' + iframeUrl.url3[0].url + '" align="MIDDLE" width="' + iframeUrl.url3[0].width + '" height="' + iframeUrl.url3[0].height + '" marginwidth="0" marginheight="0" frameborder="0" scrolling="No"></iframe>');
			}
			else if(iframeUrl.url3[0].type == "2") 
			{
				 $('#' +iframeUrl.url3[0].id).html(iframeUrl.url3[0].url);
			}
		}
	}
	/*
function showIframe(_id,_width,_height,_url,_type) {
		iframeUrl = {
			"url1" :[{
				"id" :  _id,
				"width" : _width,
				"height" : _height,
				"url" : _url,
				"type" : _type
			}]
			
		}
	}
*/

	//当二级频道下不存在Li时，删除下面的UL
	function RemoveUlWhenNotLi()
	{
		var ul = $("#sideBar>ul>li>ul>li>ul");
		for( var i = 0;i<ul.length;i++)
		{
			if($(ul[i]).children("li").html() == null)
			{
				$(ul[i]).remove();
			}
		}
	}
	
	function NotExpand()
	{
		if(typeof(notExpandSecondChannelIDs) != 'undefined')
		{
			for(var i = 0;i<notExpandSecondChannelIDs.length;i++)
			{
				var crl = $("#tab_"+notExpandSecondChannelIDs[i]+">ul");
				if(crl.html())
				{
					$(crl).hide();
				}
			}
		}
	}
	function isInteger( str )
	{
		var regu = /^[-]{0,1}[0-9]{1,}$/;
		return regu.test(str);
	}
