﻿var webServiceRange="App_CMS/Services/Range.asmx";var webServiceProduct="App_CMS/Services/Product.asmx";var key;var preview;var range;var products;var colours;var sizes;var fits;var rangeContentId;var productIndex=0;var colourIndex=0;var colourId=0;var isZoom=false;var speed=850;var scrollInProgress=false;var preLoad=false;var originalPageTitle;var lingerieDrawerButton;var lingerieDrawerDisabled;function scrollRightEnd(){$("#scroll .range:first").remove();scrollInProgress=false}function scrollLeftEnd(){scrollInProgress=false}function scrollProductEnd(){$("#rangeitems .scroll .product:first").remove();scrollInProgress=false}function failed(){}function close(){zoom(null);$(".popup").hide();$(".modal").hide();$(".modal .bg").fadeTo(0,0.75);document.title=originalPageTitle;window.location="#";return false}function zoom(C){if(isZoom){isZoom=false;$(".popup .zoomImage").fadeOut(500).hide();$(".popup .productImage").fadeIn(500).show()}else{isZoom=true;var A=$(".popup .zoomImage img");if(A.length>0){$(".popup .productImage").fadeOut(500).hide();$(".popup .zoomImage").fadeIn(500).show()}else{$(".popup .loading").show();$(".popup .inner").fadeTo(100,0.5);var B=new Image();$(B).load(function(){A=$(this);var G=$(".popup .productImage");var F=$(".popup .zoomImage");F.append(A);var E=A[0].width;var D=A[0].height;A.draggable({helper:"original",containment:".popup .zoomImage"});F.css({left:(0-E)+G.width(),top:(0-D)+G.height(),width:(E*2)-G.width(),height:(D*2)-G.height()});F.contents(".zoomOut").css({left:E-G.width()+20,top:D-G.height()+20});A.css({left:(E/2)-(G.width()/2),top:(D/2)-(G.height()/2)});A.attr("alt",colours.attributes[colourIndex].name+" - "+range.Label+" - "+products[productIndex].Title);G.fadeOut(500).hide();F.fadeIn(500).show();$(".popup .inner").fadeTo(100,1);$(".popup .loading").hide();A.unbind("load")}).attr("src",C).attr("alt",$(".popup .productImage").attr("alt")+" Zoom")}}}function enableKnickerDrawer(){var A=$("#sizes .fit");if(fits!=null){if(A.val()!="0"){$(".buttons .add").attr("src",lingerieDrawerButton).css("cursor","pointer").removeAttr("disabled")}else{$(".buttons .add").attr("src",lingerieDrawerDisabled).css("cursor","default").attr("disabled","disabled")}}else{A.hide();A.children().remove();if($("#sizes .size").val()!="0"){$(".buttons .add").attr("src",lingerieDrawerButton).css("cursor","pointer").removeAttr("disabled")}else{$(".buttons .add").attr("src",lingerieDrawerDisabled).css("cursor","default").attr("disabled","disabled")}}}function updateSize(){$.ajax({type:"POST",url:webServiceProduct+"/GetAttributes",data:'{"ProductId":'+products[productIndex].ProductId+', "AttributeTypeId":2, "AttributeIdsAsCSV":"'+colours.attributes[colourIndex].id+'"}',contentType:"application/json; char=utf-8",dataType:"json",success:function(C,A){sizes=JSON.parse(C);if(sizes!=null){var D=$("#sizes .size");if(D.length>0){D.children().remove();D.append('<option value="0">Size</option>');for(var B=0;B<sizes.attributes.length;B++){D.append('<option value="'+sizes.attributes[B].id+'">'+sizes.attributes[B].name+"</option>")}}}updateFit()}})}function updateFit(){fits=null;var A=$("#sizes .fit");if(A.length>0){if($("#sizes .size").val()!="0"){$.ajax({type:"POST",url:webServiceProduct+"/GetAttributes",data:'{"ProductId":'+products[productIndex].ProductId+', "AttributeTypeId":3, "AttributeIdsAsCSV":"'+colours.attributes[colourIndex].id+","+$("#sizes .size").val()+'"}',contentType:"application/json; char=utf-8",dataType:"json",global:false,success:function(D){var B=$("#sizes .fit");if(D!=null){fits=JSON.parse(D);if(B.length>0){B.show();B.children().remove();B.append('<option value="0">Cup Size</option>');for(var C=0;C<fits.attributes.length;C++){B.append('<option value="'+fits.attributes[C].id+'">'+fits.attributes[C].name+"</option>")}}}else{enableKnickerDrawer()}}})}else{enableKnickerDrawer()}}else{enableKnickerDrawer()}}function changeColour(){$(".popup .loading").show();$(".popup .inner").fadeTo(100,0.5);if(colours!=null){for(i=0;i<colours.attributes.length;i++){if(colours.attributes[i].name==this.title){colourIndex=i;colourId=colours.attributes[i].id}}getImages();return false}else{return true}}function changeProduct(){if(products!=null){for(i=0;i<products.length;i++){if(products[i].Title==this.title){productIndex=i}}switchProduct();return false}else{return true}}function switchProduct(){sizes=null;fits=null;$("#sizes .size").children().remove();$("#sizes .fit").hide().children().remove();$(".productId").val(products[productIndex].ProductId);$("#details .productTitle").html(products[productIndex].Title);document.title=(products[productIndex].BrowserTitle);$.ajax({type:"POST",url:webServiceProduct+"/GetAttributes",data:'{"ProductId":'+products[productIndex].ProductId+',"AttributeTypeId":1,"AttributeIdsAsCSV":null}',contentType:"application/json; char=utf-8",dataType:"json",success:function(B,A){colours=JSON.parse(B);colourIndex=0;for(i=0;i<colours.attributes.length;i++){if(colours.attributes[i].id==colourId){colourIndex=i}}if(colours!=null){$("#swatches .colour").remove();for(i=0;i<colours.attributes.length;i++){$.ajax({type:"POST",url:webServiceProduct+"/GetProductImageByTypeAndAttribute",data:'{"Key":"'+key+'","ProductId":'+products[productIndex].ProductId+',"ImageTypeId":13,"AttributeId":"'+colours.attributes[i].id+'"}',contentType:"application/json; char=utf-8",dataType:"json",success:function(E,C){var F=JSON.parse(E);if(F!=null){var D=$('<div class="colour"><a id="'+F.AttributeId+'" href="'+products[productIndex].InternalPath+"?colour="+F.AttributeName+'" title="'+F.AttributeName+'"><img src="'+F.Image.ImageUrl+'" alt="'+F.AttributeName+" - "+range.Label+" - "+products[productIndex].Title+' colour swatch"></a><div>'+F.AttributeName+"</div></div>");D.children("a").click(changeColour);$("#swatches h2").after(D)}},error:failed})}$(".colourId").val(colours.attributes[colourIndex].id);getImages()}},error:failed})}function getImages(){$.ajax({type:"POST",url:webServiceProduct+"/GetProductImageByTypeAndAttribute",data:'{"Key":"'+key+'","ProductId":'+products[productIndex].ProductId+',"ImageTypeId":11,"AttributeId":"'+colours.attributes[colourIndex].id+'"}',contentType:"application/json; char=utf-8",dataType:"json",success:function(B,A){var C=JSON.parse(B);if(C!=null){$(".productImage img").attr("src",C.Image.ImageUrl)}},error:failed});$("#rangeitems .scroll .product").remove();for(i=0;i<products.length;i++){if(i!=productIndex){$.ajax({type:"POST",url:webServiceProduct+"/GetProductImageByTypeAndAttribute",data:'{"Key":"'+key+'","ProductId":'+products[i].ProductId+',"ImageTypeId":10,"AttributeId":"'+colours.attributes[colourIndex].id+'"}',contentType:"application/json; char=utf-8",dataType:"json",success:function(D,A){var E=JSON.parse(D);var B=JSON.parse(this.data);if(E!=null){for(i=0;i<products.length;i++){if(products[i].ProductId==B.ProductId){var C=$('<div class="product"><a id="'+products[i].ProductId+'" href="'+products[i].InternalPath+"?colour="+colours.attributes[colourIndex].name+'" title="'+products[i].Title+'"><img src="'+E.Image.ImageUrl+'" alt="'+colours.attributes[colourIndex].name+" - "+range.Label+" - "+products[i].Title+' thumbnail"><h3>'+products[i].Title.toUpperCase()+"</h3></a></div>");C.children("a").click(changeProduct);$("#rangeitems .scroll").prepend(C)}}}},error:failed})}}$.ajax({type:"POST",url:webServiceProduct+"/GetAttributes",data:'{"ProductId":'+products[productIndex].ProductId+', "AttributeTypeId":3, "AttributeIdsAsCSV":null}',contentType:"application/json; char=utf-8",dataType:"json",success:function(B,A){if(B!=null){fits=JSON.parse(B);if(fits!=null){$("#details .fits").html(fits.attributes[0].name.toUpperCase()+"-"+fits.attributes[fits.attributes.length-1].name.toUpperCase())}}else{$("#details .fits").html("")}},error:failed});updateSize();$.ajax({type:"POST",url:webServiceProduct+"/GetProductImageByTypeAndAttribute",data:'{"Key":"'+key+'","ProductId":'+products[productIndex].ProductId+',"ImageTypeId":12,"AttributeId":"'+colours.attributes[colourIndex].id+'"}',contentType:"application/json; char=utf-8",dataType:"json",success:function(C,A){var D=JSON.parse(C);isZoom=false;var B=$(".popup .zoomImage img");if(B.length>0){B.remove()}if(D!=""){$(".popup .productImage .zoomIn").attr("href","javascript:zoom('"+D.Image.ImageUrl+"');")}$(".popup .zoomImage").fadeOut(500).hide();$(".popup .productImage").fadeIn(500).show();$(".popup").slideDown(600);$(".modal .bg").fadeTo(0,0.01)},error:failed})}function renderPopUp(B,A){productIndex=0;range=JSON.parse(B);if(range!=null){window.location="#"+range.Label;$("#details .title").html(range.Label.toUpperCase());$("#details .productTitle+p").remove();$("#details .productTitle").after(range.Description);$.ajax({type:"POST",url:webServiceProduct+"/GetProducts",data:'{"Key":"'+key+'","RangeId":'+range.RangeId+',"CategoryId":null,"StartRowIndex":null,"MaximumRows":null,"Preview":"'+preview+'"}',contentType:"application/json; char=utf-8",dataType:"json",success:function(D,C){products=JSON.parse(D);if(products.length>6){$(".rightarrow").show()}else{$(".rightarrow").hide()}switchProduct()},error:failed})}else{close()}}function selectRange(A,B){rangeContentId=B;$(".modal").show();$.ajax({type:"POST",url:webServiceRange+"/GetRange",data:'{"Key":"'+key+'","ContentId":'+rangeContentId+',"Preview":"'+preview+'"}',contentType:"application/json; char=utf-8",dataType:"json",success:renderPopUp,error:failed});return false}$(document).ready(function(){if(preLoad){$("#rangeitems .scroll .product:gt(5) img").css("opacity",0);$.ajax({type:"POST",url:webServiceRange+"/GetRange",data:'{"Key":"'+key+'","ContentId":'+rangeContentId+',"Preview":"'+preview+'"}',contentType:"application/json; char=utf-8",dataType:"json",success:function(B,A){range=JSON.parse(B);originalPageTitle=document.title.replace(" : "+range.Label,"");$.ajax({type:"POST",url:webServiceProduct+"/GetProducts",data:'{"Key":"'+key+'","RangeId":'+range.RangeId+',"CategoryId":null,"StartRowIndex":null,"MaximumRows":null,"Preview":"'+preview+'"}',contentType:"application/json; char=utf-8",dataType:"json",success:function(D,C){products=JSON.parse(D);if(products.length>6){$(".rightarrow").show()}else{$(".rightarrow").hide()}$.ajax({type:"POST",url:webServiceProduct+"/GetAttributes",data:'{"ProductId":'+products[productIndex].ProductId+',"AttributeTypeId":1,"AttributeIdsAsCSV":null}',contentType:"application/json; char=utf-8",dataType:"json",success:function(F,E){colours=JSON.parse(F);colourIndex=0;for(i=0;i<colours.attributes.length;i++){if(colours.attributes[i].id==colourId){colourIndex=i}}},error:failed})},error:failed})},error:failed})}else{originalPageTitle=document.title}$(".popup").ajaxStart(function(){$(this).contents(".loading").show();$(this).contents(".inner").fadeTo(100,0.5)});$(".popup").ajaxStop(function(){$(this).contents(".inner").fadeTo(100,1);$(this).contents(".loading").hide()});$("#scroll .range:gt(4) img").css("opacity",0);$(".slideRight").mousedown(function(){if(!scrollInProgress){scrollInProgress=true;var A=$("#scroll .range:first");A.clone(true).appendTo("#scroll");A.animate({marginLeft:-225},speed,scrollRightEnd);A.children("a").children("img").animate({opacity:0},speed);$("#scroll .range:eq(4) img").animate({opacity:1},speed);$("#scroll .range:last img").css("opacity",0)}});$(".slideLeft").mousedown(function(){if(!scrollInProgress){scrollInProgress=true;var A=$("#scroll .range:last");A.css("margin-left",-225);A.children("a").children("img").css("opacity",0);A.clone(true).prependTo("#scroll");A.remove();$("#scroll .range:first").animate({marginLeft:0},speed);$("#scroll .range:first img").animate({opacity:1},speed);$("#scroll .range:eq(4) img").animate({opacity:0},speed,scrollLeftEnd)}});$(".popup a.close").click(close);$("#swatches .colour a").click(changeColour);$("#rangeitems .scroll .product a").click(changeProduct);$(".rightarrow").mousedown(function(){if(!scrollInProgress){scrollInProgress=true;var A=$("#rangeitems .scroll .product:first");A.clone(true).appendTo("#rangeitems .scroll");A.animate({marginLeft:-136},speed,scrollProductEnd)}});$(".top").click(function(){$(".menu").slideToggle(200)});$(document).click(function(){$(".menu").hide()});$("#sizes .size").change(updateFit);$("#sizes .fit").change(enableKnickerDrawer)});