$(document).ready(function(){

	
if ($("#portal_series ul ul").length==0){ 
/******************************** start no-subcategories**/	
	

	if(anchor==""){
		autoshowfirst();
	}
	else if($("#portal_series ul:not(:has(ul)) a[href$="+anchor+"]").size()>>0){ 
	//if the anchor exists as a link on the listing
		$("#portal_series ul:not(:has(ul)) li").removeClass("active");
		$("#portal_series ul:not(:has(ul)) a[href$="+anchor+"]").addClass("active");
		$("div#videos").load("/assets_tube/includes/series_videos_ajax.asp?series="+anchor);	
	}
	else{
		autoshowfirst();
	}
	
	
	$("#portal_series ul:not(:has(ul)) a").click(function(){
		theitem=$(this).closest("li");
		if($(this).not(".active")){	
			theitem.find("a").addClass("active");
			theitem.siblings().find("a").removeClass("active");
			x=theitem.find("a").attr("href").replace('#','');
			$("div#videos").load("/assets_tube/includes/series_videos_ajax.asp?series="+x);
		}
	});
	
/******************************** end no-subcategories**/	
}else{
/******************************** start has-subcategories**/	
	
	if(anchor==""){
		autoshowfirst();
	}
	else if($("#portal_series ul ul a[href$="+anchor+"]").size()>>0){ //if the anchor exists as a link on the listing
		z=$("#portal_series ul ul a").index($("#portal_series ul ul a[href$="+anchor+"]"));
		$("#portal_series ul ul li a").eq(z).addClass("active");
		$("#portal_series ul ul li a").eq(z).closest("ul").parent().find(">a").addClass("active");
		$("#portal_series ul ul li a").eq(z).closest("ul").show();
		
		$("div#videos").load("/assets_tube/includes/series_videos_ajax.asp?series="+anchor);	
	}
	else{
		autoshowfirst();
	}
	
	
	$("#portal_series ul>li:has(ul)>a").click(function(){ //grouping link
		theitem=$(this).parent("li");
		$("#portal_series ul>li a").removeClass("active");
		//theitem.parent().closest("ul").siblings().find("a").removeClass("active");
		
		if($(this).hasClass("active")){	}else{
			theitem.siblings().find("ul").slideUp(400);

			theitem.find("ul").slideDown(400);
			theitem.find(">a").addClass("active");
			
			firstlink=theitem.find("ul a:eq(0)");
			firstlink.addClass("active");
			x=firstlink.attr("href").replace('#','');
			$("div#videos").load("/assets_tube/includes/series_videos_ajax.asp?series="+x);
		}
	});
	
	$("#portal_series ul ul li:eq(0)")
		.find(">a").addClass("active")
		.find("a").eq(0).addClass("active");

	
	$("#portal_series ul ul a").click(function(){
		x=$(this).attr("href").replace('#','');
		$("div#videos").load("/assets_tube/includes/series_videos_ajax.asp?series="+x);
		$(this).parents("li").siblings().find("a").removeClass("active");
		$(this).addClass("active");
		});
		
/******************************** end has-subcategories**/	
}
	
	
});


function autoshowfirst(){

	
	if($("#portal_series").length>0){
		if ($("#portal_series ul ul").length==0){  //no subcategories
				firstlink=$("#portal_series ul:not(:has(ul)) li:eq(0)>a").attr("href").substring(1);
				$("#portal_series ul:not(:has(ul)) li").removeClass("active");
				$("#portal_series ul:not(:has(ul)) a[href$="+firstlink+"]").addClass("active");
				$("div#videos").load("/assets_tube/includes/series_videos_ajax.asp?series="+firstlink);
				
		}
		else{	//has subcategories
		
				firstlink=$("#portal_series ul ul li:eq(0)>a").attr("href").substring(1);
				$("#portal_series ul li a:eq(0)").addClass("active");
				$("#portal_series ul ul:eq(0)").addClass("active").show();
				$("div#videos").load("/assets_tube/includes/series_videos_ajax.asp?series="+firstlink);
		}
	}
	else{
	}
	
}	
	 
	
	
	
		
function loadmixtape(allvars){
				allvars=$.parseQuery(allvars);
				newurl="/assets_tube/includes/mixtape_videos_ajax.asp?mixtape="+allvars.mixtape+"&page="+allvars.page;
				
				$("div#videos").load(newurl);

				$("#mixtapes a").each(function(){
					href=$.parseQuery(delhash($(this).attr('href')));
					if(href.mixtape==undefined){
						$("#mixtapes a").eq(0).addClass("active");
					}
					else if(href.mixtape==allvars.mixtape){
						$("#mixtapes a").eq(0).removeClass("active");
						$(this).addClass("active");
					}else{
						$(this).removeClass("active");
					}
					
				});
}
		  
function delhash(d){
		d=Right(d,d.length-1);
		return d;
}



