

 
/*!============================================================*\
 || Superclass										           ||
 *=============================================================*/
  
  var Widget;
  jQuery(document).ready(function(){
  Widget = function()
  {
	this.type = "Widget";
	this.id = undefined;
	this.isRendered = false;
	this.element = undefined;

	this.render=function(element)
	{
		element.append('<div>Widget</div>');
	};
	
	this.fail=function(e)
	{
		slib.dump(e);
		slib.throwError("Widget error - see last dumped object.",false,true,true,null,this);
		this.element.fadeOut().hide();
	};
	
	this.j=function(){return (this.isRendered) ? jQuery(this.id) : false;}
  }
 });

/*!============================================================*\
 || Widgets											           ||
 *=============================================================*/
 
var GroupMenuWidget; //###########################################################################################################################################
jQuery(document).ready(function () {
    GroupMenuWidget = function () {
        this.id = wlib.getID();
        this.type = "GroupMenuWidget";
        this.picClassName = "";
        this.linksClassName = "";
        this.columnClassName = "";
        this.isColumned = false;
        this.render = function (parent, picClass, linksClass) {
            if (!this.isRendered) {

                this.isColumned = (linksClass == undefined);

                this.picClassName = picClass;
                this.linksClassName = linksClass;


                this.id = (this.id == undefined) ? wlib.getID() : this.id;
                var me = jQuery(document.createElement("div"));
                me.attr("id", this.id);
                me.addClass("widget");
                this.element = me;
                parent.append(me);
                this.isRendered = true;
                var x = this.id;

                var g = slib.Session.getGender();

                if (g == "?" || (g != 'm' && g != 'f')) {
                    parent.parent().parent().hide();
                } else {
                    slib.API.getGroupList(function (r) { wlib.find(x).cb_getGroupList(r); }, function (e) { wlib.find(x).fail(e); });
                }
            }
        }
        this.cb_getGroupList = function (r) {

            r = r.result;

            var c = this.isColumned;

            var i; var m = r.length;

            var pd; //picture/column div
            var ld; //links div

            var genderLink = 'ladies';  //set gender ranges - neccessary when browsing outlet
            if (slib.Session.gender == 'm') { genderLink = 'mens'; }; //overwite with mens gender if set

            pd = jQuery(document.createElement("div"));
            pd.addClass(this.picClassName);

            ld = jQuery(document.createElement("div"));
            ld.addClass(this.linksClassName);

            //New Arrivals
            if (c) {
                //dont show new arrivals if this is the category list in the page rather than the drop down. If this changes uncomment below 2 lines:
                //pd.append("<h3><a href=\"/" + slib.Encoder.URLEncode(slib.Session.range.name.toLowerCase()) + "/new/\">New Arrivals</a></h3>");
                //this.element.append(pd);
            } else {
                ld.append("<h3><a href=\"/" + slib.Encoder.URLEncode(slib.Session.range.name.toLowerCase()) + "/new/\">New Arrivals</a></h3>");
                if (slib.Session.gender == 'f') {
                    //ld.append("<h3><a href=\"/ladies/categories/spring%20preview\">Spring Preview</a></h3>");
                    //ld.append("<h3><a style=\"color:red!important\" href=\"/" + slib.Encoder.URLEncode(slib.Session.range.name.toLowerCase()) + "/search/sale\">Sale</a></h3>");
                }


                this.element.append(ld);
            }

            for (i = 0; i < m; i++) {
                if (r[i].name.toUpperCase() != 'SALE'){
                    pd = jQuery(document.createElement("div"));
                    pd.addClass(this.picClassName);

                    if (c) {
                        //After 5 columns (when new arrivals active otherwise 6) add a clear as only 6 columns in total can fit.
                        if (i == 6) { this.element.append("<div class=\"clear\"></div><br />") }
                        pd.append("<h3><a href=\"/" + genderLink + "/categories/" + slib.Encoder.URLEncode(r[i].name.toLowerCase()) + "\">" + slib.Encoder.HTMLEncode(r[i].name.toLowerCase()) + "</a></h3>");
                    } else {
                        ld = jQuery(document.createElement("div"));
                        ld.addClass(this.linksClassName);
                        ld.append("<h3><a href=\"/" + genderLink + "/categories/" + slib.Encoder.URLEncode(r[i].name.toLowerCase()) + "\">" + slib.Encoder.HTMLEncode(r[i].name.toLowerCase()) + "</a></h3>");
                    }


                    var sg = "";
                    for (var k = 0; k < r[i].subgroups.length; k++) {
                        sg = sg + "<p><a href=\"/" + genderLink + "/categories/" + slib.Encoder.URLEncode(r[i].name.toLowerCase()) + "/" + slib.Encoder.URLEncode(r[i].subgroups[k].name.toLowerCase()) + "\">" + slib.Encoder.HTMLEncode(r[i].subgroups[k].name.replace('/', ' / ').toLowerCase()) + "</a></p>";
                    }


                    if (c) {
                        pd.append(sg);
                        this.element.append(pd);
                    } else {
                        ld.append(sg);
                        this.element.append(ld);

                        slib.MenuManager.register(jQuery("#btnCategorymenu"), jQuery("#categorymenu"));

                    }
                }
            }
        }
    }; GroupMenuWidget.prototype = new Widget();
});
 
 
 var BrandMenuWidget; //###########################################################################################################################################
 jQuery(document).ready(function () {
     BrandMenuWidget = function () {
         this.id = wlib.getID();
         this.type = "BrandMenuWidget";
         this.itemClassName = "item";
         this.colour = 'black';
         this.render = function (parent, itemClass, colour) {

             //You can have any colour you like, as long as it's black.
             this.colour = (colour == undefined) ? 'black' : 'grey';

             if (!this.isRendered) {
                 this.itemClassName = itemClass;
                 this.id = (this.id == undefined) ? wlib.getID() : this.id;
                 var me = jQuery(document.createElement("div"));
                 me.attr("id", this.id);
                 me.addClass("widget");
                 me.addClass(this.colour + "BrandMenu");
                 

                 this.element = me;
                 parent.append(me);
                 this.isRendered = true;
                 var x = this.id;

                 var g = slib.Session.getGender();

                 if (g == "?" || (g != 'm' && g != 'f')) {
                     parent.parent().hide();
                 } else {
                     slib.API.getBrandList(
					function (r) { wlib.find(x).cb_getBrandList(r.result); },
					function (e) { wlib.find(x).fail(e); }
					);
                 }
             }
         }
         this.cb_getBrandList = function (r) {

             var genderLink = 'ladies';  //set gender ranges - neccessary when browsing outlet
             if (slib.Session.gender == 'm') { genderLink = 'mens'; }; //overwite with mens gender if set

             var i; var m = r.length;
             for (i = 0; i < m; i++) {
                 this.element.append("<a href='/" + genderLink + "/brands/" + slib.Encoder.URLEncode(r[i].name.toLowerCase()) + "' class=\"" + this.itemClassName + "\"><img src=\"" + r[i].getImagePath(this.colour) + "\"/></a>");
             }
             slib.MenuManager.register(jQuery("#btnBrandmenu"), jQuery("#brandmenu"));
         }
     }; BrandMenuWidget.prototype = new Widget();
 });


var OutletMenuWidget; //###########################################################################################################################################
 //Remixed 11/02/2011 to become the SALE group, no longer OUTLET range - multiple categories etc.
 jQuery(document).ready(function() {
 OutletMenuWidget = function()
{
         this.id = wlib.getID();
         this.type = "OutletMenuWidget";
         this.picClassName = "";
         this.linksClassName = "";
         this.columnClassName = "";
         this.isColumned = false;
         this.render = function(parent, picClass, linksClass) {
             if (!this.isRendered) {

                 this.isColumned = (linksClass == undefined);

                 this.picClassName = picClass;
                 this.linksClassName = linksClass;


                 this.id = (this.id == undefined) ? wlib.getID() : this.id;
                 var me = jQuery(document.createElement("div"));
                 me.attr("id", this.id);
                 me.addClass("widget");
                 this.element = me;
                 parent.append(me);
                 this.isRendered = true;
                 var x = this.id;

                 var g = slib.Session.getGender();

                 //outlet is gender independent
                 slib.API.getOutletList(function(r) { wlib.find(x).cb_getOutletList(r); }, function(e) { wlib.find(x).fail(e); });
             }
         }
         this.cb_getOutletList = function(r) {

             r = r.result;

             var c = this.isColumned;

             var i; var m = r.length;

             var pd; //picture/column div
             var ld; //links div

             pd = jQuery(document.createElement("div"));
             pd.addClass(this.picClassName);

             ld = jQuery(document.createElement("div"));
             ld.addClass(this.linksClassName);


             for (i = 0; i < m; i++) {
                 pd = jQuery(document.createElement("div"));
                 pd.addClass(this.picClassName);

                 if (c) {
                     //After 5 columns (when new arrivals active otherwise 6) add a clear as only 6 columns in total can fit.
                     if (i == 6) { this.element.append("<div class=\"clear\"></div><br />") }
                     pd.append("<a href=\"/" + slib.Encoder.URLEncode(r[i].range.toLowerCase()) + "/categories/" + slib.Encoder.URLEncode(r[i].name.toLowerCase()) + "?f_sale=1\">" + slib.Encoder.HTMLEncode(r[i].range.toLowerCase()) + " " + slib.Encoder.HTMLEncode(r[i].name.toLowerCase()) + "</a>");
                 } else {
                     ld = jQuery(document.createElement("div"));
                     ld.addClass(this.linksClassName);
                     ld.append("<a href=\"/" + slib.Encoder.URLEncode(r[i].range.toLowerCase()) + "/categories/" + slib.Encoder.URLEncode(r[i].name.toLowerCase()) + "?f_sale=1\">" + slib.Encoder.HTMLEncode(r[i].range.toLowerCase()) + " " + slib.Encoder.HTMLEncode(r[i].name.toLowerCase()) + "</a>");
                 }

                 //var sg = "<p>";
                 
                 //var first = true;

                 // for (var k = 0; k < r[i].subgroups.length; k++) {
                 //    if (first) {
                 //        first = false;
                 //    } else {
                 //        if (c) {
                 //            sg = sg + "<br/>";
                 //        } else {
                 //            sg = sg + "<br/>";
                 //        }
                 //    }
                 //    sg = sg + "<a href=\"/" + slib.Encoder.URLEncode(r[i].range.toLowerCase()) + "/categories/" + slib.Encoder.URLEncode(r[i].name.toLowerCase()) + "/" + slib.Encoder.URLEncode(r[i].subgroups[k].name.toLowerCase()) + "?f_sale=1\">" + slib.Encoder.HTMLEncode(r[i].subgroups[k].name.toLowerCase()) + "</a>";
                 //}

                 //sg = sg + "</p>";

                 if (c) {
                     //pd.append(sg);
                     this.element.append(pd);
                 } else {
                     //ld.append(sg);
					 
					 
					 
					 
					 
                     this.element.append(ld);

                     slib.MenuManager.register(jQuery("#btnOutletmenu"), jQuery("#outletmenu"));

                 }
             }
			 
			 ld = jQuery(document.createElement("div"));
			 ld.addClass(this.linksClassName);
			 ld.append("<a style=\"font-weight:bold;\" href=\"/ladies/search/?f_sale=1\">Ladies Sale</a>");
			 this.element.append(ld);
			 
			 ld = jQuery(document.createElement("div"));
			 ld.addClass(this.linksClassName);
			 ld.append("<a style=\"font-weight:bold;\" href=\"/mens/search/?f_sale=1\">Mens Sale</a>");
			 this.element.append(ld);
			 
			 
         }
 };OutletMenuWidget.prototype = new Widget();
  });
 
 var BreadCrumbWidget; //###########################################################################################################################################
 jQuery(document).ready(function(){
 BreadCrumbWidget = function() { //Displays service status
	this.id = wlib.getID();
	this.type = "BreadCrumbWidget";	
	this.render = function(parent) {
		if(!this.isRendered) {
			this.id = (this.id == undefined) ? wlib.getID() : this.id;
			var me = jQuery(document.createElement("div"));

			me.attr("id",this.id);
			me.addClass("widget");
			me.addClass("breadcrumbbar");

			//Work out breadcrumb display text and links from current URL using LinkController object in slib
			var breadCrumb = "";
			var breadCrumbURL = "";
			for (var i=0;i<slib.LinkController.parameters.length;i++) {   												
				//Sequentially build up bread crumb links
				
				breadCrumbURL = breadCrumbURL + "/" + slib.Encoder.URLEncode(slib.LinkController.parameters[i]);
				
				//breadCrumbURL = (i+1 != slib.LinkController.parameters.length)? breadCrumbURL + "/" : breadCrumbURL + "";
				
				breadCrumbURL = breadCrumbURL.replace(".asp/",".asp");
				//Switch to exclude certain paths.
				switch(slib.Encoder.URLEncode(slib.LinkController.parameters[i]).toLowerCase()) {
					case "categories":
					case "brands":
					case "style":
					case "default.asp":
						break;
					default:
						//Display breadcrumb
						//breadCrumb = (i == 0) ? breadCrumb + "<a href=\"/\">Home</a> &gt; " : breadCrumb + " &gt; ";
						breadCrumb = (i == 0) ? breadCrumb + "" : breadCrumb + " &gt; ";
						breadCrumb=breadCrumb+"<a href=\"" + breadCrumbURL + "\">";
						breadCrumb=breadCrumb+slib.Encoder.HTMLEncode(slib.LinkController.parameters[i]).replace(".asp","");
						breadCrumb=breadCrumb+"</a>";
				}								
			}
			
			me.append(breadCrumb);

			this.element = me;
			parent.append(me);

			this.isRendered = true;
			jQuery(this.id).fadeIn();
		}
	}
 };BreadCrumbWidget.prototype = new Widget();
 });



var AdvertWidget; //###########################################################################################################################################
jQuery(document).ready(function(){
AdvertWidget = function() { //Displays the adverts
	this.id = wlib.getID();
	this.type = "AdvertWidget";	
	this.render = function(parent) {
		if(!this.isRendered) {
			
			if(wlib.findType("AlsoLikeWidget") != null)
			{
				return;
			}
			
			this.id = (this.id == undefined) ? wlib.getID() : this.id;
			var me = jQuery(document.createElement("div"));			
			me.attr("id",this.id);
			me.addClass("widget");
			me.addClass("advertbar");
			this.element = me;
			
			parent.append(me);
			
			this.isRendered = true;

			var x = this.id;
			slib.API.getAdverts(function(r){wlib.find(x).cb_populate(r);},function(e){wlib.find(x).fail(e);});
			
			jQuery(this.id).fadeIn();
		}
	}	
	this.cb_populate = function(r){
		var i;var m = r.result.length;
		for(i = 0;i < m;i++){
			this.element.append("<a href=\"" + r.result[i].link + "\"><img src=\"" + r.result[i].image + "\" alt=\"" + r.result[i].title + "\" /></a>");						
			this.element.children("a").hover(function(event){
				jQuery(this).fadeTo("fast", 0.7);
			},function(event){
				jQuery(this).fadeTo("fast", 1);
			});
		}

	}
 };AdvertWidget.prototype = new Widget();
 });
 



 
  var GenderMenuWidget; //###########################################################################################################################################
  jQuery(document).ready(function(){
 GenderMenuWidget = function() //Displays service status
 {
	this.id = wlib.getID();
	this.type = "GenderMenuWidget";	
	this.render = function(parent)
	{
		if(!this.isRendered)
		{
			this.id = (this.id == undefined) ? wlib.getID() : this.id;
			var me = jQuery(document.createElement("div"));
			me.attr("id",this.id);
			me.addClass("widget");
		
			if(slib.Session.gender == "m")
			{
				me.append("<a onclick=\"slib.Session.setGender('f',true)\"><img src=\"" + slib.Session.image_path + "/nav/switchtowomens.jpg\"/></a>");
			}
			else if(slib.Session.gender == "f")
			{
				me.append("<a onclick=\"slib.Session.setGender('m',true)\"><img src=\"" + slib.Session.image_path + "/nav/switchtomens.jpg\"/></a>");
			}
			this.element = me;
			parent.append(me);
			this.isRendered = true;
			jQuery(this.id).fadeIn();
		}
	}
 };GenderMenuWidget.prototype = new Widget();
 });
 
 
 
 
 var LoginWidget; //###########################################################################################################################################
  jQuery(document).ready(function(){
 LoginWidget = function() //Displays fixed position div with iframe
 {
	this.id = wlib.getID();
	this.type = "LoginWidget";
	this.liWelcome = null;
	this.liLogin = null;
	this.liLogout = null;
	this.liMyAccount= null;
	this.liRegister = null;
	
	this.render = function()
	{
		if(!this.isRendered)
		{
			
			var parent = jQuery(document.body);
			
			this.id = (this.id == undefined) ? wlib.getID() : this.id;
			var me = jQuery(document.createElement("div"));
			me.attr("id","login_popup");
			me.addClass("widget");
			
			var width = 450;
			
			var left = (slib.Session.screen_width - width)/2;
			var top = (slib.Session.screen_height > 700) ? 300 : 100;
			
			var toolsMenu = jQuery('#tools > ul');
			
			this.liLogin = jQuery(document.createElement("li"));
			
			var that = this;
			
			var loginAnc = jQuery(document.createElement("a")).click(function(){that.show();}).append("Login");
			
			this.liLogin.append(loginAnc);
			
			this.liLogout = jQuery(document.createElement("li")).append(jQuery(document.createElement("a")).click(function(){slib.API.logout(function(){slib.Session.refresh();document.location='/';},null)}).append("Logout"));
			
			this.liWelcome = jQuery(document.createElement("li")).append("Welcome");
			
			this.liMyAccount = jQuery(document.createElement("li")).append("<a href=\"/myaccount/\">My Account</a>");
			
			var loc = document.location + "";
			
			if(loc.indexOf("//") > -1)
			{
				loc = loc.substring(loc.indexOf("//")+2);
				loc = loc.substring(loc.indexOf("/"));
			}
			
			this.liRegister = jQuery(document.createElement("li")).append("<a href=\"/register/?url=" + slib.Encoder.URLEncode(slib.Encoder.URLDecode(loc)) + "\">Sign Up</a>");
			
			this.liLogin.hide();
			this.liLogout.hide();
			this.liWelcome.hide();
			this.liMyAccount.hide();
			this.liRegister.hide();
			
			toolsMenu.prepend(this.liMyAccount);
			toolsMenu.prepend(this.liRegister);
			toolsMenu.prepend(this.liLogout);
			toolsMenu.prepend(this.liLogin);
			toolsMenu.prepend('<li><a onclick="slib.Session.clearCookies();document.location=\'/\'">Home</a></li>');
			toolsMenu.prepend(this.liWelcome);
			
			
			
			
		
			var ssl = (slib.LinkController.ssl) ? "y" : "n";
		
			me.append("<div class='loginpopup_close'><a onclick='jQuery(\"#login_popup\").fadeOut();'><img src='/images/shoestudio/buttons/btn.zclose.png' alt='Close' border='0' /></a></div>");		
			me.append("<iframe src=\"https://" + slib.LinkController.domain + "/includes/login.asp?rssl=" + ssl + "\" height=\"275px\" width=\"450px\" frameborder=\"0\" scrolling=\"no\" />");
			
			me.hide();
			
			//me.css("z-index","5");
			
			this.element = me;
			parent.append(me);
			this.isRendered = true;
			
		}
	};
	
	this.show = function(msg)
	{
		wlib.center(this.element);
		this.element.fadeIn();
	};
	
	this.refresh = function()
	{
		
		var that = this;
		
		this.element.fadeOut();
		
		if(slib.Session.logged_in)
		{
			this.liWelcome.html("Welcome, " + slib.Session.forename + "");
			that.liRegister.fadeOut();
			this.liLogin.fadeOut("",function(){that.liLogout.css("display","inline");that.liWelcome.css("display","inline");that.liMyAccount.css("display","inline");});
		}else{
			this.liLogout.fadeOut("",function(){that.liLogin.css("display","inline");that.liRegister.css("display","inline");});
			that.liMyAccount.fadeOut();
			this.liWelcome.fadeOut();
		}
	};
	
 };LoginWidget.prototype = new Widget();
 });
  
 
 var SearchBoxWidget; //###########################################################################################################################################
 jQuery(document).ready(function() {
     SearchBoxWidget = function() //Basic search form
     {
         this.id = wlib.getID();
         this.type = "SearchBoxWidget";
         this.render = function(parent) {
             if (!this.isRendered) {
                 this.id = (this.id == undefined) ? wlib.getID() : this.id;
                 var me = jQuery(document.createElement("form"));
                 me.attr("id", this.id);
                 me.addClass("widget");
                 me.attr("method", "get");
				 if(slib.Session.range == null)
				 {
					me.attr("action", "/ladies/search/.");
				 }else{
					me.attr("action", "/" + slib.Encoder.URLEncode(slib.Session.range.name) + "/search/.");
				 }

                 var x = this.id;

                 me.submit(
				 function() {
				     var terms = jQuery("#" + x + "_searchinput").attr("value");

				     if (terms == "" || terms == "Search...") {
				         //what to do if no search term is entered...
				         terms = "";
				         wlib.msgbox('Please enter at least one search term to perform a search.');
				         return false;
				     }

				     var collection = wlib.findType("CollectionWidget");
				     if(collection == null)
				     {
						//slib.dump(jQuery("#" + x + "_searchinput"));
					 document.location= "/" + slib.Encoder.URLEncode(slib.Session.range.name) + "/search/" + slib.Encoder.URLEncode(terms);
				     }else{
				     	collection.search(terms);
				     }
				     return false;
				 }
			);


                 var si = jQuery(document.createElement("input"));
                 si.attr("type", "text");
                 si.attr("size", "15");
                 si.attr("name", "search");
                 si.attr("id", x + "_searchinput");
                 si.attr("value", "Search...");
                 si.addClass("search-field");

                 si.focus(function() { if (this.value == 'Search...') { this.value = ''; } });
                 si.blur(function() { if (this.value == '') { this.value = 'Search...'; } });

                 var sb = jQuery(document.createElement("input"));
                 sb.attr("type", "submit");
                 sb.attr("value", "");
                 sb.addClass("search-go");

                 me.append(si);
                 me.append(sb);

                 this.element = me;
                 parent.append(me);
                 this.isRendered = true;
                 jQuery(this.id).fadeIn();
             }
         }
     }; SearchBoxWidget.prototype = new Widget();
 });


var CollectionWidget; //###########################################################################################################################################
jQuery(document).ready(function () {
    CollectionWidget = function () {
        this.id = wlib.getID();
        this.type = "CollectionWidget";
        this.dataset = null;
        this.filtered = null;

        this.masthead = null;

        this.filters = {
            category: false,
            category_selection: null,

            brand: false,
            brand_selection: null,

            price: false,
            price_low: null,
            price_high: null,

            sale: false,

            colour: false,
            colour_selection: null,

            size: false,
            size_selection: null,

            heel: false,
            heel_selection: null,

            theme: false,
            theme_selection: null,
            theme_keywords: null
        };

        this.page = 1;
        this.productsPerPage = 30;

        this.loading = null,
	this.masthead = null,
	this.shelves = null,
	this.masthead_src = '',
	this.hasMasthead = false,

	this.render = function (parent, forceMethod, param1, param2, param3) {
	    if (!this.isRendered) {

	        this.id = (this.id == undefined) ? wlib.getID() : this.id;

	        var me = jQuery(document.createElement("div"));
	        me.attr("id", this.id);
	        me.addClass("widget");
	        me.css("position", "relative");

	        //this.loading = jQuery(document.createElement("div")).css("position","absolute").css("top","0px").css("left","0px").css("opacity","0.8").css("background-color","#ffffff").css("width","100%").css("height","100%").attr("id",this.id + "_loading").html("<h3>Loading..</h3>").hide();
	        this.loading = jQuery(document.createElement("img")).attr("src", slib.Session.image_path + "/loading.gif").hide();
	        this.masthead = jQuery(document.createElement("img")).hide();
	        this.shelves = jQuery(document.createElement("div"));

	        me.append(this.loading);
	        me.append(jQuery('<p class="masthead"></p>').append(this.masthead));
	        me.append(this.shelves);

	        this.element = me;
	        parent.append(me);
	        this.isRendered = true;
	        var x = this.id;

	        var g = slib.Session.getGender();

	        if (g != 'm' && g != 'f') // ...although should search be unisex?
	        {
	            if (slib.Session.site_id == 5) {
	                document.location = '/home';
	            } else {
	                g = 'u';
	            }
	        }

	        var params = slib.LinkController.parameters;
	        params[2] = (param1 == undefined) ? params[2] : param1;
	        params[3] = (param2 == undefined) ? params[3] : param2;
	        params[4] = (param3 == undefined) ? params[4] : param3;

	        var method = "standard";

	        if (params[1] == "search") {
	            method = "search";
	        } else if (params[1] == "new") {
	            //show new arrivals
	            method = "new"
	        } else if (params[1] == "wishlist") {
	            //show wishlist
	            method = "wishlist"
	        } else if (params[1] == "brands") {
	            //display brand [,group [,subgroup]] 
	            method = "brand"
	        } else if (params[1] == "categories") {
	            //display group [,subgroup]
	            method = "group"
	        }



	        // Find filter widget, set filters
	        this.reconfigureFilters();

	        method = (typeof forceMethod == 'undefined') ? method : forceMethod;

	        var pathName;

	        if (method == "brand") {
	            this.loading.fadeIn();
	            pathName = params[2].toLowerCase().replace(/ /g, "");
	            if (params[0] == 'outlet') { pathName = params[0].toLowerCase().replace(/ /g, ""); };   //change parameter used for outlet masthead

	            this.masthead.attr("src", slib.Session.image_path + "/mastheads/" + pathName + ".jpg");

	            if (params.length == 3) {
	                slib.API.getProductsByBrandName(function (r) { wlib.find(x).cb_query(r); }, function (r) { wlib.find(x).fail(r); }, params[2]);
	            } else if (params.length == 4) {
	                slib.API.getProductsByBrandName(function (r) { wlib.find(x).cb_query(r); }, function (r) { wlib.find(x).fail(r); }, params[2], params[3]);
	            } else if (params.length >= 5) {
	                slib.API.getProductsByBrandName(function (r) { wlib.find(x).cb_query(r); }, function (r) { wlib.find(x).fail(r); }, params[2], params[3], params[4]);
	            } else {
	                //bad request
	                //alert("Fail!");
	            }
	        } else if (method == "group") {
	            this.loading.fadeIn();
	            pathName = params[0].toLowerCase().replace(/ /g, "") + "." + params[2].toLowerCase().replace(/ /g, "")
	            if (params[0] == 'outlet') { pathName = params[0].toLowerCase().replace(/ /g, ""); };   //change parameter used for outlet masthead

	            this.masthead.attr("src", slib.Session.image_path + "/mastheads/" + pathName + ".jpg");

	            if (params.length == 3) {
	                slib.API.getProductsByGroupName(function (r) { wlib.find(x).cb_query(r); }, function (r) { wlib.find(x).fail(r); }, params[2]);
	            } else if (params.length >= 4) {
	                slib.API.getProductsByGroupName(function (r) { wlib.find(x).cb_query(r); }, function (r) { wlib.find(x).fail(r); }, params[2], params[3]);
	            }
	        } else if (method == "search") {
	            //this.loading.fadeIn();
	            if (params[2] == 'sale') {
	                this.masthead.attr("src", slib.Session.image_path + "/mastheads/sale." + slib.Session.range.name + ".jpg");
	            }

	            this.forceMH = true;

	            this.search(params[2]);
	        } else if (method == "new") {
	            this.loading.fadeIn();
	            this.masthead.attr("src", slib.Session.image_path + "/mastheads/" + "newarrivals" + ".jpg");
	            if (slib.Session.range == null) {
	                slib.API.getNewArrivals(function (r) { wlib.find(x).cb_query(r); }, function (r) { wlib.find(x).fail(r); }, FORCE_GENDER);
	            } else {
	                slib.API.getNewArrivals(function (r) { wlib.find(x).cb_query(r); }, function (r) { wlib.find(x).fail(r); }, slib.Session.range.name);
	            }
	        } else if (method == "wishlist") {
	            this.loading.fadeIn();
	            this.masthead.attr("src", slib.Session.image_path + "/mastheads/" + "wishlist" + ".jpg");
	            slib.API.getWishlist(function (r) { wlib.find(x).cb_query(r); }, function (r) { wlib.find(x).fail(r); });
	        } else if (method == "none") {
	            //don't do nuffink
	        } else {
	            alert("Not supported yet (" + method + ").");
	        }

	        this.masthead.hide();

	    }
	}


        this.search = function (keywords) {
            this.loading.show();
            this.page = 1;
            var x = this.id;
            if (keywords == "sale") {
                slib.API.getProductsBySale(function (r) { slib.gui.findType("CollectionWidget").cb_query(r); }, function (r) { wlib.find(x).fail(r); });
            } else {
                slib.API.getProductsBySearch(function (r) { slib.gui.findType("CollectionWidget").cb_query(r); }, function (r) { wlib.find(x).fail(r); }, keywords);
            }
        }

        this.reconfigureFilters = function () {
            var filterWidget = wlib.findType('SearchFilterWidget');

            if (filterWidget != null) {
                this.filters = filterWidget.filters;
            }
        }

        this.cb_query = function (r) {
            //r.result = slib.sort(r.result,"name",slib.constants.ASCENDING);


            this.dataset = (r.status == "OK") ? slib.cast(r.result.products, "Product") : []; //bugfix for slib: failure to correctly cast types on nested array                                    
            try {
                if (this.forceMH == undefined || this.forceMH) {
                    this.masthead_src = (r.status == "OK") ? r.result.masthead : "";
                }
            } catch (e) {
                this.masthead_src = (r.status == "OK") ? r.result.masthead : "";
            }

            if (slib.Session.dbs != "shoestudio") {
                this.masthead.hide();
                this.hasMasthead = false;
            } else {

                if (this.masthead_src != "") {
                    if (!/\/\//.test(this.masthead_src)) {
                        this.masthead.attr("src", this.masthead_src).fadeIn();
                    }
                    this.hasMasthead = true;
                    this.masthead.fadeIn();
                } else if (this.masthead.attr("src") && this.masthead.attr("src") != "") {
                    this.hasMasthead = true;
                    this.masthead.fadeIn();
                } else {
                    this.masthead.hide();
                    this.hasMasthead = false;
                }

            }

            this.filter();
        }

        //TODO: error handling

        this.filter = function () {
            //loop through all results and decide whether each fits the current filter set

            this.filtered = [];

            var display;
            var cFound = false;

            var stock = 0;

            if (this.dataset == null) { return; } //no dataset yet!

            for (var i = 0; i < this.dataset.length; i++) {
                //set product to display before checking filters
                display = true;

                //filter out products with no stock
                try {
                    stock = 0;
                    for (var j = 0; j < this.dataset[i].availableColours.length; j++) {
                        for (var k = 0; k < this.dataset[i].availableColours[j].availableSizes.length; k++) { //this may be undefined depending on query type - hence the try
                            stock = stock + this.dataset[i].availableColours[j].availableSizes[k].stock;
                        }
                    }
                    if (stock == 0) {
                        display = false;
                    }
                } catch (e) { }

                //Category filter
                if (this.filters.category) {
                    //case insensitive category comparison
                    if (this.dataset[i].group.name.toLowerCase() != this.filters.category_selection.toLowerCase()) {
                        display = false;
                    }
                }

                //Brand filter
                if (this.filters.brand) {
                    if (this.dataset[i].brand.name.toLowerCase() != this.filters.brand_selection.toLowerCase()) {
                        display = false;
                    }
                }

                //Price filter
                if (this.filters.price) {
                    if (slib.Session.currency == "GBP") {
                        if (this.dataset[i].salePrice_GBP < this.filters.price_low || this.dataset[i].salePrice_GBP > this.filters.price_high) {
                            display = false;
                        }
                    } else if (slib.Session.currency == "EUR") {
                        if (this.dataset[i].salePrice_EUR < this.filters.price_low || this.dataset[i].salePrice_EUR > this.filters.price_high) {
                            display = false;
                        }
                    } else if (slib.Session.currency == "USD") {
                        if (this.dataset[i].salePrice_USD < this.filters.price_low || this.dataset[i].salePrice_USD > this.filters.price_high) {
                            display = false;
                        }
                    }
                }

                //Sale only filter
                if (this.filters.sale) {
                    if (!this.dataset[i].isSale) {
                        display = false;
                    }
                }

                //Colour filter
                cFound = false;
                if (this.filters.colour) {
                    for (var ii in this.dataset[i].availableColours) {
                        if (this.dataset[i].availableColours[ii].name.toLowerCase().indexOf(this.filters.colour_selection.toLowerCase()) != -1) {
                            cFound = true;
                            this.dataset[i].colour = this.dataset[i].availableColours[ii];
                        }
                    }

                    if (!cFound) {
                        display = false;
                    }
                }


                //Size filter
                cFound = false;
                if (this.filters.size) {
                    for (var ii in this.dataset[i].availableColours) {
                        for (var iii in this.dataset[i].availableColours[ii].availableSizes) {
                            if ((this.dataset[i].availableColours[ii].availableSizes[iii].size.toLowerCase().indexOf(this.filters.size_selection.toLowerCase()) != -1) && (this.dataset[i].availableColours[ii].availableSizes[iii].stock > 0)) {
                                cFound = true;
                            }
                        }
                    }

                    if (!cFound) {
                        display = false;
                    }
                }


                //Heel height filter
                cFound = false;
                if (this.filters.heel) {
                    if (this.dataset[i].heel.toLowerCase().indexOf('heel height') != -1) {
                        var heelFilter = "";
                        var heelunit = "";
                        var heel = this.dataset[i].heel.toLowerCase();

                        heel = heel.replace(/heel height/g, ''); //remove just text - heel height can be present with or without a colon
                        heel = heel.replace(/bo.*/gi, ''); //remove just text - heel height can be present with or without a colon
                        heel = heel.replace(/:/g, ''); //remove just colon                        
                        heel = heel.replace(/ /g, ''); //remove any remaining spaces                        

                        //Regular expressions to find measurement unit
                        //inches 
                        var inches = /"$/;
                        //centimetres (including typos in database)
                        var cm = [];
                        cm[0] = /cm$/;
                        cm[1] = /c$/;
                        cm[2] = /xm$/;

                        //Find out if we've got centimetres or inches
                        if (inches.test(heel)) heelunit = 'inches';
                        heel = heel.replace(inches, ''); //remove measurement symbol
                        for (var he = 0; he < cm.length; he++) {
                            if (cm[he].test(heel)) heelunit = 'cm';
                            heel = heel.replace(cm[he], ''); //remove measurement symbol
                        }

                        if (!isNaN(heel)) {
                            if (heelunit == 'inches') {
                                if (heel < 1) { heelFilter = "flat" } else
                                    if ((heel > 1) && (heel < 4)) { heelFilter = "mid" } else
                                        if (heel > 4) { heelFilter = "high" }
                            }
                            if (heelunit == 'cm') {
                                if (heel <= 5.9) { heelFilter = "flat" } else
                                    if ((heel >= 6) && (heel <= 9.5)) { heelFilter = "mid" } else
                                        if (heel >= 10) { heelFilter = "high" }
                            }
                        } else {
                            //add exceptions for unusual string matches seen across all databases for future use
                            if (heel == 'low') { heelFilter = "flat" } else
                                if (heel == 'medium') { heelFilter = "mid" } else
                                    if (heel == 'highwedge') { heelFilter = "high" } else
                                        if (heel == 'veryhigh') { heelFilter = "high" }
                        }

                        if (heelFilter.indexOf(this.filters.heel_selection.toLowerCase()) != -1) {
                            cFound = true;
                        }
                    } else {
                        cFound = false;
                    }

                    if (!cFound) {
                        display = false;
                    }
                }


                //Theme filter
                cFound = false;
                if (this.filters.theme) {
                    for (var ii in this.dataset[i].availableColours) {
                        var arProdKeys = this.dataset[i].availableColours[ii].keywords.split(',');
                        var arThemKeys = this.filters.theme_keywords.split(',');
                        arProdKeys[arProdKeys.length] = this.dataset[i].range.name;    //add range name to product keys
                        arProdKeys[arProdKeys.length] = this.dataset[i].group.name;    //add range name to product keys
                        arProdKeys[arProdKeys.length] = this.dataset[i].subgroup.name; //add range name to product keys
                        for (var a in arProdKeys) {
                            for (var aa in arThemKeys) {
                                if (arProdKeys[a].toLowerCase().indexOf(arThemKeys[aa].toLowerCase()) != -1) {
                                    cFound = true;
                                }
                            }
                        }
                        if (!cFound) {
                            display = false;
                        }
                    }
                }


                if (display) {
                    this.filtered[this.filtered.length] = this.dataset[i];
                }

            }

            this.display();
        };

        this.switchColour = function (item, colour) {
            this.filtered[item].setCollectionImage(jQuery("#" + this.id + "_collection_item_" + item), this.filtered[item].availableColours[colour]);
            this.filtered[item].setCode(this.filtered[item].availableColours[colour].code);
            this.filtered[item].setCollectionLink(jQuery("#" + this.id + "_collection_item_a" + item), this.filtered[item].buildLink());
        };



        this.display = function (page) {
            this.loading.hide();

            this.shelves.html("");

            if (slib.Session.dbs == "shoestudio") {
                if (this.filtered.length == 0) { this.shelves.html("<p>Sorry, no products were found matching the chosen criteria.</p><p>You can broaden the criteria using the 'refine by' filters at the top right of the page or using the shop by product and brand menus underneath the Shoe Studio logo. You can also search all products using the search box at the very top right.</p>"); return; }
            } else {
                if (this.filtered.length == 0) { this.shelves.html("<p>Sorry, no products were found matching the chosen criteria.</p>"); return; }
            }


            //If current page not defined use default value
            this.page = (page == undefined) ? this.page : page;

            var je;
            var set = null;
            var products = null;
            var shelf;

            var that = this;
            var x = this.id;

            //If we want to view all products then set products per page to length of dataset for the loop below.
            var prodsForLoop = (this.page == "all") ? (this.filtered.length + 1) : this.productsPerPage;
            var prodsAll = this.page;
            var all = (this.page == "all");
            this.page = (this.page == "all") ? 1 : this.page;



            //Set products on page based on current page
            var max = (this.page * prodsForLoop);

            //If max is larger than the amount of products then reduce max to length of products.
            max = (max > this.filtered.length) ? this.filtered.length : max;

            //--Create Paginator--			
            var pagHTML = "";
            //Loop through pages creating page links for each if there's more than 1 page worth of products.
            if (this.countPages() > 1) {
                //Show previous button if it can be used
                if (this.page > 1) {
                    pagHTML += "<a onclick='wlib.find(\"" + x + "\").prevPage()'><li onclick='wlib.find(\"" + x + "\").prevPage()'>&lt;</li></a>";
                }
                for (var l = 1; l < this.countPages() + 1; l++) {
                    //If current page and not viewing the 'all' page..
                    var liclass = ((this.page == l) && (prodsAll != "all")) ? "selected" : "";
                    pagHTML += "<a onclick='wlib.find(\"" + x + "\").display(" + l + ")'><li onclick='wlib.find(\"" + x + "\").display(" + l + ")' class=\"" + liclass + "\">" + l + "</li></a>";
                }
                //Show next button if it can be used
                if (this.page < this.countPages() && prodsAll != "all") {
                    pagHTML += "<a onclick='wlib.find(\"" + x + "\").nextPage()'><li onclick='wlib.find(\"" + x + "\").nextPage()'>&gt;</li></a> ";
                }
                //Show 'show all' button
                var liclass = ((prodsAll == "all")) ? "selected" : "";
                pagHTML += "<a onclick='wlib.find(\"" + x + "\").display(\"all\")'><li onclick='wlib.find(\"" + x + "\").display(\"all\")' class='showall " + liclass + "'>Show all</li></a>";
            }

            //Display paged controler (paginator) at the top.
            if ((slib.Session.dbs != "dune") || (slib.Session.multi_site)) var paginator = jQuery(document.createElement("ul")).addClass("paginator").html(pagHTML + "<br class=\"clear\"/>");


            this.shelves.append(paginator);

            var last = "";

            for (var k = ((this.page - 1) * prodsForLoop); k < max; k++) {

                inf = '';

                if (slib.Session.dbs == "shoestudio") {

                    if (set == null) {
                        set = jQuery(document.createElement("div")).addClass("productset");
                        products = jQuery(document.createElement("div")).addClass("products");
                    }

                    //Product image

                    je = jQuery(document.createElement("div")).addClass("collectionitem");
                    je.append(jQuery(document.createElement("a")).attr("id", this.id + "_collection_item_a" + k).attr("href", this.filtered[k].buildLink()).append(jQuery(document.createElement("img")).attr("id", this.id + "_collection_item_" + k)).css("position", "relative"));


                    //##### Swatch Popup

                    var mo = '';

                    var popdivWidth = 100;
                    var mwf = false;

                    for (var zz in this.filtered[k].availableColours) {
                        mo += '<a onclick="wlib.findType(\'CollectionWidget\').switchColour(' + k + ',' + zz + ')"><img src="' + this.filtered[k].getSwatchPath(this.filtered[k].availableColours[zz]) + '" alt="' + this.filtered[k].availableColours[zz].name + '" title="' + this.filtered[k].availableColours[zz].name + '"/></a>';
                        if (zz > 1) {
                            popdivWidth += 27;
                            mwf = true;
                        }
                    }

                    var popdiv = jQuery(document.createElement("div")).addClass("popupswatches").html(mo).css("width", popdivWidth);
                    var mod = jQuery(document.createElement("div")).addClass("productpopup").attr("id", this.id + "_collection_item_hover_" + k); ;
                    mod.append(popdiv);


                    //#######

                    je.append(mod); //add popup to Product Image div			
                    products.append(je); //add Product image div to products div


                    //Product info
                    var inf = '';


                    inf += '<div class="popupdetails">';

                    inf += '<p class="popuptitle">' + this.filtered[k].brand.name.toLowerCase() + ' ' + this.filtered[k].name + ' <br />';

                    if (this.filtered[k].isSale) {
                        inf += '<span class=\'strikeout\'>';
                    }

                    inf += '<strong>' + slib.Session.currencySymbol;

                    var fp;

                    if (slib.Session.currency == "GBP") {
                        fp = this.filtered[k].fullPrice_GBP;
                    } else if (slib.Session.currency == "EUR") {
                        fp = this.filtered[k].fullPrice_EUR;
                    } else if (slib.Session.currency == "USD") {
                        fp = this.filtered[k].fullPrice_USD;
                    }

                    fp = fp + ""; if (fp.indexOf(".") > -1) { var pence = fp.substring(fp.indexOf(".") + 1); while (pence.length < 2) { pence += "0"; fp += "0"; } }
                    inf += fp;

                    if (this.filtered[k].isSale) {
                        inf += '</span> '
                        inf += '<span class=\'saleprice\'>'
                        inf += slib.Session.currencySymbol;
                        if (slib.Session.currency == "GBP") {
                            fp = this.filtered[k].salePrice_GBP;
                        } else if (slib.Session.currency == "EUR") {
                            fp = this.filtered[k].salePrice_EUR;
                        } else if (slib.Session.currency == "USD") {
                            fp = this.filtered[k].salePrice_USD;
                        }

                        fp = fp + ""; if (fp.indexOf(".") > -1) { var pence = fp.substring(fp.indexOf(".") + 1); while (pence.length < 2) { pence += "0"; fp += "0"; } }
                        inf += fp;

                        inf += '</span>'
                    }
                    inf += '</strong>';
                    inf += '</p>';
                    inf += '</div>';

                    je.append(inf); //add info to Product Image div

                    if ((k + 1) % 3 == 0) {
                        set.append(products);

                        shelf = jQuery(document.createElement("div"));
                        shelf.addClass("shelf");
                        //shelf.append(jQuery(document.createElement("img")).attr("src",slib.Session.image_path + "/shelf.jpg").attr("border","0"));

                        set.append(shelf);
                        this.shelves.append(set);
                        set = null;
                        products = null;
                    }
                    this.filtered[k].setCollectionImage(je.children(":first-child").children(":first-child"));

                } else {


                    //Pricing
                    var fp; if (slib.Session.currency == "GBP") { fp = this.filtered[k].fullPrice_GBP; } else if (slib.Session.currency == "EUR") { fp = this.filtered[k].fullPrice_EUR; } else if (slib.Session.currency == "USD") { fp = this.filtered[k].fullPrice_USD; } else { fp = this.filtered[k].fullPrice_GBP; }
                    var sp; if (slib.Session.currency == "GBP") { sp = this.filtered[k].salePrice_GBP; } else if (slib.Session.currency == "EUR") { sp = this.filtered[k].salePrice_EUR; } else if (slib.Session.currency == "USD") { sp = this.filtered[k].salePrice_USD; } else { sp = this.filtered[k].salePrice_GBP; }
                    sp = sp + '';
                    fp = fp + '';
                    if (sp.indexOf(".") > -1) { if (sp.substring(sp.indexOf(".") + 1).length == 1) { sp = sp + '0'; } }
                    if (fp.indexOf(".") > -1) { if (fp.substring(fp.indexOf(".") + 1).length == 1) { fp = fp + '0'; } }

                    //HTML built here!

                    var inf = '';

                    // this.filtered[k] is the current product object
                    // everything created here needs to be appended to this.shelves
                    if (slib.Session.multi_site) {

                        var ccc = this.filtered[k].colour;
                        //DPOS
                        for (var zz in this.filtered[k].availableColours) {
                            inf = '<a href="/dpos/product.asp?ItemCode=' + this.filtered[k].availableColours[zz].barcode + '&fw=1"><img src="" id="' + this.id + '_collection_item_' + k + "_" + zz + '"/></a>';
                            this.shelves.append(inf);
                            this.filtered[k].colour = this.filtered[k].availableColours[zz];
                            this.filtered[k].setCollectionImage($('#' + this.id + '_collection_item_' + k + "_" + zz), undefined, 100, 120);
                        }

                        this.filtered[k].colour = ccc;



                    } else if (slib.Session.dbs == "piedaterre") {

                        inf = '<div class="rangetile"><div class="rangeimage">';
                        inf += '<a id="' + this.id + '_collection_item_a' + k + '" style="cursor:pointer;" href="' + this.filtered[k].buildLink() + '" onMouseover="PM_popProduct(\'div_name_' + this.filtered[k].name + '' + this.filtered[k].colour.name + '\',\'show\');"><img id="' + this.id + '_collection_item_' + k + '" name="pos_' + this.filtered[k].name + '" style="border:0px;" /></a>';
                        inf += '</div><div class="rangetitle">' + slib.Text.cap(this.filtered[k].name) + ' <i id="prod_' + this.filtered[k].name + '" >' + slib.Session.currencySymbol;
                        inf += sp;
                        inf += '</i></div>';
                        inf += '<div class="rangeswatches">';
                        var swatchLimit = 4;
                        var swatchCount = 0;
                        //Swatches
                        for (var zz in this.filtered[k].availableColours) {

                            if (swatchCount < swatchLimit) {
                                inf += '<li class="liLocal_subgroupDisplay_swatch">';
                                inf += '<div style="width:25px;height:25px;border:1px solid #b9ada1;background-image:url(/images/clear.gif);background-position:166px 77px;">';
                                inf += '<a style="cursor:pointer;" onclick="wlib.findType(\'CollectionWidget\').switchColour(' + k + ',' + zz + ')" ';
                                inf += 'onMouseover="PM_popProduct(\'div_name_' + this.filtered[k].name + '\',\'show\');">';
                                inf += '<img src="' + this.filtered[k].getSwatchPath(this.filtered[k].availableColours[zz]) + '" alt="' + this.filtered[k].name + ' ' + this.filtered[k].availableColours[zz].name + '" style="width:25px;height:25px;border:0px;" />';
                                inf += '</a><br/>';
                                inf += '<img id="swa_' + this.filtered[k].name + '_' + this.filtered[k].availableColours[zz].id + '" src="/images/clear.gif" style="width:25px;height:8px;"/>';
                                inf += '</div>';
                                inf += '</li>';
                            } else {
                                break;
                            }

                            swatchCount++
                        }

                        inf += '</div></div>';

                        this.shelves.append(inf);

                        //Set image
                        this.filtered[k].setCollectionImage($('#' + this.id + '_collection_item_' + k), undefined, slib.Session.collectionImageWidth, slib.Session.collectionImageHeight);

                    } else if (slib.Session.dbs == "dune") {

                        var ww; var hh; var view;

                        if (slib.LinkController.getQueryStringVar("view") == "grid") {
                            //grid view
                            slib.Session.collectionImageWidth = 100;
                            slib.Session.collectionImageHeight = 120;
                            ww = 100;
                            hh = 120;
                            view = "grid";
                        } else {
                            slib.Session.collectionImageWidth = 200; //sliding!
                            slib.Session.collectionImageHeight = 230;
                            ww = 200;
                            hh = 230;
                            view = "sliding";
                        }


                        if (view == "sliding") {

                            inf = '<div class="divLocal_subgroupDisplayContainer" style="width:' + ww + 'px;height:300px !important;">';
                            inf += '<div class="divLocal_subgroupDisplayContent" style="width:' + ww + 'px;height:' + hh + 'px;">';
                            inf += '	<a id="' + this.id + '_collection_item_a' + k + '" style="cursor:pointer;" href="' + this.filtered[k].buildLink() + '" onMouseover="PM_popProduct(\'div_name_' + this.filtered[k].name + '\',\'show\');">';
                            inf += '<img id="' + this.id + '_collection_item_' + k + '" name="pos_' + this.filtered[k].name + '" alt="' + this.filtered[k].name + '" src="" style="width:' + slib.Session.collectionImageWidth + 'px;height:' + slib.Session.collectionImageHeight + 'px;border:0px;" /></a>';

                            inf += '<div id="div_name_' + this.filtered[k].name + '" class="divLocal_subgroupDisplay_popup">';




                            inf += '<div class="divLocal_subgroupDisplay_popupBottom"  style="';
                            if (sp < fp) {
                                inf += 'background-color:rgb(165, 35, 45);color:#ffffff';
                            } else {
                                inf += 'background-color: rgb(234, 231, 224); color: rgb(115, 102, 94);';
                            }
                            inf += ';">';
                            inf += this.filtered[k].name.toUpperCase() + '<br />';
                            inf += '<span class="spnLocal_subgroupDisplay_popupBottom_price_centre" style="font-size:0.85em;">';
                            inf += '<span class="spnLocal_subgroupDisplay_popupBottom_price_old">';
                            if (sp < fp) {
                                inf += slib.Session.currencySymbol + fp;
                            }
                            inf += '</span>';
                            inf += slib.Session.currencySymbol + sp;
                            inf += '</span></div></div></div>';

                            inf += '<div class="divLocal_subgroupDisplay_swatchContainer"><div style="position:relative;margin:auto;"><ul style="position:relative;padding:0px;width:' + (((this.filtered[k].availableColours.length + 1) * 30)) + 'px;margin:auto;">';


                            for (var zz in this.filtered[k].availableColours) {
                                if (this.filtered[k].availableColours.length > 1) {
                                    inf += '<li class="liLocal_subgroupDisplay_swatch" style=""><div style="width:25px;height:25px;border:1px solid #b9ada1;background-image:url(/images/clear.gif);background-position:166px 77px;">';
                                    inf += '<a style="cursor:pointer;" onclick="wlib.findType(\'CollectionWidget\').switchColour(' + k + ',' + zz + ')" ';
                                    inf += 'onMouseover="PM_popProduct(\'div_name_' + this.filtered[k].name + '\',\'show\');">';
                                    inf += '<img src="' + this.filtered[k].getSwatchPath(this.filtered[k].availableColours[zz]) + '" alt="' + this.filtered[k].name + ' ' + this.filtered[k].availableColours[zz].name + '" style="width:25px;height:25px;border:0px;" />';
                                    inf += '</a><br/>';
                                    inf += '<img id="swa_' + this.filtered[k].name + '_' + this.filtered[k].availableColours[zz].id + '" src="/images/clear.gif" style="width:25px;height:8px;"/>';
                                    inf += '</div></li>';
                                }
                            }
                            inf + '</ul></div></div>';

                            inf += '</div>';
                            this.shelves.append(inf);
                            this.filtered[k].setCollectionImage($('#' + this.id + '_collection_item_' + k), undefined, slib.Session.collectionImageWidth, slib.Session.collectionImageHeight);
                        } else {

                            for (var zz in this.filtered[k].availableColours) {

                                this.filtered[k].colour = this.filtered[k].availableColours[zz];

                                inf = '<div class="divLocal_subgroupDisplayContainer" style="width:' + ww + 'px;">';
                                inf += '<div class="divLocal_subgroupDisplayContent" style="width:' + ww + 'px;height:250px;">';
                                inf += '	<a id="' + this.id + '_collection_item_a' + k + '" style="cursor:pointer;" href="' + this.filtered[k].buildLink() + '" onMouseover="PM_popProduct(\'div_name_' + this.filtered[k].name + zz + '\',\'show\');">';
                                inf += '<img id="' + this.id + '_collection_item_' + k + "_" + zz + '" name="pos_' + this.filtered[k].name + '" alt="' + this.filtered[k].name + '" src="" style="width:' + slib.Session.collectionImageWidth + 'px;height:' + slib.Session.collectionImageHeight + 'px;border:0px;" /></a>';

                                inf += '<div id="div_name_' + this.filtered[k].name + zz + '" class="divLocal_subgroupDisplay_popup" style="top:110px;width:100px;">';

                                inf += '<div class="divLocal_subgroupDisplay_popupTop" style="background-image:url(/images/prodnav.arrow.gif);"><!--SPACER--></div>';

                                inf += '<div class="divLocal_subgroupDisplay_popupBottom_small" style="background-color:#eae7e0;color:#73665e;">';

                                inf += this.filtered[k].name.toUpperCase() + '<br />';

                                if (sp < fp) {
                                    inf += '<div class="divLocal_subgroupDisplay_popupBottom_small_sale">&nbsp;</div>';
                                }

                                inf += '<span style="font-size:0.85em;" class="spnLocal_subgroupDisplay_popupBottom_small_price" style="font-size:0.85em;73665e;">';
                                inf += slib.Session.currencySymbol + fp;
                                inf += '</span></div></div></div></div>';

                                this.shelves.append(inf);
                                //Set image
                                this.filtered[k].setCollectionImage($('#' + this.id + '_collection_item_' + k + "_" + zz), undefined, slib.Session.collectionImageWidth, slib.Session.collectionImageHeight);

                            }

                        }





                    } else if (slib.Session.dbs == "chelsea") {

                        slib.Session.collectionImageWidth = 190; //sliding!
                        slib.Session.collectionImageHeight = 190;

                        inf += '<div class="divLocal_subgroupDisplayContainer" style="width:180px;">';
                        inf += '<div class="divLocal_subgroupDisplayContent" style="width:180px;height:200px;">';
                        inf += '<a id="' + this.id + '_collection_item_a' + k + '" style="cursor:pointer;" href="' + this.filtered[k].buildLink() + '" onMouseover="PM_popProduct(\'div_name_' + this.filtered[k].name + '' + this.filtered[k].colour.name + '\',\'show\');"><img id="' + this.id + '_collection_item_' + k + '" name="pos_' + this.filtered[k].name + '" style="border:0px;width:' + slib.Session.collectionImageWidth + 'px;height:' + slib.Session.collectionImageHeight + 'px;" /></a><br/>';
                        inf += ' <div class="divLocal_staticProductData"><strong>';
                        inf += '<a style="cursor:pointer;color:#aeaeae;text-decoration:none !important;" href="' + this.filtered[k].buildLink() + '">'
                        inf += slib.Text.cap(this.filtered[k].name)
                        inf += '</a></strong><br/>';



                        inf += '<span style="color:#aa0000;">';
                        if (sp < fp) {
                            inf += slib.Session.currencySymbol + sp;
                        }
                        inf += '</span><span style="font-size:8pt;">';
                        if (sp < fp) { inf += '(was '; }
                        inf += slib.Session.currencySymbol + fp;
                        if (sp < fp) { inf += ')'; }
                        inf += '</span></div>';
                        inf += '<div class="divLocal_staticProductBrand">';
                        inf += '<img src="' + slib.Session.image_path + "/brands/on_white/" + this.filtered[k].range.name.replace(/ /gi, "").toLowerCase() + ".jpg" + '"/>';
                        inf += '</div></div></div>';

                        this.shelves.append(inf);

                        //Set image
                        this.filtered[k].setCollectionImage($('#' + this.id + '_collection_item_' + k), undefined, slib.Session.collectionImageWidth, slib.Session.collectionImageHeight);

                    } else if (slib.Session.dbs == "bertie") {

                        var ww; var hh; var view;

                        if (slib.LinkController.getQueryStringVar("view") == "grid") {
                            //grid view
                            slib.Session.collectionImageWidth = 100; //sliding!
                            slib.Session.collectionImageHeight = 120;
                            ww = 100;
                            hh = 120;
                            view = "grid";
                        } else {
                            slib.Session.collectionImageWidth = 200; //sliding!
                            slib.Session.collectionImageHeight = 230;
                            ww = 205;
                            hh = 300;
                            view = "sliding";
                        }

                        if (view == "sliding") {

                            inf = '<div class="divLocal_subgroupDisplayContainer" style="width:' + ww + 'px;height:' + hh + 'px !important;">';
                            inf += '<div class="divLocal_subgroupDisplayContent" style="width:' + ww + 'px;height:250px;">';
                            inf += '	<a id="' + this.id + '_collection_item_a' + k + '" style="cursor:pointer;" href="' + this.filtered[k].buildLink() + '" onMouseover="PM_popProduct(\'div_name_' + this.filtered[k].name + '\',\'show\');">';
                            inf += '<img id="' + this.id + '_collection_item_' + k + '" name="pos_' + this.filtered[k].name + '" alt="' + this.filtered[k].name + '" src="" style="width:' + slib.Session.collectionImageWidth + 'px;height:' + slib.Session.collectionImageHeight + 'px;border:0px;" /></a>';

                            inf += '<div id="div_name_' + this.filtered[k].name + '" class="divLocal_subgroupDisplay_popup">';

                            if (sp < fp) {
                                inf += '<div class="divLocal_subgroupDisplay_popupTop_sale" style="background-image:url(\'/images/prodnav.arrow.sale.gif\')"><!--SPACER--></div>';
                            }

                            inf += '<div class="divLocal_subgroupDisplay_popupBottom"  style="background-color:rgb(165, 35, 45);color:#ffffff;">';
                            inf += slib.Text.cap(this.filtered[k].name) + '<br />';
                            if (sp < fp) {
                                inf += '<span class="spnLocal_subgroupDisplay_popupBottom_price" style="font-size:0.85em;">';
                            } else {
                                inf += '<span class="spnLocal_subgroupDisplay_popupBottom_price_centre" style="font-size:0.85em;">';
                            }
                            inf += '<span class="spnLocal_subgroupDisplay_popupBottom_price_old">';
                            if (sp < fp) {
                                inf += slib.Session.currencySymbol + fp;
                            }
                            inf += '</span>';

                            inf += slib.Session.currencySymbol + sp;
                            inf += '</span>';
                            if (sp < fp) {
                                inf += '<span class="divLocal_subgroupDisplay_popupBottom_sale">&nbsp;</span>';
                            }

                            inf += '</div></div></div>';


                            inf += '<div class="divLocal_subgroupDisplay_swatchContainer"><div style="position:relative;margin:auto;"><ul style="position:relative;padding:0px;width:' + ((this.filtered[k].availableColours.length + 1) * 26) + 'px;margin:auto;">';

                            for (var zz in this.filtered[k].availableColours) {
                                if (this.filtered[k].availableColours.length > 1) {
                                    inf += '<li class="liLocal_subgroupDisplay_swatch"><div style="width:25px;height:25px;border:1px solid #b9ada1;background-image:url(/images/clear.gif);background-position:166px 77px;">';
                                    inf += '<a style="cursor:pointer;" onclick="wlib.findType(\'CollectionWidget\').switchColour(' + k + ',' + zz + ')" ';
                                    inf += 'onMouseover="PM_popProduct(\'div_name_' + this.filtered[k].name + '\',\'show\');">';
                                    inf += '<img src="' + this.filtered[k].getSwatchPath(this.filtered[k].availableColours[zz]) + '" alt="' + this.filtered[k].name + ' ' + this.filtered[k].availableColours[zz].name + '" style="width:25px;height:25px;border:0px;" />';
                                    inf += '</a><br/>';
                                    inf += '<img id="swa_' + this.filtered[k].name + '_' + this.filtered[k].availableColours[zz].id + '" src="/images/clear.gif" style="width:25px;height:8px;"/>';
                                    inf += '</div></li>';
                                }
                            }



                            inf += '</ul></div></div></div>';

                            this.shelves.append(inf);
                            //Set image
                            this.filtered[k].setCollectionImage($('#' + this.id + '_collection_item_' + k), undefined, slib.Session.collectionImageWidth, slib.Session.collectionImageHeight);


                        } else {

                            for (var zz in this.filtered[k].availableColours) {

                                this.filtered[k].colour = this.filtered[k].availableColours[zz];

                                inf = '<div class="divLocal_subgroupDisplayContainer" style="width:' + ww + 'px;">';
                                inf += '<div class="divLocal_subgroupDisplayContent" style="width:' + ww + 'px;height:250px;">';
                                inf += '	<a id="' + this.id + '_collection_item_a' + k + '" style="cursor:pointer;" href="' + this.filtered[k].buildLink() + '" onMouseover="PM_popProduct(\'div_name_' + this.filtered[k].name + zz + '\',\'show\');">';
                                inf += '<img id="' + this.id + '_collection_item_' + k + '_' + zz + '" name="pos_' + this.filtered[k].name + '" alt="' + this.filtered[k].name + '" src="" style="width:' + slib.Session.collectionImageWidth + 'px;height:' + slib.Session.collectionImageHeight + 'px;border:0px;" /></a>';

                                inf += '<div id="div_name_' + this.filtered[k].name + zz + '" class="divLocal_subgroupDisplay_popup" style="top:110px;width:100px;">';

                                inf += '<div class="divLocal_subgroupDisplay_popupTop" style="background-image:url(/images/prodnav.arrow.gif);"><!--SPACER--></div>';

                                inf += '<div class="divLocal_subgroupDisplay_popupBottom_small" style="background-color:#eae7e0;color:#73665e;">';

                                inf += this.filtered[k].name + '<br />';

                                if (sp < fp) {
                                    inf += '<div class="divLocal_subgroupDisplay_popupBottom_small_sale">&nbsp;</div>';
                                }

                                inf += '<span style="font-size:0.85em;" class="spnLocal_subgroupDisplay_popupBottom_small_price" style="font-size:0.85em;73665e;">';
                                inf += slib.Session.currencySymbol + fp;
                                inf += '</span></div></div></div></div>';

                                this.shelves.append(inf);
                                //Set image
                                this.filtered[k].setCollectionImage($('#' + this.id + '_collection_item_' + k + "_" + zz), undefined, slib.Session.collectionImageWidth, slib.Session.collectionImageHeight);


                            }

                        }

                    }

                }

                if ((slib.Session.dbs == "dune" || slib.Session.dbs == "bertie") && view == 'sliding') {
                    $('#collection').css("width", (this.filtered.length * 235) + 'px');
                }

            }


            if (max % 3 != 0 && slib.Session.dbs == "shoestudio") {

                if (set == null) {
                    set = jQuery(document.createElement("div")).addClass("productset");
                    products = jQuery(document.createElement("div")).addClass("products");
                }

                set.append(products);

                shelf = jQuery(document.createElement("div"));
                shelf.addClass("shelf");

                set.append(shelf);
                this.shelves.append(set);
            }

            for (var k = ((this.page - 1) * prodsForLoop); k < max; k++) {
                slib.MenuManager.register(jQuery('#' + this.id + "_collection_item_" + k), jQuery('#' + this.id + "_collection_item_hover_" + k));
            }

            this.shelves.append('<br style="clear:both;">');

            //Display paged controler (paginator) at the bottom.
            var paginator = jQuery(document.createElement("ul")).addClass("paginator").html(pagHTML);

            this.shelves.append(paginator);



            //When drawing complete fadeout loading and fadein masthead.

            if (this.hasMasthead) {
                this.masthead.fadeIn();
            }

            //when paging move to the top of the page after redraw
            if (window.scrollTo) { window.scrollTo(0, 0); };

            if (all) {
                this.page = "all";
            }

        }

        this.goToPage = function (page) { this.display(page); }
        this.countPages = function () { return ((this.filtered.length - (this.filtered.length % this.productsPerPage)) / this.productsPerPage) + 1; }
        this.nextPage = function () { this.display(this.page + 1); }
        this.prevPage = function () { this.display(this.page - 1); }

    }; CollectionWidget.prototype = new Widget();
});
 
 
 

var ShoeHunterWidget; //###########################################################################################################################################
jQuery(document).ready(function() {
    ShoeHunterWidget = function() //Picture Competition Widget
    {
        this.id = wlib.getID();
        this.type = "ShoeHunterWidget";
		this.photos = null;

        this.render = function(parent, count) {

            count = (count == undefined) ? 1 : count + 1;

            if (count == 20) { return; } //give up after 20 render attempts (2 sec)

            if (!this.isRendered) {

                if (slib.Content.canVote == undefined) {
                    setTimeout(function() { wlib.findType("ShoeHunterWidget").render(parent); }, 100);
                    return;
                }

                if (jQuery('#comment-form').length == 0 || jQuery('#edit-shoehunter').length == 0) {
                    //this is not the shoe hunter page so something bad has happened - send to homepage
                    document.location = '/';
                    return;
                }

                this.id = (this.id == undefined) ? wlib.getID() : this.id;
                var me = jQuery(document.createElement("div"));

                me.attr("id", this.id);
                me.addClass("widget");
				me.addClass("shoehunter");

                this.element = me;

                //build main content
                var button = jQuery(document.createElement("img")).attr("src", slib.Session.image_path + "/hunter/upload.jpg");
				var upload = jQuery(document.createElement("div")).addClass("uploadyourphoto");
				this.photos = jQuery(document.createElement("div")).addClass("photos");
				
                button.click(function() { wlib.findType("ShoeHunterWidget").showEntryForm(); });


                this.isRendered = true;

                jQuery('#content .box').hide();

                this.showVotes();

                parent.append(this.element);

				upload.append(button);
				
				me.append(this.photos);
                me.append(upload);

                jQuery(this.id).fadeIn();

            }
        }

        this.vote = function(eid) {
            if (slib.Session.logged_in) {
				jQuery('#edit-userid').attr("value", slib.Session.user_id);
				
				if(slib.Session.email == "")
				{
					jQuery('#edit-mail').attr("value", "anonymous_user@shoestudio.com");
				}else{
					jQuery('#edit-mail').attr("value", slib.Session.email);
				}
			}else{
				jQuery('#edit-userid').attr("value", 0);
				jQuery('#edit-mail').attr("value", "anonymous_user@shoestudio.com");
			}
                jQuery('#edit-vote').attr("value", eid);
                jQuery('#edit-spam').attr("value", 0);
                jQuery('#edit-comment').html("Vote for " + eid);
                jQuery('#edit-preview').attr("name", "edit-preview");
                jQuery('#edit-save').attr("name", "edit-save");
                jQuery('#comment-form').append('<input name="op" value="Save" type="hidden"/>')
                jQuery('#comment-form').submit();
        }

        this.showVotes = function() {
            var vdiv;
            var btn;

            

			var max = (slib.Content.comments.length <= 3) ? slib.Content.comments.length : 3;
			
            for (var i = 0; i < max; i++) {


				vdiv = jQuery(document.createElement("div")).addClass("photo" + (i+1));
               
                vdiv.append("<a href=\""+ slib.Content.comments[i].photo + "\"><img src=\"" + slib.Content.comments[i].photo + "\" style=\"width:230px;\"/></a>");
				btn = jQuery(document.createElement("a"));
				btn.append(jQuery(document.createElement("img")).attr("src",slib.Session.image_path + "/hunter/vote.jpg"));

                //if (slib.Content.canVote) {
                    //different vars for scoping
                    if (i == 0) { var eid1 = slib.Content.comments[i].eid; btn.click(function() { wlib.findType("ShoeHunterWidget").vote(eid1); }); }
                    if (i == 1) { var eid2 = slib.Content.comments[i].eid; btn.click(function() { wlib.findType("ShoeHunterWidget").vote(eid2); }); }
                    if (i == 2) { var eid3 = slib.Content.comments[i].eid; btn.click(function() { wlib.findType("ShoeHunterWidget").vote(eid3); }); }
                //} else {
					btn.append("<br/>")
                    btn.append(jQuery(document.createElement("b")).html(slib.Encoder.HTMLEncode(slib.Content.comments[i].votes + " Votes")));
                //}

                vdiv.append("<br/>");
                vdiv.append(btn);

                this.photos.append(vdiv);
            }
			
			this.photos.append('<br style="clear:both"/>');
        }

        this.showEntryForm = function() {

            if (!slib.Session.logged_in) {
                return wlib.login();
            }

            var form = jQuery(document.createElement("form"))
            form.attr("action", jQuery('#comment-form').attr("action"));
            form.attr("accept-charset", jQuery('#comment-form').attr("accept-charset"));
            form.attr("method", jQuery('#comment-form').attr("method"));
            form.attr("enctype", jQuery('#comment-form').attr("enctype"));

            form.append("<h2>Enter Shoe Hunter</h2>")            

            var name = jQuery(document.createElement("input"));
            name.attr("type", "hidden");
            name.attr("name", "name");
            name.attr("value", slib.Session.forename);
            form.append(name);

            var email = jQuery(document.createElement("input"));
            email.attr("type", "hidden");
            email.attr("name", "mail");
            email.attr("value", slib.Session.email);
            form.append(email);

            var homepage = jQuery(document.createElement("input"));
            homepage.attr("type", "hidden");
            homepage.attr("name", "homepage");
            homepage.attr("value", "");
            form.append(homepage);

            form.append("<h3>Comment</h3>")
            var comment = jQuery(document.createElement("textarea"));
            comment.attr("cols", "60");
            comment.attr("rows", "15");
            comment.attr("name", "comment");
            form.append(comment);

            var format = jQuery(document.createElement("input"));
            format.attr("type", "hidden");
            format.attr("name", "format");
            format.attr("value", "1");
            form.append(format);

            var spam = jQuery(document.createElement("input"));
            spam.attr("type", "hidden");
            spam.attr("name", "spam");
            spam.attr("value", "0");
            form.append(spam);

            var ops = jQuery('#comment-form input');

            var build = "";

            for (var i in ops) {
                if (jQuery(ops[i]).attr("name") == 'form_build_id') {
                    build = jQuery(ops[i]).attr("value");
                    break;
                }
            }

            var buildid = jQuery(document.createElement("input"));
            buildid.attr("type", "hidden");
            buildid.attr("name", "form_build_id");
            buildid.attr("value", build);
            form.append(buildid);

            var formid = jQuery(document.createElement("input"));
            formid.attr("type", "hidden");
            formid.attr("name", "form_id");
            formid.attr("value", "comment_form");
            form.append(formid);

            form.append("<h3>Upload a Photo</h3>")
            var photo = jQuery(document.createElement("input"));
            photo.attr("type", "file");
            photo.attr("name", "files[photo]");
            photo.attr("size", "60");
            form.append(photo);

            var shoehunter = jQuery(document.createElement("input"));
            shoehunter.attr("type", "hidden");
            shoehunter.attr("name", "shoehunter");
            shoehunter.attr("value", "1");
            form.append(shoehunter);

            var userid = jQuery(document.createElement("input"));
            userid.attr("type", "hidden");
            userid.attr("name", "userid");
            userid.attr("value", slib.Session.user_id);
            form.append(userid);


            form.append("<br/>");            
            var submit = jQuery(document.createElement("input"));
            submit.attr("type", "submit");
            submit.attr("name", "op");
            submit.attr("value", "Save");
            form.append(submit);

            var fixdiv;

            if (jQuery('#sh_entry').length == 0) {
                fixdiv = jQuery(document.createElement("div")).attr("id", "sh_entry");                
                jQuery(document.body).append(fixdiv);
            } else {
                fixdiv = jQuery('#sh_entry');
            }			
			
            fixdiv.html(form);
			
			fixdiv.prepend("<div class='addedbasket_close'><a onclick=\"jQuery('#sh_entry').fadeOut();\"><img src='/images/shoestudio/buttons/close.png' alt='Close' border='0' /></a></div>")

            wlib.center(fixdiv);

			

            fixdiv.fadeIn();

        }

    }; ShoeHunterWidget.prototype = new Widget();
});
















var MSProductDetailWidget; //###########################################################################################################################################
jQuery(document).ready(function() {
    MSProductDetailWidget = function() {
        this.id = wlib.getID();
        this.type = "MSProductDetailWidget";
        this.product = null;
        this.productElement = null;
        this.detail = null;
        this.buttons = null;
        this.choices = null;
        this.hasBasics = false; //whether the title etc. is rendered
		this.highlight = false;
		this.barcode = "";
		
        this.render = function(parent,barcode,nonspecific) {
            if (!this.isRendered) {
                this.id = (this.id == undefined) ? wlib.getID() : this.id;
                var me = jQuery(document.createElement("div"));
                me.attr("id", this.id);
                me.addClass("widget");
                this.element = me;
                parent.append(me);
                this.isRendered = true;
                var x = this.id;

				this.barcode = barcode;
				
				var limg = $(document.createElement("img")).css("display","none");
				limg.attr("src",slib.Session.image_path + "/bigloading.gif");
				$(document.body).append(limg);
				
                this.productElement = jQuery(document.createElement("div")).attr("id", "product");
                this.element.append(this.productElement);

				if(slib.Session.multi_site && barcode != undefined){
					nonspecific = nonspecific == undefined ? true : nonspecific;
					this.highlight = !nonspecific;
					slib.API.getProductDetailByAttrs(
					function(r) { wlib.find(x).cb_getProductDetailByAttrs(r); },
					function(e) { wlib.find(x).fail(e); },
					barcode,
					nonspecific,
					'%');
					return;
				}else{
					//should never occur, thanks to rewrites. if it does, go home
					document.location = '/dpos/browse.asp';
				}
            }
        }
		
		this.refresh = function()
		{
			var mo = '';

            if (this.product.isSale) {
                mo += '<img src=\'' + slib.Session.image_path + '/salenotice.png\' alt=\'Sale\' align=\'absmiddle\' /> ';
                mo += '<span class=\'strikeout\'>';
            }

            mo += slib.Session.currencySymbol;

            if (slib.Session.currency == "GBP") {
                mo += this.product.fullPrice_GBP;
            } else if (slib.Session.currency == "EUR") {
                mo += this.product.fullPrice_EUR;
            } else if (slib.Session.currency == "USD") {
                mo += this.product.fullPrice_USD;
            }

            if (this.product.isSale) {
                mo += '</span> '
                mo += '<span class=\'saleprice\'>'
                mo += slib.Session.currencySymbol;
                if (slib.Session.currency == "GBP") {
                    mo += this.product.salePrice_GBP;
                } else if (slib.Session.currency == "EUR") {
                    mo += this.product.salePrice_EUR;
                } else if (slib.Session.currency == "USD") {
                    mo += this.product.salePrice_USD;
                }
                mo += '</span>'
            }

            jQuery('.productprice').html(mo);
		}
		
		this.zoomLevel = 8;
		this.zoomHeight = 700;
		this.zoomWidth = 950;
		
		this.switchZoomLevel = function(dir){
		
			var levels = ["200px","250px","350px","500px","700px","950px","1250px","1600px","2000px","2500px","3200px","4000px","6000px"];
		
			var oldw = levels[this.zoomLevel].replace(/px/i,"");
			oldw = (oldw == "auto" || oldw == "") ? 2000 : oldw * 1;
		
			var nl = this.zoomLevel + dir;
		
			this.zoomLevel = (nl >= 0 && nl < levels.length) ? nl : this.zoomLevel;
		
			var zim = $('#zoomImage');
			
			var w = levels[this.zoomLevel].replace(/px/i,"") * 1;
			
			var left = Math.floor(zim.css("left").replace(/px/i,"") * 1) + Math.floor((oldw-w)/2) ;
			var top = Math.floor(zim.css("top").replace(/px/i,"") * 1) + Math.floor(((oldw-w)/2) ) ;
			
			if (left > this.zoomWidth - (w/2) || top > this.zoomHeight - (w/2) || left + w <  (w/2)  || top + w < (w/2)){
				left =  Math.floor((this.zoomWidth - w)/2);
				top =  Math.floor((this.zoomHeight - w)/2);
			}
			
			left = (left < -w) ? 0 : left;
			top = (top < -w) ? 0 : top;
			
			zim.css("left",left + "px");
			zim.css("top",top + "px");
			
			zim.css("width",levels[this.zoomLevel]);
			zim.css("height","auto");
			
			
			
			var w_hi = (w < this.zoomWidth) ? this.zoomWidth : w;
			var h_hi = (w < this.zoomHeight) ? this.zoomHeight : w;
			var w_lo = (w < this.zoomWidth) ? 1 : this.zoomWidth - w;
			var h_lo = (w < this.zoomHeight) ? 1 : this.zoomHeight - w;
			
			zim.draggable('destroy');
			//zim.draggable({containment : [w_lo,h_lo,w_hi,h_hi]});
			zim.draggable();
			
			
		}
		
		this.zoomDisplay = false;
		
		this.zoom = function(){
			
			if(!this.product.hasImg_Zoom){return;}
			
			
			
			var w = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth;
			var h = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
			
			this.zoomHeight = 700;
			this.zoomWidth = 950;
			
			//if(w < this.zoomWidth || h < this.zoomHeight){
				this.zoomHeight = h - 150;
				this.zoomWidth = w - 150;
			//}
			
			this.zoomHeight = (this.zoomHeight < 37) ? 37 : this.zoomHeight;
			this.zoomWidth = (this.zoomWidth < 105) ? 105 : this.zoomWidth;
			
			var zDiv;
			var zClose;
			var zImg;
			var zDrag;
			var zFade;
			
			if($('#zoomDiv').length == 0){
				
				
				
				window.onresize = function(){
					if(wlib.findType("MSProductDetailWidget").zoomDisplay){
						
						wlib.findType("MSProductDetailWidget").zoom();
					}
				};
			
			}
			
				$('#zoomDiv').remove();
				$('#zoomFade').remove();
				
				zDiv = $(document.createElement("div")).attr("id","zoomDiv").hide();
				zClose = $(document.createElement("div")).attr("id","zoomClose");
				zDrag = $(document.createElement("div")).attr("id","zoomDrag");
				zImg = $(document.createElement("img")).attr("id","zoomImage");
				zFade = $(document.createElement("div")).attr("id","zoomFade");
				zLoad = $(document.createElement("img")).attr("id","zoomLoading");
				
				zFade.css("background-color","black");
				zFade.css("position","fixed");
				zFade.css("top","0px");
				zFade.css("left","0px");
				zFade.css("width",w + "px");
				zFade.css("height",h + "px");
				zFade.css("z-index","997");
				zFade.css("opacity","0.75");
				$(document.body).append(zFade);
				
				zDiv.css("position","fixed");
				zDiv.css("text-align","center");
				
				var l = ((w - this.zoomWidth)/2)-5;l = (l < 0) ? 0 : l;
				var t = ((h-this.zoomHeight)/2) - 25;t = (t < 0) ? 0 : t;
				
				zDiv.css("left", l+ "px");
				zDiv.css("top",  t+ "px");
				zDiv.css("width",this.zoomWidth + "px");
				zDiv.css("height",this.zoomHeight+"px");
				
				zDiv.css("z-index","998");
				
				zClose.html('<a style="font-size:24px;" onclick="$(\'#zoomFade\').fadeOut();$(\'#zoomDiv\').fadeOut();wlib.findType(\'ProductDetailWidget\').zoomDisplay = false;"><img src="' + slib.Session.image_path + '/buttons/btn.zclose.png"/></a>');
				zClose.css("position","absolute");
				zClose.css("background-color","white");
				zClose.css("top","0px");
				zClose.css("right","0px");
				zClose.css("z-index","999");
				zClose.css("border","1px solid black");
				zDiv.append(zClose);
				
				zDrag.css("position","absolute");
				zDrag.css("background-color","white");
				zDrag.css("border","1px solid black");
				zDrag.css("top","35px");
				zDrag.css("right","0px");
				zDrag.css("overflow","hidden");
				zDrag.css("width",this.zoomWidth+"px");
				zDrag.css("height",this.zoomHeight+"px");
				zDrag.css("z-index","999");
				zDiv.append(zDrag);
				
				zImg.hide();
				
				zLoad.css("position","absolute");
				zLoad.css("left",((this.zoomWidth-100)/2) + "px");
				zLoad.css("top",((this.zoomHeight-100)/2) + "px");
				zLoad.css("z-index","999");
				
				zLoad.attr('src',slib.Session.image_path + "/bigloading.gif");
				zDiv.append(zLoad);
				
				
				zImg.css("position","absolute");
				zImg.css("left",Math.floor((this.zoomWidth - 2000)/2)+"px");
				zImg.css("top",Math.floor((this.zoomHeight) - 2000)/2 + "px");
				zImg.css("cursor","move");
				zImg.css("z-index","999");
				zDrag.append(zImg);
				
				
				zImg.attr("src",this.product.getZoomImage() + "?" + Math.floor(Math.random()*9999)).load(
					function(){
						$('#zoomLoading').fadeOut("fast",function(){
							$('#zoomImage').fadeIn();
						});
					}
				);
				
				var zOut = $(document.createElement("a"));
				zOut.css("position","absolute");
				zOut.css("right","10px");
				zOut.css("bottom","10px");
				zOut.css("width","20px");
				zOut.css("height","20px");
				zOut.css("text-align","center");
				zOut.css("z-index","999");
				zOut.css("display","block");
				zOut.html('<img src="' + slib.Session.image_path + '/buttons/btn.out.png"/>');
				zOut.click(function(){wlib.findType("MSProductDetailWidget").switchZoomLevel(-1);});
				
				var zIn = $(document.createElement("a"));
				zIn.css("position","absolute");
				zIn.css("right","35px");
				zIn.css("bottom","10px");
				zIn.css("width","20px");
				zIn.css("height","20px");
				zIn.css("text-align","center");
				zIn.css("z-index","999");
				zIn.css("display","block");
				zIn.html('<img src="' + slib.Session.image_path + '/buttons/btn.in.png"/>');
				zIn.click(function(){wlib.findType("MSProductDetailWidget").switchZoomLevel(1);});
				
				zDrag.append(zIn);
				zDrag.append(zOut);
				
				jQuery(document.body).append(zDiv);
				
				zFade.fadeIn();
				
				var zi = document.getElementById('zoomDrag');
				
				var callback = function(e){
					e = e ? e : window.event;
					var scroll = e.detail ? e.detail / -3 : e.wheelDelta / 120;
					scroll = (scroll < -1) ? -1 : ((scroll > 1) ? 1 : scroll);
					wlib.findType("MSProductDetailWidget").switchZoomLevel(scroll);
					if(e.stopPropagation)
						e.stopPropagation();
					if(e.preventDefault)
						e.preventDefault();
					 
					e.cancelBubble = true;
					e.cancel = true;
					e.returnValue = false;
					return false;
				}
				
				if(zi.addEventListener)
				{
					zi.addEventListener('DOMMouseScroll', callback, false);  
					zi.addEventListener('mousewheel', callback, false);
				}else if(zi.attachEvent){
					zi.attachEvent("onmousewheel", callback);
				}
			
				var zi = document.getElementById('zoomFade');
			
				if(zi.addEventListener)
				{
					zi.addEventListener('DOMMouseScroll', callback, false);  
					zi.addEventListener('mousewheel', callback, false);
				}else if(zi.attachEvent){
					zi.attachEvent("onmousewheel", callback);
				}
			
				
				this.zoomDisplay = true;
			
				
				this.zoomLevel = 8;
				this.switchZoomLevel(0);
				
			
			
			
			
			
			zDiv.fadeIn();
			
		}

        this.cb_getProductDetailByAttrs = function(r) {
		
            this.element.css("opacity", "0");
			
            this.product = r.result;

            jQuery(".productinfo").remove(); //remove info for old colour
            jQuery(".productpic").remove(); //remove pic/flash for old colour

            var fdiv = jQuery(document.createElement("div"));
            fdiv.attr("id", this.id + "_flash").addClass("productpic");


			var info = jQuery(document.createElement("div"))
            this.detail = jQuery(document.createElement("div"))
			
			var description = jQuery(document.createElement("div"))
			description.attr("id", "ulProdDesc");
			description.css("width","100%").css("background-color","white");
						
            if (slib.Encoder.HTMLEncode(this.product.bullet1) != "") {	this.detail.append("<b>Description</b>"); 
																		description.append("<p>" + slib.Encoder.HTMLEncode(this.product.bullet1) + "</p>"); }
            if (slib.Encoder.HTMLEncode(this.product.bullet2) != "") {	description.append("<p>" + slib.Encoder.HTMLEncode(this.product.bullet2) + "</p>"); }
            if (slib.Encoder.HTMLEncode(this.product.bullet3) != "") {	description.append("<p>" + slib.Encoder.HTMLEncode(this.product.bullet3) + "</p>"); }
            this.detail.append(description);
            this.detail.append("<br /><p>" + slib.Encoder.HTMLEncode(slib.Text.cap(this.product.heel)) + "</p>");            
			
			var that = this;
			
            //collate sections together
            info.append(this.detail);
            info.append("<br class=\"clear\"/>");

            if (!this.hasBasics) {
				this.productElement.append("<h1>" + slib.Text.cap(this.product.name) + "</h1>"); //product name
                this.hasBasics = true;
            }

            this.productElement.append(fdiv); //picture/flash div

            this.productElement.append(info); //info

            this.product.setFlash(fdiv);

            this.element.fadeTo("", "1.0");

            //rest of info is added on API callback vvv

            var x = this.id;

            this.product.getAvailableSizes(function(r) { wlib.find(x).cb_getAvailableSizes(r); }, function(e) { wlib.find(x).fail(e); })
			
        }

        this.cb_getAvailableSizes = function(r) {
            var dd = jQuery(document.createElement("table"));
            var row;
			var td;
			var x = this.id;

            var qs = slib.LinkController.parameters;    //added to allow size display to change based on gender

            dd.attr("id", "size");
            dd.attr("name", "size");
            
            this.product.availableSizes = r.result;

            var chp = jQuery(document.createElement("p"));
            
			row = jQuery(document.createElement("tr"));
			row.append('<th>Product</th>');
			row.append('<th>Colour</th>');
			row.append('<th>Size (UK/EU/US)</th>');
			row.append('<th>Stock</th>');
			row.append('<th>Price</th>');
			row.append('<th>Add</th>');
			dd.append(row);
			
			for (var k = 0; k < this.product.availableSizes.length; k++) {
				if (isNaN(this.product.availableSizes[k].size)) {
					var z = this.product.availableSizes[k].size;
					var w = this.product.availableSizes[k].size;
				} else {
					var w = '';
					var z = parseFloat(this.product.availableSizes[k].size.toString()); //change value to float to allow for size conversion before converting back to string for encode function
					var y = 0;
					if(this.product.availableSizes[k].website!=4){
						if(this.product.gender != 'm'){y--;}
					}
					w = (z - y - 34) + '&nbsp;&nbsp;&nbsp;&nbsp;/&nbsp;&nbsp;' + z + '&nbsp;&nbsp;&nbsp;/&nbsp;&nbsp;&nbsp;' + (z - y - y - 33); //format string output
				}
				
				row = jQuery(document.createElement("tr"));
				
				if(this.highlight){
					if(this.barcode == this.product.availableSizes[k].barcode){
						row.css('background-color','#ffff77');
					}
				}
				
				td = jQuery(document.createElement("td")).css('width','100px');
				td.append(slib.Text.cap(this.product.name));
				row.append(td);
				
				td = jQuery(document.createElement("td")).css('width','100px');
				td.append(slib.Text.cap(this.product.colour.name));
				row.append(td);
				
				td = jQuery(document.createElement("td")).css('width','150px');
				td.append(w);
				row.append(td);
				
				td = jQuery(document.createElement("td")).css('width','100px');
				td.append(this.product.availableSizes[k].stock);
				row.append(td);
				
				td = jQuery(document.createElement("td")).css('width','100px');
				if(this.product.availableSizes[k].stock >= 3){
					td.append('&pound;'+this.product.availableSizes[k].price_GBP);
				}else{
					td.append('n/a');
				}
				row.append(td);
				
				td = jQuery(document.createElement("td")).css('width','130px');
				if(this.product.availableSizes[k].stock > 0){
					td.append('<a style="cursor:pointer;display:block;border:1px solid black;padding:3px;text-align:center;" onclick="wlib.find(\'' + x + '\').addToBasket(\'' + this.product.availableSizes[k].barcode + '\');">Add to Basket</a>');
				}else{
					td.append('n/a');
				}
				row.append(td);
				
				dd.append(row);
			}

			this.detail.prepend('<br />');
            this.detail.prepend(dd);
            
            this.product.getAvailableColours(function(r) { wlib.find(x).cb_getAvailableColours(r); }, function(e) { wlib.find(x).fail(e); })

        }

        this.cb_getAvailableColours = function(r) {
            this.product.availableColours = r.result;

            for (var bb in this.product.availableColours) {
                this.detail.append('<a onclick="wlib.findType(\'ProductDetailWidget\').selectColour(' + this.product.availableColours[bb].id + ');"><img class="textmiddle swatch" src="' + this.product.getSwatchPath(this.product.availableColours[bb]) + '" title="' + this.product.availableColours[bb].name + '"/></a>');
            }
        }
		
		this.addToBasket=function(barcode){
			slib.API.addProductToBasketByBarcode(
				function(r){
					r=r.result;
					if(r.status != "OK" || typeof r.problem != 'undefined'){
						alert('Sorry, failed - reason is ' + r.problem + ' status is ' + r.status);
					}else{
						alert('Product added to basket!');
					}
				},function(){alert('Failed to add to basket!' );},barcode);
		}

        this.selectColour = function(id) {
            var found = false;

            if (id == this.product.colour.id) {
                return;
            }

            for (var i in this.product.availableColours) {
                if (this.product.availableColours[i].id == id) {
                    this.product.colour = this.product.availableColours[i];
                    this.product.code = this.product.colour.code;
                    found = true;
                    break;
                }
            }



            var x = this.id;

            if (found) {
                //Cause browser to switch page (doing this until we find a way of updating the URL while staying on the page)
                parent.location.href = this.product.buildLink();
                /*slib.API.getProductDetailByAttrs(
                function(r){wlib.find(x).cb_getProductDetailByAttrs(r);},
                function(e){wlib.find(x).fail(e);},
                this.product.name,
                this.product.code,
                this.product.colour.name
                );*/

            } else {
                slib.throwError("", false, true, false, null, this);
            }
        }

    }; MSProductDetailWidget.prototype = new Widget();
});























var ProductDetailWidget; //###########################################################################################################################################
jQuery(document).ready(function() {
    ProductDetailWidget = function() {
        this.id = wlib.getID();
        this.type = "ProductDetailWidget";
        this.product = null;
        this.productElement = null;
        this.detail = null;
        this.buttons = null;
        this.choices = null;
        this.hasBasics = false; //whether the title etc. is rendered
		
		
        this.render = function(parent,barcode,highlight) {
            if (!this.isRendered) {
                this.id = (this.id == undefined) ? wlib.getID() : this.id;
                var me = jQuery(document.createElement("div"));
                me.attr("id", this.id);
                me.addClass("widget");
                this.element = me;
                parent.append(me);
                this.isRendered = true;
                var x = this.id;

				var limg = $(document.createElement("img")).css("display","none");
				limg.attr("src",slib.Session.image_path + "/bigloading.gif");
				$(document.body).append(limg);
				
                this.productElement = jQuery(document.createElement("div")).attr("id", "product");
                this.element.append(this.productElement);

				if(slib.Session.multi_site && barcode != undefined){
					highlight = highlight == undefined ? false : highlight;
					slib.API.getProductDetailByAttrs(
					function(r) { wlib.find(x).cb_getProductDetailByAttrs(r); },
					function(e) { wlib.find(x).fail(e); },
					barcode,
					highlight,
					'%');
					return;
				}
				
                var qs = slib.LinkController.parameters;
								
                if (qs.length >= 7) {
                    slib.API.getProductDetailByAttrs(
					function(r) { wlib.find(x).cb_getProductDetailByAttrs(r); },
					function(e) { wlib.find(x).fail(e); },
					qs[4],
					qs[6],
					qs[5]
				);
                } else if(qs.length==6) {
                    slib.API.getProductDetailByAttrs(
					function(r) { wlib.find(x).cb_getProductDetailByAttrs(r); },
					function(e) { wlib.find(x).fail(e); },
					qs[4],
					qs[5],
					'%');
                } else if(qs.length==5) {
                    slib.API.getProductDetailByAttrs(
					function(r) { wlib.find(x).cb_getProductDetailByAttrs(r); },
					function(e) { wlib.find(x).fail(e); },
					qs[4],
					'%',
					'%');
                }else{
					//should never occur, thanks to rewrites. if it does, go home
					document.location = '/';
				}
            }
        }
		
		this.refresh = function()
		{
			var mo = '';

            if (this.product.isSale) {
                mo += '<img src=\'' + slib.Session.image_path + '/salenotice.png\' alt=\'Sale\' align=\'absmiddle\' /> ';
                mo += '<span class=\'strikeout\'>';
            }

            mo += slib.Session.currencySymbol;

			var fsp;
			
            if (slib.Session.currency == "GBP") {
                fsp = this.product.fullPrice_GBP + "";
				
            } else if (slib.Session.currency == "EUR") {
                fsp = this.product.fullPrice_EUR + "";
            } else if (slib.Session.currency == "USD") {
                fsp = this.product.fullPrice_USD + "";
            }

			if(fsp.indexOf(".") > -1){var pence = fsp.substring(fsp.indexOf(".")+1);while(pence.length < 2){pence += "0";fsp += "0";}}
			mo += fsp;
			
            if (this.product.isSale) {
                mo += '</span> '
                mo += '<span class=\'saleprice\'>'
                mo += slib.Session.currencySymbol;
                if (slib.Session.currency == "GBP") {
                    fsp = this.product.salePrice_GBP + "";
                } else if (slib.Session.currency == "EUR") {
                    fsp = this.product.salePrice_EUR + "";
                } else if (slib.Session.currency == "USD") {
                    fsp = this.product.salePrice_USD + "";
                }
				if(fsp.indexOf(".") > -1){var pence = fsp.substring(fsp.indexOf(".")+1);while(pence.length < 2){pence += "0";fsp += "0";}}
				mo += fsp;
                mo += '</span>'
            }

            jQuery('.productprice').html(mo);
		}
		
		this.zoomLevel = 8;
		this.zoomHeight = 700;
		this.zoomWidth = 950;
		
		this.switchZoomLevel = function(dir){
		
			var levels = ["200px","250px","350px","500px","700px","950px","1250px","1600px","2000px","2500px","3200px","4000px","6000px"];
		
			var oldw = levels[this.zoomLevel].replace(/px/i,"");
			oldw = (oldw == "auto" || oldw == "") ? 2000 : oldw * 1;
		
			var nl = this.zoomLevel + dir;
		
			this.zoomLevel = (nl >= 0 && nl < levels.length) ? nl : this.zoomLevel;
		
			var zim = $('#zoomImage');
			
			var w = levels[this.zoomLevel].replace(/px/i,"") * 1;
			
			var left = Math.floor(zim.css("left").replace(/px/i,"") * 1) + Math.floor((oldw-w)/2) ;
			var top = Math.floor(zim.css("top").replace(/px/i,"") * 1) + Math.floor(((oldw-w)/2) ) ;
			
			if (left > this.zoomWidth - (w/2) || top > this.zoomHeight - (w/2) || left + w <  (w/2)  || top + w < (w/2)){
				left =  Math.floor((this.zoomWidth - w)/2);
				top =  Math.floor((this.zoomHeight - w)/2);
			}
			
			left = (left < -w) ? 0 : left;
			top = (top < -w) ? 0 : top;
			
			zim.css("left",left + "px");
			zim.css("top",top + "px");
			
			zim.css("width",levels[this.zoomLevel]);
			zim.css("height","auto");
			
			
			
			var w_hi = (w < this.zoomWidth) ? this.zoomWidth : w;
			var h_hi = (w < this.zoomHeight) ? this.zoomHeight : w;
			var w_lo = (w < this.zoomWidth) ? 1 : this.zoomWidth - w;
			var h_lo = (w < this.zoomHeight) ? 1 : this.zoomHeight - w;
			
			zim.draggable('destroy');
			//zim.draggable({containment : [w_lo,h_lo,w_hi,h_hi]});
			zim.draggable();
			
			
		}
		
		this.zoomDisplay = false;
		
		this.zoom = function(){
			
			if(!this.product.hasImg_Zoom){return;}
			
			
			
			var w = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth;
			var h = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
			
			this.zoomHeight = 700;
			this.zoomWidth = 950;
			
			//if(w < this.zoomWidth || h < this.zoomHeight){
				this.zoomHeight = h - 150;
				this.zoomWidth = w - 150;
			//}
			
			this.zoomHeight = (this.zoomHeight < 37) ? 37 : this.zoomHeight;
			this.zoomWidth = (this.zoomWidth < 105) ? 105 : this.zoomWidth;
			
			var zDiv;
			var zClose;
			var zImg;
			var zDrag;
			var zFade;
			
			if($('#zoomDiv').length == 0){
				
				
				
				window.onresize = function(){
					if(wlib.findType("ProductDetailWidget").zoomDisplay){
						
						wlib.findType("ProductDetailWidget").zoom();
					}
				};
			
			}
			
				$('#zoomDiv').remove();
				$('#zoomFade').remove();
				
				zDiv = $(document.createElement("div")).attr("id","zoomDiv").hide();
				zClose = $(document.createElement("div")).attr("id","zoomClose");
				zDrag = $(document.createElement("div")).attr("id","zoomDrag");
				zImg = $(document.createElement("img")).attr("id","zoomImage");
				zFade = $(document.createElement("div")).attr("id","zoomFade");
				zLoad = $(document.createElement("img")).attr("id","zoomLoading");
				
				zFade.css("background-color","black");
				zFade.css("position","fixed");
				zFade.css("top","0px");
				zFade.css("left","0px");
				zFade.css("width",w + "px");
				zFade.css("height",h + "px");
				zFade.css("z-index","997");
				zFade.css("opacity","0.75");
				$(document.body).append(zFade);
				
				zDiv.css("position","fixed");
				zDiv.css("text-align","center");
				
				var l = ((w - this.zoomWidth)/2)-5;l = (l < 0) ? 0 : l;
				var t = ((h-this.zoomHeight)/2) - 25;t = (t < 0) ? 0 : t;
				
				zDiv.css("left", l+ "px");
				zDiv.css("top",  t+ "px");
				zDiv.css("width",this.zoomWidth + "px");
				zDiv.css("height",this.zoomHeight+"px");
				
				zDiv.css("z-index","998");
				
				zClose.html('<a style="font-size:24px;" onclick="$(\'#zoomFade\').fadeOut();$(\'#zoomDiv\').fadeOut();wlib.findType(\'ProductDetailWidget\').zoomDisplay = false;"><img src="' + slib.Session.image_path + '/buttons/btn.zclose.png"/></a>');
				zClose.css("position","absolute");
				zClose.css("background-color","white");
				zClose.css("top","0px");
				zClose.css("right","0px");
				zClose.css("z-index","999");
				zClose.css("border","1px solid black");
				zDiv.append(zClose);
				
				zDrag.css("position","absolute");
				zDrag.css("background-color","white");
				zDrag.css("border","1px solid black");
				zDrag.css("top","35px");
				zDrag.css("right","0px");
				zDrag.css("overflow","hidden");
				zDrag.css("width",this.zoomWidth+"px");
				zDrag.css("height",this.zoomHeight+"px");
				zDrag.css("z-index","999");
				zDiv.append(zDrag);
				
				zImg.hide();
				
				zLoad.css("position","absolute");
				zLoad.css("left",((this.zoomWidth-100)/2) + "px");
				zLoad.css("top",((this.zoomHeight-100)/2) + "px");
				zLoad.css("z-index","999");
				
				zLoad.attr('src',slib.Session.image_path + "/bigloading.gif");
				zDiv.append(zLoad);
				
				
				zImg.css("position","absolute");
				zImg.css("left",Math.floor((this.zoomWidth - 2000)/2)+"px");
				zImg.css("top",Math.floor((this.zoomHeight) - 2000)/2 + "px");
				zImg.css("cursor","move");
				zImg.css("z-index","999");
				zDrag.append(zImg);
				
				
				zImg.attr("src",this.product.getZoomImage() + "?" + Math.floor(Math.random()*9999)).load(
					function(){
						$('#zoomLoading').fadeOut("fast",function(){
							$('#zoomImage').fadeIn();
						});
					}
				);
				
				var zOut = $(document.createElement("a"));
				zOut.css("position","absolute");
				zOut.css("right","10px");
				zOut.css("bottom","10px");
				zOut.css("width","20px");
				zOut.css("height","20px");
				zOut.css("text-align","center");
				zOut.css("z-index","999");
				zOut.css("display","block");
				zOut.html('<img src="' + slib.Session.image_path + '/buttons/btn.out.png"/>');
				zOut.click(function(){wlib.findType("ProductDetailWidget").switchZoomLevel(-1);});
				
				var zIn = $(document.createElement("a"));
				zIn.css("position","absolute");
				zIn.css("right","35px");
				zIn.css("bottom","10px");
				zIn.css("width","20px");
				zIn.css("height","20px");
				zIn.css("text-align","center");
				zIn.css("z-index","999");
				zIn.css("display","block");
				zIn.html('<img src="' + slib.Session.image_path + '/buttons/btn.in.png"/>');
				zIn.click(function(){wlib.findType("ProductDetailWidget").switchZoomLevel(1);});
				
				zDrag.append(zIn);
				zDrag.append(zOut);
				
				jQuery(document.body).append(zDiv);
				
				zFade.fadeIn();
				
				var zi = document.getElementById('zoomDrag');
				
				var callback = function(e){
					e = e ? e : window.event;
					var scroll = e.detail ? e.detail / -3 : e.wheelDelta / 120;
					scroll = (scroll < -1) ? -1 : ((scroll > 1) ? 1 : scroll);
					wlib.findType("ProductDetailWidget").switchZoomLevel(scroll);
					if(e.stopPropagation)
						e.stopPropagation();
					if(e.preventDefault)
						e.preventDefault();
					 
					e.cancelBubble = true;
					e.cancel = true;
					e.returnValue = false;
					return false;
				}
				
				if(zi.addEventListener)
				{
					zi.addEventListener('DOMMouseScroll', callback, false);  
					zi.addEventListener('mousewheel', callback, false);
				}else if(zi.attachEvent){
					zi.attachEvent("onmousewheel", callback);
				}
			
				var zi = document.getElementById('zoomFade');
			
				if(zi.addEventListener)
				{
					zi.addEventListener('DOMMouseScroll', callback, false);  
					zi.addEventListener('mousewheel', callback, false);
				}else if(zi.attachEvent){
					zi.attachEvent("onmousewheel", callback);
				}
			
				
				this.zoomDisplay = true;
			
				
				this.zoomLevel = 8;
				this.switchZoomLevel(0);
				
			
			
			
			
			
			zDiv.fadeIn();
			
		}

        this.addToBasket = function() {
            
			
			
			var x = this.id;
            slib.API.addProductToBasket(function(r) { wlib.find(x).cb_addToBasket(r); }, function(e) { wlib.find(x).fail(e); }, this.product);
        }

        this.addToWishlist = function() {
            var x = this.id;
            slib.API.addProductToWishlist(function(r) { wlib.find(x).cb_addToWishlist(r); }, function(e) { wlib.find(x).fail(e); }, this.product);
        }

        this.removeFromWishlist = function() {
            var x = this.id;
            slib.API.removeProductFromWishlist(function(r) { wlib.find(x).cb_removeFromWishlist(r); }, function(e) { wlib.find(x).fail(e); }, this.product);
        }

        this.cb_addToWishlist = function(r) {
            if (r.result.success) {

                if (jQuery('#added_basket').length == 0) {
                    jQuery(document.body).append("<div id='added_basket'></div>");
                }

                //create product image object
                i = 0;
                var pi = jQuery(document.createElement("div")).addClass("addedbasket_product");
                pi.append(jQuery(document.createElement("a")).attr("id", this.id + "_collection_item_a" + i).attr("href", "javascript:void\(0\)").append(jQuery(document.createElement("img")).attr("id", this.id + "_collection_item_" + i).attr("align", "absmiddle")).css("position", "relative").css("cursor", "default"));
                pi.append("You've added " + slib.Text.cap(slib.Encoder.HTMLEncode(this.product.name)) + " to your wishlist.");
                this.product.setCollectionImage(pi.children(":first-child").children(":first-child"));

                //create close button
                var cb = jQuery(document.createElement('div')).addClass("addedbasket_close");
                cb.append("<a onclick=\"jQuery('#added_basket').fadeOut();\"><img src='/images/shoestudio/buttons/close.png' alt='Close' border='0' /></a>");

                //create action buttons
                var aba = jQuery(document.createElement('div')).addClass("addedbasket_action");
                aba.append("<a onclick=\"jQuery('#added_basket').fadeOut();\"><img src='/images/shoestudio/buttons/continueshopping.jpg' alt='Continue shopping' border='0' /></a>&nbsp;");
                aba.append("<a href='/" + slib.Session.range.name + "/wishlist'><img src='/images/shoestudio/buttons/viewwishlist.jpg' alt='Wishlist' border='0' /></a>");

                //build complete popup object
                var aw = jQuery(document.createElement('added_basket'));
                aw.append(cb);  //add close button
                aw.append(pi);  //add product image
                aw.append(aba); //add action buttons

                wlib.center(jQuery('#added_basket'));
                jQuery('#added_basket').html(aw).fadeIn();

                //change from
                jQuery('#add_wlist').hide();
                jQuery('#add_wlist').html('<a class="pbbox" onclick="wlib.findType(\'ProductDetailWidget\').removeFromWishlist();"><img src="' + slib.Session.image_path + '/buttons/addtowishlist.jpg" alt="Remove from wishlist" border="0" class="textmiddle" />&nbsp;&nbsp;Remove from wishlist</a>').fadeIn();

            } else {
                alert("Could not add to wishlist, you're probably not logged in.");
            }
        }

        this.cb_removeFromWishlist = function(r) {
            if (r.result.success) {

                if (jQuery('#added_basket').length == 0) {
                    jQuery(document.body).append("<div id='added_basket'></div>");
                }

                //create product image object
                i = 0;
                var pi = jQuery(document.createElement("div")).addClass("addedbasket_product");
                pi.append(jQuery(document.createElement("a")).attr("id", this.id + "_collection_item_a" + i).attr("href", "javascript:void\(0\)").append(jQuery(document.createElement("img")).attr("id", this.id + "_collection_item_" + i).attr("align", "absmiddle")).css("position", "relative").css("cursor", "default"));
                pi.append("You've removed " + slib.Text.cap(slib.Encoder.HTMLEncode(this.product.name)) + " from your wishlist.");
                this.product.setCollectionImage(pi.children(":first-child").children(":first-child"));

                //create close button
                var cb = jQuery(document.createElement('div')).addClass("addedbasket_close");
                cb.append("<a onclick=\"jQuery('#added_basket').fadeOut();\"><img src='/images/shoestudio/buttons/close.png' alt='Close' border='0' /></a>");

                //create action buttons
                var aba = jQuery(document.createElement('div')).addClass("addedbasket_action");
                aba.append("<a onclick=\"jQuery('#added_basket').fadeOut();\"><img src='/images/shoestudio/buttons/continueshopping.jpg' alt='Continue shopping' border='0' /></a>&nbsp;");
                aba.append("<a href='/" + slib.Session.range.name + "/wishlist'><img src='/images/shoestudio/buttons/viewwishlist.jpg' alt='Wishlist' border='0' /></a>");

                //build complete popup object
                var aw = jQuery(document.createElement('added_basket'));
                aw.append(cb);  //add close button
                aw.append(pi);  //add product image
                aw.append(aba); //add action buttons

                wlib.center(jQuery('#added_basket'));
                jQuery('#added_basket').html(aw).fadeIn();

                //change from
                jQuery('#add_wlist').hide();
                jQuery('#add_wlist').html('<a class="pbbox" onclick="wlib.findType(\'ProductDetailWidget\').addToWishlist();"><img src="' + slib.Session.image_path + '/buttons/addtowishlist.jpg" alt="Add to wishlist" border="0" class="textmiddle" />&nbsp;&nbsp;Add to wishlist</a>').fadeIn();

            } else {
                //alert("Could not remove from wishlist, you're probably not logged in.");
            }
        }

        this.cb_addToBasket = function(r) {
            if (r.result.status == "OK") {
                var bw = wlib.findType("BasketWidget");
                if (bw != null) //add product into basket widget so is visible without page refresh (if basketwidget exists)
                {
                    bw.addProduct(this.product);
                }

                if (jQuery('#added_basket').length == 0) {
                    jQuery(document.body).append("<div id='added_basket'></div>");
                }

                //create product image object
                i = 0;
                var pi = jQuery(document.createElement("div")).addClass("addedbasket_product");
                pi.append(jQuery(document.createElement("a")).attr("id", this.id + "_collection_item_a" + i).attr("href", "javascript:void\(0\)").append(jQuery(document.createElement("img")).attr("id", this.id + "_collection_item_" + i).attr("align", "absmiddle")).css("position", "relative").css("cursor", "default"));
                pi.append("You have added <b>" + slib.Text.cap(slib.Encoder.HTMLEncode(this.product.name)) + "</b> to your basket.");
                this.product.setCollectionImage(pi.children(":first-child").children(":first-child"));

                //create close button
                var cb = jQuery(document.createElement('div')).addClass("addedbasket_close");
                cb.append("<a onclick=\"jQuery('#added_basket').fadeOut();\"><img src='/images/shoestudio/buttons/close.png' alt='Close' border='0' /></a>");

                //create action buttons
                var aba = jQuery(document.createElement('div')).addClass("addedbasket_action");
                aba.append("<a onclick=\"jQuery('#added_basket').fadeOut();\"><img src='/images/shoestudio/buttons/continueshopping.jpg' alt='Continue shopping' border='0' /></a>&nbsp;");
                aba.append("<a href='/checkout/basket.asp'><img src='/images/shoestudio/buttons/checkout.jpg' alt='Checkout' border='0' /></a>");

                //build complete popup object
                var aw = jQuery(document.createElement('added_basket'));
                aw.append(cb);  //add close button
                aw.append(pi);  //add product image
                aw.append(aba); //add action buttons

                wlib.center(jQuery('#added_basket'));
                jQuery('#added_basket').html(aw).fadeIn();

            } else if (r.result.problem == "SIZE") {
                wlib.msgbox("Please select a size from the dropdown before adding to your basket.");
            } else if (r.result.problem == "FULL") {
                wlib.msgbox("Sorry, your basket is full. Please remove an item in order to add more.");
            } else if (r.result.problem == "STOCK") {
                wlib.msgbox("Sorry, but this product is not in stock at this time. If you would like to be notified when this product is back in stock please enter your e-mail address below. If you have requested to be notified about a sale item, please note we are unlikely to get further stock.<p style=\"width:100%;\"><table><tr><td style=\"width:200px;\">Email:</td><td style=\"width:200px;\"><input id=\"stocknotifyemail\" type=\"text\" value=\"" + slib.Session.email + "\"/></td><td style=\"width:200px;\"><a onclick=\"wlib.findType('ProductDetailWidget').setStockNotification()\"><img style=\"margin-top:5px;\"  src=\"/images/shoestudio/buttons/btn.notify.gif\"/></a></td></tr></table></p>"); 
                slib.API.logOutOfStock(this.product);
            } else {
                wlib.msgbox("Sorry, this product could not be added to your basket at this time.");
            }
        }

        this.setStockNotification = function() {

            jQuery('#added_basket').hide();

            var email = jQuery('#stocknotifyemail').attr("value");

            if (email != "" && email != undefined) {
                slib.API.addStockNotification(null, null, this.product, email);
            }
        }

        this.cb_getProductDetailByAttrs = function(r) {
			
            this.element.css("opacity", "0");

            this.product = r.result;

			slib.breakout(this.product.barcode);
			
            var mo = '<p class=\'productprice\'>';

            if (this.product.isSale) {
                mo += '<img src=\'' + slib.Session.image_path + '/salenotice.png\' alt=\'Sale\' align=\'absmiddle\' /> ';
                mo += '<span class=\'strikeout\'>';
            }

            mo += slib.Session.currencySymbol;

			var fp;
			
            if (slib.Session.currency == "GBP") {
                fp = this.product.fullPrice_GBP + "";
            } else if (slib.Session.currency == "EUR") {
                fp = this.product.fullPrice_EUR + "";
            } else if (slib.Session.currency == "USD") {
                fp = this.product.fullPrice_USD + "";
            }
			
			if(fp.indexOf(".") > -1){var pence = fp.substring(fp.indexOf(".")+1);while(pence.length < 2){pence += "0";fp += "0";}}
			//fp =fp.toFixed(2);
			
			mo += fp;
					
            if (this.product.isSale) {
                mo += '</span> '
                mo += '<span class=\'saleprice\'>'
                mo += slib.Session.currencySymbol;
                if (slib.Session.currency == "GBP") {
                    fp= this.product.salePrice_GBP;
                } else if (slib.Session.currency == "EUR") {
                    fp= this.product.salePrice_EUR;
                } else if (slib.Session.currency == "USD") {
                    fp= this.product.salePrice_USD;
                }
				
				
				
				fp=fp+"";if(fp.indexOf(".") > -1){var pence = fp.substring(fp.indexOf(".")+1);while(pence.length < 2){pence += "0";fp += "0";}}
				//fp =fp.toFixed(2);
				
				mo += fp;
				
                mo += '</span>'
            }

            mo += '</p>';

            jQuery(".productinfo").remove(); //remove info for old colour
            jQuery(".productpic").remove(); //remove pic/flash for old colour

            var fdiv = jQuery(document.createElement("div"));
            fdiv.attr("id", this.id + "_flash").addClass("productpic");


            var info = jQuery(document.createElement("div")).addClass("productinfo"); //info div

            this.detail = jQuery(document.createElement("div")).addClass("productcol"); //bullets, heel height etc.
            this.choices = jQuery(document.createElement("div")).addClass("productcol").addClass("right"); //colours, sizes etc.
            this.buttons = jQuery(document.createElement("div")).addClass("productcol").addClass("productbuttons"); //add to wishlist, tell a friend etc.

			this.detail.css("font-size","14px");			
			
			var description = jQuery(document.createElement("ul"))
			description.attr("id", "ulProdDesc");
			description.css("width","100%").css("background-color","white");
						
            if (slib.Encoder.HTMLEncode(this.product.bullet1) != "") {	this.detail.append("<b>Description</b>"); 
																		description.append("<li>" + slib.Encoder.HTMLEncode(this.product.bullet1) + "</li>"); }
            if (slib.Encoder.HTMLEncode(this.product.bullet2) != "") {	description.append("<li>" + slib.Encoder.HTMLEncode(this.product.bullet2) + "</li>"); }
            if (slib.Encoder.HTMLEncode(this.product.bullet3) != "") {	description.append("<li>" + slib.Encoder.HTMLEncode(this.product.bullet3) + "</li>"); }
            this.detail.append(description);
            this.detail.append("<br /><p>" + slib.Encoder.HTMLEncode(slib.Text.cap(this.product.heel)) + "</p>");            
            this.detail.append("<p>Product code: <b>" + slib.Encoder.HTMLEncode(this.product.search_code) + "</b></p>");
			
			var that = this;
			
			this.buttons.append('<div id="add_wlist"></div>');
			
            //this.buttons.append('<div><a href="#"><img src="' + slib.Session.image_path + '/buttons/tellafriend.jpg" alt="Tell a friend" border="0" class="textmiddle" />&nbsp;&nbsp;Tell a friend</a></div>');

            //collate sections together
            info.append(this.detail);
            info.append(this.choices);
            info.append(this.buttons);
            info.append("<br class=\"clear\"/>");

			
			
			
			
            if (!this.hasBasics) {
                this.productElement.append("<h1>" + slib.Text.cap(this.product.brand.name) + " " + slib.Text.cap(this.product.name) + "</h1>"); //product name
                this.productElement.append(mo); //price
				
				var zim = this.product.getZoomImage();
				if(zim != ""){
					var zl = $(document.createElement("div")).css("position","absolute").css("left","0px").css("top","495px").css("z-index","995");
					zl.html('<a onclick="wlib.findType(\'ProductDetailWidget\').zoom()"><img src="' + slib.Session.image_path + '/buttons/btn.zoom.jpg" style="float:left;"/>&nbsp;See bigger</a>');
					this.productElement.append(zl); //zoom link
				}
				
                this.hasBasics = true;
            }

            this.productElement.append(fdiv); //picture/flash div

            this.productElement.append(info); //info


            this.product.setFlash(fdiv);

            this.element.fadeTo("", "1.0");

            //rest of info is added on API callback vvv

            var x = this.id;

			// BROKEN D:
			var sharethis_widget = new ShareThisWidget();
			wlib.register(sharethis_widget);
			sharethis_widget.render(this.buttons);
			
            this.product.getAvailableSizes(function(r) { wlib.find(x).cb_getAvailableSizes(r); }, function(e) { wlib.find(x).fail(e); })

			slib.API.isInWishlist(function(r){that.cb_isInWishlist(r);},null,this.product.code,this.product.colour.id);
			
        }

		this.cb_isInWishlist = function(r)
		{
			jQuery('#add_wlist').hide();
			if(r.result)
			{
				jQuery('#add_wlist').html('<a class="pbbox" onclick="wlib.findType(\'ProductDetailWidget\').removeFromWishlist();"><img src="' + slib.Session.image_path + '/buttons/addtowishlist.jpg" alt="Remove from wishlist" border="0" class="textmiddle" />&nbsp;&nbsp;Remove from wishlist</a>').fadeIn();
			}else{
				jQuery('#add_wlist').html('<a class="pbbox" onclick="wlib.findType(\'ProductDetailWidget\').addToWishlist();"><img src="' + slib.Session.image_path + '/buttons/addtowishlist.jpg" alt="Add to wishlist" border="0" class="textmiddle" />&nbsp;&nbsp;Add to wishlist</a>').fadeIn();
			}
			
			
		}
		
        this.selectSize = function(size) {
            this.product.size = null;

            if (size != undefined) {
                if (size != "") {
                    this.product.size = size;
                }
            }
        }

        this.cb_getAvailableSizes = function(r) {
            var dd = jQuery(document.createElement("select"));
            var x = this.id;

            var qs = slib.LinkController.parameters;    //added to allow size display to change based on gender

            dd.change(function() { wlib.find(x).selectSize(this.value); });
            dd.attr("id", "size");
            dd.attr("name", "size");
            if ((qs[2] != "bags") && (qs[2] != "accessories")) { //display exclusions
                dd.append("<option value=\"\" selected >UK / EU / US</option>");
            } else {
                dd.append("<option value=\"\" selected >Select...</option>");
            }

            this.product.availableSizes = r.result;

            var chp = jQuery(document.createElement("p"));
            this.colours = jQuery(document.createElement("p"));

            this.choices.append(this.colours);


            if (this.product.availableSizes.length == 1) {
                if (this.product.availableSizes[0].size != '') {
                    chp.append("Size:&nbsp;&nbsp;" + this.product.availableSizes[0].size);  //append size value as string only when a single options is available
                }
                wlib.find(x).selectSize(this.product.availableSizes[0].size) //pass dd value to wlib - this was added because the function to choose size works on dropdown change, not dropdown value so changing programatically doesn't actually set the value properly.
            } else {
                for (var k = 0; k < this.product.availableSizes.length; k++) {
                    if (isNaN(this.product.availableSizes[k].size)) {
                        var z = this.product.availableSizes[k].size;
						var w = this.product.availableSizes[k].size;
                    } else {
                        var w = '';
                        var z = parseFloat(this.product.availableSizes[k].size.toString()); //change value to float to allow for size conversion before converting back to string for encode function
                        var y = 0;
                        if(this.product.gender != 'm'){y--;} //this removes an additional figure from the  size display depending on mens or womens NOTE: UK size differs by one, but US by two, hence z-y-y-33 at the end of the line below
                        w = (z - y - 34) + '&nbsp;&nbsp;&nbsp;&nbsp;/&nbsp;&nbsp;' + z + '&nbsp;&nbsp;&nbsp;/&nbsp;&nbsp;&nbsp;' + (z - y - y - 33); //format string output
                    }
					
					if(this.product.availableSizes[k].stock == "true")
					{
						dd.append("<option value=\"" + z + "\">" + w + "</option>")
					}else{
						dd.append("<option style=\"background-color:#999999;\" value=\"" + z + "\">" + w + "</option>")
					}
                }
                chp.append("Size:&nbsp;&nbsp;");
                chp.append(dd); //append dd only when multiple options are available
            }


            chp.append("<br/><a href=\"/sizeguide/\">Size guide</a>");
            this.choices.append(chp);

            this.choices.append("<p><a onclick=\"wlib.find('" + this.id + "').addToBasket()\"><input type='image' id='imgAddToBasket' src='" + slib.Session.image_path + "/buttons/addtobasket.jpg' /></a></p>");
            //this.choices.append("<p><a onclick=\"document.location='/checkout/basket.asp'\">Proceed to Checkout</a></p>");

            this.product.getAvailableColours(function(r) { wlib.find(x).cb_getAvailableColours(r); }, function(e) { wlib.find(x).fail(e); })


        }

        this.cb_getAvailableColours = function(r) {
            this.product.availableColours = r.result;

            this.colours.append("Available in:&nbsp;&nbsp;");

            for (var bb in this.product.availableColours) {
                this.colours.append('<a onclick="wlib.findType(\'ProductDetailWidget\').\selectColour(' + this.product.availableColours[bb].id + ');"><img class="textmiddle swatch" src="' + this.product.getSwatchPath(this.product.availableColours[bb]) + '" title="' + this.product.availableColours[bb].name + '"/></a>');
            }
        }

        this.selectColour = function(id) {
            var found = false;

            if (id == this.product.colour.id) {
                return;
            }

            for (var i in this.product.availableColours) {
                if (this.product.availableColours[i].id == id) {
                    this.product.colour = this.product.availableColours[i];
                    this.product.code = this.product.colour.code;
                    found = true;
                    break;
                }
            }



            var x = this.id;

            if (found) {
                //Cause browser to switch page (doing this until we find a way of updating the URL while staying on the page)
                parent.location.href = this.product.buildLink();
                /*slib.API.getProductDetailByAttrs(
                function(r){wlib.find(x).cb_getProductDetailByAttrs(r);},
                function(e){wlib.find(x).fail(e);},
                this.product.name,
                this.product.code,
                this.product.colour.name
                );*/

            } else {
                slib.throwError("", false, true, false, null, this);
            }
        }

    }; ProductDetailWidget.prototype = new Widget();
});



var ShareThisWidget; //###########################################################################################################################################
jQuery(document).ready(function() {
    ShareThisWidget = function() {
        this.id = wlib.getID();
        this.type = "ShareThisWidget";
        this.render = function(parent) {
            if (!this.isRendered) {
				
				var pd;
				
				pd = wlib.findType("ProductDetailWidget");
				
				if(pd == null)
				{
					var that = this;
					setTimeout(function(){that.render(parent);},100);
					return;
				}
				
				if(pd.product == null)
				{
					var that = this;
					setTimeout(function(){that.render(parent);},100);
					return;
				}
				
				if(parent.length == 0){
					var that = this;
					setTimeout(function(){that.render(parent);},1000);
					return;
				}
                this.id = (this.id == undefined) ? wlib.getID() : this.id;
				
				
				
				var container = jQuery(document.createElement("div")); 
				container.attr("id", "sharethisdiv");
				
				addthis_share = { url: slib.Encoder.URLEncode(document.URL) , title: slib.Text.cap(pd.product.brand.name) + slib.Text.cap(pd.product.name) };var addthis_title = slib.Text.cap(pd.product.brand.name) + ' ' + slib.Text.cap(pd.product.name);
				
				container.append('<div class="pbbox"><script type="text/javascript">var addthis_config = { ui_click: true, data_track_clickback: false };</script><a href="http://addthis.com/bookmark.php?v=250" class="addthis_button"><img width="23" height="23" border="0" alt="Share" src="'+slib.Session.image_path + '/buttons/tellafriend.jpg"/><div class="sharetext">Share</div></a><a class="addthis_button_email"></a><a class="addthis_button_facebook"></a><a class="addthis_button_twitter"></a><a class="addthis_button_googlebuzz"></a></div><script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#username=xa-4c121ae33019918f"></script>');
				container.append('<a class="addthis_button_facebook_like"></a>');
				container.fadeIn();
				this.element = container;
				parent.append(this.element);
				this.isRendered = true;			
            }
        }
		
		        
    }; ShareThisWidget.prototype = new Widget();
});




var ReviewWidget; //###########################################################################################################################################
 jQuery(document).ready(function(){
 ReviewWidget = function() //Displays service status
 {
	this.id = wlib.getID();
	this.type = "ReviewWidget";
	this.product=null;
	this.stars = 0;
	this.img = '';
	
	this.render = function(parent)
	{
		if(!this.isRendered)
		{
						
			var pd = wlib.findType("ProductDetailWidget");
			
			var that = this;
			
			
			
			
			if(pd==null)
			{
				setTimeout(function(){that.render(parent);},500);
				return;
			}
			
			if(pd.product==null)
			{
				setTimeout(function(){that.render(parent);},500);
				return;
			}
			
			this.product = pd.product;
			
			var range = this.product.range.name.toUpperCase();
			
			var group = this.product.group.name.toUpperCase();;
			
			if(range == "OUTLET")
			{
				range = this.product.group.name.toUpperCase();
				group = this.product.subgroup.name.toUpperCase();;
			}
			
			
			
			if(range == 'LADIES' || range == 'LADIES OUTLET')
			{
				if(group == "ACCESSORIES" || group == "BAGS")
				{
					this.img = "bagstar.png";
				}else{
					this.img = "ladiesstar.png";
				}
			}else if(range == 'MENS' || range == 'MENS OUTLET')
			{
				if(group == "ACCESSORIES" || group == "BAGS")
				{
					this.img = "mensstar.png";
				}else{
					this.img = "mensstar.png";
				}
			}else{
				this.img = "bagstar.png";
			}
			
			this.id = (this.id == undefined) ? wlib.getID() : this.id;
			var me = jQuery(document.createElement("div"));
			
			me.addClass("widget");
			me.addClass("container");
			me.addClass("reviews");
			
			slib.API.getProductReviews(function(r){that.cb_getProductReviews(r);},null,pd.product);
			
			this.element = me;
			parent.append(me);
			
			this.isRendered = true;
			this.element.fadeIn();
		}
	}
	
	this.cb_getProductReviews = function(r)
	{
		this.element.html("<div id=\"titleCustReviews\"><h3 style=\"color:#a40000;\">Customer reviews</h3></div>");
		
		if(r.result.average == 0)
		{
		
			this.element.append("<div style=\"float:left;margin-top:5px;color:#a40000;\">Nobody has reviewed this product yet - <a onclick=\"wlib.findType('ReviewWidget').showForm();\"><b>be the first</b></a>!</div>");
		
		}else{
		
			var star_thing = '<div style=\"float:left;margin-right:10px;margin-top:5px;color:#a40000;\"><b>Average review score: </b></div>';
			star_thing += '<img id="rated_shoe_1" style="float:left;" src="' + slib.Session.image_path + '/buttons/' + this.img + '"/>';
			star_thing += '<img id="rated_shoe_2" style="float:left;" src="' + slib.Session.image_path + '/buttons/' + this.img + '"/>';
			star_thing += '<img id="rated_shoe_3" style="float:left;" src="' + slib.Session.image_path + '/buttons/' + this.img + '"/>';
			star_thing += '<img id="rated_shoe_4" style="float:left;" src="' + slib.Session.image_path + '/buttons/' + this.img + '"/>';
			star_thing += '<img id="rated_shoe_5" style="float:left;" src="' + slib.Session.image_path + '/buttons/' + this.img + '"/>';
			star_thing += '<br style="clear:both;"/>';
			
			this.element.append("<div style=\"width:310px;float:left;\">"+star_thing+"</div>");
						
			for(var i = 1;i <= 5;i++)
			{
				if(i > r.result.average)
				{
					jQuery('#rated_shoe_' + i).css("opacity","0.3");
				}
			}
												
			this.element.append("<div style=\"float:left;margin-left:20px;margin-top:5px;color:#a40000;\">Why not <a onclick=\"wlib.findType('ReviewWidget').showForm();\"><b>write your own review</b></a>?</div>");
			
			this.element.append('<div style="clear:both;"></div>');
			
			var rnum = 0;
			var rn;
			
			var rev;
			
			var brief;
			
			var brief_length = 50;
			
			var shortReview = true;
			
			for(var ii in r.result.reviews)
			{
				rnum++;
				rn = rnum + '';
				star_thing = '';
				star_thing += '<img id="rev_' + rn + '_rated_shoe_1" style="float:left;" src="' + slib.Session.image_path + '/buttons/' + this.img + '"/>';
				star_thing += '<img id="rev_' + rn + '_rated_shoe_2" style="float:left;" src="' + slib.Session.image_path + '/buttons/' + this.img + '"/>';
				star_thing += '<img id="rev_' + rn + '_rated_shoe_3" style="float:left;" src="' + slib.Session.image_path + '/buttons/' + this.img + '"/>';
				star_thing += '<img id="rev_' + rn + '_rated_shoe_4" style="float:left;" src="' + slib.Session.image_path + '/buttons/' + this.img + '"/>';
				star_thing += '<img id="rev_' + rn + '_rated_shoe_5" style="float:left;" src="' + slib.Session.image_path + '/buttons/' + this.img + '"/>';
				star_thing += '<br style="clear:both;"/>';
				
				rev = jQuery('<div class="review"></div>')
				
				brief = slib.Encoder.HTMLEncode(r.result.reviews[ii].review);
				
				shortReview = (brief.length <= brief_length);
				
				
				for(var b = 0;b < brief.length;b++)
				{
					if(brief.charAt(b) == '.')
					{
						brief = brief.substring(0,b+1) + '..';
						break;
					}
				}
				
				if(brief.length > brief_length)
				{
					for(var b = brief_length;b >= 0;b--)
					{
						if(brief.charAt(b) == ' ')
						{
							brief = brief.substring(0,b) + '...';
							break;
						}
					}
				}
				
				if(brief.length > brief_length)
				{
					brief = brief.substring(0,brief_length) + '...';
				}
				
				rev.append('<div class="review_rating">'+star_thing+'</div>');				
				rev.append('<div class="review_name">Review by <b>' + slib.Encoder.HTMLEncode(r.result.reviews[ii].name)  + '</b></div>');
				rev.append('<div class="review_brief" id="rev_' + rn + '_brief">' + brief + '</div>');
				if(!shortReview)
				{
					rev.append('<div class="review_more" id="rev_' + rn + '_more"><a onclick="jQuery(\'#rev_' + rn + '_brief\').hide();jQuery(\'#rev_' + rn + '_more\').hide();jQuery(\'#rev_' + rn + '_less\').show();jQuery(\'#rev_' + rn + '_full\').show();">Read More</a></div><div class="review_less" id="rev_' + rn + '_less"><a onclick="jQuery(\'#rev_' + rn + '_more\').show();jQuery(\'#rev_' + rn + '_less\').hide();jQuery(\'#rev_' + rn + '_brief\').show();jQuery(\'#rev_' + rn + '_full\').hide();">Read Less</a></div>');
				}
				rev.append('<div class="review_full" id="rev_' + rn + '_full"><p>' + slib.Encoder.HTMLEncode(r.result.reviews[ii].review) + '</p></div>');
				rev.append('<div style="clear:both;"><!--x--></div>');
				
				this.element.append(rev);
				
				for(var i = 1;i <= 5;i++)
				{
					if(i > r.result.reviews[ii].rating)
					{
						jQuery('#rev_' + rn  + '_rated_shoe_' + i).css("opacity","0.3");
					}
				}
			}
			
		}
	}
	
	this.showForm = function()
	{
		
		if(!slib.Session.logged_in)
		{
			wlib.login();
			return;
		}
		
		var table = jQuery('<table style="margin-top:10px;width:100%;text-align:left;"></table>');
	
		var star_thing = '';
		
		this.stars = 0;
		
		star_thing += '<img id="rating_shoe_1" class="rating_shoe" style="float:left;" src="' + slib.Session.image_path + '/buttons/' + this.img + '"/>';
		star_thing += '<img id="rating_shoe_2" class="rating_shoe" style="float:left;" src="' + slib.Session.image_path + '/buttons/' + this.img + '"/>';
		star_thing += '<img id="rating_shoe_3" class="rating_shoe" style="float:left;" src="' + slib.Session.image_path + '/buttons/' + this.img + '"/>';
		star_thing += '<img id="rating_shoe_4" class="rating_shoe" style="float:left;" src="' + slib.Session.image_path + '/buttons/' + this.img + '"/>';
		star_thing += '<img id="rating_shoe_5" class="rating_shoe" style="float:left;" src="' + slib.Session.image_path + '/buttons/' + this.img + '"/>';				
		
		var name = jQuery('<tr><td style="padding-top:10px;width:100px;">Display Name</td><td style="padding-top:10px;"><input style="width:200px;" id="review_name" type="text" value="' + slib.Session.forename + '"/></td><td></td></tr>');
		var rating = jQuery('<tr><td style="width:100px;">Rating</td><td id="review_rating_container">' + star_thing + '</td><td rowspan=3 valign=top>1 - Don\'t Like<br />2 - Like<br />3 - Love<br />4 - Fantastic<br />5 - Must Have</td></tr>');
		
		var rating_desc = jQuery('<tr><td style="width:100px;"></td><td><span style="margin-left:11px;margin-right:11px;">1</span><span style="margin-left:11px;margin-right:11px;">2</span><span style="margin-left:11px;margin-right:11px;">3</span><span style="margin-left:11px;margin-right:11px;">4</span><span style="margin-left:11px;margin-right:11px;">5</span><br /><br /></td></tr>');
		
		var review = jQuery('<tr><td style="width:100px;">Review</td><td><textarea rows="8" style="width:200px;" id="review_review"/></textarea></td></tr>');
		var submit = jQuery('<tr><td style="width:100px;"></td><td><img src="' + slib.Session.image_path + '/buttons/btn.submit.gif" onclick="jQuery(\'#added_basket\').fadeOut();wlib.findType(\'ReviewWidget\').review()"/></td></tr>');
	
		table.append(name);
		table.append(rating);
		table.append(rating_desc);		
		table.append(review);
		table.append(submit);
	
			var mo = '<p class=\'productprice\'>';

            if (this.product.isSale) {
                mo += '<img src=\'' + slib.Session.image_path + '/salenotice.png\' alt=\'Sale\' align=\'absmiddle\' /> ';
                mo += '<span class=\'strikeout\'>';
            }

            mo += slib.Session.currencySymbol;

			var fp;
			
            if (slib.Session.currency == "GBP") {
                fp = this.product.fullPrice_GBP + "";
            } else if (slib.Session.currency == "EUR") {
                fp = this.product.fullPrice_EUR + "";
            } else if (slib.Session.currency == "USD") {
                fp = this.product.fullPrice_USD + "";
            }
			
			if(fp.indexOf(".") > -1){var pence = fp.substring(fp.indexOf(".")+1);while(pence.length < 2){pence += "0";fp += "0";}}
			//fp =fp.toFixed(2);
			
			mo += fp;
					
            if (this.product.isSale) {
                mo += '</span> '
                mo += '<span class=\'saleprice\'>'
                mo += slib.Session.currencySymbol;
                if (slib.Session.currency == "GBP") {
                    fp= this.product.salePrice_GBP;
                } else if (slib.Session.currency == "EUR") {
                    fp= this.product.salePrice_EUR;
                } else if (slib.Session.currency == "USD") {
                    fp= this.product.salePrice_USD;
                }
				
				
				
				fp=fp+"";if(fp.indexOf(".") > -1){var pence = fp.substring(fp.indexOf(".")+1);while(pence.length < 2){pence += "0";fp += "0";}}
				//fp =fp.toFixed(2);
				
				mo += fp;
				
                mo += '</span>'
            }

            mo += '</p>';
	
	
		var productHTML = '<h1>' + slib.Text.cap(this.product.brand.name) + ' ' + slib.Text.cap(this.product.name) + '</h1>' + mo + '<br/><img src="' + this.product.getBasketImage() + '"/>';
	
		var reviewForm = jQuery('<div class="review_form"><div class="review_product">'+productHTML+'</div></div>')
	
		var reviewTable = jQuery('<div class="review_table"></div>').append(table);
	
		reviewForm.append(reviewTable);
	
		wlib.msgbox(reviewForm,false,"Write Review",760,undefined);
		
		var that = this;
		
		for(var i = 1;i <= 5;i++)
		{
			jQuery('#rating_shoe_' + i).css("opacity","0.3");
			jQuery('#rating_shoe_' + i).click(
				function(){
				
					try{
						var c = jQuery(this).attr('id').substring(12);
						c = c * 1;
				
						that.stars = c;
				
						for(var j = 1;j <= 5;j++)
						{
							if(j <= c)
							{
								jQuery('#rating_shoe_' + j).css("opacity","1");
							}else{
								jQuery('#rating_shoe_' + j).css("opacity","0.3");
							}
						}
					}catch(e){}
				}
			);
		}
		
		jQuery('#review_review').focus(function(){if(jQuery('#review_review').html() == "Add your review here..."){jQuery('#review_review').html("");}});
		jQuery('#review_review').blur(function(){if(jQuery('#review_review').html() == ""){jQuery('#review_review').html("Add your review here...");}});
		jQuery('#review_review').html("Add your review here...");
		
	}
	
	this.review = function()
	{
		var that = this;
		
		var rating = this.stars;
		var review = jQuery('#review_review').attr("value");
		var name = jQuery('#review_name').attr("value");
		
		if(this.stars == 0)
		{
			jQuery('#added_basket').append('<span style="color:red">Please rate the product using the shoes!</span><br/><br/>')
			jQuery('#added_basket').fadeIn();
			return;
		}
		
		slib.API.addProductReview(function(){that.thank();},null,this.product,rating,review,name);
	}
	
	this.thank = function()
	{
		wlib.msgbox("Thanks very much for submitting your review!");
	}
	
 };ReviewWidget.prototype = new Widget();
 });
 
 
 
 var BasketWidget; //###########################################################################################################################################
 jQuery(document).ready(function () {
     BasketWidget = function () //Displays basket contents
     {
         this.id = wlib.getID();
         this.type = "BasketWidget";
         this.dropdown = null;
         this.products = [];
         this.render = function () {
             if (!this.isRendered) {
                 this.id = (this.id == undefined) ? wlib.getID() : this.id;
                 var me = jQuery(document.createElement("div"));

                 var tools = jQuery('#tools').children("ul:first-child");

                 var li = jQuery(document.createElement("li"));
                 var parent = jQuery(document.createElement("a")).attr("href", "/checkout/basket.asp");
                 parent.html('Basket <img src="' + slib.Session.image_path + '/buttons/basket.jpg" alt="Basket" title="Basket" border="0" align="absmiddle" />');

                 me.attr("id", this.id);
                 me.addClass("widget");


                 this.dropdown = jQuery(document.createElement("div")).attr("id", "basket_popup").hide().css("z-index", "3000");

                 li.append(parent);
                 tools.append(li);

                 jQuery('#tools').append(this.dropdown);

                 this.isRendered = true;

                 slib.MenuManager.register(parent, this.dropdown);

                 this.fill();
             }
         }

         this.fill = function () {
             var x = this.id;
             slib.API.getBasketContents(function (r) { wlib.find(x).cb_fill(r); }, function (e) { wlib.find(x).fail(e); });
         }

         this.cb_fill = function (r) {
             this.products = r.result;
             this.redraw();
         }

         this.addProduct = function (product) {
             this.products[this.products.length] = product;

             if (this.isRendered) {
                 this.redraw();
             }
         }


         this.redraw = function () {
             this.dropdown.html("");

             this.dropdown.append("<div class='close'><a onclick='wlib.findType(\"BasketWidget\").dropdown.hide()'><img src='" + slib.Session.image_path + "/buttons/close.png' alt='Close' border='0' /></a></div>");

             var total = 0;

             var je;

             for (var i in this.products) {

                 var price = this.products[i].getLocalSalePrice();

                 total += price;

                 var bl = jQuery(document.createElement('div')).addClass("basket_line");

                 //create image object
                 je = jQuery(document.createElement("div")).addClass("popbasketimage");
                 je.append(jQuery(document.createElement("a")).attr("id", this.id + "_collection_item_a" + i).attr("href", this.products[i].buildLink()).append(jQuery(document.createElement("img")).attr("id", this.id + "_collection_item_" + i)).css("position", "relative"));

                 this.products[i].setCollectionImage(je.children(":first-child").children(":first-child"));

                 bl.append(je); //add info to Basket Product div

                 bl.append("<div class='basket_item'><b>" + slib.Text.cap(slib.Encoder.HTMLEncode(this.products[i].name)) + "</b><br/>" + slib.Session.currencySymbol + this.products[i].getLocalSalePrice() + "</div><br class='clear' />");
                 this.dropdown.append(bl);
             }

             if (this.products.length == 0) {
                 this.dropdown.append("<p>Your basket is empty</p>");
             } else {
                 this.dropdown.append("<div class='basket_action'>Total: <b>" + slib.Session.currencySymbol + total + "</b><a href='/checkout/basket.asp'><img src='/images/shoestudio/buttons/checkout.jpg' align='absmiddle' alt='Checkout' border='0' /></a></div>");
             }
         }

     }; BasketWidget.prototype = new Widget();
 });
 
 
 
 
 
 var CurrencyWidget; //###########################################################################################################################################
 jQuery(document).ready(function(){
 CurrencyWidget = function() //Displays currency and lets user select alternatives
 {
	this.id = wlib.getID();
	this.type = "CurrencyWidget";	
	this.dropdown = null;
	this.products = [];
	this.parent = null;
	this.render = function()
	{
		if(!this.isRendered)
		{
			this.id = (this.id == undefined) ? wlib.getID() : this.id;
			
			var tools = jQuery('#tools').children("ul:first-child");
			
			var li = jQuery(document.createElement("li"));
			this.parent = jQuery(document.createElement("a"));
			this.parent.html('Currency (<span id="currencysymbol">' + slib.Session.currencySymbol + '</span>)');
						
			if(jQuery('#currency').attr("id") == undefined)
			{
				this.dropdown = jQuery(document.createElement("div")).attr("id","currency").css("position","absolute");
			}else{
				this.dropdown = jQuery('#currency');
			}
			
			
			this.dropdown.append('<a onclick="wlib.findType(\'CurrencyWidget\').select(\'GBP\',\'&pound;\')"><img src="/images/shoestudio/currency/pound.png" alt="GBP" border="0" /></a>');
			this.dropdown.append('<a onclick="wlib.findType(\'CurrencyWidget\').select(\'EUR\',\'&euro;\')"><img src="/images/shoestudio/currency/euro.png" alt="Euro" border="0" /></a>');
			this.dropdown.append('<a onclick="wlib.findType(\'CurrencyWidget\').select(\'USD\',\'&#36;\')"><img src="/images/shoestudio/currency/dollar.png" alt="Dollar" border="0" /></a>');
			
			this.parent.append(this.dropdown);
			
			li.append(this.parent);
			
			tools.append(li);
			
			slib.MenuManager.register(this.parent,this.dropdown);
			
			this.isRendered = true;
		}
	}
	
		
	this.select = function(currency,symbol)
	{
		var that = this;
		slib.Session.setCurrency(currency,symbol, function()
																						{
																							if(slib.LinkController.parameters[0] == "checkout"){document.location = document.location + "?cxc";}
																						}
		);
		
		jQuery('#currencysymbol').html(symbol);
		
		var pd = wlib.findType("ProductDetailWidget");
		
		if(pd != null)
		{
			pd.refresh();
		}
		
		var pd = wlib.findType("CollectionWidget");
		
		if(pd != null)
		{
			pd.display();
		}
		
		var pd = wlib.findType("BasketWidget");
		
		if(pd != null)
		{
			pd.fill();
		}		
	}
		
 };CurrencyWidget.prototype = new Widget();
 });
 
 
 
 var BadgeWidget; //###########################################################################################################################################
 jQuery(document).ready(function(){
 BadgeWidget = function() //Displays currency and lets user select alternatives
 {
	this.id = wlib.getID();
	this.type = "BadgeWidget";	
	this.dropdown = null;
	this.parent = null;
	this.element = null;
	this.badges = [];
	this.product;
	this.render = function(parent)
	{
		if(slib.Session.range.name.toUpperCase() == "OUTLET") {return;} 
	
		if(!this.isRendered)
		{
			this.id = (this.id == undefined) ? wlib.getID() : this.id;
			
			var that = this;
			
			if(slib.Session.gender == "m"){return;}
			
			 var rw = wlib.findType("ReviewWidget");
			 
			 if(rw == null && slib.Session.gender == 'f'){
				setTimeout(function(){that.render(parent);},100);
				return;
			 }
			 
			 if(!rw.isRendered && slib.Session.gender == 'f'){
				setTimeout(function(){that.render(parent);},100);
				return;
			 }
			
			this.parent = parent;
					
			var pd = wlib.findType("ProductDetailWidget");
			
			if(pd.product == null) //if product detail widget hasn't initialised properly yet then cancel this render and try again in 100ms
			{
				setTimeout(function(){that.render(parent);},100);
				return;
			}
			
			this.product = pd.product;
			
			this.element = jQuery(document.createElement("div")).attr("id","stamps");
			this.dropdown = jQuery(document.createElement("div")).attr("id","badges_popup").hide();
			this.dropdown.append("<div class='badges_close'><a href='#'><img src='images/buttons/close.png' alt='Close' border='0' /></div>");
			
			this.parent.append(this.dropdown);
			
			this.parent.append(this.element);
			
			slib.API.getProductRatings(function(r){that.cb_getProductRatings(r);},function(e){that.fail(e);},this.product);
			
			this.isRendered = true;
		}
	}
	
	this.cb_getProductRatings = function(r)
	{
		
		this.badges = slib.sort(r.result,"ratings",slib.constants.DESCENDING);
		
		var max = (this.badges.length  < 3) ? this.badges.length : 3;
		
		this.element.html("<h3>Stamp your mark on this shoe!</h3>"); //empty div...
		this.dropdown.html(""); //empty div...
		
		var src;
		var col;
		
		this.dropdown.append("<div class='badges_close'><a onclick=\"jQuery('#badges_popup').fadeOut();\"><img src='" + slib.Session.image_path + "/buttons/close.png' alt='' border='0' /></a></div>");
		
		if(max == 0)
		{
			this.element.append(jQuery(document.createElement("p")).addClass("stamp").append("Nobody has rated this product yet!"));
		}
		
		for(var i = 0;i < this.badges.length;i++) // ...and fill it with top three badges...
		{
			src = slib.Session.image_path + "/stamps/" + this.badges[i].filename;
		
			this.dropdown.append('<a onclick="wlib.findType(\'BadgeWidget\').select(' + this.badges[i].id + ')"><img src="' + slib.Session.image_path + '/stamps/' + this.badges[i].filename + '" alt="" border="0" /></a>');
		
			if(i < max)
			{
				col = jQuery(document.createElement("p")).addClass("stamp");

				//col.append('<a onclick="jQuery(\'#badges_popup\').fadeIn();"><img src="' + src + '"/></a><br/>' + this.badges[i].ratings);
				col.append('<a onclick="wlib.center(jQuery(\'#badges_popup\'));jQuery(\'#badges_popup\').fadeIn()"><img src="' + src + '"/></a><br/>' + this.badges[i].ratings);
				
				this.element.append(col)
			}
		}
		
		//this.dropdown.append("<div class='badges_point'><img src='images/stamps/point.png' alt='' border='0' /></div>");
		
		col = jQuery(document.createElement("p")).addClass("addstamp");
		
		col.append('Choose a fashion stamp!<br/><a style="font-size:15px;" onclick="wlib.center(jQuery(\'#badges_popup\'));jQuery(\'#badges_popup\').fadeIn()">Click here to choose a stamp...</a>');
		
		this.element.append(col);
		this.element.append('<br class="clear"/>');
	}
	
	this.select = function(badge_id)
	{
		var chosen = false;
		var that = this;

		jQuery('#badges_popup').fadeOut();

		/*if(!slib.Session.logged_in)
		{			
			this.notLoggedIn();
			return;
		}*/
		
		for(var i in this.badges)
		{
			if(this.badges[i].id == badge_id)
			{
				chosen = this.badges[i];
			}
		}
		
		if(chosen)
		{
			slib.API.rateProduct(function(r){that.cb_rate(r);},function(e){that.fail(e);},this.product,chosen);
		}
	}
	
	this.cb_rate = function(r)
	{
		if(r.result)
		{
			//success - update ratings!
			var that = this;
			slib.API.getProductRatings(function(r){that.cb_getProductRatings(r);},function(e){that.fail(e);},this.product);
		}else{
			this.notLoggedIn();
		}
	}
	
	this.notLoggedIn = function()
	{
		wlib.login();
	}
	
 };BadgeWidget.prototype = new Widget();
 });
 
 
 
 
 var AlsoLikeWidget; //###########################################################################################################################################
 jQuery(document).ready(function() {
     AlsoLikeWidget = function() { //Displays the products customers may also like
         this.id = wlib.getID();
         this.type = "AlsoLikeWidget";
         this.render = function(parent) {
             if (!this.isRendered) {


                 var pdw = wlib.findType("ProductDetailWidget"); //find product detail widget so we can recommendations for the product it's showing
                 var that = this;
                 if (pdw == null) //if a product detail widget doesnt exist yet, give it 100ms and try again
                 {
                     setTimeout(function() { that.render(parent); }, 100);
                     return;
                 } else if (pdw.product == null) { //if a product detail widget doesnt have a product yet, give it 100ms and try again
                     setTimeout(function() { that.render(parent); }, 100);
                     return;
                 }

                 //sort general rendering stuff out
                 this.id = (this.id == undefined) ? wlib.getID() : this.id;
                 var me = jQuery(document.createElement("div"));
                 me.attr("id", "also");
                 me.addClass("widget");
                 this.element = me;
                 parent.prepend(me);

                 //create div
                 this.container = jQuery(document.createElement("div"));
                 this.container.attr("id", "also");


                 //lookup also products via API
                 slib.API.getAlsoLike(function(r) { that.cb_populate(r); }, function(e) { that.fail(e); }, pdw.product);

                 this.isRendered = true;
             }
         }
         this.cb_populate = function(r) {

             this.element.html("");

             this.element.append("<center><h3>You may also like</h3></center>");

             var je;

             var i; var m = r.result.length;
             for (i = 0; i < m; i++) {

                 //Product info
                 var inf = '';

                 je = jQuery(document.createElement("div")).addClass("alsoproduct");
                 je.append(jQuery(document.createElement("a")).attr("id", this.id + "_collection_item_a" + i).attr("href", r.result[i].buildLink()).append(jQuery(document.createElement("img")).attr("id", this.id + "_collection_item_" + i)).css("position", "relative"));

                 //this.element.append(je);

                 inf += '<p class="popuptitle">' + slib.Text.cap(r.result[i].brand.name) + " " +  slib.Text.cap(r.result[i].name) + ' <br />';
                 inf += '<strong>';

                 if (r.result[i].isSale) {
                     inf += '<span class=\'strikeout\'>';
                 }

                 inf += slib.Session.currencySymbol;

                 if (slib.Session.currency == "GBP") {
                     inf += r.result[i].fullPrice_GBP;
                 } else if (slib.Session.currency == "EUR") {
                     inf += r.result[i].fullPrice_EUR;
                 } else if (slib.Session.currency == "USD") {
                     inf += r.result[i].fullPrice_USD;
                 }

                 if (r.result[i].isSale) {
                     inf += '</span> ';
                     inf += '<span class=\"saleprice\">';
                     inf += slib.Session.currencySymbol;
                     if (slib.Session.currency == "GBP") {
                         inf += r.result[i].salePrice_GBP.toFixed(2);
                     } else if (slib.Session.currency == "EUR") {
                         inf += r.result[i].salePrice_EUR.toFixed(2);
                     } else if (slib.Session.currency == "USD") {
                         inf += r.result[i].salePrice_USD.toFixed(2);
                     }
					 inf += '</span>';
                 }
                 
                 inf += '</strong>';
                 inf += '</p>';

				 
                 je.append(inf); //add info to Also Product div

                 r.result[i].setCollectionImage(je.children(":first-child").children(":first-child"));

                 this.element.append(je); //add info to Also Product div
                 
                 //this.element.append("<div class=\"alsoproduct\"><a href=\"" + r.result[i].buildLink() + "\"><img src=\"" + r.result[i].getBasketImage() + "\" alt=\"" + r.result[i].name + "\" /></a></div>");
             }

			 this.container.append("<br style=\"clear:both;\"/>&nbsp;");
			 this.element.append("<br style=\"clear:both;\"/>&nbsp;");
			 jQuery('.advertbar').hide();
			 
         }
     }; AlsoLikeWidget.prototype = new Widget();
 });
 
 
 
 
 var SearchFilterWidget; //###########################################################################################################################################
 jQuery(document).ready(function () {
     SearchFilterWidget = function () //Allows Collection contents to be filtered
     {
         this.id = wlib.getID();
         this.type = "SearchFilterWidget";
         this.searchIdent = '';



         this.filters = {
             category: false,
             category_selection: null,

             brand: false,
             brand_selection: null,

             price: false,
             price_low: null,
             price_high: null,

             sale: false,
             size: false,

             heel: false,
             heel_selection: null,

             colour: false,
             colour_selection: null,

             theme: false,
             theme_selection: null,
             theme_keywords: null,

             heelheight: false,
             heelheight_selection: null

         };

         this.render = function (parent) {
             if (!this.isRendered) {

                 var qs = slib.LinkController.parameters;

                 var show = false;

                 if (qs[0] == "mens" || qs[0] == "ladies" || qs[0] == "outlet") {
                     if (qs[1] == "new" || qs[1] == "brands" || qs[1] == "categories" || qs[1] == "search") {
                         show = true;
                     }
                 }


                 if (!show) { return; }


                 this.id = (this.id == undefined) ? wlib.getID() : this.id;
                 var me = jQuery(document.createElement("div"));

                 me.attr("id", this.id);
                 me.addClass("widget");

                 me.addClass("filtercontainer");

                 me.append("<div style=\"text-align:left;\"><h2 style=\"margin-top:0px;margin-bottom:7px;\">Refine By...</h2></div>");


                 //Category Filter
                 var fCategory = jQuery(document.createElement("div")).addClass("firstfilter").addClass("filter");
                 var fCategoryUl = jQuery('<ul></ul>');
                 fCategoryUl.append('<li>Category</li>');
                 var fCategoryLi = jQuery(document.createElement("li")).append("Any").attr("id", "selected-category");
                 fCategoryUl.append(fCategoryLi);
                 var fCategoryPopup = jQuery(document.createElement("div")).attr("id", "categorypopup").addClass("filterpopup");
                 fCategoryPopup.append('<p class="popup_arrow"><img src="' + slib.Session.image_path + '/backgrounds/popup_arrow.png" alt="" /></p>');
                 fCategoryPopup.append('<ol id="categoryselectable" class=""></ol>');

                 var fCategoryA = jQuery(document.createElement("a"));
                 fCategoryA.append(fCategoryUl);
                 fCategory.append(fCategoryA);
                 fCategory.append(fCategoryPopup);

                 if ((qs[1] != "categories") && (qs[0] != "outlet")) { me.append(fCategory); }

                 fCategory.css("z-index", "45");



                 //Brand Filter
                 var fBrand = jQuery(document.createElement("div")).addClass("filter");
                 var fBrandUl = jQuery('<ul></ul>');
                 fBrandUl.append('<li>Brand</li>');
                 var fBrandLi = jQuery(document.createElement("li")).append("Any").attr("id", "selected-brand");
                 fBrandUl.append(fBrandLi);
                 var fBrandPopup = jQuery(document.createElement("div")).attr("id", "brandpopup").addClass("filterpopup");
                 fBrandPopup.append('<p class="popup_arrow"><img src="' + slib.Session.image_path + '/backgrounds/popup_arrow.png" alt="" /></p>');
                 fBrandPopup.append('<ol id="brandselectable" class=""></ol>');

                 var fBrandA = jQuery(document.createElement("a"));
                 fBrandA.append(fBrandUl);
                 fBrand.append(fBrandA);
                 fBrand.append(fBrandPopup);

                 fBrand.css("z-index", "40");

                 if (qs[1] != "brands") { me.append(fBrand); }




                 //Price Filter
                 var fPrice = jQuery(document.createElement("div")).addClass("filter");
                 var fPriceUl = jQuery('<ul></ul>');
                 fPriceUl.append('<li>Price</li>');
                 var fPriceLi = jQuery(document.createElement("li")).append("Any").attr("id", "selected-price");
                 fPriceUl.append(fPriceLi);

                 var fPricePopup = jQuery(document.createElement("div")).attr("id", "pricepopup").addClass("filterpopup");
                 fPricePopup.append('<p class="popup_arrow"><img src="' + slib.Session.image_path + '/backgrounds/popup_arrow.png" alt="" /></p>');
                 fPricePopup.append('<div class="priceslider"><div id="slider-range"></div><p id="amount" class="slideramount"></p></div>');

                 var fPriceA = jQuery(document.createElement("a"));
                 fPriceA.append(fPriceUl);
                 fPrice.append(fPriceA);
                 fPrice.append(fPricePopup);

                 fPrice.css("z-index", "35");

                 me.append(fPrice);







                 //Colour Filter
                 var fColour = jQuery(document.createElement("div")).addClass("firstfilter").addClass("filter");
                 var fColourUl = jQuery('<ul></ul>');
                 fColourUl.append('<li>Colour</li>');

                 var fColourLi = jQuery(document.createElement("li")).append("Any").attr("id", "selected-colour");
                 fColourUl.append(fColourLi);
                 var fColourPopup = jQuery(document.createElement("div")).attr("id", "colourpopup").addClass("filterpopup");
                 fColourPopup.append('<p class="popup_arrow"><img src="' + slib.Session.image_path + '/backgrounds/popup_arrow.png" alt="" /></p>');
                 fColourPopup.append('<ol id="colourselectable" class=""></ol>');

                 var fColourA = jQuery(document.createElement("a"));
                 fColourA.append(fColourUl);
                 fColour.append(fColourA);
                 fColour.append(fColourPopup);

                 fColour.css("z-index", "30");

                 me.append(fColour);





                 //Size filter
                 var fSize = jQuery(document.createElement("div")).addClass("firstfilter").addClass("filter");
                 var fSizeUl = jQuery('<ul></ul>');
                 fSizeUl.append('<li>Size</li>');
                 var fSizeLi = jQuery(document.createElement("li")).append("Any").attr("id", "selected-size");
                 fSizeUl.append(fSizeLi);
                 var fSizePopup = jQuery(document.createElement("div")).attr("id", "sizepopup").addClass("filterpopup");
                 fSizePopup.append('<p class="popup_arrow"><img src="' + slib.Session.image_path + '/backgrounds/popup_arrow.png" alt="" /></p>');
                 fSizePopup.append('<ol id="sizeselectable" class=""></ol>');

                 var fSizeA = jQuery(document.createElement("a"));
                 fSizeA.append(fSizeUl);
                 fSize.append(fSizeA);
                 fSize.append(fSizePopup);

                 fSize.css("z-index", "25");

                 if ((qs[2] != "bags") && (qs[2] != "accessories")) { me.append(fSize); };




                 //Heel height filter
                 var fHeel = jQuery(document.createElement("div")).addClass("firstfilter").addClass("filter");
                 var fHeelUl = jQuery('<ul></ul>');
                 fHeelUl.append('<li>Heel</li>');
                 var fHeelLi = jQuery(document.createElement("li")).append("Any").attr("id", "selected-heel");
                 fHeelUl.append(fHeelLi);
                 var fHeelPopup = jQuery(document.createElement("div")).attr("id", "heelpopup").addClass("filterpopup");
                 fHeelPopup.append('<p class="popup_arrow"><img src="' + slib.Session.image_path + '/backgrounds/popup_arrow.png" alt="" /></p>');
                 fHeelPopup.append('<ol id="heelselectable" class=""></ol>');

                 var fHeelA = jQuery(document.createElement("a"));
                 fHeelA.append(fHeelUl);
                 fHeel.append(fHeelA);
                 fHeel.append(fHeelPopup);

                 fHeel.css("z-index", "20");

                 if ((qs[0] != "mens") && (qs[2] != "bags") && (qs[2] != "accessories")) { me.append(fHeel); };






                 //Theme Filter
                 var fTheme = jQuery(document.createElement("div")).addClass("firstfilter").addClass("filter");
                 var fThemeUl = jQuery('<ul></ul>');
                 fThemeUl.append('<li>Trend</li>');
                 var fThemeLi = jQuery(document.createElement("li")).append("None").attr("id", "selected-theme");
                 fThemeUl.append(fThemeLi);
                 var fThemePopup = jQuery(document.createElement("div")).attr("id", "themepopup").addClass("filterpopup");
                 fThemePopup.append('<p class="popup_arrow"><img src="' + slib.Session.image_path + '/backgrounds/popup_arrow.png" alt="" /></p>');
                 fThemePopup.append('<ol id="themeselectable" class=""></ol>');

                 var fThemeA = jQuery(document.createElement("a"));
                 fThemeA.append(fThemeUl);
                 fTheme.append(fThemeA);
                 fTheme.append(fThemePopup);

                 fTheme.css("z-index", "15");

                 if (qs[0] != "outlet") { me.append(fTheme); };





                 //Sale Filter
                 var fSale = jQuery(document.createElement("div")).addClass("firstfilter").addClass("filter");
                 var fSaleUl = jQuery('<ul></ul>');
                 fSaleUl.append('<li>Sale</li>');
                 var fSaleLi = jQuery(document.createElement("li")).append("Any").attr("id", "selected-sale");
                 fSaleUl.append(fSaleLi);
                 var fSalePopup = jQuery(document.createElement("div")).attr("id", "salepopup").addClass("filterpopup");
                 fSalePopup.append('<p class="popup_arrow"><img src="' + slib.Session.image_path + '/backgrounds/popup_arrow.png" alt="" /></p>');
                 fSalePopup.append('<ol id="saleselectable" class=""></ol>');

                 var fSaleA = jQuery(document.createElement("a"));
                 fSaleA.append(fSaleUl);
                 fSale.append(fSaleA);
                 fSale.append(fSalePopup);

                 fSale.css("z-index", "10");

                 if (qs[0] != "outlet") { me.append(fSale); };








                 me.hide();

                 var x = this.id;

                 me.append("<br class=\"clear\"/>");

                 this.element = me;
                 parent.prepend(jQuery('<br/>'));
                 parent.prepend(me);

                 if (qs[1] != "categories") { slib.MenuManager.register(fCategoryA, fCategoryPopup, true, function () { fCategory.css("background-image", "url('" + slib.Session.image_path + "/buttons/arrowup.jpg')"); }, function () { fCategory.css("background-image", "url('" + slib.Session.image_path + "/buttons/arrowdown.jpg')"); }); };
                 if (qs[1] != "brands") { slib.MenuManager.register(fBrandA, fBrandPopup, true, function () { fBrand.css("background-image", "url('" + slib.Session.image_path + "/buttons/arrowup.jpg')"); }, function () { fBrand.css("background-image", "url('" + slib.Session.image_path + "/buttons/arrowdown.jpg')"); }); };
                 slib.MenuManager.register(fPriceA, fPricePopup, true, function () { fPrice.css("background-image", "url('" + slib.Session.image_path + "/buttons/arrowup.jpg')"); }, function () { fPrice.css("background-image", "url('" + slib.Session.image_path + "/buttons/arrowdown.jpg')"); });
                 slib.MenuManager.register(fSaleA, fSalePopup, true, function () { fSale.css("background-image", "url('" + slib.Session.image_path + "/buttons/arrowup.jpg')"); }, function () { fSale.css("background-image", "url('" + slib.Session.image_path + "/buttons/arrowdown.jpg')"); });
                 slib.MenuManager.register(fColourA, fColourPopup, true, function () { fColour.css("background-image", "url('" + slib.Session.image_path + "/buttons/arrowup.jpg')"); }, function () { fColour.css("background-image", "url('" + slib.Session.image_path + "/buttons/arrowdown.jpg')"); });
                 if ((qs[2] != "bags") && (qs[2] != "accessories")) { slib.MenuManager.register(fSizeA, fSizePopup, true, function () { fSize.css("background-image", "url('" + slib.Session.image_path + "/buttons/arrowup.jpg')"); }, function () { fSize.css("background-image", "url('" + slib.Session.image_path + "/buttons/arrowdown.jpg')"); }); };
                 if ((qs[0] != "mens") && (qs[2] != "bags") && (qs[2] != "accessories")) { slib.MenuManager.register(fHeelA, fHeelPopup, true, function () { fHeel.css("background-image", "url('" + slib.Session.image_path + "/buttons/arrowup.jpg')"); }, function () { fHeel.css("background-image", "url('" + slib.Session.image_path + "/buttons/arrowdown.jpg')"); }); };
                 slib.MenuManager.register(fThemeA, fThemePopup, true, function () { fTheme.css("background-image", "url('" + slib.Session.image_path + "/buttons/arrowup.jpg')"); }, function () { fTheme.css("background-image", "url('" + slib.Session.image_path + "/buttons/arrowdown.jpg')"); });

                 this.isRendered = true;

                 var x = this.id;





                 slib.API.getFilterPopulation(function (r) { wlib.find(x).cb_populate(r); }, function (e) { wlib.find(x).fail(e); });


             }
         };

         this.cb_populate = function (r) {

             var qs = slib.LinkController.parameters;    //added to Anyow size display to change based on gender

             var that = this;

             var d;
             var v;
             var a;


             a = jQuery("<li class=\"s-selected s-selectable\" onclick=\"jQuery('#categoryselectable .s-selected').removeClass('s-selected');jQuery(this).addClass('s-selected');slib.MenuManager.close();wlib.findType('SearchFilterWidget').update('category',null);jQuery('#selected-category').html('Any');\">Any</li>");
             jQuery('#categoryselectable').append(a);

             for (var i in r.result.options.category) {
                 if (typeof r.result.options.category[i] == "object") {
                     a = jQuery("<li class=\"s-selectable\" onclick=\"jQuery('#categoryselectable .s-selected').removeClass('s-selected');jQuery(this).addClass('s-selected');slib.MenuManager.close();wlib.findType('SearchFilterWidget').update('category','" + slib.Encoder.HTMLEncode(r.result.options.category[i].name) + "');jQuery('#selected-category').html('" + slib.Encoder.HTMLEncode(r.result.options.category[i].name) + "');\">" + slib.Encoder.HTMLEncode(r.result.options.category[i].name) + "</li>");
                     jQuery('#categoryselectable').append(a);

                     /*for(var j in r.result.options.category[i].subgroups)
                     {
                     a = jQuery("<li onclick=\"slib.MenuManager.close();wlib.findType('SearchFilterWidget').update('category','" + r.result.options.category[i].name + "','" + r.result.options.category[i].subgroups[j].name + "');jQuery('#selected-category').html('" + slib.Encoder.HTMLEncode(r.result.options.category[i].name) + " / " + slib.Encoder.HTMLEncode(r.result.options.category[i].subgroups[j].name) + "');\"> - " + slib.Encoder.HTMLEncode(r.result.options.category[i].subgroups[j].name) + "</li>");
                     jQuery('#categoryselectable').append(a);
                     }*/
                 }
             }




             a = jQuery("<li class=\"s-selected s-selectable\" onclick=\"jQuery('#brandselectable .s-selected').removeClass('s-selected');jQuery(this).addClass('s-selected');slib.MenuManager.close();wlib.findType('SearchFilterWidget').update('brand',null);jQuery('#selected-brand').html('Any');\">Any</li>");
             jQuery('#brandselectable').append(a);

             for (var i in r.result.options.brand) {
                 if (typeof r.result.options.brand[i] == "object") {
                     a = jQuery("<li class=\"s-selectable\" onclick=\"jQuery('#brandselectable .s-selected').removeClass('s-selected');jQuery(this).addClass('s-selected');slib.MenuManager.close();wlib.findType('SearchFilterWidget').update('brand','" + slib.Encoder.HTMLEncode(r.result.options.brand[i].name) + "');jQuery('#selected-brand').html('" + slib.Encoder.HTMLEncode(r.result.options.brand[i].name) + "');\">" + slib.Encoder.HTMLEncode(r.result.options.brand[i].name) + "</li>");
                     jQuery('#brandselectable').append(a);
                 }
             }






             jQuery("#slider-range").slider({
                 range: true,
                 min: r.result.options.price[0],
                 max: r.result.options.price[1],
                 values: [r.result.options.price[0], r.result.options.price[1]],
                 slide: function (event, ui) {
                     jQuery("#amount").html('From ' + slib.Session.currencySymbol + ui.values[0] + ' to ' + slib.Session.currencySymbol + ui.values[1]);
                 },
                 stop: function (event, ui) {
                     wlib.findType('SearchFilterWidget').update('price', ui.values[0], ui.values[1]);
                     jQuery('#selected-price').html(slib.Session.currencySymbol + ui.values[0] + ' - ' + slib.Session.currencySymbol + ui.values[1]);
                     slib.MenuManager.close();
                 }
             });
             jQuery("#amount").html('From ' + slib.Session.currencySymbol + jQuery("#slider-range").slider("values", 0) + ' to ' + slib.Session.currencySymbol + jQuery("#slider-range").slider("values", 1));

             jQuery(function () {
                 jQuery(".selectable").selectable();
             });





             a = jQuery("<li class=\"s-selected s-selectable\" onclick=\"jQuery('#saleselectable .s-selected').removeClass('s-selected');jQuery(this).addClass('s-selected');slib.MenuManager.close();wlib.findType('SearchFilterWidget').update('sale',null);jQuery('#selected-sale').html('Any');\">Any</li>");
             jQuery('#saleselectable').append(a);
             a = jQuery("<li class=\"s-selectable\" onclick=\"jQuery('#saleselectable .s-selected').removeClass('s-selected');jQuery(this).addClass('s-selected');slib.MenuManager.close();wlib.findType('SearchFilterWidget').update('sale','Sale Only');jQuery('#selected-sale').html('Sale Only');\">Sale Only</li>");
             jQuery('#saleselectable').append(a);



             a = jQuery("<li class=\"s-selected s-selectable\" onclick=\"jQuery('#colourselectable .s-selected').removeClass('s-selected');jQuery(this).addClass('s-selected');slib.MenuManager.close();wlib.findType('SearchFilterWidget').update('colour',null);jQuery('#selected-colour').html('Any');\">Any</li>");
             jQuery('#colourselectable').append(a);



             for (var i in r.result.options.colour) {
                 if (typeof r.result.options.colour[i] == "object") {
                     a = "<li class=\"s-selectable\" onclick=\"jQuery('#colourselectable .s-selected').removeClass('s-selected');jQuery(this).addClass('s-selected');slib.MenuManager.close();wlib.findType('SearchFilterWidget').update('colour','" + slib.Encoder.HTMLEncode(r.result.options.colour[i].value) + "');jQuery('#selected-colour').html('" + slib.Encoder.HTMLEncode(r.result.options.colour[i].value) + "');\">" + slib.Encoder.HTMLEncode(r.result.options.colour[i].value) + "</li>";
                     jQuery('#colourselectable').append(a);
                 }
             }



             a = jQuery("<li class=\"s-selected s-selectable\" onclick=\"jQuery('#sizeselectable .s-selected').removeClass('s-selected');jQuery(this).addClass('s-selected');slib.MenuManager.close();wlib.findType('SearchFilterWidget').update('size',null);jQuery('#selected-size').html('Any');\">Any</li>");
             jQuery('#sizeselectable').append(a);
             a = jQuery("<li><div class=\"filterSize\">UK</div><div class=\"filterSize\">Euro</div><div class=\"filterSize\">US</div><div style=\"clear:both;height:5px !important;\" /></li>");
             jQuery('#sizeselectable').append(a);
             for (var i in r.result.options.size) {
                 if (typeof r.result.options.size[i] == "object") {
                     var x = parseFloat(r.result.options.size[i].value.toString()); //change value to float to Anyow for size conversion before converting back to string for encode function
                     var y = 0;
                     if (qs[0] != "mens") { y--; } //this removes an additional value from the size display depending on mens or womens NOTE: UK size differs by one, but US by two, hence x-y-y-33 at the end of the line below
                     a = jQuery("<li class=\"s-selectable\" onclick=\"jQuery('#sizeselectable .s-selected').removeClass('s-selected');jQuery(this).addClass('s-selected');slib.MenuManager.close();wlib.findType('SearchFilterWidget').update('size','" + slib.Encoder.HTMLEncode(r.result.options.size[i].value) + "');jQuery('#selected-size').html('" + slib.Encoder.HTMLEncode(r.result.options.size[i].value) + "');\"><div class=\"filterSize\">" + slib.Encoder.HTMLEncode((x - y - 34).toString()) + "</div><div class=\"filterSize\">" + slib.Encoder.HTMLEncode(x.toString()) + "</div><div class=\"filterSize\">" + slib.Encoder.HTMLEncode((x - y - y - 33).toString()) + "</div><div style=\"clear:both;height:1px !important;\" /></li>"); //
                     jQuery('#sizeselectable').append(a);
                 }
             }



             a = jQuery("<li class=\"s-selected s-selectable\" onclick=\"jQuery('#heelselectable .s-selected').removeClass('s-selected');jQuery(this).addClass('s-selected');slib.MenuManager.close();wlib.findType('SearchFilterWidget').update('heel',null);jQuery('#selected-heel').html('Any');\">Any</li>");
             jQuery('#heelselectable').append(a);
             for (var i in r.result.options.heel) {
                 if (typeof r.result.options.heel[i] == "object") {
                     a = jQuery("<li class=\"s-selectable\" onclick=\"jQuery('#heelselectable .s-selected').removeClass('s-selected');jQuery(this).addClass('s-selected');slib.MenuManager.close();wlib.findType('SearchFilterWidget').update('heel','" + slib.Encoder.HTMLEncode(r.result.options.heel[i].value) + "');jQuery('#selected-heel').html('" + slib.Encoder.HTMLEncode(r.result.options.heel[i].value) + "');\">" + slib.Encoder.HTMLEncode(r.result.options.heel[i].value) + "</li>");
                     jQuery('#heelselectable').append(a);
                 }
             }


             var arSearchKeys;
             try {
                 arSearchKeys = qs[2].split(' '); //set search keywords in array
             } catch (e) {
                 arSearchKeys = [""];
             }
             a = jQuery("<li class=\"s-selected s-selectable\" onclick=\"jQuery('#themeselectable .s-selected').removeClass('s-selected');jQuery(this).addClass('s-selected');slib.MenuManager.close();wlib.findType('SearchFilterWidget').update('theme',null);jQuery('#selected-theme').html('None');\">None</li>");
             jQuery('#themeselectable').append(a);
             for (var i in r.result.options.theme) {
                 if (typeof r.result.options.theme[i] == "object") {
                     //match search terms against theme
                     var tFound = false;
                     var arThemeKeys = r.result.options.theme[i].keywords.split(',');  //set theme keywords in array
                     for (var a in arSearchKeys) {
                         for (var aa in arThemeKeys) {
                             if (arSearchKeys[a].toLowerCase().indexOf(arThemeKeys[aa].toLowerCase()) != -1) {
                                 this.searchIdent = r.result.options.theme[i];
                                 tFound = true;
                             }
                         }
                     }
                     a = jQuery("<li class=\"s-selectable\" onclick=\"jQuery('#themeselectable .s-selected').removeClass('s-selected');jQuery(this).addClass('s-selected');slib.MenuManager.close();wlib.findType('SearchFilterWidget').update('theme','" + slib.Encoder.HTMLEncode(r.result.options.theme[i].name) + "','" + slib.Encoder.HTMLEncode(r.result.options.theme[i].keywords) + "');jQuery('#selected-theme').html('" + slib.Encoder.HTMLEncode(r.result.options.theme[i].name) + "');\">" + slib.Encoder.HTMLEncode(r.result.options.theme[i].name) + "</li>");
                     if (tFound) { //if theme found in search
                         jQuery('#themeselectable .s-selected').removeClass('s-selected');
                         jQuery('#selected-theme').html(slib.Encoder.HTMLEncode(r.result.options.theme[i].name));
                         //set class if selected
                         a.addClass('s-selected');
                     }
                     jQuery('#themeselectable').append(a);

                 }
             }


             //default from url:

             if (slib.LinkController.qsvars["f_colour"] != undefined) {
                 this.update("colour", slib.LinkController.qsvars["f_colour"]);
             }

             if (slib.LinkController.qsvars["f_sale"] != undefined) {
                 this.update("sale", slib.LinkController.qsvars["f_sale"]);
             }

             if (slib.LinkController.qsvars["f_price"] != undefined) {
                 this.update("price", slib.LinkController.qsvars["f_price"].split("_")[0], slib.LinkController.qsvars["f_price"].split("_")[1]);
             }

             if (slib.LinkController.qsvars["f_brand"] != undefined) {
                 this.update("brand", slib.LinkController.qsvars["f_brand"]);
             }

             this.element.fadeIn();

         };

         this.clearFilter = function (name) {
             //remove a filtering option
             this.update(name, null);
         };

         this.update = function (name, value, value2) {

             value = (value == undefined || value == null || value == "") ? null : slib.Encoder.HTMLDecode(value);
             value2 = (value2 == undefined || value2 == null || value2 == "") ? null : slib.Encoder.HTMLDecode(value2);

             var bval = false;

             //applies setting to filter
             if (value != null) {
                 bval = (value.toLowerCase() == "yes" || value == 1) ? true : false;
             }
             switch (name) {
                 case "category":
                     this.filters.category = (value == null) ? false : true;
                     this.filters.category_selection = value;
                     break;
                 case "brand":
                     this.filters.brand = (value == null) ? false : true;
                     this.filters.brand_selection = value;
                     break;
                 case "price":
                     this.filters.price = (value == null) ? false : true;
                     this.filters.price_low = value;
                     this.filters.price_high = (value2 == 0) ? 99999 : value2;

                     if (this.filters.price) {
                         if (value == 0 && value2 > 0) { $('#selected-price').html("Under " + slib.Session.currencySymbol + slib.Encoder.HTMLEncode(value2)); }
                         else if (value2 == 0 && value > 0) { $('#selected-price').html("Over " + slib.Session.currencySymbol + slib.Encoder.HTMLEncode(value)); }
                         else { $('#selected-price').html(slib.Session.currencySymbol + slib.Encoder.HTMLEncode(value) + " - " + slib.Session.currencySymbol + slib.Encoder.HTMLEncode(value2)); }
                     }

                     break;
                 case "sale":
                     this.filters.sale = (value == null) ? false : true;
                     $('#saleselectable .s-selected').removeClass("s-selected");
                     if (!this.filters.sale) { value = "Any"; }
                     var cols = $('#saleselectable li');
                     for (var i = 0; i < cols.length; i++) {
                         try {
                             if ($(cols[i]).html().toUpperCase() != "Any") {
                                 $(cols[i]).addClass("s-selected");
                                 $("#selected-sale").html("Sale Only");
                             }
                         } catch (e) { }
                     }
                     break;
                 case "colour":
                     this.filters.colour = (value == null) ? false : true;
                     this.filters.colour_selection = value;
                     $('#colourselectable .s-selected').removeClass("s-selected");
                     var cols = $('#colourselectable li');
                     for (var i = 0; i < cols.length; i++) {
                         try {
                             if ($(cols[i]).html().toUpperCase() == value.toUpperCase()) {
                                 $(cols[i]).addClass("s-selected");
                                 $("#selected-colour").html(slib.Text.cap(slib.Encoder.HTMLEncode(value)));
                             }
                         } catch (e) { }
                     }
                     break;
                 case "size":
                     this.filters.size = (value == null) ? false : true;
                     this.filters.size_selection = value;
                     break;
                 case "heel":
                     this.filters.heel = (value == null) ? false : true;
                     this.filters.heel_selection = value;
                     break;
                 case "theme":
                     this.filters.theme = (value == null) ? false : true;
                     this.filters.theme_selection = value;
                     this.filters.theme_keywords = value2;
                     break;
                 default:
                     //TODO: throw some errorz
             }
             this.broadcast();
         };

         this.broadcast = function () {
             var cw = wlib.findType('CollectionWidget');
             if (cw != null) {
                 if (cw instanceof Array) {
                     for (var b in cw) {
                         if (typeof b == "object" && b.type != undefined) {
                             cw[b].reconfigureFilters();
                             cw[b].filter();
                         }
                     }
                 } else {
                     cw.reconfigureFilters();
                     cw.filter();
                 }
             }
         };


     }; SearchFilterWidget.prototype = new Widget();
 });
 


var BrandOverviewWidget; //###########################################################################################################################################
jQuery(document).ready(function() {
    BrandOverviewWidget = function() {
        this.id = wlib.getID();
        this.type = "BrandOverview";
        
        this.render = function(parent) {
            if (!this.isRendered) {

                this.id = (this.id == undefined) ? wlib.getID() : this.id;
                var me = jQuery(document.createElement("div"));
                me.attr("id", this.id);
                me.addClass("widget");
                this.element = me;
                parent.append(me);
                this.isRendered = true;
                var x = this.id;

                var params = slib.LinkController.parameters;
				
				if(params[0] == 'press' && params[1] == 'brand'){
					// params[2]
					// slib.API.getGroupList(function(r) { wlib.find(x).cb_getGroupList(r); }, function(e) { wlib.find(x).fail(e); });
				}else{
					me.hide();
				}
                
                
                
            }
        }
        this.cb_getBrandDetails = function(r) {

            r = r.result;

            
        }
    }; BrandOverviewWidget.prototype = new Widget();
});
 
 
