/*	----------------------  detail tabs -------------------------  */


									
		$(document).ready(function(){

								
		$(".tab_content").hide(); 
		$("ul.tabs li:first").addClass("active").show();
		$(".tab_content:first").show(); 

		
		$("ul.tabs li").click(function() {
			$("ul.tabs li").removeClass("active"); 
			$(this).addClass("active"); 
			$(".tab_content").hide(); 
			var activeTab = jQuery(this).find("a").attr("href"); 			
$(activeTab).fadeIn(); 
			return false;
		});


$("#detail_page_video_links").hide(); 
	 $(".linktovideo").click(function () {
      $("#detail_page_video_links").slideToggle("slow");
	  return false;
    });

	
  
  lightsoff();
  });



/*	----------------------  mousewheel -------------------------  */

$(function() {         
         
    $("div.scrollable").scrollable({ 
        vertical:true,  
        size: 1
         
    }).mousewheel();     
     
}); 





/* Memberpanel */

$(document).ready(function(){

//Adjust panel height
	$.fn.adjustPanel = function(){ 
		$(this).find("ul, .subpanel").css({ 'height' : 'auto'}); //Reset subpanel and ul height
		
		var windowHeight = $(window).height(); //Get the height of the browser viewport
		var panelsub = $(this).find(".subpanel").height(); //Get the height of subpanel	
		var panelAdjust = windowHeight - 100; //Viewport height - 100px (Sets max height of subpanel)
		var ulAdjust =  panelAdjust - 25; //Calculate ul size after adjusting sub-panel (27px is the height of the base panel)
		
		if ( panelsub >= panelAdjust ) {	 //If subpanel is taller than max height...
			$(this).find(".subpanel").css({ 'height' : panelAdjust }); //Adjust subpanel to max height
			$(this).find("ul").css({ 'height' : ulAdjust}); //Adjust subpanel ul to new size
		}
		else if ( panelsub < panelAdjust ) { //If subpanel is smaller than max height...
			$(this).find("ul").css({ 'height' : 'auto'}); //Set subpanel ul to auto (default size)
		}
	};
	
	//Execute function on load
	$("#footcategories").adjustPanel(); //Run the adjustPanel function on #footcategories
	$("#footcomments").adjustPanel(); //Run the adjustPanel function on #footcomments
    $("#footistatics").adjustPanel(); //Run the adjustPanel function on #footistatics
	
	//Each time the viewport is adjusted/resized, execute the function
	$(window).resize(function () { 
		$("#footcategories").adjustPanel();
		$("#footcomments").adjustPanel();
        $("#footistatics").adjustPanel();
	});
	
	//Click event on Chat Panel + Alert Panel	
	$("#footcategories a:first, #footcomments a:first,#footistatics a:first").click(function() { //If clicked on the first link of #footcategories and #footcomments...
		if($(this).next(".subpanel").is(':visible')){ //If subpanel is already active...
			$(this).next(".subpanel").hide(); //Hide active subpanel
			$("#footpanel li a").removeClass('active'); //Remove active class on the subpanel trigger
		}
		else { //if subpanel is not active...
			$(".subpanel").hide(); //Hide all subpanels
			$(this).next(".subpanel").toggle(); //Toggle the subpanel to make active
			$("#footpanel li a").removeClass('active'); //Remove active class on all subpanel trigger
			$(this).toggleClass('active'); //Toggle the active class on the subpanel trigger
		}
		return false; //Prevent browser jump to link anchor
	});
	
	//Click event outside of subpanel
	$(document).click(function() { //Click anywhere and...
		$(".subpanel").hide(); //hide subpanel
		$("#footpanel li a").removeClass('active'); //remove active class on subpanel trigger
	});
	$('.subpanel ul').click(function(e) { 
		e.stopPropagation(); //Prevents the subpanel ul from closing on click
	});
	
	

});





/* equal */


function equalHeight(group) {
    var tallest = 0;
    group.each(function() {
        var thisHeight = $(this).height();
        if(thisHeight > tallest) {
            tallest = thisHeight;
        }
    });
    group.height(tallest);
}
$(document).ready(function() {
    equalHeight($(".column3"));
  equalHeight($(".column-home"));
});




$(document).ready(function() {



    var button = $('#hideButton a');

    //check the cookie when the page loads
    if ($.cookie('currentToggle') === 'hidden') {
        togglePanel(button, false);
    }
    else {
        togglePanel(button, true);
    }

    //handle the clicking of the show/hide toggle button
    button.click(function() {
        //toggle the panel as required, base on current state
        if (button.text() === "+") {
            togglePanel($(this), true);
        }
        else {
            togglePanel($(this), false);
        }
    });

});

function togglePanel(button, show) {

    var panel = $('#footpanel');

    if (show) {
        panel.css('bottom','0');
        button.text('-').css('background-position','0 0').css('top','0');
        $.cookie('currentToggle', '', { path: '/' });
    }
    else {
        panel.css('bottom','-33px');
        button.text('+').css('top','-30px').css('background-position','0 -30px');
        $.cookie('currentToggle', 'hidden', { path: '/' });
    }
}

$(document).ready(function(){


    $("ul#main-menu li").hover(function(){

    

        $(this).addClass("hover");

        $('ul:first',this).css('visibility', 'visible');

    

    }, function(){

    

        $(this).removeClass("hover");

        $('ul:first',this).css('visibility', 'hidden');

    

    });

    

    $("ul#main-menu li ul li:has(ul)").find("a:first").prepend("&laquo; ");











$(".item, #video-list li, .top-videos-list li").append("<small></small>");

            $(".item, #video-list li,.top-videos-list li").hover(function(){

                 $(this).addClass('hoverthat');

                $(this).children("small").fadeIn(600);

            },function(){

                $(this).removeClass('hoverthat');

                $(this).children("small").fadeOut(200);

            });

		





$(".item, #video-list li,.top-videos-list li,.articles-on-sidebar li,.relatedArticles li").click(function(){    
 window.location=$(this).find("a").attr("href");     return false;});
$(".articles-on-sidebar li,.relatedArticles li").hover(function(){$(this).addClass('hoverblock');},
function(){$(this).removeClass('hoverblock');  }); 


//view swicher	

$("a.switch_thumb").toggle(function(){	  $(this).addClass("swap"); 	
  $("ul.top-videos-list li").fadeOut("fast", function() {	  
	$(this).fadeIn("fast").addClass("list_view"); 		 });	  }, 
function () {      $(this).removeClass("swap");	 
 $("ul.top-videos-list li").fadeOut("fast", function() {	  
	$(this).fadeIn("fast").removeClass("list_view");		});	 


});


	
});
/*	----------------------  memberbox -------------------------  */
		
		$(function() { 

$("#member-box").tabs("#member-box div.pane", {tabs: '#member-box-nav li', effect: 'slide', initialIndex: null});
});
		
		
			/*	---------------------- article slider	 -------------------------  */
			

$(function() {
$('#article-box-home ul').bxSlider({			
controls: true,            
easing: 'swing',             
speed: 2000, 			
pause:2000, 			
auto: true, 				
autoHover: true			});
 
				

	
	$("#topvideo-watched-nav ul").tabs("#topvideo-watched > .topvideo-watched-panel", {effect: 'fade', fadeOutSpeed: 400});
});



	


		/*	---------------------- lights off -------------------------  */




function getPageSize() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
}

function lightsoff() {
	$("#lightsoff").click( 
	 function() {
	 	$('#Playerholder, #Player, embed, object')
		.css({ 'visibility' : 'visible' });
		$('body')
		.append('<div id="lightsoff-background"></div>');

		var page_size = getPageSize();
		
		$('#lightsoff-background')
		.css({
			backgroundColor:	"#000",
			opacity:			0.9,
			width:				page_size[2],
			height:				page_size[1]
		}).show();

		$('#lightsoff-background').click(function() {
			$('#lightsoff-background')
			.fadeOut(function() { 
				$('#lightsoff-background').remove(); 
			});
			return false;
		});
		return false;
	 });
}







