//=======================================================================================================
//-------------------------------------------------------------------------------------------------------
//	Custom Javascript functions
//-------------------------------------------------------------------------------------------------------
//=======================================================================================================
//-------------------------------------------------------------------------------------------------------
//	jquery hide empty menus
//-------------------------------------------------------------------------------------------------------
$(function(){
	$(document.body).ready
	(
		function(){$(this).find('ul.m2').HideEmpty();}
	);
});

jQuery.fn.HideEmpty = function() {
  return this.each(function(){
	var itemcount	= $(this).find('li').length;
	if( !itemcount || itemcount == 0 )
	  {
		$(this).css( "visibility", "hidden" );
		$(this).css( "display", "none" );
	  }
  });
};

$(document).ready(function(){
	//---------------------------------------------------------------------------------------------------------
	//	Fix #&*#@! IE
	//---------------------------------------------------------------------------------------------------------
	if ($.browser.msie) {
//		$('#subnav,.widget,.featurebox,#content,.newsscroller,button,a.button,#features').corner('round');
//		$('#breadcrumb, #pagetabs ul#tabs a, #nav-section-top').corner('round top');
//		$('ul.m1, ul.m1 ul').corner('round bottom');
		$('.widget,.featurebox,.newsscroller').corner('round');
		$('#content').corner('round');
		$('#breadcrumb, #pagetabs ul#tabs a').corner('round top');
		$('#nav-section-top').corner("round top").parent().css('padding', '2px').corner("round");
	}
	
	//---------------------------------------------------------------------------------------------------------
	//	Expandible widgets
	//---------------------------------------------------------------------------------------------------------
    $("h2.expand").click(function () {
		$(this).next("div.expandable").slideToggle("fast");
    });    

	$("h2.plus").toggle(
	      function () {
	        $(this).css({"border-bottom":"none"});
	      },
	      function () {
	        $(this).css({"border-bottom":"1px solid #ccc"});
	      }
	    );

	//	Menu button active (mouseover) states
	$("ul.m1").hover(
		function() {
			var menu_id		= $(this).attr("id");
			var button_id	= "#b-" + menu_id.substring( 2, menu_id.length );
			$( button_id ).addClass( "j-active" );
		},
		function() {
			var menu_id		= $(this).attr("id");
			var button_id	= "#b-" + menu_id.substring( 2, menu_id.length );
			$( button_id ).removeClass( "j-active" );
		});
		
	$('.print').click(function() {
				window.print();
				return false;
			});


	//	For video details pages, if left side bar is empty, hide it
    $("#subnav:empty").parent().css("display","none");

});

//-------------------------------------------------------------------------------------------------------
//	Super Simple Tabs 1.0
//		http://andreaslagerkvist.com/jquery/super-simple-tabs/
//-------------------------------------------------------------------------------------------------------
jQuery.fn.superSimpleTabs = function () {
    return this.each(function () {
        var ul = jQuery(this);

        // Go through all the in-page links in the ul
        ul.find('a[href^=#]').each(function (i) {
            var link = jQuery(this);

            // Hide all containers cept the first
            if (i) {
                jQuery(link.attr('href')).hide();
            }
            else {
                link.addClass('selected');
            }

            // When clicking link
            link.click(function () {
                // Hide selected link's containers
                jQuery(ul.find('a.selected').removeClass('selected').attr('href')).hide();

                // Show this one's
                jQuery(link.addClass('selected').attr('href')).show();

                return false;
            });
        });
    });
};


