//=======================================================================================================
//-------------------------------------------------------------------------------------------------------
//	Custom Javascript functions
//-------------------------------------------------------------------------------------------------------
//=======================================================================================================


//-------------------------------------------------------------------------------------------------------
//	JAuery 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(){
	//---------------------------------------------------------------------------------------------------------
	//	IE hack
	//---------------------------------------------------------------------------------------------------------
	if ($.browser.msie) {
		$('.widget').addClass("ie-widget").after('<img style="margin-bottom:10px;" src="/site/images/ie/widget_bottom.gif">');
		$('#content,.newsscroller').after('<img src="/site/images/ie/content_bottom.gif">');
		$('#homecontent,.homenewsscroller').after('<img style="margin-bottom:10px;" src="/site/images/ie/home_bottom.gif">');
//		$('#subnav').after('<img src="/site/images/ie/sectionnav_bottom.gif">');
	}


//---------------------------------------------------------------------------------------------------------
//	Expandible widgets
//---------------------------------------------------------------------------------------------------------
    $("h2.expand").click(function () {
//		alert( "test" );
//		$(this).parent().next(".expandable").slideToggle("fast");
		$(this).next("div.expandable").slideToggle("fast");
//		alert( $(this).next("div.expandable").attr("id");
//      $(this).parent().toggleClass("exp-header-active");
    });    



	//	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" );
		});
});




//-------------------------------------------------------------------------------------------------------
//	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;
            });
        });
    });
};

