//**************************************************************************************
// JQUERY.COMMON.JS

/*
   Common javascript functions - originally provided by Graphico.*/

//**************************************************************************************


$(document).ready(function(){
//Start common code
    
    /*Call the bookmark.js function when ready*/
    try{
        var bookmark = new Bookmark();
        bookmark.init( "http://news.bbc.co.uk/", "bookmarkContainer" );
    }catch( e ){
        
    }
    
    /*PNG fix for IE*/
    jQuery(document).pngFix(); 
    
    //Tabs
    jQuery('#tabbedContent > ul').tabs();
    
    //fake round corners
    jQuery(".genericBox").append("<span class='tl corner'></span><span class='tr corner' ></span><span class='bl corner'></span><span class='br corner'></span>");
    
    
      
    /*find the news box,
    add the "read more" link,
    hide it, 
    toogle the portion (toReveal) to show and hide*/
    
    jQuery("#primaryBox .toReveal").before("<p class='linkReadMore'><a href='#'>Show more</a></p>");
    jQuery(".toReveal").hide();
    
    jQuery(".linkReadMore").toggle(
      function () {
        jQuery(".toReveal").slideDown("slow");
        jQuery(".linkReadMore").attr("id","readLess").html("<a href='#'>Show less</a>");
        return false;
      },
      function () {
        jQuery(".toReveal").slideUp("slow");
        jQuery(".linkReadMore").removeAttr("id").html("<a href='#'>Show more</a>");
        return false;
      }
    );
    
    /*more fake corbners*/
    jQuery(".linkReadMore").append("<span class='bl corner'></span><span class='br corner'></span>");

    /*add hover state for ie 6 on the secondary navigation*/
    jQuery("#secondaryNavigation li span").hover(function(){
        jQuery(this).addClass("hover");
    },
    function(){
        jQuery(this).removeClass("hover");
    }
    
    );
    
    /*show and hide for "grouped Items"*/
    jQuery(".reveal").hide();

    
    jQuery(".moreItems a").toggle(
      function () {
        jQuery(this).parent().next().slideDown("slow");
        jQuery(this).addClass("minus");
        return false;
      },
      function () {
        jQuery(this).parent().next().slideUp("slow");
        jQuery(this).removeClass("minus");
        return false;
      }
    );



// Remove events from current events lists that are past their date
// MF 15 November 2010
  var todaysDate = new Date().setHours(0,0,0,0);
  $('.eventList.current > li, h4.current.dayTitle').each(function(){
    var theDate = $(this).attr('id').substring($(this).attr('id').indexOf('_')+1, $(this).attr('id').length).replace('event', '').replace(/-/g, '/');
    if(theDate != ''){
     theDate = new Date(theDate);
     if(theDate < todaysDate){
       $(this).remove();
       }
     }
   });
    
    
		
    
//End common code       

// Call function to remove empty related links sections (see below)
removeEmptyRelatedLinks();

});

// Function to remove empty related links sections - should be defunct after 8 June 2011
function removeEmptyRelatedLinks(){
  if($('#relatedLinks  ul  li').size() == 1){    
	if($.trim($('#relatedLinks ul li:first').text()) == ''){
	  $('#relatedLinks').hide();
	  }
	}
  }

