$(document).ready(function(){				   
	//分类搜索
	showsearch();
	//展示地区列表
	if($("#areahtml").length>0){
		showarea(array_str);
	}	
	//展示年份列表
	if($("#yearhtml").length>0){
		showyear();
	}
	//展示自定义列表
	if($("#cschhtml").length>0){
		showcsch(array_csch);
	}
	//内容页同类热门影视
	if($("#hot_video").length>0){
		$("#hot_video").load($("#hot_video").attr('href'));	
	}
	//内容页同类热门新闻
	if($("#hot_info").length>0){
		$("#hot_info").load($("#hot_info").attr('href'));	
	}
	
	//首页幻灯片控制
	if($("#next_to").length>0){
         $("#next_to").click(function() {
			stepcarousel.stepBy('slides', 1);
		    });
	}
	
	//收起展开列表 <span id="detail_hot"></span>
	$("#plMore").click(function(){	
		$html = $(this).html();
		if($html=='展开列表'){
			$(this).html('收起列表');
			$("#pmoreContain").attr('class','play-list-right-c');
			$("#all-plist").show();
		}else{
			$(this).html('展开列表');
			$("#pmoreContain").attr('class','play-list-right');	
			$("#all-plist").hide();
		}
	});	
});


function showsearch(){
	$('#sort').hide();
	$('#cur_txt').click(function(){
		$('#sort').show();
		$('#sort>li>a').click(function(){
			$html = $(this).html();
			$action = $('#search').attr('action');
			if($html=='新闻'){
				$('#cur_txt').html('新闻');
				$('#search').attr('action',$action.replace('video/','info/'));	
			}else{
				$('#cur_txt').html('视频');
				$('#search').attr('action',$action.replace('info/','video/'));
			}
			$('#sort').hide();
		});
	});
	$('#cur_txt').blur(function(){	
		$('#sort').hide();
	});
}

function showyear(){
	var $html='';
	var $year = $('#yearhtml').html()*1;
	if($("#areas").length>0){
	var $area= $('#areas').html().replace(/^\s+|\s+$/g,"");
	}else{
	var $area= '';	
	}
	if($year==0){
		$html +='<a href="'+SitePath+'index.php?s=video/lists/id/'+SiteCid+'/show/1/area/'+encodeURIComponent($area)+'/year/" class="Year">全部</a>|';
		}else{
		$html +='<a href="'+SitePath+'index.php?s=video/lists/id/'+SiteCid+'/show/1/area/'+encodeURIComponent($area)+'/year/">全部</a> |';
		}
	for(i=2011;i>1999;i--){
		if(i == $year){
			$html +='<a href="'+SitePath+'index.php?s=video/lists/id/'+SiteCid+'/show/1/area/'+encodeURIComponent($area)+'/year/'+i+'" class="Year">'+i+'</a>|';
		}else{
			$html +='<a href="'+SitePath+'index.php?s=video/lists/id/'+SiteCid+'/show/1/area/'+encodeURIComponent($area)+'/year/'+i+'">'+i+'</a>|';
		}
	}
	if($year == '20001990'){
	$html +='<a href="'+SitePath+'index.php?s=video/lists/id/'+SiteCid+'/show/1/year/20001990" class="Year">90年代</a>|';
	}else{
	$html +='<a href="'+SitePath+'index.php?s=video/lists/id/'+SiteCid+'/show/1/year/20001990">90年代</a>|';
	}
	if($year == '19901980'){
	$html +='<a href="'+SitePath+'index.php?s=video/lists/id/'+SiteCid+'/show/1/year/19901980" class="Year" >80年代</a>|';	
	}else{
	$html +='<a href="'+SitePath+'index.php?s=video/lists/id/'+SiteCid+'/show/1/year/19901980">80年代</a>|';
	}
	if($year == '1980'){
	$html +='<a href="'+SitePath+'index.php?s=video/lists/id/'+SiteCid+'/show/1/year/1980" class="Year" >更早>></a>';
	}else{
	$html +='<a href="'+SitePath+'index.php?s=video/lists/id/'+SiteCid+'/show/1/year/1980" class="links">更早>></a>';
	}
	$('#yearhtml').html($html);
}

function showarea(array_str){
	var $html='';
	var $years = $('#years').html()*1;
	var $area= $('#areahtml').html().replace(/^\s+|\s+$/g,"");
	for (var key in array_str){
		if($area == array_str[key]){
			$html +='<a href="'+SitePath+'index.php?s=video/lists/id/'+SiteCid+'/show/1/area/'+encodeURIComponent(array_str[key])+'/year/'+$years+'" class="Area" >'+array_str[key]+'</a>|';
		}else{
			$html +='<a href="'+SitePath+'index.php?s=video/lists/id/'+SiteCid+'/show/1/area/'+encodeURIComponent(array_str[key])+'/year/'+$years+'">'+array_str[key]+'</a>|';
		}
	}
	$('#areahtml').html($html);
}

function showcsch(array_csch){
	var $html='';
	var $years = $('#years').html()*1;
	if($("#areas").length>0){
	var $area= $('#areas').html().replace(/^\s+|\s+$/g,"");
	}else{
	var $area= '';
	}
	var $csch = $('#cschhtml').html().replace(/^\s+|\s+$/g,"");
	for (var key in array_csch){
		if($csch == array_csch[key]){
			$html +='<a href="'+SitePath+'index.php?s=video/lists/id/'+SiteCid+'/show/1/area/'+encodeURIComponent($area)+'/year/'+$years+'/wd/'+encodeURIComponent(array_csch[key])+'" class="Area" >'+array_csch[key]+'</a>';
		}else{
			$html +='<a href="'+SitePath+'index.php?s=video/lists/id/'+SiteCid+'/show/1/area/'+encodeURIComponent($area)+'/year/'+$years+'/wd/'+encodeURIComponent(array_csch[key])+'" >'+array_csch[key]+'</a>';
		}
	}
	$('#cschhtml').html($html);
	
}


function switchTab(a,b,c,d,e){
	try{
		for(i=0;i<c;i++){
		var f=document.getElementById("Tab_"+a+"_"+i),g=document.getElementById("List_"+a+"_"+i);
		if(i!=b){
			f.className=e;g.style.display="none"
			}
		}
	try{
		for(ind=0;ind<CachePic[a][b].length;ind++)
			document.getElementById(a+"_pic_"+b+"_"+ind).src=CachePic[a][b][ind]}
			catch(h){}
			document.getElementById("Tab_"+a+"_"+b).className=d;
			document.getElementById("List_"+a+"_"+b).style.display=""
			loadimg = ".Loadimg_"+a+"_"+b;
			lazyload({defObj: loadimg});
		}
	catch(j){}
//loadimg = "List_"+a+"_"+b;
//alert(loadimg);
//lazyload({defObj: loadimg});
}

function TabChange(DivKey,ID){for(var i=1;i<=3;i++){if(i==ID){$('#'+DivKey).addClass("hd hd"+ID);}else{$('#'+DivKey).removeClass("hd"+i);}}}

function SwapDiv(DivKey,ID){
    for(var i=1;i<=10;i++){
        $('#'+DivKey+'_S'+i).css("display","");
        $('#'+DivKey+'_B'+i).css("display","none");                       
        }
        $('#'+DivKey+'_S'+ID).css("display","none");            
        $('#'+DivKey+'_B'+ID).css("display","");
}



function move(obj,li1,li2){
	var la=document.getElementById(obj).getElementsByTagName("li");
	var lb=document.getElementById(obj+"_s").getElementsByTagName("dl");
	for (i=0;i<la.length ;i++ ){
		la[i].className=li1;//onMouseOver
		la[i].a=i;
		la[i].setAttribute("rr", i);
		lb[i].style.display="none";
		la[i].onmouseover=function(){
			for (j=0;j<la.length;j++ ){
				la[j].className=li1;
				lb[j].style.display="none";
			}
			this.className=li2;
			var k=this.getAttribute("rr");
			lb[k].style.display="";
		}
		lb[0].style.display="";
		la[0].className=li2;	
	}
}

if($("#historynav").length>0){
sfHover = function() {
   var sfEls = document.getElementById("historynav").getElementsByTagName("li");
   for (var i=0; i<sfEls.length; i++) {
      sfEls[i].onmouseover=function() {
      this.className+=" sfhover";
   }
  sfEls[i].onmouseout=function() {
     this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
    }
   }
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
}

//兼容ie6 hover
IE6hover=function (el,haverClass){
haverClass=haverClass||'hover';
el.onmouseout=function (){
this.className=this.className
.replace(new RegExp('(^|\\s)' + haverClass + '(?=\\s|$)','g'),'')
.replace(/^\s+|\s+$/,'')
.replace(/\s+/,' ');
}
el.onmouseover=function (){
el.onmouseout();
this.className+=' '+haverClass;
};
};

window.onload = function (){
var lis=document.getElementsByTagName("li");
for (var i=0;i<lis.length;++i ) IE6hover(lis[i])
}
