// client.js
var pathN=location.href;var countryISO="GB";if($.cookie('country_iso').length>0){countryISO=$.cookie('country_iso')}function getUrlVars(){var vars=[],hash;var hashes=window.location.href.slice(window.location.href.indexOf('?')+1).split('&');for(var i=0;i<hashes.length;i++){hash=hashes[i].split('=');vars.push(hash[0]);vars[hash[0]]=hash[1]}return vars}function Left(str,n){if(n<=0)return"";else if(n>String(str).length)return str;else return String(str).substring(0,n)}function Right(str,n){if(n<=0)return"";else if(n>String(str).length)return str;else{var iLen=String(str).length;return String(str).substring(iLen,iLen-n)}}function MM_swapImgRestore(){var i,x,a=document.MM_sr;for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++)x.src=x.oSrc}function MM_preloadImages(){var d=document;if(d.images){if(!d.MM_p)d.MM_p=new Array();var i,j=d.MM_p.length,a=MM_preloadImages.arguments;for(i=0;i<a.length;i++)if(a[i].indexOf("#")!=0){d.MM_p[j]=new Image;d.MM_p[j++].src=a[i]}}}function MM_findObj(n,d){var p,i,x;if(!d)d=document;if((p=n.indexOf("?"))>0&&parent.frames.length){d=parent.frames[n.substring(p+1)].document;n=n.substring(0,p)}if(!(x=d[n])&&d.all)x=d.all[n];for(i=0;!x&&i<d.forms.length;i++)x=d.forms[i][n];for(i=0;!x&&d.layers&&i<d.layers.length;i++)x=MM_findObj(n,d.layers[i].document);if(!x&&d.getElementById)x=d.getElementById(n);return x}function MM_swapImage(){var i,j=0,x,a=MM_swapImage.arguments;document.MM_sr=new Array;for(i=0;i<(a.length-2);i+=3)if((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x;if(!x.oSrc)x.oSrc=x.src;x.src=a[i+2]}}
// iphone.js
function checkCookie(){cookiename=getCookie('oasisiPhone');isiPhone=checkifiPhone();if(isiPhone=='FALSE'){return}else if((cookiename==null)&&(isiPhone=='TRUE')){window.location="/pws/client/iPhone/OasisiPhoneHome.html"}else{return}}function setCookie(c_name,value,expiredays){var exdate=new Date();exdate.setDate(exdate.getDate()+expiredays);document.cookie=c_name+"="+escape(value)+((expiredays==null)?"":";expires="+exdate.toUTCString())}function getCookie(c_name){if(document.cookie.length>0){c_start=document.cookie.indexOf(c_name+"=");if(c_start!=-1){c_start=c_start+c_name.length+1;c_end=document.cookie.indexOf(";",c_start);if(c_end==-1)c_end=document.cookie.length;return unescape(document.cookie.substring(c_start,c_end))}}return""}function checkifiPhone(){var isiPhone;if((navigator.userAgent.match(/iPhone/i))||(navigator.userAgent.match(/iPod/i))){isiPhone='TRUE'}else{isiPhone='FALSE'}return isiPhone}
// newletter.js
function OnSubmitForm(formname){document.forms[formname].thx.value=document.forms[formname].thx.value+'?emailID='+document.forms[formname].elements["Email Address"].value;return true}function checkEmail(){if((document.forms["subscribeForm"].elements["Email Address"].value=="Enter your email address")||(document.forms["subscribeForm"].elements["Email Address"].value=="")){document.forms["subscribeForm"].elements["Email Address"].value="";document.forms["subscribeForm"].elements["Email Address"].focus()}else{OnSubmitForm('subscribeForm');document.forms["subscribeForm"].submit()}}

$(document).ready(function(){
	$('#headerLinkStoreFinder').attr('href','http://www.oasis-stores.com/fcp/content/store_locator/information');
	//XMASS NAV	
	$('#topNavCategories_dept_Christmas_Landing .level1Link').attr('href', 'http://www.oasis-stores.com/fcp/content/christmas-shop/information');
	$('#dept_Winter_Warmers').after('<li id="advent-calendar" class="level2Category" style="width: 135px"><a href="/fcp/content/advent-calendar/information" title="Advent Calendar" class="level2Link">Advent Calendar</a></li>');
	
	if ($('.basketPage').length > 0) { 
		$("input.deliveryType").click(function(){ 
		  $(this).parents("form").submit(); 
		}); 
	}
	
	//model image priority
	if(pathN.search('/True_Decadence|Max_C|Fever|20_20|Yumi|/i') != -1){
		$('.productImg').each(function(){
			$(this).attr('src', $(this).attr('src').replace('.jpg', '_1.jpg'));
		});
		$(".productImg").mouseover(function() {
				$(this).attr('src', $(this).attr('src').replace('_1.jpg', '.jpg'));
			}).mouseout(function() {
				$(this).attr('src', $(this).attr('src').replace('.jpg', '_1.jpg'));
			});		
	}

	$('#reserveAndCollectLink').insertAfter('.goToCheckout');
	$('div.topNavCategoriesLevel2').prepend('<span class="subNavArrowFix"></span>');
	$('a#priceDesc').text('High to low');
	$('a#priceAsc').text('Low to high');
	$('a#view_3,a#view_4,a#view_5').attr('title','Click to change viewing format');
	
	$('div#productOptions').append('<div id="highLowPrices"><select id="highLow"><option><span>Sort by Price:</span></option><option class="class1"><span >High</span></option><option class="class2"><span >Low</span></option></div>');
	
	$('#highLow').change(function(){	
	if ($('#highLow').val() == 'High'){
		
		$('a#priceDesc').trigger('click');
	}
	if ($('#highLow').val() == 'Low'){
		$('a#priceAsc').trigger('click');
	}	
	});
	

	$('li#fAVAILABLE_SIZE ul li:nth-child(6)').appendTo('#fAVAILABLE_SIZE ul');
	$('li#fAVAILABLE_SIZE ul li:nth-child(2)').appendTo('#fAVAILABLE_SIZE ul');
	$('li#fAVAILABLE_SIZE ul li:nth-child(2)').appendTo('#fAVAILABLE_SIZE ul');
	$('li#fAVAILABLE_SIZE ul li:nth-child(2)').appendTo('#fAVAILABLE_SIZE ul');
	$('li#fAVAILABLE_SIZE ul li:nth-child(1)').appendTo('#fAVAILABLE_SIZE ul');
	$('li#fAVAILABLE_SIZE ul li:nth-child(1)').appendTo('#fAVAILABLE_SIZE ul');
	
	///pws/RegisterProspect.ice
	$('form#footerNewsForm').replaceWith('<form action="http://aurora.ed4.net/dualpost/index.cfm" method="post" id="footerNewsForm"><fieldset class="formWrapper"><input type="hidden" name="action" value="signup"><input type="hidden" name="brand" value="OASIS"><input type="hidden" name="redirect" value="http://www.oasis-stores.com/fcp/content/Newsletter/information"><input name="email" title="Please enter your email address" value="SIGN UP FOR NEWSLETTER" maxlength="128" class="headerFormInput clearValue" id="emailNewsletter" /><input type="submit" value="" class="submitBtn headerFormSubmit" /></fieldset></form>');
	
	var Input = $('input[name=email]');
	var default_value = Input.val();
	Input.focus(function() {
		if(Input.val() == default_value) Input.val("");
	}).blur(function(){
		if(Input.val().length == 0) Input.val(default_value);
	});
	
	var browser = navigator.userAgent;
	if (browser.toLowerCase().indexOf('safari') > 0)
	{
	if(navigator.userAgent.indexOf('Mac') != -1){
		var divArray = document.getElementById('footer');
	divArray.style.position = 'relative';
	}
	}
	
	//temp rollovers
	$('#submitPromo').hover(function() { $(this).attr('src', '/pws/client/images/btn_ApplyPromotion_1.gif') }, function() { $(this).attr('src', '/pws/images/btn_ApplyPromotion.gif') });
	$('a.continueShopping img').hover(function() { $(this).attr('src', '/pws/client/images/btn_ContinueShopping_1.jpg') }, function() { $(this).attr('src', '/pws/client/images/buttons/btn_ContinueShopping_0.jpg') });
	$('a.goToCheckout img').hover(function() { $(this).attr('src', '/pws/client/images/btn_GoToCheckout_1.gif') }, function() { $(this).attr('src', '/pws/images/btn_GoToCheckout.gif') });
	$('a#storeReturn img').hover(function() { $(this).attr('src', '/pws/client/images/bt_return_to_bag_1.gif') }, function() { $(this).attr('src', '/pws/images/bt_return_to_bag.gif') });
	$('button#storeSelectReserve img').hover(function() { $(this).attr('src', '/pws/client/images/bt_reserve_order_1.gif') }, function() { $(this).attr('src', '/pws/images/bt_reserve_order.gif') });
	$('input#createAddressBtn').hover(function() { $(this).attr('src', '/pws/client/images/btn_GoToPayment_1.gif') }, function() { $(this).attr('src', '/pws/images/btn_GoToPayment.gif') });
	$('input#postcodeSearchButton').hover(function() { $(this).attr('src', '/pws/client/images/btn_SearchAddress_1.gif') }, function() { $(this).attr('src', '/pws/images/btn_SearchAddress.gif') });
	$('input#paymentButton').hover(function() { $(this).attr('src', '/pws/client/images/btn_MakePayment_1.gif') }, function() { $(this).attr('src', '/pws/images/btn_MakePayment.gif') });
	$('span#addNewAddress img').removeClass('rollover').hover(function() { $(this).attr('src', '/pws/client/images/btn_AddNewAddress_1.jpg') }, function() { $(this).attr('src', '/pws/images/btn_AddNewAddress_0.jpg') });
	$('#addToBagBtn').hover(function() { $(this).attr('src', '/pws/client/images/btn_productBag_1.jpg') }, function() { $(this).attr('src', '/pws/images/btn_productBag.jpg') });
	$('#addToBagAndCheckout img').hover(function() { $(this).attr('src', '/pws/client/images/btn_productCheckout_1.jpg') }, function() { $(this).attr('src', '/pws/images/btn_productCheckout.jpg') });  
	$('button#quickBuyAddToBag img').hover(function() { $(this).attr('src', '/pws/client/images/btn_addToBag_1.png') }, function() { $(this).attr('src', '/pws/images/btn_addToBag.png') });
	$('button#quickBuyCheckout img').hover(function() { $(this).attr('src', '/pws/client/images/btn_bagAndCheckout_1.png') }, function() { $(this).attr('src', '/pws/images/btn_bagAndCheckout.png') });
	$('#basketViewBagButton').hover(function() { $(this).attr('src', '/pws/client/images/btn_viewBag_1.png') }, function() { $(this).attr('src', '/pws/images/btn_viewBag.png') });
	$('#baskePayNowButton').hover(function() { $(this).attr('src', '/pws/client/images/btn_payNow_1.png') }, function() { $(this).attr('src', '/pws/images/btn_payNow.png') });
	$('.formFieldAlign input').removeClass('rollover').hover(function() { $(this).attr('src', '/pws/client/images/btn_Submit_1.jpg') }, function() { $(this).attr('src', '/pws/images/btn_Submit_0.jpg') });
	$('#storeFinderSubmit').hover(function() { $(this).attr('src', '/pws/client/images/btn_Search_1.jpg') }, function() { $(this).attr('src', '/pws/images/btn_Search_0.jpg') });
	//$('input.submit').hover(function() { $(this).attr('src', '/pws/client/images/btn_Login_1.gif') }, function() { $(this).attr('src', '/pws/images/btn_Login.gif') });

	//Click to zoom -> Rollover zoom [jquery-frescaZoom.js]
	$('#mainProductImageCont').unbind('click').hover(function(e){
		$('iframe#zoomFrame, div#zoomCont').show();
		$('a#closeWindow').hide();
		return false
	}, function(e) {
		$('iframe#zoomFrame, div#zoomCont, a#closeWindow').hide()
	});
	$('#clickToZoom').parent('li').css('display','none');
	
/*
	Top Navigation Cufon rollovers
*/

		Cufon.replace($('#topNavCategoriesLevel1 #topNavCategories_dept_sale a.level1Link'), {
			color: '#d01e8f'
		})	

	
	$('#topNavCategoriesLevel1 li a').hover(function(){	
		if($(this).hasClass('level1Link'))
		{
			Cufon.replace($(this), {
				color: '#ffffff'
			})
		}
		
	},function(){
		if($(this).hasClass('level1Link'))
		{	
			Cufon.replace($(this), {
				color: '#1e1e1e'
			})
		}
		if($(this).parent('#topNavCategories_dept_sale').length){
				Cufon.replace($(this), {
				color: '#d01e8f'
			})	
		}
	});


});



