$(document).ready( function() { //When the document is ready
	

  /* ------------------------- Open external links in new windows - */
  
  var external = $('a[rel="external"]'); //Get all links with rel="external" and place them into the 'external'
	
  external.attr("title", external.attr("title") + " - Link opens in a new window"); //Take the links current title and append it with the external link message
  
  external.click( function() { //When an external link is clicked
  
    window.open( $(this).attr('href') ); //Open its href in a new window
  
    return false; //Cancel the links default behaviour	
  
  }); //End function


 

  
  /* ------------------------- Toggle expandable boxes - */

	// If Pretty Photo is included, attempt to instantiate lightbox effect
	if('function' == typeof $.fn.prettyPhoto){
		$("a[rel^='prettyPhoto']").prettyPhoto({
			animationSpeed: 'normal',
			padding: 40,
			opacity: 0.35,
			showTitle: false,
			allowresize: true,
			theme: 'light_square'
		});
	}
	
	
	
	
	
	
	
	

// -- Accordion function for 'By category listing page' --


// -- Initialise --

	$('.headingExpansion').text("Shop online categories list (click to expand)");
	$('.headingExpansionRetailers').text("Shop online retailers list (click to expand)");

	$("ul.accordion li h4:odd").addClass('goldStripe');


	$('ul.innerAccordionList').hide();
	$('ul.accordion li h4 a').css({'background-image': 'url("/contents/images/site/accordion/accordionExpand.gif")'});




// -- Actual Accordion movement function --

	$('ul.accordion li h4 a').click( function(){
		
		
		if($(this).parents('h4').siblings('ul').is(":hidden")){
			
			$('ul.innerAccordionList').slideUp('fast');
			$('ul.accordion li h4').removeClass('activeItem');
			$('ul.accordion li h4 a').css({'background-image': 'url("/contents/images/site/accordion/accordionExpand.gif")'})
			
			$(this).parent('h4').addClass('activeItem');
			$(this).css({'background-image': 'url("/contents//images/site/accordion/accordionCollapse.gif")'})
			$(this).parents('h4').siblings('ul').slideDown('slow');
		
		} else {

			$(this).parent('h4').removeClass('activeItem');			
			$(this).css({'background-image': 'url("/contents/images/site/accordion/accordionExpand.gif")'})
			$(this).parents('h4').siblings('ul').slideUp('fast');					
			
		}
		
				
		return false;
		
	});
	

tooltip();


}); //end document ready






	
/* -- General Tooltip device (give any a tag a class of 'tooltip' and put a 'div class="tip"' containing the tooltip content next to the a tag) - */

		var xOffset = 10;
		var yOffset = 20;
		var pageWidth;
		var pageX;
		var pageY;
		var e;

	this.tooltip = function(){
			
			
		$("a.tooltip").hover(function(e){
			
			pageWidth = $('body').width();
			yOffset = 20;
			if((e.pageX + 300) >= pageWidth){
				yOffset = yOffset - 300;
			}
			
			$(this).attr('title','');
			var tipContent = $(this).siblings('.tip').html();										  								  
			$("body").append("<div id='tooltip'>"+ tipContent +"</div>");
			
			$("#tooltip")
				.css("top",(e.pageY - xOffset) + "px")
				.css("left",(e.pageX + yOffset) + "px")
				.fadeIn("fast");
	 
	    },	function(){	
			
			$("#tooltip").remove();
			
	    });	
		
		
		$("a.tooltip").mousemove(function(e){
			$("#tooltip")
				.css("top",(e.pageY - xOffset) + "px")
				.css("left",(e.pageX + yOffset) + "px");
		});
		
					
	};
