﻿var isZoom=false;var webService="Services/";var colourNotAvailable="";var productTitle;var browserTitle;var colourPlaceholder="[!--colour--!]";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",scroll:false});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(a,c,b){$("#productinfo h1")[0].innerHTML=productTitle.replace(colourPlaceholder,a.title);document.title=browserTitle.replace(colourPlaceholder,a.title);$(".zoomImage").fadeTo(100,0.5);$(".productImage").fadeTo(100,0.5);$(".loading").show();$("#swatches .colour").attr("value",a.title);$("#rangeitems .image").each(function(d){if(this.title!=""){$.ajax({type:"POST",url:webService+"Product.asmx/GetImage",data:'{"ProductId":'+this.title+',"ImageTypeId":1,"AttributeId":"'+b+'"}',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 "+a.title)}else{if(h!=""){var l=new Querystring();if(l.contains("colour")){h=h.replace("colour="+l.get("colour"),"colour="+a.title)}else{h+="&colour="+a.title}}else{h="?colour="+a.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",a.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+"Product.asmx/GetImage",data:'{"ProductId":'+c+',"ImageTypeId":2,"AttributeId":"'+b+'"}',contentType:"application/json; charset=utf-8",dataType:"json",success:function(d){$(".productImage").attr("src",d)}});$.ajax({type:"POST",url:webService+"Product.asmx/GetImage",data:'{"ProductId":'+c+',"ImageTypeId":3,"AttributeId":"'+b+'"}',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()}});if(typeof(updateBuyOnlinePopup)=="function"){updateBuyOnlinePopup(a.search)}return false};
