$(document).ready(function(){
	$(".toggle-click").toggle(
	function(){
		$($(this).attr("href")).slideDown();
		return false;
	
	},
	function(){
	$($(this).attr("href")).slideUp();
	return false;
	});


});
var CAROUSEL_ROWS = 1;
var CAROUSEL_VISIBLE = 1;
var CAROUSEL_VERTICAL = false;
var TABS_HEIGHT = 453;//467;
var DO_CAROUSEL= true;
var carousels={};
function showTab(tab,index){
		index = typeof(index) != "undefined" && $("#relvid"+index).length?(""+index):"";
		
		var tabs=["relvid","relvidx","comvid","relps"];
		var clickedTab = $(tab);
		var id=clickedTab.attr("id");
		var rel;
		var el;
		var toDo;
		var activeRel;
		var activeTab;
	for(idx in tabs){
		tab = tabs[idx];
		tab+=index;
		el =$("#"+tab);
		rel = el.attr("rel");
			if(tab != id){
					
					el.removeClass("rel_on").addClass("rel_off");
					$(rel).hide();
					
				}else{
					el.removeClass("rel_off").addClass("rel_on");
					$(rel).show();
					activeRel=rel;
					activeTab = tab;
					if(!carousels[rel] & DO_CAROUSEL){
						toDo = rel;
						
					}
			
					/*if(tab !="comvid"){
						$(".tabs").animate({height:TABS_HEIGHT  },700);
					}else{
						$(".tabs").animate({height:270},700);
					}*/
				}

		}
		if(toDo){
				
						var _toDo= toDo;
						carousels[toDo]=$(toDo +" .carousel").jCarouselLite({
							visible:CAROUSEL_VISIBLE,
							scroll:1,
							rows:CAROUSEL_ROWS,
							vertical:CAROUSEL_VERTICAL,
							circular:false,
							btnNext:toDo+" .next",
							btnPrev:toDo+" .prev",
							onInit:function(o){
								adjustHeight($(o.context),$(o));
							},
							afterEnd:function(o){
							adjustHeight($(o.context),$(o));
							  //var id = div.attr("id");
							//	$(".tabs").animate({height:$parent.height()},700);
							}
							
						});
		}
		function adjustHeight(div,li){
			
			 var liHeight = li.height();
			li.css({height:liHeight});
			div.css({height:liHeight});
								  //var diff= $(".tabs").height()-div.height();
			$(".tabs"+index).animate({height:liHeight+32},700);
			
		}
		if(activeTab.indexOf("comvid")==-1){
			if(window[activeRel]){
			adjustHeight($(activeRel +" .carousel"),$(window[activeRel]()));
			}
			//adjustHeight(carousels[toDo]);
			//$(".tabs").animate({height:$(activeRel).height()},700);
		}else{
			$(".tabs"+index).animate({height:270},700);		
		}


	
}
	$(document).ready(function(){
		showTab($("#vid_nag span:first").get(0),1);
	});
