﻿var isZoom=false;var webService="Services/Product.asmx";var colourNotAvailable="";var productId=0;var colourId=0;$(document).ready(function(){$("#sizes .size").change(updateFit);$("#sizes .fit").change(enableKnickerDrawer)});function zoom(H){if(isZoom){isZoom=false;$(".zoomImage").fadeOut(500);$(".productImage").fadeIn(500);$(".productImage").fadeTo(100,1)}else{isZoom=true;var E=$(".zoomImage");if(E.length>0){var G=$(".productImage");var B=$("#image");var C=$("#image .inner");var D=G.width();var A=G.height();B.css({width:D,height:A,overflow:"hidden"});C.css({left:D-E.width(),top:A-E.height(),width:(E.width()*2)-D,height:(E.height()*2)-A});E.css({left:(E.width()/2)-(D/2),top:(E.height()/2)-(A/2)});E.fadeIn(500).fadeTo(100,1);G.fadeOut(500)}else{$(".productImage").fadeTo(100,0.5);$(".loading").show();var F=new Image();$(F).load(function(){var M=$(this);var N=$(".productImage");var J=$("#image");var K=$("#image .inner");K.append(M);var L=N.width();var I=N.height();M.draggable({helper:"original",containment:"#image .inner"});J.css({width:L,height:I,overflow:"hidden"});K.css({left:L-M.width(),top:I-M.height(),width:(M.width()*2)-L,height:(M.height()*2)-I});M.css({left:(M.width()/2)-(L/2),top:(M.height()/2)-(I/2)});M.fadeIn(500);N.fadeOut(500);$(".loading").hide();M.unbind("load")}).fadeOut(500).attr("src",H).attr("alt",$(".productImage").attr("alt")+" Zoom").addClass("zoomImage")}}$(".zoom .In").toggle();$(".zoom .Out").toggle()}function changeColour(B,C,A){$(".zoomImage").fadeTo(100,0.5);$(".productImage").fadeTo(100,0.5);$(".loading").show();$("#swatches .colour").attr("value",B.title);updateSize(B.title);$("#rangeitems .image").each(function(D){if(this.title!=""){$.ajax({type:"POST",url:webService+"/GetImage",data:'{"ProductId":'+parseInt(this.title)+',"ImageTypeId":1,"AttributeTypeId":1,"AttributeValue":"'+B.title+'"}',contentType:"application/json; charset=utf-8",dataType:"json",success:function(F){var K=JSON.parse(this.data);var J=$('#rangeitems div[title="'+K.ProductId+'"]');if(J!=null){var H=document.location.search.toLowerCase();if(F==""){if(H!=""){var L=new Querystring();if(L.contains("colour")){H=H.replace("colour="+L.get("colour"),"")}}J.children("span").children("a").children("img").attr("src",colourNotAvailable);J.children("span").children("a").children("img").attr("alt","Not available in "+B.title)}else{if(H!=""){var L=new Querystring();if(L.contains("colour")){H=H.replace("colour="+L.get("colour"),"colour="+B.title)}else{H+="&colour="+B.title}}else{H="?colour="+B.title}J.children("span").children("a").children("img").attr("src",F);var E=J.children("span").children("a").children("img").attr("alt");J.children("span").children("a").children("img").attr("alt",B.title+" "+E.substr(E.indexOf("-")))}var I=J.children("span").children("a");var G=I.attr("href");if(G.indexOf("?")>=0){G=G.substr(0,G.indexOf("?"))}I.attr("href",G+H.toLowerCase())}}})}});$.ajax({type:"POST",url:webService+"/GetImage",data:'{"ProductId":'+C+',"ImageTypeId":2,"AttributeTypeId":1,"AttributeValue":"'+B.title+'"}',contentType:"application/json; charset=utf-8",dataType:"json",success:function(D){$(".productImage").attr("src",D)}});$.ajax({type:"POST",url:webService+"/GetImage",data:'{"ProductId":'+C+',"ImageTypeId":3,"AttributeTypeId":1,"AttributeValue":"'+B.title+'"}',contentType:"application/json; charset=utf-8",dataType:"json",success:function(D){isZoom=false;var E=$(".zoomImage");E.fadeOut(500);if(D!=""){E.attr("src",D);$(".zoom .In").attr("href","javascript:zoom('"+D+"');");$(".zoom").show()}else{E.remove();$(".zoom").hide()}$(".productImage").fadeIn(500).fadeTo(100,1);$(".zoom .Out").hide();$(".zoom .In").show();$(".loading").hide()}});return false}function updateSize(A){updateFit();$.ajax({type:"POST",url:webService+"/GetAttributeByName",data:'{"AttributeTypeId":4, "Name":"'+A+'"}',contentType:"application/json; charset=utf-8",dataType:"json",success:function(B){var C=JSON.parse(B);colourId=C.id;$.ajax({type:"POST",url:webService+"/GetAttributes",data:'{"ProductId":'+productId+', "AttributeTypeId":2, "AttributeIdsAsCSV":"'+colourId+'"}',contentType:"application/json; char=utf-8",dataType:"json",success:function(F){var D=JSON.parse(F);var G=$("#sizes .size");if(G.length>0){G.children().remove();G.append('<option value="0">Size</option>');for(var E=0;E<D.attributes.length;E++){G.append('<option value="'+D.attributes[E].id+'">'+D.attributes[E].name+"</option>")}}}})}})}function updateFit(){var A=$("#sizes .fit");if(A.length>0){if($("#sizes .size").val()!="0"){A.removeAttr("disabled");A.removeClass("disabled");$.ajax({type:"POST",url:webService+"/GetAttributes",data:'{"ProductId":'+productId+', "AttributeTypeId":3, "AttributeIdsAsCSV":"'+colourId+","+$("#sizes .size").val()+'"}',contentType:"application/json; char=utf-8",dataType:"json",success:function(E){var C=JSON.parse(E);var B=$("#sizes .fit");if(B.length>0){B.children().remove();B.append('<option value="0">Cup Size</option>');for(var D=0;D<C.attributes.length;D++){B.append('<option value="'+C.attributes[D].id+'">'+C.attributes[D].name+"</option>")}}}})}else{A.attr("disabled",true);A.addClass("disabled");A.children().remove();A.append('<option value="0">Cup Size</option>')}$(".drawer a").attr("class","disabled")}else{enableKnickerDrawer()}}function enableKnickerDrawer(){var A=$("#sizes .fit");if(A.length>0){if(A.val()!="0"){$(".drawer a").attr("class","enabled")}else{$(".drawer a").attr("class","disabled")}}else{if($("#sizes .size").val()!="0"){$(".drawer a").attr("class","enabled")}else{$(".drawer a").attr("class","disabled")}}};