// 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 = "<h3>Durham Deal</h3>";

		if ( GetOfferText.indexOf("DURHAM DEAL - 25% off") > 0)
			 NewOfferText = "<h3>Durham Deal</h3>";

//	Keep for reference
//		if ( GetOfferText.indexOf("DURHAM DEAL - 25% off") > 0)
//			 NewOfferText = "&lt;p class=&quot;dealHide&quot;&gt;&amp;nbsp;&lt;/p&gt;";
			 
		if ( GetOfferText.indexOf("DURHAM DEAL - 15% off") > 0)
			 NewOfferText = "<h3>Durham Deal</h3>";

		if ( GetOfferText.indexOf("Durham Deals Winter 2011/12 Eating Out") > 0)
			 NewOfferText = "<h3>Durham Deal</h3>";

		if ( GetOfferText.indexOf("Durham Deals Winter 2011/12 Shopping") > 0)
			 NewOfferText = "<h3>Durham Deal</h3>";

		if ( GetOfferText.indexOf("Durham Deals Winter 2011/12 Attractions") > 0)
			 NewOfferText = "<h3>Durham Deal</h3>";

		if ( GetOfferText.indexOf("DURHAM DEAL - 2 nights for the price of 1") > 0)
			 NewOfferText = "<h3>Durham Deal</h3>";

		if ( GetOfferText.indexOf("DURHAM DEAL - 3 nights for the price of 2") > 0)
			 NewOfferText = "<h3>Durham Deal</h3>"
			 ;

		if ( GetOfferText.indexOf("LUMIERE DEALS - Accommodation") > 0)
			 NewOfferText = "<h3>Lumiere Deal</h3>";

		if ( GetOfferText.indexOf("accommodation Lumiere Deals") > 0)
			 NewOfferText = "<h3>Lumiere Deal</h3>";

		// 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 + " " + '#specialoffers' + "'>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];			  	  
}

// Replace Special Offers title with new title: Durham Deals

$(".specoffers h3").text("Durham Deal");
$("body.Accommodation .relatedOffers li p a").text("accommodation Durham Deals");


// DP replace text

$("body.checkout fieldset#personalDetails div.disclaimer div.row div.field ul.options li label[for='happytoemail_61990']").text("Please email me the monthly Durham e-newsletter with news, events and special offers");
$("body.checkout fieldset#personalDetails div.disclaimer div.row div.field ul.options li label[for='happyto3rdparty_61990']").text("I would like to receive information from carefully selected partners in the future");
