$(document).ready(function(){
	/* remove no script warning for browsers with JScript turned on */	
	$('#no-script').remove();
	
	/* set up news items visibility settings */
	$('#general_news_table p').hide();  
	$('#competition_news_table p').hide();
	$('#general_news_table p.show').show();
	$('#competition_news_table p.show').show();
	
	/* Toggle general news items */
	$('#general_news_table h2').click(function(){
		$(this).next("p").toggle(); 		
		if($(this).next("p").is(':visible')) 
		{
      		$(this).find(".read").text("Close >" );	
    	} 
		else 
		{
      		$(this).find(".read").text("Read More >" );	
    	}
 		});	
	
	/* Toggle competition news items */
	$('#competition_news_table h2').click(function(){
		$(this).next("p").toggle(); 
		if($(this).next("p").is(':visible')) 
		{
      		$(this).find(".read").text("Close >" );	
    	} 
		else 
		{
      		$(this).find(".read").text("Read More >" );	
    	}			    
 		});	
		
	/* top buttons animation */
	$('#buttons img').hover(function(){
	    $(this).animate({paddingTop: '+=3px'}, 100);
	  	}, function(){
	    $(this).animate({paddingTop: '-=3px'}, 100);
	  });	
	 
	/* main image fadeout  
	$('.top-image').click(function() {
		$(this).hide('slow');
	    setTimeout(function() {$(this).remove();}, 500);
	  });
	*/
	
	/* Close the main popup div */	
	$('#close_1').click(function() {
		$('#urgent_message').fadeOut('slow');
	  });
		
	/* Close the secondary popup div */	
	$('#close_2').click(function() {
	$('#reminder_message').fadeOut('slow');
	  });
	  
	 /* CODE FOR LARGE IMAGE REMOVAL
		$('#image').click(function() {
		$(this).toggle('slow');
		});
	*/
	
}); // END DOCUMENT.READY FUNCTION

$(document).ready(function(){
  $('#top_image').hide();
 setTimeout(function() {$('#top_image').show();}, 350); 		  
  rotatePics(1);
});

function rotatePics(currentPhoto) {
  var numberOfPhotos = $('#top_image img').length;
  currentPhoto = currentPhoto % numberOfPhotos;
	
  $('#top_image img').eq(currentPhoto).fadeOut(function() {
		// re-order the z-index
    $('#top_image img').each(function(i) {
      $(this).css(
        'zIndex', ((numberOfPhotos - i) + currentPhoto) % numberOfPhotos
      );
    });
    $(this).show();
    setTimeout(function() {rotatePics(++currentPhoto);}, 7000);
  });
}
