// :focus fix for Internet Explorer
function focusfix() {
$('a').focus(function() {
$(this).addClass('focus');
});
// Removes class when focus is lost
$('a').blur(function() {
$(this).removeClass('focus');
});
}

// Toggle text function
jQuery.fn.toggleText = function(a, b) {
	return this.each(function() {
		jQuery(this).text(jQuery(this).text() == a ? b : a);
	});
};

// Fade toggle function
jQuery.fn.fadeToggle = function(speed, easing, callback) {
  return this.animate({opacity: 'toggle'}, speed, easing, callback);  
};

////////////////////////////////////////////////////////// DOCUMENT READY FUNCTIONS ///////////////////////////////////////////////////
//:focus fix for IE - all pages
jQuery(document).ready(function($) {
	focusfix();
});

//basket preview animation - all pages
jQuery(document).ready(function($) {

$('a#basketLink').click(function() {
    $('#basketItemsPreview').slideToggle(600);
    return false;
  });

$('a#basketSummaryClose').click(function() {
    $('#basketItemsPreview').slideUp(600);
    return false;
  });

});

//basket preview - flyouts - all pages
jQuery(document).ready(function() {
	$(".basketPreviewProduct").each(function() { $(this).simpletip($(this).find(".additionalInfo").html(), {
		hook: { target: 'topLeft', tooltip: 'bottomRight' },
		offset: [15, 15],
		width: 150,
		delay: 300,
		showEffect: 'fade',
		hideEffect: 'fade',
		border: { size: 2, color: '#7F7F7F' },
		contentClass: 'tooltipContentPreview'
		});
		});
});

//fancy box - all pages
jQuery(document).ready(function() {
	$("#loginLink").fancybox({
		'zoomSpeedIn':	0, 
		'zoomSpeedOut':	0, 
		'overlayShow':	true,
		'overlayOpacity': 0.7,
		'frameWidth': 400,
		'frameHeight': 190
	});
});

//fancy box - all pages
jQuery(document).ready(function() {
	$("#trackLink").fancybox({
		'zoomSpeedIn':	0, 
		'zoomSpeedOut':	0, 
		'overlayShow':	true,
		'overlayOpacity': 0.7,
		'frameWidth': 400,
		'frameHeight': 190
	});
});




//start homepage brands scroll - home page
jQuery(document).ready(function() {
	if ( $("#scroller").length > 0 ) {
		
	$("#scroller").simplyScroll({
		autoMode: 'loop',
		pouseOnHover: true,
		speed: 1,
		frameRate: 24
	});
	
	}
});

//ajax tabs - homepage
/*
jQuery(document).ready(function() {
	
	if ( $("#createTabs").length > 0 ) {
	
	$('#createTabs').tabs();
	
	$('.ui-tabs-nav').bind('tabsshow', function(event, ui) {

		//run first carousel
		$("div.scrollable").scrollable({
			size: 3,
			clickable: false,
			speed: 1400,
			prevPage: ".prevPage",
			nextPage: ".nextPage"
		});
		
		//run second carousel
		$("div.scrollable2").scrollable({
			size: 3,
			speed: 1400,
			items: ".items2",
			clickable: false,
			prevPage: ".prevPage2",
			nextPage: ".nextPage2"
		});	
	});
	}
});
*/

//homepage newsletter input focus / blur
jQuery(document).ready(function() {
	if ( $("#homepageNewsletter").length > 0 ) {

		$('#homepageNewsletter input').focus(function() {
			if($(this).val()=="email address here...") {
				$(this).attr("value","");
			}
		});
		$('#homepageNewsletter input').blur(function() {
			if($(this).val()=="") {
				$(this).val("email address here...");
			}
		});
	}
});

//leftnav newsletter input focus / blur
jQuery(document).ready(function() {
	if ( $("#newsletterLeftnavForm").length > 0 ) {

		$('#newsletterLeftnavForm input').focus(function() {
			if($(this).val()=="email address here...") {
				$(this).attr("value","");
			}
		});
		$('#newsletterLeftnavForm input').blur(function() {
			if($(this).val()=="") {
				$(this).val("email address here...");
			}
		});
	}
});


//access keys show/hide - all pages
jQuery(document).ready(function() {
	$("#toggleAccessKeys").click(function() {
		$("#closeAccessKeys").html("Hide available access keys");
		$("#accessKeys").slideToggle();
		$("#toggleAccessKeys").toggleText("Hide available access keys","Show available access keys");
	});
	$("#closeAccessKeys").click(function() {
		$("#accessKeys").slideUp();
		$("#toggleAccessKeys").toggleText("Hide available access keys","Show available access keys");
	});
});


//start leftnav accordion - category list
jQuery(document).ready(function() {
	if ( $("#leftMenuAccordion").length > 0 ) {
	
		jQuery('#leftMenuAccordion').accordion({
			autoheight: false,
			header: "h3",
			animated: false
		});
	}
});

//start superfish menu - leftnav flyouts - category list
jQuery(document).ready(function() {
	if ( $("ul.sf-menu").length > 0 ) {
		$('ul.sf-menu').superfish();
	}
});


//facet selection control - itemlist page
jQuery(document).ready(function() {
	//clear one item
	$("a.clearSelection").click(function () {
		$(this).parent().fadeOut('slow');
	});
	
	//clear all items
	$("a.clearAllSelection").click(function () {
		$(this).parent().css({'visibility':'hidden'});
		$("#selectedFacets").slideUp('slow');
	});
	
	//show - hide more facets
	$("ul.hideFacets").hide();  //hide more
	
	$("div.showMoreFacets").html("<span>Show more</span>");  //create link and css
	$("div.showMoreFacets span").mouseover(function() {
		$(this).css({'text-decoration':'underline'});											
	}).mouseout(function() {
		$(this).css({'text-decoration':'none'});											
	});
	
	//toggle
	$("div.showMoreFacets").click(function() {
		$(this).parent().find(".hideFacets").slideToggle("slow");
		$(this).find("span").toggleText("Show less", "Show more");
		$(this).find("span").toggleClass("opened");
	});
	
	//mark selected swatches
	$("#colourSelection ul li a").click(function() {
		$(this).toggleClass("selectedColour");											 
	});
	
});


//start price range slider - itemlist page
jQuery(document).ready(function() {
	
	if ( $("#slider-range").length > 0 ) {
	
	$("#slider-range").slider({
		range: true,
		min: 0,
		max: 500,
		values: [25, 475],
		slide: function(event, ui) {
			$("#amount").val('From L' + ui.values[0] + ' - To L' + ui.values[1]);
		}
	});
	$("#amount").val('From L' + $("#slider-range").slider("values", 0) + ' - To L' + $("#slider-range").slider("values", 1));
	}
});

//start dropdown styling - itemlist page
jQuery(document).ready(function() {
	
	if ( $(".itemlistControls").length > 0 ) {
		
		$('#listerForm_top, #listerForm_bottom').jqTransform();
		
	}
});


//start itemlist popup with quick view link - itemlist page
/*jQuery(document).ready(function() {
	$(".productContainer").each(function() { $(this).simpletip($(this).find(".quickviewPopup").html(), {
		hook: { target: 'bottomRight', tooltip: 'bottomRight' },
		offset: [-20, -110],
		width: 147,
		hideOthers: true,
		hideAfter: 2000,
		hideOn: false,
		showEffect: 'slide',
		hideEffect: 'slide',
		border: { size: 3, color: '#7425B7' },
		contentClass: 'tooltipContent'
		});
		});
});

//start quick view modal window - itemlist page
jQuery(document).ready(function() {
	$(".openFancy").fancybox({
		'zoomSpeedIn':	0, 
		'zoomSpeedOut':	0, 
		'overlayShow':	true,
		'overlayOpacity': 0.7,
		'frameWidth': 624,
		'frameHeight': 395
	});
});*/

//start related items carousel - product detail page
jQuery(document).ready(function() {
	if ( $("div.scrollableRelated").length > 0 ) {
	
	$("div.scrollableRelated").scrollable({
		size: 12,
		clickable: false,
		speed: 400
	});
	}
});

//start related items popups - product detail page
jQuery(document).ready(function() {
	$(".relatedProdBox").each(function() { $(this).simpletip($(this).find(".additionalInfo").html(), {
		hook: { target: 'topMiddle', tooltip: 'bottomMiddle' },
		offset: [0, 20],
		width: 135,
		delay: 300,
		showEffect: 'slide',
		hideEffect: 'slide',
		border: { size: 2, color: '#7F7F7F' },
		contentClass: 'tooltipContentRelated'
		});
		});
});

//start recent items popups - product detail page
jQuery(document).ready(function() {
	$(".recentProdBox").each(function() { $(this).simpletip($(this).find(".additionalInfo").html(), {
		hook: { target: 'topMiddle', tooltip: 'bottomMiddle' },
		offset: [0, 20],
		width: 135,
		delay: 300,
		showEffect: 'slide',
		hideEffect: 'slide',
		border: { size: 2, color: '#7F7F7F' },
		contentClass: 'tooltipContentRelated'
		});
		});
});


//main product image zoom - using Licensed Magic Zoom - product detail page - product2.html
jQuery(document).ready(function() {
	$("#zoomTrigger").click(function() {
		$(".offerBadgeDetail").fadeOut("slow");
		$(this).hide();
		$("#zoomControl").removeClass("zoomIsOff");
		return false;
	});
	
	$("a[rel*=productZoomGate]").click(function() {
		$("#zoomTrigger").show();
		$("#zoomControl").addClass("zoomIsOff");
		$(".offerBadgeDetail").show();
	});
	
	$("#zoomControl").click(function() {
		$("#zoomTrigger").show();
		$(this).addClass("zoomIsOff");
		$(".offerBadgeDetail").show();
	});
});

//signup for email alerts - product detail page
jQuery(document).ready(function() {
	
	if ( $(".alertSignupText").length > 0 ) {
		
		$(".alertSignup").attr("id", "alertSignupPopup");
		$("#alertSignupPopup").hide();
		$(".alertSignupText").click(function() {
			$("#alertSignupPopup").slideDown();
		});
		$("#alertSignupPopup").find('.close').click(function() {
			$("#alertSignupPopup").slideUp();
		});
	}
});

//product detail page brands alert signup input focus / blur
jQuery(document).ready(function() {
	if ( $("#alertSignupField").length > 0 ) {

		$('#alertSignupField').focus(function() {
			if($(this).val()=="Your email address...") {
				$(this).attr("value","");
			}
		});
		$('#alertSignupField').blur(function() {
			if($(this).val()=="") {
				$(this).val("Your email address...");
			}
		});
	}
});

//product detail page brands alert signup input focus / blur
jQuery(document).ready(function() {
	if ( $("#alertSignupFieldSoldOut").length > 0 ) {

		$('#alertSignupFieldSoldOut').focus(function() {
			if($(this).val()=="Your email address...") {
				$(this).attr("value","");
			}
		});
		$('#alertSignupFieldSoldOut').blur(function() {
			if($(this).val()=="") {
				$(this).val("Your email address...");
			}
		});
	}
});

//Start product details tabs - product detail page
jQuery(document).ready(function() {
		if ( $("#productTabs").length > 0 ) {
		$("#productTabs").tabs();
		}
});

//Start complete the look popups - product detail page
jQuery(document).ready(function() {
	$(".completeTheLookBox").each(function() { 								   
		$(this).simpletip($(this).find(".additionalInfo").html(), {
		hook: { target: 'bottomLeft', tooltip: 'topLeft' },
		offset: [40, -10],
		width: 135,
		delay: 300,
		showEffect: 'slide',
		hideEffect: 'slide',
		border: { size: 2, color: '#7F7F7F' },
		contentClass: 'tooltipContentRelated'
		});
	});
});

//Open tab from remote link - product detail page
jQuery(document).ready(function() {
	
	if ( $("#openDeliveryInfo").length > 0 ) {
		
		$("#openDeliveryInfo").each(function() { 								   
		$(this).simpletip($(this).find(".additionalDeliveryInfo").html(), {
		hook: { target: 'topLeft', tooltip: 'bottomLeft' },
		offset: [-13, -2],
		width: 230,
		delay: 300,
		showEffect: 'slide',
		hideEffect: 'slide',
		border: { size: 2, color: '#7F7F7F' },
		contentClass: 'tooltipContentDeliveryInfo'
		});
	});
	}
});

//Forward to a friend - product detail page
jQuery(document).ready(function() {
	
	if ( $("#friendForwardLink").length > 0 ) {

		$("#friendForwardPopup").hide();
		$("#friendForwardLink").click(function() {
			$("#friendForwardPopup").fadeIn();
			$('#yourMessage').val("I love this!");
		});
		$("#friendForwardPopup").find('span.close').click(function() {
			$("#friendForwardPopup").fadeOut();
		});

	}
});

//Start you may also like popups - basket page
jQuery(document).ready(function() {
	$(".upsellItemsBox").each(function() { 								   
		$(this).simpletip($(this).find(".additionalInfo").html(), {
		hook: { target: 'topLeft', tooltip: 'bottomLeft' },
		offset: [60, 30],
		width: 135,
		delay: 300,
		showEffect: 'slide',
		hideEffect: 'slide',
		border: { size: 2, color: '#7F7F7F' },
		contentClass: 'tooltipContentRelated'
		});
	});
});

//modal window - buttons - My account page
jQuery(document).ready(function() {
	$(".sectionButton,#orderHistoryTable a").fancybox({
		'zoomSpeedIn':	0, 
		'zoomSpeedOut':	0, 
		'overlayShow':	true,
		'overlayOpacity': 0.7,
		'frameWidth': 430,
		'frameHeight': 280
	});
});

//modal window - ORDER DETAILS - My account page
jQuery(document).ready(function() {
	$("#orderHistoryTable a").fancybox({
		'zoomSpeedIn':	0, 
		'zoomSpeedOut':	0, 
		'overlayShow':	true,
		'overlayOpacity': 0.7,
		'frameWidth': 520,
		'frameHeight': 480
	});
});

//modal window - EDIT LOGIN DETAILS - My account page
jQuery(document).ready(function() {
	$("#editLogin").fancybox({
		'zoomSpeedIn':	0, 
		'zoomSpeedOut':	0, 
		'overlayShow':	true,
		'overlayOpacity': 0.7,
		'frameWidth': 430,
		'frameHeight': 280
	});
});

//modal window - EDIT CONTACT DETAILS - My account page
jQuery(document).ready(function() {
	$("#editContact").fancybox({
		'zoomSpeedIn':	0, 
		'zoomSpeedOut':	0, 
		'overlayShow':	true,
		'overlayOpacity': 0.7,
		'frameWidth': 430,
		'frameHeight': 340
	});
});

//modal window - EDIT BILLING ADDRESS - My account page
jQuery(document).ready(function() {
	$("#editBilling").fancybox({ 
		'zoomSpeedIn':	0, 
		'zoomSpeedOut':	0, 
		'overlayShow':	true,
		'overlayOpacity': 0.7,
	    'itemCloseCallback' : refreshBillingAddress,
	    'frameWidth': 430,
		'frameHeight': 320
	});	
});

//modal window - EDIT DELIVERY ADDRESS - My account page
jQuery(document).ready(function() {
	$("#editDelivery").fancybox({
		'zoomSpeedIn':	0, 
		'zoomSpeedOut':	0, 
		'overlayShow':	true,
		'overlayOpacity': 0.7,
		'frameWidth': 430,
		'frameHeight': 450
	});
});

//modal window - EDIT CONTACT PREFERENCES - My account page
jQuery(document).ready(function() {
	$("#editContactPreferences").fancybox({
		'zoomSpeedIn':	0, 
		'zoomSpeedOut':	0, 
		'overlayShow':	true,
		'overlayOpacity': 0.7,
		'frameWidth': 430,
		'frameHeight': 180
	});
});


//order history table - hide extra rows
jQuery(document).ready(function() {
	$("#orderHistoryTable .hiddenRow").hide();
	$("#seeAllOrders").click(function() {
		$("#orderHistoryTable .hiddenRow").fadeIn("slow");
		$(this).hide();
	});
});

//Delivery more info - checkout page
jQuery(document).ready(function() {
	$(".deliveryInfo").each(function() { 								   
		$(this).simpletip($(this).find(".moreDeliveryInfo").html(), {
		hook: { target: 'topLeft', tooltip: 'bottomLeft' },
		offset: [-30, -5],
		width: 200,
		delay: 300,
		showEffect: 'slide',
		hideEffect: 'slide',
		border: { size: 2, color: '#7F7F7F' },
		contentClass: 'tooltipContentDeliveryOptions'
		});
	});
});

//Card more info - checkout page
jQuery(document).ready(function() {
	
	if ( $(".helpIcon").length > 0 ) {
	
	$(".helpIcon").each(function() { 								   
		$(this).simpletip($(this).find(".moreCardInfo").html(), {
		hook: { target: 'topLeft', tooltip: 'bottomLeft' },
		offset: [-30, -5],
		width: 230,
		delay: 300,
		showEffect: 'slide',
		hideEffect: 'slide',
		border: { size: 2, color: '#7F7F7F' },
		contentClass: 'tooltipContentDeliveryOptions'
		});
	});
	$('.tooltipContentDeliveryOptions').bgiframe();
	}
});

//modal window - buttons - Checkout Page
jQuery(document).ready(function() {
	$("#deliveryAddressOptions a").fancybox({
		'zoomSpeedIn':	0, 
		'zoomSpeedOut':	0, 
		'overlayShow':	true,
		'overlayOpacity': 0.7,
		'frameWidth': 430,
        'frameHeight': 650
	});
});

//modal window - terms and conditions link - Checkout Page
jQuery(document).ready(function() {
	$('#termsCheckoutLink').fancybox({
		'zoomSpeedIn':	0, 
		'zoomSpeedOut':	0, 
		'overlayShow':	true,
		'overlayOpacity': 0.7,
		'frameWidth': 800,
		'frameHeight': 500
	});
});

//print button - order confirmation page
jQuery(document).ready(function() {
	
	if ( $("#printReceipt").length > 0 ) {
	
	$("#printReceipt").show();
	$("#printReceipt").click(function() {
		window.print();							  
	});
	
	}
});

//faq menu toggle - show/hide sublinks
jQuery(document).ready(function() {
	
	if ( $("#leftMenuCMS h3#tab3").length > 0 ) {
	
	$("#tab3").next().hide();
	$(".selected").next().show();
	
	$("#tab3").click(function() {
    	$(this).next().slideToggle('slow');
  	});

	}
});

//faq slide toggle
jQuery(document).ready(function() {
	
	if ( $("#faqList").length > 0 ) {
	
	$("#faqList dd").hide();
	$("#faqList dt").click(function() {
    	$(this).next().fadeToggle('slow');
		$(this).toggleClass("activeFaqTitle");
  	});

	}
});


//columnizer - brands page
jQuery(document).ready(function() {
	
	if ( $("#brandList").length > 0 ) {
	
	//jquery scroll
	$("#mainContentFullWidth").localScroll();
	//columnize content
	/*$("#brandList").columns({
		columns: 3
	});*/
	$(".brandListContainer").addClass("dontsplit");
	$("#brandList").columnize({
	    columns: 3
	});
	
	//hightlight selected container
	$("#brandListNavigation a").click(function() {
		
		var idname = $(this).attr("href");
		$(idname).parent().animate({backgroundColor: "#e6d3f1"}, 700);
		$(idname).parent().animate({backgroundColor: "#fff"}, 2000);
	});

	}
});

//start calendar carousel - sale preview page
jQuery(document).ready(function() {
	if ( $("div.scrollableCalendarContainer").length > 0 ) {
	
	//run scrollable calendar
	$("div.scrollableCalendarContainer").scrollable({
		vertical: true,
		size: 3,
		clickable: false,
		speed: 600,
		prev: ".calendarUp",
		next: ".calendarDown",
		disabledClass: "calendarDisabled"
	});
	//set initial row
	$("div.scrollableCalendarContainer").scrollable().seekTo(2);
	
	//run fancy box
	$(".saleSignupLink,#salePreviewSignupLink").fancybox({
		'zoomSpeedIn':	0, 
		'zoomSpeedOut':	0, 
		'overlayShow':	true,
		'overlayOpacity': 0.7,
		'frameWidth': 750,
		'frameHeight': 300
	});
	
	}
});

//start just arrived cycle - sale preview page
jQuery(document).ready(function() {
	if ( $("div.cycleJustArrivedContainer").length > 0 ) {

	$('.cycleJustArrivedContainer').cycle({ 
		fx:     'scrollHorz', 
		timeout: 6600,
		speed: 1600,
		pause: 1,
		height: 108,
		width: 319,
		next:   '.justArrivedNext', 
    	prev:   '.justArrivedPrev' 
	});
	
	}
});

//zebra table - feefo page
jQuery(document).ready(function() {
	if ( $("#feefoPage").length > 0 ) {
	$("#feefoFeedTable tr:even").addClass("darker"); 
	}
}); 




function externalLinks() {
  if (!document.getElementsByTagName && document.getElementById) return;

  var anchors = document.getElementsByTagName("a");

  for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
       anchor.target = "_blank";
 }
}
window.onload = externalLinks;