	/**
	* @projectDescription Part of the core Arcadia JavaScript library - contains Methods and Properties used on the ProductDisplay view, used by all brands
	* @author Andrew Disley andrew.disley@codecomputerlove.com
	* @version 1.2.0
	* @since 1.0.0
	*/

	/* Abbreviate Brand.ProductConfig Object */
	var pc = Brand.ProductConfig;

	function ProductDisplay() {}
	ProductDisplay.prototype = {

		version: "1.2.0",

		/* Configuration, Flags and Messages */
		cMdlOpacity: pc.cMdlOpacity,
		cMdlSizeGuide: pc.cMdlSizeGuide,
		cSizeAmmount: pc.cSizeAmmount,
		cSizeGuideHide: pc.cSizeGuideHide,
		cSizeGuideURL: '/sizeguide/global_sizes.html', /* size guide URL for content-only modal version */
		cFormActionURL: '/webapp/wcs/stores/servlet/NewProductDetailsActionControl', /* URL for AJAX form POST */
		cImgLargeURL: null,
		cImgLargeURLAttr: 'scrollbars=yes,menubar=no,width=620,height=520,resizable=yes,toolbar=no,location=no,status=no,screenX=200,screenY=100,left=200,top=100',
		cImgLargeURLWindowID: 'LargeImageView',
		fFormSubmitted: null,
		mOutOfStock: pc.mOutOfStock,
		mBasket: pc.mBasket,
		mAJAXError: pc.mAJAXError,
		mAJAXH2Error: pc.mAJAXH2Error,
		mAJAXH2Success: pc.mAJAXH2Success,
		mAddingToBag: pc.mAddingToBag,
		mErrorSize: pc.mErrorSize,
		mErrorWishlist: pc.mErrorWishlist,

		/* jQuery Object References to the Elements this speeds up the DOM */
		jEOImgColumn: null,
		jEOImgLarge: null,
		jEOImgAct: null,
		jEOImgActMore: null,
		jEOProductForm: null,
		jEOProductFormSubmit: null,
		jEOHiddenSizeSelect: null,
		jEOAddToWishlist: null,
		jEODetails: null,
		jEOOverview: null,
		jEOSize: null,
		jEOSizeSelect: null,
		jEOSizeError: null,
		jEOWishlistError: null,
		jEOQuantity: null,
		jEOQuantitySelect: null,

		/* Modal Object References and Loaded Flag */
		jEOMdlWinSizeGuide: null,
		jEOMdlWinFriend: null,
		jEOMdlWinWishlist: null,
		jEOMdlWinNotify: null,
		jEOMdlASizeGuide: null,
		jEOMdlAFriend: null,
		jEOMdlAWishlist: null,
		jEOMdlANotify: null,

		jEOTabs: null,
		jEOAJAXLoader: null,
		jEOConfirmation: null,
		jEOConfirmationOverlay: null,
		jEOHeaderCart: null,

		/* Initialise */ 
		init : function() {

			/* Product Display Class Context */
			var cc = this;

			// replace currency symbol in basket header with correct store currency symbol (requires exact markup: "&pound;"
			cc.mBasket = cc.mBasket.replace('&pound;', Brand.storeCurrencySymbol);

			/* jQuery Object References */
			cc.jEOImgColumn = $('#product_display_column_1');
			cc.jEOImgLarge = $('#product_display_image_large');
			cc.jEODetails = $('#product_display_details');
			cc.jEOOverview = $('#product_display_overview');
			cc.jEOSize = $('#product_display_size');
			cc.jEOSizeSelect = $('#choosesize'); /* ID of Size Select */
			cc.jEOQuantity = $('#product_display_quantity');
			cc.jEOQuantitySelect = $('#quantity'); /* ID of Qty Select */
			// cc.jEOMerchColumn = $('#product_display_column_3'); // merch associations wrapper

			/* Modals */
			if (cc.cMdlSizeGuide) {
				/* if cc.cMdlSizeGuide is true in brand config enable Size Guide Modal */
				cc.jEOMdlWinSizeGuide = $('<div class="jqmWindow" id="product_display_modal_sizeguide"><p><img alt="Loading please wait... " src="/wcsstore/ConsumerDirectStorefrontAssetStore/images/colors/color' + Brand.directory + '/productdisplay/icon_loader.gif" /></p></div>');				
			}
			cc.jEOMdlWinFriend = $('<div class="jqmWindow" id="product_display_modal_friend"><h3>Tell a Friend</h3><p>Think your friends may be interested in this item? Why not add their name and email and we&lsquo;ll send them a message from you!</p><div class="jqmGutter"><form action="#" class="clearfix" id="friend_form" name="friend_form" method="get"><dl><dt><label for="friend_your_name"><span class="label">Your name:</span></label></dt><dd><input id="friend_your_name" name="friend_your_name" type="text" value="" /></dd><dt><label for="friend_your_email"><span class="label">Your email address:</span></label></dt><dd><input id="friend_your_email" name="friend_your_email" type="text" value="" /></dd><dt><label for="friend_friends_name"><span class="label">Friend&lsquo;s name:</span></label></dt><dd><input id="friend_friends_name" name="friend_friends_name" type="text" value="" /></dd><dt><label for="friend_friends_email"><span class="label">Friend&lsquo;s email address:</span></label></dt><dd><input id="friend_friends_email" name="friend_friends_email" type="text" value="" /></dd></dl><p class="frow-action"><input alt="Send" class="submit_button" id="friend_send" name="login_submit" src="/wcsstore/ConsumerDirectStorefrontAssetStore/images/colors/color' + Brand.directory + '/productdisplay/btn_send.gif" type="image" /></p></form><p>Don&lsquo;t worry we won&lsquo;t send personal details to any 3rd parties!</p></div><a class="jqmClose">Close Window</a></div>');
			cc.jEOMdlWinWishlist = $('<div class="jqmWindow" id="product_display_modal_wishlist"><h3>Wishlist</h3><p>Product successfully added to your wish list.</p><div class="jqmGutter" id="product_display_modal_wishlist_actions"><ul class="clearfix"><li class="replace" id="product_display_modal_wishlist_actions_wishlist"><a href="#" title="View wishlist">View wishlist</a></li><li class="replace" id="product_display_modal_wishlist_actions_checkout"><a href="#" title="Go to checkout">Go to checkout</a></li></ul></div><a class="jqmClose">Close Window</a></div>');
			cc.jEOMdlWinNotify = $('<div class="jqmWindow" id="product_display_modal_notify"><h3>Notify</h3><p>Do you want us to contact you when this product is back in stock? Drop your details in the boxes below and and we&lsquo;ll send you an email to notify you.</p><div class="jqmGutter"><form action="#" class="clearfix" id="notify_form" name="notify_form" method="get"><dl><dt><label for="notify_name"><span class="label">Your name:</span></label></dt><dd><input id="notify_name" name="notify_name" type="text" value="" /></dd><dt><label for="notify_email"><span class="label">Your email address:</span></label></dt><dd><input id="notify_email" name="notify_email" type="text" value="" /></dd></dl><p class="frow-action"><input alt="Send" class="submit_button" id="notify_send" name="login_submit" src="/wcsstore/ConsumerDirectStorefrontAssetStore/images/colors/color' + Brand.directory + '/productdisplay/btn_send.gif" type="image" /></p></form><p>Don&lsquo;t worry we won&lsquo;t send personal details to any 3rd parties!</p></div><a class="jqmClose">Close Window</a></div>');

			/* Modal anchors */
			if (cc.cMdlSizeGuide) {
				/* if cc.cMdlSizeGuide is true in brand config enable Size Guide Modal */
				cc.jEOMdlASizeGuide = $('#product_display_size_sizeguide a');
			}
			cc.jEOMdlAFriend = $('#product_display_actions_friend a');
			cc.jEOMdlAWishlist = $('#product_display_actions_wishlist a');
			cc.jEOMdlANotify = $('#product_display_actions_notify a');

			/* ID of Product Form and Submit input */
			cc.jEOProductForm = $('form#productdetailsform');
			cc.jEOProductFormSubmit = $('input#Add2ShopCart');
			cc.jEOAttributes = $('input#item0'); /* Hidden Attributes input */
			cc.jEOAddToWishlist = $("input#Add2WishList"); /* Add to wishlist input */
			cc.jEOHiddenSizeSelect = $("input[name='selectedSize']"); /* Hidden Size Select */

			/* Create AJAX Loader icon */
			cc.jEOAJAXLoader = $('<dd id="product_display_ajax_loader"><p><strong>' + cc.mAddingToBag + '</strong></p></dd>');

			/* Tabs Navigation */
			cc.jEOTabs = $('<div id="product_display_overview_tabs"><ul class="clearfix"><li class="first"><a href="#product_display_overview_info" title="Product info">Product info</a></li><li><a href="#product_display_overview_delivery" title="Delivery">Delivery</a></li><li><a href="#product_display_overview_returns" title="Returns policy">Returns policy</a></li></ul></div>');

			/* Inline Size Error */
			cc.jEOSizeError = $('<dd id="product_display_error"><p><a href="#product_display_size" id="product_display_size_error" title="' + cc.mErrorSize + '"><strong>' + cc.mErrorSize + '</strong></a></p></dd>');

			/* Inline Wishlist Size Error */
			cc.jEOWishlistError = $('<dd id="product_display_error"><p><a href="#product_display_size" id="product_display_size_error" title="' + cc.mErrorWishlist + '"><strong>' + cc.mErrorWishlist + '</strong></a></p></dd>');

			/* Create Confirmation container and hide */
			cc.jEOConfirmation = $('<div class="clearfix" id="product_display_confirmation"><h2></h2><p id="product_display_confirmation_error"></p><dl><dt>Item:</dt><dd class="product_display_confirmation_item"></dd><dt>Colour:</dt><dd class="product_display_confirmation_colour"></dd><dt>Size:</dt><dd class="product_display_confirmation_size"></dd><dt>Quantity:</dt><dd class="product_display_confirmation_quantity"></dd><dt>Price:</dt><dd class="product_display_confirmation_price">' + Brand.storeCurrencySymbol + '<strong></strong></dd></dl><p id="product_display_confirmation_bag"><span class="product_display_confirmation_items"></span> item(s) in bag<br /> Subtotal: <strong>' + Brand.storeCurrencySymbol + '</strong><strong class="product_display_confirmation_total"></strong><br /> <a href="#" title="View your bag">View your bag</a><span class="hide"> | </span><span class="replace" id="product_display_confirmation_bag_gotocheckout"><a class="rollover" href="#" title="Go to checkout">Go to checkout</a></span></p></div>');
			cc.jEOConfirmationOverlay = $('<div id="product_display_confirmation_overlay"></div>');

			cc.jEOQuantity.after(cc.jEOConfirmation);
			cc.jEOConfirmation.hide();

			/* Header Cart */
			cc.jEOHeaderCart = $('#itemsummary a');

			cc.initTabs();
			cc.initSizeSelector();
			cc.initProductForm();
			cc.initImageActions();
			cc.initModals();

		},

		/* New Window function for Large / More Image anchors */
		launchImgLargeWindow : function() {

			/* Product Display Class Context */
			var cc = this;

			return !window.open(cc.cImgLargeURL, cc.cImgLargeURLWindowID, cc.cImgLargeURLAttr);

		},

		/* Initialise Image Actions bind Events */
		initImageActions : function() {
			
			/* Product Display Class Context */
			var cc = this;

			/* Large/More Images URL */
			var itemName = $('#product_display_details_title_dd', cc.jEODetails).text();
			var itemCode = $('span.catcode', cc.jEODetails).text();
			cc.cImgLargeURL = '/webapp/wcs/stores/servlet/ProductLargerImageDisplay?langId=-1&storeId=' + Arcadia.currentStoreId + '&catalogId=' + Arcadia.currentCatalogId + '&amp;pageTitle=' + itemName + '&imageURL=%2Fwcsstore%2F' + Brand.name + '%2F%2Fimages%2Fcatalog%2F' + itemCode + '_large.jpg&amp;altText=' + itemName;

			/* 360 and Video are embedded directly into the flash only More/Zoom image configuration is here. */

			/* If hasMore parameters is true create LI and append to image actions UL */
			if (imageConfig.hasMore) {
				cc.jEOImgActMore = $('<li class="replace" id="product_display_image_actions_more"><a class="new_window" href="' + cc.cImgLargeURL + '" title="More views">More views</a></li>');
				cc.jEOImgAct = $('<div id="product_display_image_actions"><ul class="clearfix"></ul></div>'); /* Create <ul> for Image Action <li>s */
				$('ul', cc.jEOImgAct).append(cc.jEOImgActMore); /* Append <li>s to <ul> */
				cc.jEOImgColumn.append(cc.jEOImgAct); /* Prepend Image Action <ul> to bottom of image column */
				$('a', cc.jEOImgActMore).click(function(){ cc.launchImgLargeWindow(); return false; }); /* On click of MoreImage anchor launch new_window functionality */
				/* The above line replaces Behaviour.addTargets(); */
			}
		},

		/* Initialise Tabs and bind Events */
		initTabs : function() {

			/* Product Display Class Context */
			var cc = this;

			/* Prepends a Tab Navigation and Adds class to #product_display_overview and sets up active and tab clicks */
			cc.jEOOverview.prepend(cc.jEOTabs).addClass('product_display_overview_tabs');

			/* Hide div's and h2's that are not used */
			$('div.product_display_item, div.product_display_item h2', cc.jEOOverview).hide();

			/* Sets up first tab in source - currently Product Info */
			$('div.product_display_item:first', cc.jEOOverview).show();
			$('a:first', cc.jEOOverview).addClass('active');
			
			// check for merch associations and if we have one, append a link to the product description to highlight to to the customer
			/*pc.mMerchHighlight = "Like this? You might also like these...";
			if (cc.jEOMerchColumn.children(".product_display_column_3_item").size()) {
				cc.jEOMerchLink = $("<a name=\"merch_associations\"></a>").prependTo(cc.jEOMerchColumn);
				$("#product_display_overview_info").append("<p id=\"merch_highlight\"><a href=\"#merch_associations\" title=\"" + pc.mMerchHighlight + "\">" + pc.mMerchHighlight + "</a></p>");
				// add scrollto here instead?
				}*/

			/* Re-show #product_display_overview as it's hidden via CSS */
			cc.jEOOverview.show();

			/* Sets up click events for each li a */
			$('a', cc.jEOTabs).click(function() {
				var jObj = $(this); /* Internal jQuery object - less DOM requests */
				if (jObj.attr('class') != 'active') {
					/* Hide active div */
					$('div.product_display_item', cc.jEOOverview).hide();
					/* Show div based on href of clicked anchor */
					var href = jObj.attr('href');
					var index = href.indexOf('#');
					$('#' + href.substring(index + 1), cc.jEOOverview).show();
					/* Remove class of active li */
					$('a.active', cc.jEOTabs).removeClass('active');
					/* Aadd class to a to show active */
					jObj.addClass('active');
					/* return false to avoid page jump */
				}
				return false;
			});
		},

		/* Initialise Modals and bind Events */
		initModals : function() {

			/* Product Display Class Context */
			var cc = this;

			/* Show Modal, fadeIn and Hide Flash and Selects */
			var showModal = function(mdlID) {
				$('embed, object, select', cc.jEOProductForm).addClass('jqmHide');
				mdlID.w.hide();
				mdlID.w.fadeIn('800', function(){
					/* Scroll to top of window as Modal is positioned absolutely */
					var scrollOffsetY = self.pageYOffset || $.boxModel && document.documentElement.scrollTop || document.body.scrollTop;
					if (scrollOffsetY > '100') { /* Only scroll if .scrollTop() is greater than 100 pixels */
						$('html,body').animate({scrollTop: 0}, 800);
					}
				});
			};

			/* Remove Modal, fadeOut and restore Flash and Selects */
			var removeModal = function (mdlID) {
				mdlID.w.fadeOut('800', function() {
					$('embed, object, select', cc.jEOProductForm).removeClass('jqmHide');
					mdlID.o.remove();
				});
			};

			/* Insert Modal Windows after #container */
			$('body').append(cc.jEOMdlWinSizeGuide,cc.jEOMdlWinFriend,cc.jEOMdlWinWishlist,cc.jEOMdlWinNotify);

			if (cc.cMdlSizeGuide) {
				cc.jEOMdlASizeGuide.click(function() {
					cc.jEOMdlWinSizeGuide.jqm({ ajax: cc.cSizeGuideURL, overlay: cc.cMdlOpacity, onShow: showModal, onHide: removeModal }).jqmShow();
					return false;
				});
			}

			cc.jEOMdlAFriend.click(function() {
				cc.jEOMdlWinFriend.jqm({ overlay: cc.cMdlOpacity, onShow: showModal, onHide: removeModal }).jqmShow();
				return false;
			});

/* Input wishlist behaviour */
			cc.jEOAddToWishlist.click(function() {

				/* Validate: Checks if a size has been selected */
				if (cc.jEOHiddenSizeSelect.val() == 'Select Size') {
					/* Insert inline error for size not selected */
					cc.jEOSizeError.remove();
					cc.jEOWishlistError.remove();
					$('.frow-select dd', cc.jEOQuantity).after(cc.jEOWishlistError);
					cc.jEOSize.addClass('product_display_error');
					/* Scrolls to Size area */
					var scrollOffsetY = self.pageYOffset || $.boxModel && document.documentElement.scrollTop || document.body.scrollTop; /* Gets current postion from top by calculating how much the page has scrolled */
					var offsetSize = cc.jEOSize.offset().top;
					var offsetSizeScroll = offsetSize - scrollOffsetY; /* Gets current postion from top by calculating how much the page has scrolled */
					if (offsetSizeScroll >=140 || offsetSizeScroll <=20) {
						/* Show Confirmation with scroll */
						$('html,body').animate({scrollTop: (offsetSize - 30)}, 800);
					}
					return false;
				} else {
					/* Remove any Error's already visable */
					cc.jEOSizeError.remove();
					cc.jEOWishlistError.remove();
					cc.jEOSize.removeClass('product_display_error');
					cc.jEOProductForm.unbind('submit');
					cc.jEOProductForm.submit();
				}
/* 
				cc.jEOMdlWinWishlist.jqm({ overlay: cc.cMdlOpacity, onShow: showModal, onHide: removeModal }).jqmShow();
				return false;
*/
			});

			cc.jEOMdlANotify.click(function() {
				cc.jEOMdlWinNotify.jqm({ overlay: cc.cMdlOpacity, onShow: showModal, onHide: removeModal }).jqmShow();
				return false;
			});

		},

		/* Initialise Size Selector Functions and bind Events */
		initSizeSelector : function() {

			/* Product Display Class Context */
			var cc = this;

			function Attributes(colour,sizes,quantities) {
				this.colour = colour;
				this.sizes = sizes;
				this.quantities = quantities;
			}
			/* Build attributes from hidden inpit */
			var attributes = eval(cc.jEOAttributes.val());

			function checkQuantity() {

				/* Loops through quantities to see if item is fully out of stock */
				var hasQuantity = -1;
				for (var i=0; i < attributes.quantities.length; i++) {
					/* if an size has quantity return */
					if (attributes.quantities[i] > 0 ){
						hasQuantity = 1;
						break;
					}
				}

				/* if all quantities are 0 replace #product_display_quantity content and return */
				if (hasQuantity < 0) {
					cc.jEOQuantity.html(cc.mOutOfStock);
					return;
				}

			}

			/* initialise checkQuantity to if fully out of stock */
			checkQuantity();

			function updateQuantity(size) {

				cc.jEOHiddenSizeSelect.val(size); /* Update hidden select */
				/*$('#'+ cc.jEOSizeSelect.attr('id')).val(size);*/ /* Update hidden choosesize input */
				$('#choosesize').val(size); /* Update hidden choosesize input */
				$('#product_display_size_selector input').val(size); /* fix for Safari 2.x where the above line does not work */

				/* Find the index based upon passed size */
				var indexVal = -1;
				for (var i=0; i < attributes.sizes.length; i++) {
					if (attributes.sizes[i] == size){
						indexVal = i;
						break;
					}
				}

				/* if indexVal is still -1 return false */
				if (indexVal < 0) {
					cc.jEOQuantitySelect.html('<option value="0">0 - Out of Stock</option>');
					return;
				}

				/* Add options based on quantity for select size */
				var quantity = attributes.quantities[indexVal];
				/* if quantity is 0 set Quanity select to out of stock */
				if (quantity === 0) {
					cc.jEOQuantitySelect.html('<option value="0">0 - Out of Stock</option>');
				} else {
					var quantityOptions = [];
					for (var qtyi=0; qtyi < quantity; qtyi++) {
						var optionVal = (qtyi + 1);
						quantityOptions[qtyi] = '<option value="' + optionVal  + '">'+ optionVal +'</option>';
					}
					cc.jEOQuantitySelect.html(quantityOptions.join('')); /* Update quantity select */
				}

			}

			/* Creates array of size selector options and hidden input from select */
			var sizeSelectorList = [];
			$('option', cc.jEOSizeSelect).each(function(i) {
				var jObj = $(this); /* Internal jQuery object - less DOM requests */
				/* If disabled attribute is present then item is out of stock and add class to reprisent this */
				if (jObj.attr('disabled')) {
					jObj.css({color: 'silver', fontStyle: 'italic'}); /* inlne style on size <select> */
					sizeSelectorList[i] = '<li><span>' + jObj.val() + ' <img alt="Out of stock" src="/wcsstore/ConsumerDirectStorefrontAssetStore/images/colors/color' + Brand.directory + '/productdisplay/size_outofstock.gif" /></span></li>';
				} else {
					sizeSelectorList[i] = '<li><a href="#" title="' + jObj.val() + '">' + jObj.val() + '</a></li>';
				}
			});

			/* Set hidden size input to 'select size' */
			cc.jEOHiddenSizeSelect.val('Select Size');

			/* If number of size is greater than the configuration value show Scoller <select> */
			if (sizeSelectorList.length < cc.cSizeAmmount) {

				/* Removes first index of array because this is just 'Select Size' */
				sizeSelectorList.shift();

				/* Insert clickable list */
				var jESizeSelectList = $('<div id="product_display_size_selector"><input type="hidden" id="' + cc.jEOSizeSelect.attr('id') + '" name="' + cc.jEOSizeSelect.attr('name') + '" value="Select Size" /><ul class="clearfix">' + sizeSelectorList.join('') + '</ul></div>');

				/* Insert new size selector and remove old <select> */
				$('.frow', cc.jEOSize).after(jESizeSelectList).remove();

				/* Re-show #product_display_size as it's hidden via CSS */ 
				cc.jEOSize.show();

				/* If there is only one Size available have it selected by default */
				if (sizeSelectorList.length === 1) {
					/* If cSizeGuideHide is set to true then we need to hide the size guide */
					if (cc.cSizeGuideHide) { cc.jEOSize.hide(); }
					var jObj = $('li a', cc.jEOSize); /* Internal jQuery object - less DOM requests */
					var valueNew = jObj.text(); /* Newly selected size */
					jObj.addClass('active'); /* Set class to active */
					updateQuantity(valueNew);
				}

			} else {

				/* Re-show #product_display_size as it's hidden via CSS */ 
				cc.jEOSize.show();

				/* Bind change events for size select list items - On change sets selected size value to hidden input field that has the same ID/Name of the orginal <select> */
				cc.jEOSizeSelect.change(function() {
					var valueCurrent = cc.jEOHiddenSizeSelect.val(); /* Current Selected Size */
					var valueNew = cc.jEOSizeSelect.val(); /* Newly selected size */
					updateQuantity(valueNew); /* Set value of hidden input to new value and update quantity */
				});

			}

			/* Selector List hover for out of stock items */
			$('ul li span', cc.jEOSize).hover(function() {
				$(this).addClass('hover');
				/* If scroller control is active hide inline image and show scroll out of stock global image */
				if (sizeSelectorList.length > cc.cSizeAmmount) {
					$(this + ' img').hide();
					jESizeSelectListScrollOutOfStock.show();
				}
			}, function() {
				$(this).removeClass('hover');
				/* If scroller control is active hide inline image and hide scroll out of stock global image */
				if (sizeSelectorList.length > cc.cSizeAmmount) {
					jESizeSelectListScrollOutOfStock.hide();
				}
			});

			/* Bind click events for list items - On click sets selected size value to hidden input field that has the same ID/Name of the orginal <select> */
			$('ul li a', cc.jEOSize).click(function(){
				var jObj = $(this); /* Internal jQuery object - less DOM requests */
				var valueNew = jObj.text(); /* Newly selected size */
				$('ul li a', jESizeSelectList).removeClass('active'); /* Removes all current active class */
				updateQuantity(valueNew); /* Set value of hidden input to new value */
				jObj.addClass('active');
				return false;
			});

		},

		/* Initialise Product Form Functions and bind Events */
		initProductForm : function () {

			/* Product Display Class Context */
			var cc = this;

			/* Function to Display loader icon while ajax request is process */
			function loaderApply() {
				/* Inserts Loader Icon */
				$('.frow-select dd', cc.jEOQuantity).after(cc.jEOAJAXLoader.show());
				$('body').addClass('ajax_loading');
				/* If Confirmation is visable display gradient overlay effect shown sets to height of jEOConfirmation */
				if (cc.jEOConfirmation.css('display') == 'block') {
					cc.jEOConfirmation.append(cc.jEOConfirmationOverlay.height(cc.jEOConfirmation.height()).show());
				}
			}

			/* Function to renable form submition and remove loader icon */
			function loaderRemove(duration) {
				/* Fade out Overlay then remove, mimics setTimeout() */
				cc.jEOConfirmationOverlay.fadeOut(duration, function() {
					cc.jEOConfirmationOverlay.remove();
				});
				/* Fade out Loader Icon then remove, mimics setTimeout() */
				cc.jEOAJAXLoader.fadeOut(duration, function() {
					cc.jEOAJAXLoader.remove();
					/* Re-enable form Submission using the flag */
					cc.fFormSubmitted = 'No';
					$('body').removeClass('ajax_loading');
				});
			}

			/* Default form submission */
			cc.jEOProductForm.submit(function() {

				/* Validate: Checks if a size has been selected and that Quantity is no 0 */
				if (cc.jEOHiddenSizeSelect.val() == 'Select Size' || cc.jEOQuantitySelect.val() === 0) {
					/* Insert inline error for size not selected */
					cc.jEOSizeError.remove();
					cc.jEOWishlistError.remove();
					$('.frow-select dd', cc.jEOQuantity).after(cc.jEOSizeError);
					cc.jEOSize.addClass('product_display_error');
					/* Scrolls to Size area */
					var scrollOffsetY = self.pageYOffset || $.boxModel && document.documentElement.scrollTop || document.body.scrollTop; /* Gets current postion from top by calculating how much the page has scrolled */
					var offsetSize = cc.jEOSize.offset().top;
					var offsetSizeScroll = offsetSize - scrollOffsetY; /* Gets current postion from top by calculating how much the page has scrolled */
					if (offsetSizeScroll >=140 || offsetSizeScroll <=20) {
						/* Show Confirmation with scroll */
						$('html,body').animate({scrollTop: (offsetSize - 30)}, 800);
					}
					return false;
				} else {
					/* Remove any Error's already visable */
					cc.jEOSizeError.remove();
					cc.jEOWishlistError.remove();
					cc.jEOSize.removeClass('product_display_error');
				}

				/* Check for pending submission flag and disable Submit if otherwise allow AJAX and display loader icon */
				if (cc.fFormSubmitted == 'Yes') {
					return false;
				} else {
					cc.fFormSubmitted = 'Yes';
					loaderApply();
				}

				/* Set Add2ShopCart to true and Add2Wishlist false */
				cc.jEOProductFormSubmit.val('true');
				cc.jEOAddToWishlist.val('false');

				/* Builds an array of inputs within cc.jEOProductForm that will be sent in the post */
				var inputs = [];
				$(':input', cc.jEOProductForm).each(function() {
					inputs.push(this.name + '=' + escape(this.value));
				});

				/* Do AJAX Request */
				$.ajax({
					type: 'POST',
					url: cc.cFormActionURL,
					data: inputs.join('&'),
					dataType: 'json',
					cache: false,
					timeout: 20000,
					success: function(response) {
						if (response.success) {
							if (typeof omniItemAddedToBag == 'function') { omniItemAddedToBag(); } /* Omniture Tracking, first check if the function is available - if true, fire it. */
							loaderRemove(2000); /* Hide AJAX loader as process complete but fade out for 2 seconds. */
							cc.displayAJAXMessage(response); /* If there is a success response display Confirmation */
						} else {
							loaderRemove(0); /* Hide AJAX loader as soon as possible */
							cc.displayError(response,'business'); /* If there is a business error response display Error */
						}
					},
					error: function() {
						var response = {}; /* Creates response object */
						loaderRemove(0); /* Hide AJAX loader as soon as possible */
						response.message = cc.mAJAXError; /* Timeout Error defined in configuration area */
						cc.displayError(response,'major'); /* display TimeOut Error */
					}
				});

				return false;
			});

		},

		/* Error Function - accepts response and type(business,major) */
		displayError : function(response,type) {

			/* Product Display Class Context */
			var cc = this;

			if (type == 'major') {
				/* Currently behaves like a business error but could trigger different unctionality */
				cc.displayAJAXMessage(response); /* If there has been a major error show the AJAX error message */
			} else {
				cc.displayAJAXMessage(response); /* Show business error */
			}

		},

		/* Added to bag Functions / Events */
		displayAJAXMessage : function(response){

			/* Product Display Class Context */
			var cc = this;

			if (response.success) {
				/* If success is true - Setup Variables based on page item and response variables */
				var itemName = $('#product_display_details_title_dd', cc.jEODetails).text();
				var itemColour = $('#product_display_details_color_dd', cc.jEODetails).text();
				var itemSize = $(cc.jEOHiddenSizeSelect).val();
				var itemQuantity = $(cc.jEOQuantitySelect).val();
				var itemPrice = $('.itemprice', cc.jEODetails).text();
				/* Multiply itemPrice by Quantity to 2 decimal places */
				itemPrice = (itemPrice * itemQuantity).toFixed(2);

				cc.jEOConfirmation.css('background-position', 'left bottom');
				$('dl, p#product_display_confirmation_bag', cc.jEOConfirmation).show();
				$('p#product_display_confirmation_error', cc.jEOConfirmation).text('').hide();
				$('h2', cc.jEOConfirmation).text(cc.mAJAXH2Success).css('background-position', 'left top'); /* Resets background image position */
				$('.product_display_confirmation_item', cc.jEOConfirmation).text(itemName);
				$('.product_display_confirmation_colour', cc.jEOConfirmation).text(itemColour);
				$('.product_display_confirmation_size', cc.jEOConfirmation).text(itemSize);
				$('.product_display_confirmation_quantity', cc.jEOConfirmation).text(itemQuantity);
				$('.product_display_confirmation_price strong', cc.jEOConfirmation).text(itemPrice);
				$('.product_display_confirmation_items', cc.jEOConfirmation).text(response.items);
				$('.product_display_confirmation_total', cc.jEOConfirmation).text(response.total.toFixed(2));
				
				/* Updates 'view your back anchor' */
				var aViewYourBag = cc.jEOHeaderCart.attr('href');
				$('a, p#product_display_confirmation_bag', cc.jEOConfirmation).attr('href', aViewYourBag);

				/* Updates Header Cart totals and applies class of .has_items to anchor for view cart image */
				cc.jEOHeaderCart.addClass('itemsummary_items').html(cc.mBasket);
				$('.headercart-items', cc.jEOHeaderCart).html(response.items);
				$('.headercart-total', cc.jEOHeaderCart).html(response.total.toFixed(2));

			} else {
				/* There was an Error */
				cc.jEOConfirmation.css('background-position', 'right bottom');
				$('dl, p#product_display_confirmation_bag', cc.jEOConfirmation).hide(); /* Hide Confirmation dl and p */
				$('h2', cc.jEOConfirmation).text(cc.mAJAXH2Error).css('background-position', 'right top'); /* Set h2 to error heading and change background position */
				$('p#product_display_confirmation_error', cc.jEOConfirmation).html(response.message).show(); /* Show the Error */
			}

			/* Shows Confirmation on scrollTo callback */
			function showAJAXMessage() {
				/* If Confirmation not currently visable slide it down */
				if (cc.jEOConfirmation.css('display') == 'none') {
					cc.jEOConfirmation.slideDown('slow', function() {
						$(this).css('height', '100%');
					});
				}
				return false;
			}

			/* Scrolls to Quantity div and show Confirmation uses */
			var scrollOffsetY = self.pageYOffset || $.boxModel && document.documentElement.scrollTop || document.body.scrollTop;
			var offsetQuantity = cc.jEOQuantity.offset().top;
			var offsetQuantityScroll = offsetQuantity - scrollOffsetY; /* Gets current postion from top by calculating how much the page has scrolled */

			if (offsetQuantityScroll >=140 || offsetQuantityScroll <=20) {
				/* Show Confirmation with scroll */
				$('html,body').animate({scrollTop: (offsetQuantity - 30)}, 800, function(){ showAJAXMessage(); });
			} else {
				/* Show Confirmation with no scroll */
				showAJAXMessage();
			}

			return false;

		}

	};

	/* Once jqModal loaded, load dimensions then fire init */
	var pd = new ProductDisplay();
	$(document).ready( function() {
		$.getScript('/javascript/jquery/jquery.jqModal.js', function(){ pd.init(); });
	});

