//Actions to perform when page hsas finished loading (but before AJAXed content)

$(document).ready(function(){			   					   
						   
	// CSS fixes for phase 1 launch
	$("li.overlay ol li:first-child").css("margin-left","0");
	$("li.overlay ol li:last-child").css("margin-right","0");
				   
	//Make entire search result item area clickable
	$(".item").click(function(){
	  window.location=$(this).find("a").attr("href"); return false;
	});
	
	//Make clickable area use mouse pointer hand '.item' used for listings like search
	$(".item").css("cursor","pointer");
						   
	//hide rollover text
	$("p.rollover").hide();
	$("p.sliderollover").hide();
	
	//livechat pop-up
	$("li.livechat .decription").css("opacity", "0");
	
	$("li.livechat a").hover(
		function () {
   			$("li.livechat .decription").stop().css("display", "block").animate({"opacity": "1"}, "slow");
		}, 
     	function () {
			$("li.livechat .decription").stop().animate({"opacity": "0"}, "slow").css("display", "none");
  	});
	 
	// fix for webbler admin bar
	$('#adminnavcontainer').css('z-index', '9999');
	
	//Image Gallery (Galleria Plugin)
	$('.images').addClass('gallery'); // adds new class name to maintain degradability
	$('.images li:first-child').addClass('active'); // adds new class name to maintain degradability
	
	if( $('#galleria').length) {
		// Load the classic theme
		Galleria.loadTheme("/js/galleria-themes/classic/galleria.classic.js");
		$('#galleria').galleria({
			autoplay: 5000, // will move forward every 5 seconds
			clicknext: true
		});
	}

	// Make remindlink ajaxed when this (javascript) is available
	$('.remindlink').each(function(){
	    $(this).attr('href', $(this).attr('href') + '&field=remindform');
	});
	
	
	//Opacity CSS3 
	
	//$("#footer ul#sponsors li a").css("opacity", "1");
	
	//$("#footer ul#sponsors li a").hover(
	//function() {
	//$(this).stop().animate({"opacity": "0.5"}, "slow");
	//},
	//function() {
	//$(this).stop().animate({"opacity": "1"}, "slow");
	//});

});

// This will be called when recommended has AJAX-reloaded itself

function recommended_loaded() {
	final_page_loaded();
}

// This will be called when recently_viewed has AJAX-reloaded itself

function recently_viewed_loaded() {
	final_page_loaded();
	if( $('#recently_viewed_output li').length) {
    	showRecommend();
	}
}

// Will show the personalised content and relocate the Phil Channel panel to the bottom row 

function showRecommend() {
	$('.recommendon').addClass('recommendshow').removeClass('recommendhide');
	$('.recommendoff').removeClass('recommendshow').addClass('recommendhide');
	$('ul.featured-user li.channel').removeClass('colspan-2').addClass('row');
	$('ul.featured-user li.channel ol li').removeClass('highlight').removeClass('left').removeClass('right');
	$('ul.featured-user li.channel ol li img').css('width','110px').css('height','82px');
	$('ul.featured-user li.channel ol li:first-child').addClass('first');
	$('ul.featured-user li.channel ol li:last-child').addClass('last');
}

// Actions to perform when page has finished loading including AJAXed content

function final_page_loaded() {  
//Add rollover events
$(".featured ol li").find("p.rollover").hide();
$(".featured-user ol li").find("p.rollover").hide();

  $(".featured ol li").hover(
    function () {
      $(this).css("cursor","pointer");
      $(this).find("p.rollover").show();
    }, 
    function () {
      $(this).css("cursor","pointer");
      $(this).find("p.rollover").hide();
    });
  
  $(".featured-user ol li").hover(	
    function () {
      $(this).css("cursor","pointer");
      $(this).find("p.rollover").show();
	  $(this).find("p.sliderollover").show(); 
	  //$(this).find("p.sliderollover").slideToggle("slow");   
    }, 
    function () {
      $(this).css("cursor","pointer");
      $(this).find("p.rollover").hide();
      $(this).find("p.sliderollover").hide();
	  //$(this).find("p.sliderollover").slideToggle("slow");
  });

}
