// Search Results - Abbreviated Special Offer Display

$(document).ready(function() {
	
	// Replace Special Offer Text on Search Results with cut down version
	
	$("ol.searchResults ul.relatedOffers li").each( function() {

		var GetOfferText = $(this).html();
		var NewOfferText = "";
		
		// Swap Out Text for each offer
		
		if ( GetOfferText.indexOf("DURHAM DEAL") > 0)
			 NewOfferText = "<p><strong>DURHAM DEAL - offer available</strong></p>";

		if ( GetOfferText.indexOf("DURHAM DEAL - 25% off") > 0)
			 NewOfferText = "<p><strong>DURHAM DEAL - 25% off</strong></p>";
			 
		if ( GetOfferText.indexOf("DURHAM DEAL - 15% off") > 0)
			 NewOfferText = "<p><strong>DURHAM DEAL - 15% off</strong></p>";

		if ( GetOfferText.indexOf("DURHAM DEAL - 2 nights for the price of 1") > 0)
			 NewOfferText = "<p><strong>DURHAM DEAL - 2 nights for the price of 1</strong></p>";

		if ( GetOfferText.indexOf("DURHAM DEAL - 3 nights for the price of 2") > 0)
			 NewOfferText = "<p><strong>DURHAM DEAL - 3 nights for the price of 2</strong></p>";

 
		// Swap HTML out if offer found
		if (NewOfferText != "")
		{
			var ProductLink = $(this).parent().parent().parent().find("h2.ProductName a").attr("href");
			
			NewOfferText = NewOfferText + "<p>";
			NewOfferText = NewOfferText + "<a href='" + ProductLink + "'>Click here</a> for full details of offer.</p>";		
			$(this).html(NewOfferText);
		}
    });
	
	// Hide Unwanted Product Detail Additional Image
	if ( $("#productImage") && $("#productExtraImages") ) {
		
		// Hide additional image for default image
		var BigImgSrc = GetImgPath("#productImage");
		
		$("#productExtraImages li img").each( function() {
				var ThisImgSrc = GetImgPath(this);
				if (BigImgSrc == ThisImgSrc)
					$(this).attr("class","hideImage");
			});

		// Hide additional Image after it's clicked
		$("#productExtraImages li img").click( function() { 													
			$("#productExtraImages li img").each( function() {
				$(this).attr("class","showImage");
			});
			$(this).attr("class","hideImage");
		} );
	}	
});

function GetImgPath(strImage) {
// Get Image Path for Additional Image
	var MainImgSrc = $(strImage).attr("src");
	var MainImg = MainImgSrc.split("action=");
	return MainImg[0];			  	  
}