//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 a").hover(
		function () {
   			$("li.livechat .decription").show();
		}, 
     	function () {
			$("li.livechat .decription").hide();
  	});
	 
	// 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( $('ul.gallery').length) {
		$('ul.gallery').galleria({
			history   : false,                 // activates the history object for bookmarking, back-button etc.
			clickNext : true,                  // helper for making the image clickable
			insert    : '#gallery-main-image', // the containing selector for our main image
			onImage   : function(image) {      // let's add some image effects for demonstration purposes
			// fade in the image & caption
			image.css('display', 'none').fadeIn(1000);
		  }
		});
	}

	// Make remindlink ajaxed when this (javascript) is available
	$('.remindlink').each(function(){
	    $(this).attr('href', $(this).attr('href') + '&field=remindform');
	});

});

// 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");
  });
}