/**

 */

var de=document.documentElement;if(de){de.className+=" js";}

if (typeof console == "undefined" || typeof console.log == "undefined") {
	var console = { log: function() { return false; } };
}

var FS = (function() {
	var FS = {},
			document = window.document,
			location = window.location,
			cartHeight = -1,
			accountHeight = 110,
			isAccountDropdownAnimated = false,
			timeout,
			isDropdownAnimated = false;

	FS.langId = 10;
	FS.catalogId = 24505;
	FS.storeId = 36081;
	FS.langPath = 'en_GB';
	FS.hostName = location.hostname;
	FS.isNonCommerce = true;
	FS.isLocal = (location.hostname.match(/(fossil\.local|192\.168|172\.30|127\.|assetstore-stage.fossil.com)/));
	FS.zipMinLength = 4;
	FS.form = {
			'submitted': ''
	};

	FS.respond = {
		menuShown: 1, // Boolean value
		pageOffset: 0,
		currentThreshold: null,
		secondaryContentHeight: 0,
		smallContent: false,
		pinned: false,
		leftNavWidth: function() {
			return (this.currentThreshold <= 1) ? 142 : 168;
		},
		adaptCallback: function(i, width) {
			FS.respond.currentThreshold = i;

			var html = document.documentElement;
			html.className = html.className.replace(/(\s+)?threshold\d/g, '');

			if (i > -1) {
				html.className += ' threshold' + i;
			}
		}
	};

	FS.miniCart = {
		bagEmpty: true,
		cartHeight: function(height) {
			return (typeof height === "undefined") ? cartHeight : cartHeight = height;
		},
		numCartImages: 1,
		imagesLoaded: 0
	};

	FS.scene7 = {
		hostAssigned: ("https:" == location.protocol) ? "https://a248.e.akamai.net/f/248/9086/1.ccd/s7diod-isorigin.scene7.com/" : "http://s7d2.scene7.com/",
		imgPath: 'fossilResponsive',
		recipeMiniTh: "$fossil_recommended$",
		sjCallbacks: new Array()
	};

	/**
	  @param {Object} settings Object containing four keys buttonName, buttonClass, buttonId, and buttonLabel.
	 */
	FS.button = function(settings) {
		return '<button name="'+settings.buttonName+'" class="'+settings.buttonClass+'" id="'+settings.buttonId+'"><span class="buttonLeft"><span class="buttonRight"><span class="buttonContent">'+settings.buttonLabel+'</span></span></span></button>';
	};

	/**
	  @param {Object} params Object of key/value pairs to transform into a querystring for URL's.
	  @param {Boolean} includeDefaults Flag to include default parameters (storeId, langId, catalogId) defaults to true.
	 */
	FS.params = function(params, includeDefaults) {
		params = (typeof params === "undefined") ? {} : params;
		includeDefaults = (typeof includeDefaults === "undefined") ? true : includeDefaults;

		var defaults = {storeId: this.storeId, catalogId: this.catalogId, langId: this.langId};
		var data = includeDefaults ? $.extend(defaults, params) : params;

		return $.param(data);
	};

	FS.accountSlideDown = function() {
		var cartDropdown = $('#cartDropdown');
		var cartButton = $('#cartButton');
		var accountDropdown = $('#accountDropdown');
		var accountDropdownContent = $('#accountDropdownContent');
		var accountButton = $('#accountButton');

		if (isDropdownAnimated) {
			cartDropdown.css('visibility', 'hidden').hide();
			cartButton.removeClass('showBag');
			isDropdownAnimated = false;
			cartDropdown.stop().clearQueue();
		}

		if (!isAccountDropdownAnimated) {
			isAccountDropdownAnimated = true;

			//swap style
			accountDropdown.css('visibility', 'visible');
			accountButton.addClass('showBag');
			accountDropdownContent.css('height', (accountHeight-20));
			accountDropdown.show().animate({height: accountHeight},200);
		}
		else {
			var newTime = 200 * ((accountHeight-accountDropdown.height())/ accountHeight);
			accountDropdown.stop().clearQueue().animate({height: accountHeight},newTime);
		}
	};

	FS.accountSlideUp = function() {
		var accountDropdown = $('#accountDropdown');
		var accountButton = $('#accountButton');

		accountDropdown.animate({height: 0}, 300, function() {
			//swap style
			accountButton.removeClass('showBag');
			isAccountDropdownAnimated = false;
			accountDropdown.hide();
		});
	};

	FS.slideDown = function() {
		var cartDropdown = $('#cartDropdown');
		var cartButton = $('#cartButton');
		var accountDropdown = $('#accountDropdown');
		var accountButton = $('#accountButton');

		if (isAccountDropdownAnimated) {
			accountDropdown.css('visibility', 'hidden');
			accountButton.removeClass('showBag');
			isAccountDropdownAnimated = false;
		}

		if (!isDropdownAnimated) {
			isDropdownAnimated = true;
			//Only calculate height on first hover. Delayed calculation because Safari does not return proper image height immediately after ajax loads.
			//This is now used as a redundancy only! cart Height should be calculated on AJAX Success
			if (cartHeight == -1 ) {
				cartHeight = cartDropdown.height();
			}

			//swap style
			cartDropdown.css('visibility', 'visible').show();

			cartButton.addClass('showBag');
			cartDropdown.height(0).animate({height: cartHeight},300);
		}
		else {
			var newTime = 300 * ((cartHeight-cartDropdown.height())/ cartHeight);
			cartDropdown.stop().clearQueue().animate({height: cartHeight}, newTime);
		}
	};

	FS.slideUp = function() {
		var cartDropdown = $('#cartDropdown');
		var cartButton = $('#cartButton');

		cartDropdown.animate({height: 0},300,
			function() {
				cartDropdown.hide();
				//swap style
				cartButton.removeClass('showBag');
				isDropdownAnimated = false;
			}
		);
	};

	FS.htmlEncode = function(value) {
		return $('<div/>').text(value).html();
	};

	FS.htmlDecode = function(value) {
		return $('<div/>').html(value).text();
	};



	/**
		Localized validation rules. These are merged in and overwrite the default rules when FSvalidate runs.
	 */
	FS.validationRules = {
		phone: function(obj, message) {
			var phone = $(obj).val().replace(/\s/g, "");
			phone = phone.replace(/[^0-9]/g, "");
			var filter = new RegExp(/\d{10,}/);
			if(!phone.match(filter)){
				$(obj).data('errorMessage', message);
				return false;
			}
			return true;
		}
	};

	FS.queryString = function(qs) {
		this.params = {};

		if (qs == null) {
			qs = document.location.search.substring(1, document.location.search.length);
		}
		if (qs.length == 0) {
			return;
		}

		// Turn <plus> back to <space>
		// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
		qs = qs.replace(/\+/g, ' ');
		var args = qs.split('&'); // parse out name/value pairs separated via &

		// split out each name=value pair
		for (var i = 0; i < args.length; i++) {
			var pair = args[i].split('=');
			var name = decodeURIComponent(pair[0]);

			var value = (pair.length==2) ? decodeURIComponent(pair[1]) : name;
			this.params[name] = value;
		}
	}
	
	FS.getStyleSheet = function(sheetTitle) {
		for(var i=0; i<document.styleSheets.length; i++) {
			var sheet = document.styleSheets[i];
			if(sheet.title == sheetTitle) {
				return sheet;
			}
		}
	}
	
	FS.queryString.prototype.get = function(key, default_) {
		var value = this.params[key];
		return (value != null) ? value : default_;
	}

	FS.queryString.prototype.contains = function(key) {
		var value = this.params[key];
		return (value != null);
	}

	FS.local_lang = {
		labels: {
			editItem: 'Edit Item',
			close: 'Close',
			promoCodes: 'PROMOTIONAL CODES',
			havePromo: 'Have a promo code?',
			shippingMethod: 'SHIPPING METHOD',
			searchKeywordItem: 'search by keyword or style #',
			storeLocator: 'Store Locator',
			catalog: 'Catalog',
			signupThankYou: 'Thank you for signing up',
			giftWithPurchase: 'Free Gift with Purchase',
			specialOffers: 'Special Offers Details',
			sizeChartFitGuide: 'Size chart',
			watchInstructions: 'Watch Instructions',
			emailAFriend: 'Email a Friend',
			mustHaves: 'Must Haves',
			freeStandard: 'FREE on orders over £100',
			freeTwoDay: '&nbsp;',
			freeOverNight: '&nbsp',
			personSentYouWishlist: 'has sent you a fossil.com wish list.',
			viewMyList: 'Take a look at my fossil.com wish list!',
			privacyPolicy: 'Privacy Policy',
			termsConditions: 'Terms and Conditions',
			giftCardBalance: 'Check Gift Card Balance',
			whatIsPaypal: 'What is PayPal',
			securityNotice: 'Kartenpr&uuml;fnummer',
			yearPlaceholder: 'YYYY',
			monthPlaceholder: 'MM',
			dayPlaceholder: 'DD',
			TOCmodal: 'TERMS AND CONDITIONS',
			SPmodal: 'SECURITY & PRIVACY',
			shoppingBagTitle: 'Shopping Cart',
			currencyMarker: '$&nbsp;',
			decimalDelimiter: '.',
			color: 'Colour',
			size: 'Size',
			length: 'Length',
			waist: 'Waist',
			itemOutOfStock: 'This item is currently out of stock.',
			productsSelectedPlural: 'Products Selected',
			productsSelectedSingular: 'Product Selected',
			zoomIn: 'Zoom In',
			zoomOut: 'Zoom Out',
			pageLabel: 'Page',
			subcatColorOpt: 'More Colours',
			chooseAddress: 'Choose Saved Address'
		},
		errors: {
			giftCardValue: "Please select a gift card denomination",
			newPassword: 'An error occurred because the new password and password confirmation does not match; please re-submit a matching password in both fields.',
			passwordSameChars: 'A character in your password occurs more than the allowed limit of 4. Please re-enter your password.',
			passwordConsecutiveChars: 'A character in your password occurs more consecutively than the allowed limit of 3. Please re-enter your password.',
			passwordFormat: 'Passwords need to be at least 7 characters long and include both a number and letter to be valid. Please try again.',
			messageFormat: 'Please limit your message to 150 characters',
			giftCardMessageFormat: 'Please limit your message to 500 characters',
			required: 'This field is required.', /* errMapMsg_0, errMapMsg_2 */
			validEmail: 'Please enter a valid email address', /* errMapMsg_1, errMapMsg_14, errMapMsg_30, errMapMsg_41, errMapMsg_43 */
			emailNotFound: 'Email Not Found', /* errMapMsg_3 */
			validPassword: 'Please enter a valid password', /* errMapMsg_4, errMapMsg_33 */
			passwordMatch: 'Passwords entered do not match', /* errMapMsg_5 */
			validAddress: 'Please enter valid address', /* errMapMsg_6 */
			firstNameEmpty: 'Please enter your first name.', /* errMapMsg_7, errMapMsg_31 */
			lastNameEmpty: 'Please enter your last name.', /* errMapMsg_8, errMapMsg_32 */
			addressEmpty: 'Please enter your address.', /* errMapMsg_9 */
			streetEmpty: 'Please enter your street',
			houseNumberEmpty: 'Please enter your house number.',
			cityEmpty: 'Please enter your city.', /* errMapMsg_10 */
			stateEmpty: 'Please enter a County.', /* errMapMsg_11, errMapMsg_16 */
			validZipcode: 'Please enter a valid postcode.', /* errMapMsg_12 */
			validPhoneNumber: 'Please enter a valid phone number.', /* errMapMsg_13, errMapMsg_15 */
			validGCNum: 'The gift card number provided is not valid, please check the number and try again.', /* errMapMsg_17 */
			validSecurityCode: 'The security code provided is not valid, please check the number and try again.', /* errMapMsg_18 */
			validCCNum: 'Please enter a valid credit card number.', /* errMapMsg_19, errMapMsg_25 */
			noCVC: 'Please enter a credit card security code.', /* errMapMsg_20, errMapMsg_26 */
			validCCExpMonth: 'Please select a valid credit card expiration month.', /* errMapMsg_21 */
			validCCExpYear: 'Please select a valid credit card expiration year.', /* errMapMsg_22 */
			validCCExpDate: 'Please select a valid credit card expiration date.', /* errMapMsg_23 */
			selectCardType: 'Please select a credit card type.', /* errMapMsg_24 */
			noSearchTerm: 'Please enter a keyword or item number.', /* errMapMsg_28 */
			minThreeChar: 'Please enter at least three characters.', /* errMapMsg_29 */
			validPassConf: 'Please enter a valid password confirmation.', /* errMapMsg_34, errMapMsg_38 */
			enterEmail: 'Please enter an email address.', /* errMapMsg_37, errMapMsg_40 */
			validCityStateOrZip: 'Please enter a valid city and state OR postcode.', /* errMapMsg_39 */
			enterMonthOfBirth: 'Please enter your month of birth', /* errMapMsg_47 */
			enterDateOfBirth: 'Please enter your date of birth', /* errMapMsg_48 */
			enterYearOfBirth: 'Please enter your year of birth', /* errMapMsg_49 */
			validDate: 'Please enter a month.',
			lastFourSSN: 'Please enter the last 4 digits of your Social Security Code', /* errMapMsg_50 */
			billMeLaterTOC: 'We cannot complete your transaction until you agree to the electronic presentation of the Bill Me Later Terms and Conditions', /* errMapMsg_51 */
			validPromoCode:  'The promotion code entered is invalid. Please check the code and try again.',
			enterValidPromoCode: 'Invalid Promotion Code',
			promoCodeAlreadyUsed: 'has been entered twice',
			bundleSelectOneItem: 'Please select at least one product from this bundle',
			pleaseSelectLabel: 'Please select a ',
			genericWishlistError: 'There is an error with Wishlist, please try again at a later time.',
			selectColor: 'Please select a colour',
			selectLength: 'Please select a length',
			addItemsWishlistEmail: 'Please add some items to your wishlist before emailing it.',
			addItemsWishlistShare: 'Please add some items to your wishlist before sharing it.',
			nameWishlist: 'Please enter a name for your wish list.',
			wishlistNetworkError: 'There was a network or server error processing your request or your session timed out. Please try again.',
			searchMinimumChars: 'Please enter at least 3 characters.',
			termsAgreeUnchecked: 'Required to agree to terms'
		}
	}
	return FS;
}());

// Edit to suit your needs.
var ADAPT_CONFIG = {
	dynamic: true,
	callback: FS.respond.adaptCallback,
	range: [
		'0 to 1000',
		'1000 to 1300',
		'1300 to 1500',
		'1500'
	]
};

var WebFontConfig = {
	custom: { families: ['ArialNarrow', 'TradeGothicBoldCond', 'TradeGothicLTCond', 'HelveticaNeueLight', 'HelveticaNeueBoldCond'],
	urls: [ '/wcsstore/CommonFossil/css/shell/minified/fonts.css' ] }
};

