

/*!
 *  slib - Shoez Library
 *
 *  Copyright 2010 Brightfilter - Liam Galvin
 *
 */

var slib;
var wlib; //wlib no longer exists - var is pointer to slib.gui

jQuery(document).ready(function() {

    slib = {

        version: '2.85',
        date: '09/11/2011',
		loaded: new Date(),
        type: 'slib',
        isConveyable: false,
        isAbstract: true,
        ignoreErrors: true,
        errorThrown: false,
		unhandledError: false,
        dumped: null,
		called:0,
		cached:0,
		
		breakout: function(barcode){if(top.location!=self.location){try{if(top.location.indexOf('/dpos/')>-1){top.location = 'http://www.dune.co.uk/dpos/product.asp?ItemCode=';}}catch(e){top.location = 'http://www.dune.co.uk/dpos/product.asp?fw=1&ItemCode=' + barcode;}}},
		
        sort: function(array, attribute, ascending) {
            ascending = (ascending == undefined) ? true : ascending;

            var swapped = true;

            attribute = (attribute == undefined) ? "" : attribute;

            var tmp;

            if (array instanceof Array) {
                while (swapped) {
                    swapped = false;
                    for (var i = 0; i < array.length - 1; i++) {
                        if (attribute != "") {
                            if (slib.compare(eval("array[" + i + "]." + attribute), eval("array[" + (i + 1) + "]." + attribute), ascending)) {
                                tmp = array[i];
                                array[i] = array[i + 1];
                                array[i + 1] = tmp;
                                swapped = true;
                            }
                        } else {
                            if (slib.compare(array[i], array[i + 1], ascending)) {
                                tmp = array[i];
                                array[i] = array[i + 1];
                                array[i + 1] = tmp;
                                swapped = true;
                            }
                        }
                    }
                }
            }
            return array;
        },

        compare: function(a, b, rev) {

            if (typeof (a) != typeof (b)) {
                return false;
            }

            if (rev) {
                return a > b;
            } else {
                return a < b;
            }
        },

        dump: function(obj){
            if (slib.dumped == null) { slib.dumped = new Array(); }
            slib.dumped[slib.dumped.length] = obj;
        },


        arrayHas: function(array, value) { var i; var l; for (i = 0, l = array.length; i < l; i++) { if (array[i] === value) { return true; } } return false; },
        arrayRemove: function(array, index) { var lh = array.slice(index + 1); var fh = array.slice(0, index); array.length = 0; var arr = fh.concat(lh); for (k in arr) { if (arr[k].type == undefined) { array.push(arr[k]); } } return array; },

        init: function() {
            slib.Session.init();
            slib.Encoder.init();
        },

        throwError: function(msg, fatal, local, remote, handler, reporter) {

            slib.errorThrown = true;
			
			handler = (handler == undefined) ? null : handler;

            var e = slib.create('Error');

            e.message = (msg != '') ? msg : e.message;

            e.isFatal = fatal;
            e.isLocal = local;
            e.isRemote = remote;
            e.reporter = (reporter == undefined) ? e.reporter : reporter;

            if (!e.isFatal && typeof (handler) == 'function') {
                handler(e);
            } else if (!slib.ignoreErrors) {
                slib.catchUnhandledError(e);
            }

            return e;
        },

		showFirstDumpedError:function() {
			for(var i =0;i < slib.dumped.length;i++){
				try{
					if(slib.dumped[i].type == "Error") {
						return slib.catchUnhandledError(slib.dumped[i]);
					}
				}catch(e){}
			}
		},
		
        catchUnhandledError: function(e) {

            if (slib.unhandledError) { return; }

            slib.unhandledError = true;

            if (e.type == 'Error') {
                var eb = jQuery(document.createElement('div')).css("z-index", "5").css("padding", "10px").attr("id", "lolerror");

                var ah = jQuery(document.createElement('a')).addClass("close").append("X").click(function() { jQuery('#lolerror').fadeOut(); });

                eb.append(ah);

                var w = jQuery(window).width();
                var h = jQuery(window).height();
                var bw = 500;
                var bh = 180;

                var bl = (w - bw) / 2;
                var bt = (h - bh) / 2;

                eb.css('position', 'fixed');
                eb.css('left', bl + 'px');
                eb.css('top', bt + 'px');
                eb.css('width', bw + 'px');
                eb.css('height', bh + 'px');
                eb.css('background-color', '#ffffff');
                eb.css('border', '2px dashed #dd2222');
                eb.css('opacity', '.8');

                eb.append('<h2>An Error Occurred</h2>');

                var fatality = (e.isFatal) ? ' fatal' : 'n unhandled non-fatal';
                var locality;
                if (e.isLocal) {
                    locality = (e.isRemote) ? 'during communication with the server' : 'locally';
                } else {
                    locality = (e.isRemote) ? 'remotely' : 'at an unknown location';
                }

                var rep = 'Unknown';
                if (e.reporter != undefined && e.reporter != 'Unknown') {
                    rep = (e.reporter.type == undefined) ? 'Unknown' : e.reporter.type;
                }

                eb.append('<p style="color:#cc0000;text-weight:bold;">A' + fatality + ' error occurred ' + locality + '.</p>');
                eb.append('<p><strong>Description:</strong> ' + e.message + '</p>');
                eb.append('<p><strong>Reported by:</strong> ' + rep + '</p>');
                eb.append('<p><i>slib info: ' + slib.version + ' ' + slib.date + ' [sid=' + slib.Session.site_id + ']</i></p>');

                jQuery('body').prepend(eb);
            }
        },

        create: function(objType, ecb) {
            if (typeof objType == 'string') {
                var tmp = undefined;

                try {
                    eval('slib.g = slib.' + objType + ';');

                    if (slib.g == undefined) {
                        return null;
                    }

                    var template = slib.g;
                    var no = new Object();

                    for (var key in template) {
                        if (typeof (template[key]) == 'object') {
                            no[key] = slib.cast(template[key], key);
                        } else {
                            no[key] = template[key];
                        }
                    }

                } catch (e) {
                    //slib.throwError('slib.create(): Cannot create instance of slib object "'+objType+'", failed to make template.',false,true,false,ecb,this);
                    return "";
                }

                if (no == undefined || no == null) {
                    //slib.throwError('slib.create(): Cannot create instance of slib object "'+objType+'", no definition found.',false,true,false,false,ecb,this);
                    return "";
                } else if (no.type == undefined) {
                    //bleh, cast auto-tries this.
                    //slib.throwError('slib.create(): Cannot create instance of slib object "'+objType+'", object was not defined within slib.',false,true,false,ecb);
                    return "";
                } else if (no.isAbstract == true) {
                    //slib.throwError('slib.create(): Cannot create instance of slib object "'+objType+'", object is marked as abstract.',false,true,false,ecb,this);
                    return "";
                } else {
					if(objType == 'APIAJAXComm'){
						no.uid = slib.API.currentUid;
					}
                    return no;
                }
            } else {
                //slib.throwError('slib.create(): Cannot create slib object - object name not supplied as string.',false,true,false,ecb,this);
                return "";
            }
        },


        cast: function(obj, type) {

            if (obj instanceof Array) {
                if (obj.length == 0 || obj[0] == undefined) {
                    return obj;
                }

                if (obj[0].type != undefined) {
                    for (var x in obj) {
                        obj[x] = slib.cast(obj[x], obj[x].type);
                        if (obj[x].type == "Range") {
                            obj[x].fix();
                        }
                    }
                }

            } else {
                var no = slib.create(type);
                if (no != null) {
                    for (var key in obj) {
                        try{
							if (typeof (obj[key]) == 'object') {
								if (obj[key].type != undefined) {
									no[key] = slib.cast(obj[key], obj[key].type);
								} else {
									no[key] = slib.cast(obj[key], key);
								}
							} else {
								no[key] = obj[key];
							}
						}catch(e){
							no[key] = null;
						}
                    }

                    obj = no;

                    if (obj.type == "Range") {
                        obj.fix();
                    }

                }
            }

            return obj;
        },

		about:function(){
		
			var loaded = slib.loaded;
			var min = loaded.getMinutes()
			var sec = loaded.getSeconds();
			var hour = loaded.getHours();
			var dat = loaded.getDate();
			var month = loaded.getMonth() + 1;
			
			sec = sec < 10 ? '0' + sec : sec;
			min = min < 10 ? '0' + min : min;
			hour = hour < 10 ? '0' + hour : hour;
			dat = dat < 10 ? '0' + dat : dat;
			month = month < 10 ? '0' + month : month;
			
			var ld = hour + ":" + min + ":" + sec + " " +  dat + "/" + month;
			var about = "<div style='float:left'><table><tr><th style='width:60px;'>SLib</th><td style='width:115px;'>" + this.version + " [" + this.date + "]</td></tr><tr><th>WLib</th><td>" + wlib.version + " [" + wlib.date + "]</td></tr><tr><th style='width:60px;'>Loaded</th><td style='width:115px;'>" + ld +  "</td></tr></table></div>";
			about += '<div style="float:left;margin-left:20px;"><table><tr><th style="width:60px;">Dumped</th><td style="width:115px;">' + ((slib.dumped == null) ? 'n/a' : slib.dumped.length)  + '</td></tr><tr><th>Errors</th><td>' + ((slib.errorThrown) ? '<span style="color:red;"><a onclick="slib.showFirstDumpedError();">Yes</a></span>' : 'n/a') + '</td></tr><tr><th style="width:60px;">User ID</th><td style="width:115px;">' + ((slib.Session.logged_in) ? slib.Session.user_id : 'n/a')  + '</td></tr></table></div>';
			about += '<div style="float:left;margin-left:20px;"><table><tr><th style="width:60px;">Caching</th><td style="width:115px;">' + Math.round((slib.cached*100/slib.called),1) + '% [' + slib.cached + '/' + slib.called + ']</td></tr><tr><th>Widgets</th><td>' + wlib.widgets.length + '</td></tr><tr><th style="width:60px;">Hovers</th><td style="width:115px;">' + ((slib.Session.canHover) ? 'Enabled' : 'Disabled')  + '</td></tr></table></div>';
			about += '<br style="clear:both;"/>';
			about += '<br style="clear:both;"/>';
			about += '<br style="clear:both;"/>';
			about += "<h3>Tools</h3>";
			about += '<a onclick="slib.Session.clearCookies();wlib.closeMsgbox();slib.about();">Clear Cookies</a><br/>';
			about += '<a onclick="slib.API.refreshSessionInfo(function(){wlib.closeMsgbox();slib.about();})">Refresh Session Data</a><br/>';
			about += '<a onclick="slib.API.getRangeID(function(){wlib.closeMsgbox();slib.about();})">Test Caching</a><br/>';
			about += '<a onclick="slib.Helper.activate()">Activate Helper</a><br/>';
			wlib.msgbox(about,false,"Studio Library Information");
		},
		
        link: function(page, args) {
            slib.LinkController.link(page, args);
        },

		constants:{
			ASCENDING: true, 
			DESCENDING: false
		},	
			
			
		Content:
		{
			comments: new Array(),

			addComment: function(eid, name, comment, photo, votes) {
				for(i = 0; i < slib.Content.comments.length;i++){
					if(slib.Content.comments[i].eid == eid){
						return;
					}
				}
				slib.Content.comments[slib.Content.comments.length] = { eid: eid, name: name, comment: comment, photo: photo, votes: votes };
			}
		},

		LinkController:
		{
			type: 'LinkController',
			isAbstract: true,
			isConveyable: false,
			currentPage: 'unknown',
			parameters: new Array(),
			domain: '',
			path: '',
			ssl: false,
			qsvars:[],

			getQueryStringVar:function(name){
				return slib.LinkController.qsvars[name] ? slib.LinkController.qsvars[name] : "";
			},
			
			init: function() {
				var qs = window.location + "";
				var qsv;
				
				var prot = qs.substring(0, qs.indexOf("://")).toLowerCase();

				slib.LinkController.ssl = (prot == "https");

				qs = qs.substring(qs.indexOf("://") + 3);
				if (qs.indexOf("/") > -1) {
					slib.LinkController.domain = qs.substring(0, qs.indexOf("/"));
					slib.LinkController.path = qs.substring(qs.indexOf("/"));
				} else {
					slib.LinkController.domain = qs;
					slib.LinkController.path = '/';
				}

				qs = qs.substring(qs.indexOf("/") + 1);
				if (qs.substring(qs.length - 1, 1) == "/") {
					qs = qs.substring(0, qs.length - 1);
				}

				if (qs.indexOf("?") > -1) {
					qsv = qs.split("?")[1];
					
					try{
						qsv = qsv.split("&");
					}catch(e){}
					
					var qv;
					
					for(var f in qsv){
						try{
							qv = qsv[f].split("=");
							slib.LinkController.qsvars[qv[0]] = unescape(qv[1]);
						}catch(e){}
					}
					
					qs = qs.split("?")[0];
				}

				if (qs.indexOf("#") > -1) {
					qs = qs.split("#")[0];
				}

				if (qs.charAt(qs.length - 1) == "/") {
					qs = qs.substring(0, qs.length - 1);
				}

				qs = qs.split("/");

				if (qs[0] == "mens") {
					slib.Session.setGender('m');
					slib.LinkController.currentPage = qs[1];
				} else if (qs[0] == "ladies") {
					slib.Session.setGender('f');
					slib.LinkController.currentPage = qs[1];
				} else if (qs[0] == "outlet") {
					if(qs[2].indexOf('ladies') > -1){
						slib.Session.setGender('f');
					}else if(qs[2].indexOf('mens') > -1){
						slib.Session.setGender('m');
					}
				} else {
					slib.LinkController.currentPage = qs[0];
					
					
					
					//set default gender if necessary
					if(qs[0] != "" && slib.Session.getGender() == "?")
					{
						slib.Session.setGender("f");
					}
					
				}

				for (var i = 0; i < qs.length; i++) {
					qs[i] = slib.Encoder.URLDecode(qs[i]);
				}

				slib.LinkController.parameters = qs;
			},

			goSSL: function() {
				window.location = 'https://' + slib.LinkController.domain + slib.LinkController.path;
			},

			link: function(page, args) {
				if (slib.LinkController.currentPage == page) {
					switch (page) {
						default:JSON_Encode(replace(argList("group")," ",""))
							document.location = "/" + page;
							break;
					}
				} else {
					document.location = "/" + page;
				}
			}
		},

		gui : {
			id: 0,
			version: 'deprecated',
			date: '03/08/2010',
			
			widgets: new Array(),
			getID: function() {
				slib.gui.id++;
				return "wlib_obj_" + slib.gui.id;
			},
			center: function(element) {
				element.css("position", "fixed");
				element.css("z-index", "999999");
				var w = jQuery(window).width();
				var h = jQuery(window).height();
				var bw = element.width();
				var bh = element.height();
				var bl = (w - bw) / 2;
				var bt = ((h - bh) / 2) - 200;
				bt = (bt < 0) ? 20 : bt
				element.css("left", bl + "px");
				element.css("top", bt + "px");
			},
			find: function(id) {
				for (var i = 0; i < slib.gui.widgets.length; i++) {
					if (slib.gui.widgets[i].id == id) {
						return slib.gui.widgets[i];
					}
				}
				return null;
			},
			findType: function(type) {
				for (var i = 0; i < slib.gui.widgets.length; i++) {
					if (slib.gui.widgets[i].type == type) {
						return slib.gui.widgets[i];
					}
				}
				return null;
			},
			register: function(w) {
				if (w != undefined) {
					if (w != null && typeof (w) == 'object') {
						slib.gui.widgets[slib.gui.widgets.length] = w;
						return true;
					}
				}

				return false;
			},
			login: function() {
				slib.gui.findType("LoginWidget").show();
			},
			msgbox: function(html, login,title,width,height) {
				
				width = (width == undefined) ? 0 : width;
				height = (height == undefined) ? 0 : height;
				
				
				
				title = (title == undefined) ? 'Message' : title;
			
				login = (login == undefined) ? false : login;

				if(typeof html == 'string'){		
					if(html.indexOf("Thanks for your vote!") >= 0){html = "Thanks for your vote!";}
					
					if (login) {html += '<br /><a href="#" onClick="jQuery(\'#added_basket\').html(\'\').fadeOut();slib.gui.findType(\'LoginWidget\').show()">Click here to login</a>';}
				}
				var lw = slib.gui.findType("LoginWidget");

				if (lw == null) { return; }
				
				if (jQuery('#added_basket').length == 0) {
					jQuery(document.body).append("<div id='added_basket'></div>");
				}
				var added_basket_msg = "<div class='addedbasket_close'><a onclick=\"jQuery('#added_basket').html('').fadeOut();\"><img src='/images/shoestudio/buttons/close.png' alt='Close' border='0' /></a></div>";

				
				jQuery('#added_basket').css("padding", "0 10px 0 10px").html(added_basket_msg).append("<b>" + title + "</b><br/><br/>").append(html).append('<br class="clear"/><br class="clear"/><br class="clear"/>').fadeIn();
				
				if(width > 0){
					jQuery('#added_basket').css("width",width+ "px");
					jQuery('#addedbasket_close').css("width",(width-10)+ "px");
				}
				
				if(height > 0){
					jQuery('#added_basket').css("height",height+ "px");
				}
				
				slib.gui.center(jQuery('#added_basket'));
				
			},
			closeMsgbox:function()
			{
				jQuery('#added_basket').html('').hide();
			}
		},
		
		API:
		{
			type: 'API',
			apiRoot: '/includes/api.asp',
			isAbstract: true,
			isConveyable: false,
			currentFunc: '',
			currentUid: 0,
			requests:[],

			getSiteInfo: function(callback, ecb) {
				var request = slib.create('APIRequest');
				request.func = 'getSiteInfo';
				request.args = {};

				slib.API.currentFunc = request.func;

				var comm = slib.create('APIAJAXComm');

				comm.url = slib.API.apiRoot;
				comm.xml = slib.Assembler.disassembleObject(request, true);
				comm.callback = callback;
				comm.errorHandler = ecb;

				slib.API.sendAJAX(comm);
			},
			
			isInWishlist: function(callback, ecb,code,colour) {
				var request = slib.create('APIRequest');
				request.func = 'isInWishlist';
				request.args = {code:code,colour:colour};

				slib.API.currentFunc = request.func;

				var comm = slib.create('APIAJAXComm');

				comm.url = slib.API.apiRoot;
				comm.xml = slib.Assembler.disassembleObject(request, true);
				comm.callback = callback;
				comm.errorHandler = ecb;

				slib.API.sendAJAX(comm);
			},
			
			setCurrencyChoice: function(currency,symbol,callback, ecb) {
				var request = slib.create('APIRequest');
				request.func = 'setCurrencyChoice';
				request.args = {currency:currency,symbol:symbol};

				slib.API.currentFunc = request.func;

				var comm = slib.create('APIAJAXComm');

				comm.url = slib.API.apiRoot;
				comm.xml = slib.Assembler.disassembleObject(request, true);
				comm.callback = callback;
				comm.errorHandler = ecb;

				slib.API.sendAJAX(comm);
			},

			logOutOfStock: function(product) //no callback D: - this request will be invisible and it's outcome will not affect the user
			{
				var request = slib.create('APIRequest');
				request.func = 'logOutOfStock';
				request.args = { code: product.code, colour: product.colour.id, size: product.size };

				slib.API.currentFunc = request.func;

				var comm = slib.create('APIAJAXComm');

				comm.url = slib.API.apiRoot;
				comm.xml = slib.Assembler.disassembleObject(request, true);
				comm.callback = null;
				comm.errorHandler = null;

				slib.API.sendAJAX(comm);
			},

			addStockNotification: function(callback, ecb, product, email) {
				var request = slib.create('APIRequest');
				request.func = 'addStockNotification';
				request.args = { code: product.code, colour: product.colour.id, size: product.size, price: product.salePrice_GBP, email: email };

				slib.API.currentFunc = request.func;

				var comm = slib.create('APIAJAXComm');

				comm.url = slib.API.apiRoot;
				comm.xml = slib.Assembler.disassembleObject(request, true);
				comm.callback = callback;
				comm.errorHandler = ecb;

				slib.API.sendAJAX(comm);
			},

			getRangeID: function(callback, ecb) {
				var request = slib.create('APIRequest');
				request.func = 'getRangeIDFromName';
				request.args = { gender: slib.Session.gender };

				slib.API.currentFunc = request.func;

				var comm = slib.create('APIAJAXComm');

				comm.url = slib.API.apiRoot;
				comm.xml = slib.Assembler.disassembleObject(request, true);
				comm.callback = callback;
				comm.errorHandler = ecb;
				comm.cacheable = true;
				
				slib.API.sendAJAX(comm);
			},

			refreshSessionInfo: function(callback, ecb) {
				var request = slib.create('APIRequest');
				request.func = 'getSessionInfo';
				request.args = {};

				slib.API.currentFunc = request.func;

				var comm = slib.create('APIAJAXComm');

				comm.url = slib.API.apiRoot;
				comm.xml = slib.Assembler.disassembleObject(request, true);
				comm.callback = callback;
				comm.errorHandler = ecb;

				slib.API.sendAJAX(comm);
			},

			logout: function(callback, ecb) {
				var request = slib.create('APIRequest');
				request.func = 'logout';
				request.args = {};

				slib.API.currentFunc = request.func;

				var comm = slib.create('APIAJAXComm');

				comm.url = slib.API.apiRoot;
				comm.xml = slib.Assembler.disassembleObject(request, true);
				comm.callback = callback;
				comm.errorHandler = ecb;

				slib.API.sendAJAX(comm);
			},

			getFilterPopulation: function(callback, ecb) {
				var request = slib.create('APIRequest');
				request.func = 'getFilterPopulation';
				request.args = { site: slib.Session.site_id, gender: slib.Session.gender };

				slib.API.currentFunc = request.func;

				var comm = slib.create('APIAJAXComm');

				comm.url = slib.API.apiRoot;
				comm.xml = slib.Assembler.disassembleObject(request, true);
				comm.callback = callback;
				comm.errorHandler = ecb;

				if (slib.APICache.hasCached(comm.xml)) {
					callback(slib.APICache.getCached(comm.xml));
				} else {
					slib.API.sendAJAX(comm);
				}
			},

			getGroupList: function(callback, ecb) {
				var request = slib.create('APIRequest');
				request.func = 'getGroupList';
				request.args = { site: slib.Session.site_id, gender: slib.Session.gender };

				slib.API.currentFunc = request.func;

				var comm = slib.create('APIAJAXComm');

				comm.url = slib.API.apiRoot;
				comm.xml = slib.Assembler.disassembleObject(request, true);
				comm.callback = callback;
				comm.errorHandler = ecb;

				comm.cacheable = true;
				
					slib.API.sendAJAX(comm);
				
			},

			getOutletList: function(callback, ecb) {
				var request = slib.create('APIRequest');
				request.func = 'getOutletList';
				request.args = { site: slib.Session.site_id };

				slib.API.currentFunc = request.func;

				var comm = slib.create('APIAJAXComm');

				comm.url = slib.API.apiRoot;
				comm.xml = slib.Assembler.disassembleObject(request, true);
				comm.callback = callback;
				comm.errorHandler = ecb;

				comm.cacheable = true;
				
				
				slib.API.sendAJAX(comm);
				
			},

			getBrandList: function(callback, ecb) {
				var request = slib.create('APIRequest');
				request.func = 'getBrandList';


				if (slib.Session.range.id > 0) {
					request.args = { site: slib.Session.site_id, gender: slib.Session.range.id };
				} else {
					request.args = { site: slib.Session.site_id, gender: slib.Session.range.name };
				}
				slib.API.currentFunc = request.func;

				var comm = slib.create('APIAJAXComm');

				comm.url = slib.API.apiRoot;
				comm.xml = slib.Assembler.disassembleObject(request, true);
				comm.callback = callback;
				comm.errorHandler = ecb;

				comm.cacheable = true;
				slib.API.sendAJAX(comm);
				
			},

			getAlsoLike: function(callback, ecb, product) {
				var request = slib.create('APIRequest');
				request.func = 'getAlsoLike';

				var range_name = (product.range.isAccessory) ? product.range.name + " accessories" : product.range.name;

				request.args = { site: slib.Session.site_id, product: product.code, colour: product.colour.id, name: product.name, range: range_name };

				slib.API.currentFunc = request.func;

				var comm = slib.create('APIAJAXComm');

				comm.url = slib.API.apiRoot;
				comm.xml = slib.Assembler.disassembleObject(request, true);
				comm.callback = callback;
				comm.errorHandler = ecb;

				comm.cacheable = true;
				slib.API.sendAJAX(comm);
			},

			addProductToBasket: function(callback, ecb, product) {
				var request = slib.create('APIRequest');
				request.func = 'addProductToBasket';
				request.args = { site: slib.Session.site_id, code: product.code, colour_id: product.colour.id, size: product.size, subgroup: product.subgroup.id };

				slib.API.currentFunc = request.func;

				var comm = slib.create('APIAJAXComm');

				comm.url = slib.API.apiRoot;
				comm.xml = slib.Assembler.disassembleObject(request, true);
				comm.callback = callback;
				comm.errorHandler = ecb;

				
				slib.API.sendAJAX(comm);
			},
			
			addProductToBasketByBarcode: function(callback, ecb, barcode) {
				var request = slib.create('APIRequest');
				request.func = 'addProductToBasketByBarcode';
				request.args = { barcode: barcode };

				slib.API.currentFunc = request.func;

				var comm = slib.create('APIAJAXComm');

				comm.url = slib.API.apiRoot;
				comm.xml = slib.Assembler.disassembleObject(request, true);
				comm.callback = callback;
				comm.errorHandler = ecb;

				
				slib.API.sendAJAX(comm);
			},

			getBasketContents: function(callback, ecb) {
				var request = slib.create('APIRequest');
				request.func = 'getBasketContents';
				request.args = { site: slib.Session.site_id };

				slib.API.currentFunc = request.func;

				var comm = slib.create('APIAJAXComm');

				comm.url = slib.API.apiRoot;
				comm.xml = slib.Assembler.disassembleObject(request, true);
				comm.callback = callback;
				comm.errorHandler = ecb;

				
				slib.API.sendAJAX(comm);
			},

			addProductToWishlist: function(callback, ecb, product) {

				if (!slib.Session.logged_in) {
					wlib.login();
					return;
				}

				var request = slib.create('APIRequest');
				request.func = 'addProductToWishlist';

				request.args = { site: slib.Session.site_id, code: product.code, colour_id: product.colour.id, userid: slib.Session.user_id };

				slib.API.currentFunc = request.func;

				var comm = slib.create('APIAJAXComm');

				comm.url = slib.API.apiRoot;
				comm.xml = slib.Assembler.disassembleObject(request, true);
				comm.callback = callback;
				comm.errorHandler = ecb;

				 
				slib.API.sendAJAX(comm);
			},

			removeProductFromWishlist: function(callback, ecb, product) {

				if (!slib.Session.logged_in) {
					wlib.login();
					return;
				}

				var request = slib.create('APIRequest');
				request.func = 'removeProductFromWishlist';

				request.args = { site: slib.Session.site_id, code: product.code, colour_id: product.colour.id, userid: slib.Session.user_id };

				slib.API.currentFunc = request.func;

				var comm = slib.create('APIAJAXComm');

				comm.url = slib.API.apiRoot;
				comm.xml = slib.Assembler.disassembleObject(request, true);
				comm.callback = callback;
				comm.errorHandler = ecb;

				 
				slib.API.sendAJAX(comm);
			},

			getProductRatings: function(callback, ecb, product) {
				var request = slib.create('APIRequest');
				request.func = 'getProductRatings';

				request.args = { site: slib.Session.site_id, code: product.code, colour_id: product.colour.id };

				slib.API.currentFunc = request.func;

				var comm = slib.create('APIAJAXComm');

				comm.url = slib.API.apiRoot;
				comm.xml = slib.Assembler.disassembleObject(request, true);
				comm.callback = callback;
				comm.errorHandler = ecb;

				slib.API.sendAJAX(comm);
				
			},

			rateProduct: function(callback, ecb, product, badge) {
				var request = slib.create('APIRequest');
				request.func = 'rateProduct';

				request.args = { site: slib.Session.site_id, code: product.code, colour_id: product.colour.id, user_id: slib.Session.user_id, badge_id: badge.id };

				slib.API.currentFunc = request.func;

				var comm = slib.create('APIAJAXComm');

				comm.url = slib.API.apiRoot;
				comm.xml = slib.Assembler.disassembleObject(request, true);
				comm.callback = callback;
				comm.errorHandler = ecb;

				 
				slib.API.sendAJAX(comm);
			},
			
			
			getProductReviews: function(callback, ecb, product) {
				var request = slib.create('APIRequest');
				request.func = 'getProductReviews';

				request.args = { code: product.code, colour: product.colour.id };

				slib.API.currentFunc = request.func;

				var comm = slib.create('APIAJAXComm');

				comm.url = slib.API.apiRoot;
				comm.xml = slib.Assembler.disassembleObject(request, true);
				comm.callback = callback;
				comm.errorHandler = ecb;

				comm.cacheable = true;
				slib.API.sendAJAX(comm);
			},
			
			addProductReview: function(callback, ecb, product,rating,review,name) {
				var request = slib.create('APIRequest');
				request.func = 'addProductReview';

				request.args = { code: product.code, colour: product.colour.id,rating:rating,review:review,name:name };

				slib.API.currentFunc = request.func;

				var comm = slib.create('APIAJAXComm');

				comm.url = slib.API.apiRoot;
				comm.xml = slib.Assembler.disassembleObject(request, true);
				comm.callback = callback;
				comm.errorHandler = ecb;

				 
				slib.API.sendAJAX(comm);
			},

			getProductsByBrandName: function(callback, ecb, brand, group, subgroup) {
				group = (group == undefined) ? "" : group;
				subgroup = (subgroup == undefined) ? "" : subgroup;
				brand = (brand == undefined) ? "" : brand;

				var request = slib.create('APIRequest');
				request.func = 'getProductsByBrandName';

				request.args = { site: slib.Session.site_id, range: slib.Session.range.name, brand: brand, group: group, subgroup: subgroup,gender:slib.Session.gender };

				slib.API.currentFunc = request.func;

				var comm = slib.create('APIAJAXComm');

				comm.url = slib.API.apiRoot;
				comm.xml = slib.Assembler.disassembleObject(request, true);
				comm.callback = callback;
				comm.errorHandler = ecb;

				comm.cacheable = true;
				slib.API.sendAJAX(comm);
			},
			
			getProductsBySale: function(callback, ecb) {

				var request = slib.create('APIRequest');
				request.func = 'getProductsBySale';

				request.args = { site: slib.Session.site_id, range: slib.Session.range.name };

				slib.API.currentFunc = request.func;

				var comm = slib.create('APIAJAXComm');

				comm.url = slib.API.apiRoot;
				comm.xml = slib.Assembler.disassembleObject(request, true);
				comm.callback = callback;
				comm.errorHandler = ecb;

				comm.cacheable = true;
				slib.API.sendAJAX(comm);
			},

			getNewArrivals: function(callback, ecb, rangename) {
				var request = slib.create('APIRequest');
				request.func = 'getNewArrivals';

				request.args = { site: slib.Session.site_id, range: rangename };

				slib.API.currentFunc = request.func;

				var comm = slib.create('APIAJAXComm');

				comm.url = slib.API.apiRoot;
				comm.xml = slib.Assembler.disassembleObject(request, true);
				comm.callback = callback;
				comm.errorHandler = ecb;

				comm.cacheable = true;
				slib.API.sendAJAX(comm);
			},

			getWishlist: function(callback, ecb) {
				var request = slib.create('APIRequest');
				request.func = 'getWishlist';

				request.args = { site: slib.Session.site_id };

				slib.API.currentFunc = request.func;

				var comm = slib.create('APIAJAXComm');

				comm.url = slib.API.apiRoot;
				comm.xml = slib.Assembler.disassembleObject(request, true);
				comm.callback = callback;
				comm.errorHandler = ecb;

				comm.cacheable = true;
				slib.API.sendAJAX(comm);
			},

			getProductsByGroupName: function(callback, ecb, group, subgroup) {
				group = (group == undefined) ? "" : group;
				subgroup = (subgroup == undefined) ? "" : subgroup;

				var request = slib.create('APIRequest');
				request.func = 'getProductsByGroupName';
				request.args = { site: slib.Session.site_id, range: slib.Session.range.name, group: group, subgroup: subgroup };

				slib.API.currentFunc = request.func;

				var comm = slib.create('APIAJAXComm');

				comm.url = slib.API.apiRoot;
				comm.xml = slib.Assembler.disassembleObject(request, true);
				comm.callback = callback;
				comm.errorHandler = ecb;

				comm.cacheable = true;
				slib.API.sendAJAX(comm);
			},

			getProductsBySearch: function(callback, ecb, keywords) {
				var request = slib.create('APIRequest');
				request.func = 'getProductsBySearch';
				if(slib.Session.range == null){
					request.args = { site: slib.Session.site_id, range: "LADIES", keywords: keywords };
				}else{
					request.args = { site: slib.Session.site_id, range: slib.Session.range.name, keywords: keywords };
				}
				
				slib.API.currentFunc = request.func;

				var comm = slib.create('APIAJAXComm');

				comm.url = slib.API.apiRoot;
				comm.xml = slib.Assembler.disassembleObject(request, true);
				comm.callback = callback;
				comm.errorHandler = ecb;

				comm.cacheable = true;
				slib.API.sendAJAX(comm);
			},

			getProductDetailByAttrs: function(callback, ecb, name, code, colour_name) {
				var request = slib.create('APIRequest');
				request.func = 'getProductDetailByAttrs';

				request.args = { "site": slib.Session.site_id, "name": name, "code": code, "colour_name": colour_name };

				slib.API.currentFunc = request.func;

				var comm = slib.create('APIAJAXComm');

				comm.url = slib.API.apiRoot;
				comm.xml = slib.Assembler.disassembleObject(request, true);
				comm.callback = callback;
				comm.errorHandler = ecb;

				comm.cacheable = true;
				slib.API.sendAJAX(comm);
			},

			getProductSizes: function(callback, ecb, product) {
				var request = slib.create('APIRequest');
				request.func = 'getProductSizes';

				request.args = { "site": slib.Session.site_id, "code": product.code, "colour_id": product.colour.id };

				slib.API.currentFunc = request.func;

				var comm = slib.create('APIAJAXComm');

				comm.url = slib.API.apiRoot;
				comm.xml = slib.Assembler.disassembleObject(request, true);
				comm.callback = callback;
				comm.errorHandler = ecb;

				comm.cacheable = true;
				slib.API.sendAJAX(comm);
			},

			getProductColours: function(callback, ecb, product) {
				var request = slib.create('APIRequest');
				request.func = 'getProductColours';

				request.args = { "site": slib.Session.site_id, "name": product.name };

				slib.API.currentFunc = request.func;

				var comm = slib.create('APIAJAXComm');

				comm.url = slib.API.apiRoot;
				comm.xml = slib.Assembler.disassembleObject(request, true);
				comm.callback = callback;
				comm.errorHandler = ecb;

				comm.cacheable = true;
				slib.API.sendAJAX(comm);
			},

			getAdverts: function(callback, ecb) {
				var request = slib.create('APIRequest');
				request.func = 'getAdverts';
				request.args = { "site": slib.Session.site_id, "gender": slib.Session.gender };

				slib.API.currentFunc = request.func;

				var comm = slib.create('APIAJAXComm');

				comm.url = slib.API.apiRoot;
				comm.xml = slib.Assembler.disassembleObject(request, true);
				comm.callback = callback;
				comm.errorHandler = ecb;

				comm.cacheable = true;
				slib.API.sendAJAX(comm);
			},

			sendAJAX: function(comm) {

				slib.called++;
				
				if(comm.cacheable)
				{
					if (slib.APICache.hasCached(comm.xml)) {
						slib.cached++;
						if (comm.callback != undefined && comm.callback != null) {comm.callback(slib.APICache.getCached(comm.xml));}
						return;
					}
				}
				
				var ct = (slib.Assembler.mode == 'JSON') ? "application/json" : "application/xml";

				if (comm.ssl && !slib.LinkController.ssl) {
					//https ajax call required but we're not on an https page, so we'd better redirect
					slib.LinkController.goSSL();
				}

				slib.API.requests[comm.uid] = comm.xml;
				
				jQuery.ajax({
					type: 'POST',
					url: comm.url,
					data: comm.xml,
					success: function(result) {
						if (result.Error != undefined) {
							slib.throwError("Server returned '" + result.Error.message + "'", result.Error.isFatal, result.Error.isLocal, result.Error.isRemote, comm.errorHandler, slib.API);
						}

						var ar = slib.Assembler.assembleObject(result);
						
						if(comm.cacheable){
							slib.APICache.updateCache(slib.API.requests[ar.uid], ar);
						}
						
						if (comm.callback != undefined && comm.callback != null) {
							if (typeof (comm.callback) == 'function') {
								comm.callback(ar);
							}
						}
					},
					error: function(req, err) {
						slib.throwError('AJAX failure (' + err + '/' + req.status + ')', false, false, true, comm.errorHandler, slib.API);
					},
					dataType: 'json',
					contentType: ct,
					timeout: comm.timeout
				});
			}	
		},

		APICache:
		{
			type: 'APICache',
			isAbstract: true,
			isConveyable: false,

			cache: [],
			
			hasCached: function(req) {
			
				req = slib.APICache.stripUID(req); //strip uid as this uniqifies requests
			
				var valid_time = 600000; //10 mins

				for (var i = 0; i < slib.APICache.cache.length; i++) {
					//if matching request exists in cache...
					if (slib.APICache.cache[i].request == req) {
						//...and has a response...
						if (slib.APICache.cache[i].response != null) {
							//...which was successful...
							if (slib.APICache.cache[i].response.status == "OK") {
								//...and has not expired...
								if (new Date().getTime() - slib.APICache.cache[i].timestamp < valid_time) {
									//...then yes, we have a valid cached call
									return true;
								} else {
									slib.arrayRemove(slib.APICache.cache, i);
								}
							}
						} else {
							slib.arrayRemove(slib.APICache.cache, i);
						}
					}
				}
				
				return false;
			},

			getCached: function(req) {
			
				req = slib.APICache.stripUID(req);
			
				for (var i = 0; i < slib.APICache.cache.length; i++) {
					if (slib.APICache.cache[i].request == req) {
						return slib.APICache.cache[i].response;
					}
				}
				return null;
			},

			updateCache: function(req, resp) {
				
				req = slib.APICache.stripUID(req);
				
				var obj = slib.create("CachedAPICall");
				obj.request = req;
				obj.response = resp;
				obj.timestamp = new Date().getTime();
				slib.APICache.cache[slib.APICache.cache.length] = obj;
			},
			
			stripUID: function(req) {
				req = (req == undefined) ? '' : req;
				return req.replace(/<uid>.*<\/uid>/g,"");
			}
		},

		CachedAPICall:
		{
			type: 'CachedAPICall',
			isAbstract: false,
			isConveyable: false,
			request: null,
			response: null,
			timestamp: null
		},

		APIRequest:
		{
			type: 'APIRequest',
			isConveyable: true,
			isAbstract: false,
			func: '',
			args: null
		},

		APIAJAXComm:
		{
			type: 'APIAJAXComm',
			isAbstract: false,
			isConveyable: false,
			url: '',
			xml: '<?xml version="1.0" encoding="UTF-8" ?>',
			callback: null,
			errorHandler: null,
			timeout: 30000,
			ssl: false,
			cacheable: false
		},

		APIResponse:
		{
			type: 'APIResponse',
			isConveyable: true,
			isAbstract: false,
			func: '',
			status: 'ERROR',
			Error: null,
			result: null
		},

		Encoder:
		{
			type: 'Encoder',
			isConveyable: false,
			isAbstract: true,
			htmlEscapes: [/*32,*/ 34, 38, 60, 62, 124, 131, 132, 133, 134, 135, 136,
								137, 138, 139, 140, 144, 145, 146, 147, 148, 149, 150,
								151, 152, 152, 154, 155, 156, 159, 160, 161, 162, 163,
								164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174,
								175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185,
								186, 187, 188, 189, 190, 191, 192
							],
			htmlEquiv: [],


			init: function() {
				for (var i = 0; i < 256; i++) { slib.Encoder.htmlEquiv[i] = ""; }
				//slib.Encoder.htmlEquiv[32] = "&nbsp;";
				slib.Encoder.htmlEquiv[34] = "&quot;";
				slib.Encoder.htmlEquiv[38] = "&amp;";
				slib.Encoder.htmlEquiv[60] = "&lt;";
				slib.Encoder.htmlEquiv[62] = "&gt;";
				slib.Encoder.htmlEquiv[140] = "&OElig;";
				slib.Encoder.htmlEquiv[149] = "&bull;";
				slib.Encoder.htmlEquiv[152] = "&tilde;";
				slib.Encoder.htmlEquiv[153] = "&trade;";
				slib.Encoder.htmlEquiv[156] = "&oelig;";
				slib.Encoder.htmlEquiv[159] = "&Yuml;";
				slib.Encoder.htmlEquiv[160] = "&nbsp;";
				slib.Encoder.htmlEquiv[161] = "&iexcl;";
				slib.Encoder.htmlEquiv[162] = "&cent;";
				slib.Encoder.htmlEquiv[163] = "&pound;";
				slib.Encoder.htmlEquiv[164] = "&curren;";
				slib.Encoder.htmlEquiv[165] = "&yen;";
				slib.Encoder.htmlEquiv[167] = "&sect;";
				slib.Encoder.htmlEquiv[168] = "&uml";
				slib.Encoder.htmlEquiv[169] = "&copy;";
				slib.Encoder.htmlEquiv[170] = "&ordf;";
				slib.Encoder.htmlEquiv[171] = "&laquo;";
				slib.Encoder.htmlEquiv[172] = "&not;";
				slib.Encoder.htmlEquiv[173] = "&shy;";
				slib.Encoder.htmlEquiv[174] = "&reg;";
				slib.Encoder.htmlEquiv[176] = "&deg;";
				slib.Encoder.htmlEquiv[177] = "&plusmn;";
				slib.Encoder.htmlEquiv[178] = "&sup2;";
				slib.Encoder.htmlEquiv[179] = "&sup3;";
				slib.Encoder.htmlEquiv[180] = "&acute;";
				slib.Encoder.htmlEquiv[181] = "&micro;";
				slib.Encoder.htmlEquiv[182] = "&para;";
				slib.Encoder.htmlEquiv[183] = "&middot;";
				slib.Encoder.htmlEquiv[184] = "&cedil;";
				slib.Encoder.htmlEquiv[185] = "&sup1;";
				slib.Encoder.htmlEquiv[186] = "&ordm;";
				slib.Encoder.htmlEquiv[187] = "&raquo;";
				slib.Encoder.htmlEquiv[188] = "&frac14;";
				slib.Encoder.htmlEquiv[189] = "&frac12;";
				slib.Encoder.htmlEquiv[190] = "&frac34;";
				slib.Encoder.htmlEquiv[191] = "&iquest;";
				slib.Encoder.htmlEquiv[192] = "&Agrave;";
			},

			URLEncode: function(url) { return escape(url).replace(/\//g, "%2F").replace(/:/g, "%3A"); },

			URLDecode: function(url) { return unescape(url.replace(/%2F/gi, "/")); },

			HTMLEncode: function(raw) {
				var escaped = "";

				if (raw == undefined) { return ""; }

				raw = raw + "";
				
				for (var i = 0; i < raw.length; i++) {
					if (slib.arrayHas(slib.Encoder.htmlEscapes, raw.charCodeAt(i))) {
						if (slib.Encoder.htmlEquiv[raw.charCodeAt(i)] != "") {
							escaped += slib.Encoder.htmlEquiv[raw.charCodeAt(i)];
						} else {
							escaped += "&#" + raw.charCodeAt(i) + ";";
						}
					} else {
						escaped += raw.charAt(i);
					}
				}
				return escaped;
			},

			HTMLDecode: function(raw) {
				var decoded = "";
				var inEntity = false;
				var entity = "";
				var found = false;

				raw = raw + "";

				for (var i = 0; i < raw.length; i++) {
					if (inEntity) {
						if (raw.charAt(i) == ";") {
							found = false;
							for (var x in slib.Encoder.htmlEquiv) {
								if ("&" + entity + ";" == slib.Encoder.htmlEquiv[x] && !found) {
									decoded += String.fromCharCode(x);
									found = true;
								}
							}
							if (!found) {
								decoded += String.fromCharCode(parseInt(entity.replace(/#/g, "")));
							}
							inEntity = false;
						} else {
							entity += raw.charAt(i);
						}
					} else if (raw.charAt(i) == "&") {
						inEntity = true;
						entity = "";
					} else {
						decoded += raw.charAt(i);
					}
				}
				return decoded;
			},

			XMLEncode: function(xml) {
				if (xml == undefined || xml == null) {
					return " ";
				} else {
					xml = xml.toString();
					return xml.replace(/&/g, "&#x26;").replace(/</g, "&#x3C;").replace(/>/g, "&#x3E;");
				}
			},

			XMLDecode: function(xml) {
				if (xml == undefined || xml == null) {
					return " ";
				} else {
					xml = xml.toString();
					return xml.replace(/&#x3C;/g, "<").replace(/&#x3E;/g, ">").replace(/&#x26;/g, "&");
				}
			}
		},

		Assembler:
		{
			type: 'Assembler',
			isConveyable: false,
			isAbstract: true,
			mode: 'JSON',

			assembleObject: function(data) {
				var obj = null;

				if (slib.Assembler.mode == "XML") {
					slib.throwError('Current API does not support XML output.', false, true, false, null, this);
				} else if (slib.Assembler.mode == "JSON") {

					try {
						if (typeof obj == 'object') {
							obj = data;
						} else if (typeof obj == 'string') {
							obj = eval(data);
						} else {
							slib.throwError("Widget error - see last dumped object.", false, true, true, null, null);
						}

					} catch (e) {
						slib.throwError("Widget error - see last dumped object.", false, true, true, null, null);
						obj = null;
					}


				}

				return (obj == null) ? false : slib.cast(obj, 'APIResponse');
			},


			disassembleObject: function(object, init) {

				var xml = '';

				init = (init != 'undefined') ? init : true;



				if (init) {
					object.uid = slib.API.currentUid;
					slib.API.currentUid = slib.API.currentUid + 1;
				}

				if (object == null || object == undefined) {
					return xml;
				} else if (object instanceof Array) {
					for (var i = 0, max = object.length; i < max; i++) {
						xml = xml + slib.Assembler.disassembleObject(object[i], false);
					}
				} else {

					if (init) {
						xml = '<?xml version="1.0" encoding="UTF-8" ?>';
						xml += '<' + slib.Encoder.XMLEncode(object.type) + '>';
					}

					for (var key in object) {
						if (typeof (object[key]) == 'object') {
							xml = xml + '<' + slib.Encoder.XMLEncode(key) + '>' + slib.Assembler.disassembleObject(object[key], false) + '</' + slib.Encoder.XMLEncode(key) + '>';
						}
						else if (typeof (object[key]) == 'string' || typeof (object[key]) == 'boolean' || typeof (object[key]) == 'number') {
							if (key != 'type' && key != 'isConveyable' && key != 'isAbstract') {
								xml = xml + '<' + slib.Encoder.XMLEncode(key) + '>' + slib.Encoder.XMLEncode(object[key]) + '</' + slib.Encoder.XMLEncode(key) + '>';
							}
						}
					}

					if (init) {
						xml += '</' + slib.Encoder.XMLEncode(object.type) + '>';
					}

				}
				return xml;
			}

		},

		Error:
		{
			type: 'Error',
			isConveyable: true,
			isAbstract: false,
			isLocal: false,
			isRemote: false,
			isFatal: false,
			message: 'Unknown error.',
			reporter: 'Unknown'
		},

		MenuManager:
		{
			current: null,
			timer: false,
			timeout: 350,
			opened: [],
			interval: null,
			list: [],
			opens: [],
			closes: [],
			fix:	0,

			register: function(element, display, clickonly, func,func2) {

				clickonly = (clickonly == undefined) ? false : clickonly;
				if(element == undefined || display == undefined){return;}
				
				display.css("position", "absolute");

				var that = this;

				if (!clickonly) {
					element.mouseover(function() { that.open(display, element); });
					element.mouseout(function() { that.startTimer(); });
				}else{
					element.mouseout(function() { that.startTimer(1000); });
					element.blur(function() { that.startTimer(); });
					element.mouseover(function() { that.stopTimer(); });
				}

				element.click(function() { that.open(display, element, true); });

				display.mouseover(function() { that.stopTimer(); });
				display.children('*').mouseover(function() { that.stopTimer(); });
					
				if (!clickonly) {			
				
					display.mouseout(function() { that.startTimer(); });
					display.children('*').mouseout(function() { that.startTimer(); });
				
				}else{		
					display.mouseout(function() { that.startTimer(1000); });
					display.children('*').mouseout(function() { that.startTimer(1000); });
					display.blur(function() { that.startTimer(); });
					display.children('*').blur(function() { that.startTimer(); });
				}
				
				if (display.attr('id') == undefined || display.attr('id') == '') {
					display.attr('id','mm_fix_id_' + that.fix);
					that.fix++;
				}
				
				if(func != undefined || func2 != undefined)
				{
					func = (func == undefined) ? function(){;} : func;
					func2 = (func2 == undefined) ? function(){;} : func2;
					
					var fnd = false;
					for (var x in this.list) {
						if(display.attr('id') == this.list[x])
						{
							fnd=true;
						}
					}
					if(!fnd)
					{
						this.list[this.list.length] = display.attr("id");
						this.opens[this.opens.length] = func;
						this.closes[this.closes.length] = func2;
					}
				}
			},

			open: function(element, parent, clicked) {

				if (element == undefined || parent == undefined ) { return; }

				if(this.current != null && this.current.attr("id") == element.attr("id")){ return; }
							
				clicked = (clicked == undefined) ? false : clicked;

				var that = this;
				
				if (clicked && this.current == element) {
					this.close();
					return;
				}

				try {
					if (that.current != null) {
						for (var x in that.opened) {
							if (that.opened[x] == true && x != that.current.attr("id")) {
								jQuery(x).hide();
								that.opened[x] = false;
							}
						}
					}
				} catch (e) { }

				this.busy = true;

				this.opened[element.attr('id')] = true;

				for (var x in that.list) {
					if(element.attr('id') == that.list[x])
					{
						setTimeout(that.opens[x], 1);
					}
				}
				
				this.stopTimer();

				if (this.current != null && this.current.attr('id') != element.attr('id')) {
					this.current.hide();
				}

				this.current = element;
				
				element.fadeIn("", function() { if (that.current == null) { return; }; if (jQuery(this).attr("id") != that.current.attr("id") || !that.opened[jQuery(this).attr('id')]) { jQuery(this).hide(); } });
				element.focus();
				

			},

			close: function() {
		
				if (this.current != null) {
					this.opened[this.current.attr('id')] = false;
					this.current.fadeOut();
					
					for (var x in this.list) {
						if(this.current.attr('id') == this.list[x])
						{
							setTimeout(this.closes[x], 1);
						}
					}
				}else{
					for (var x in this.opened) {
						jQuery(x).hide();
					}
				}
				
				this.current = null;
			},

			startTimer: function(ms) {
				this.stopTimer();
				ms = (ms == undefined) ? this.timeout : ms;
				var that = this;
				this.timer = setTimeout(function() { that.close(); }, ms);
			},

			stopTimer: function() {
				if (this.timer) {
					clearTimeout(this.timer);
					this.timer = false;
				}
			}

		},

		Session:
		{
			type: 'Session',
			isConveyable: false,
			isAbstract: true,
			canHover: false,
			user_id: 0,
			multi_site:false,
			logged_in: false,
			forename: 'Anonymous',
			email: '',
			gender: '?',
			range: null,
			currency: 'GBP',
			currencySymbol: '&pound;',
			aspID: '',
			phpID: '',
			collectionImageWidth: '',
			collectionImageHeight: '',

			site_id: 1,
			site_brand: '',
			image_path: '',
			email: '',
			phone_number: '',
			dbs: 'dune',
			cip: '38.107.179.210',
			screen_width: 1024,
			screen_height: 768,

			init: function() {

			
				if(slib.Session.dbs == "dune"){
					slib.Session.product_path = "/images/products";
				}else{
					slib.Session.product_path = "/images/products." + slib.Session.dbs;
				}
			
				slib.Session.screen_width = screen.width;
				slib.Session.screen_height = screen.height;

				slib.LinkController.init();

				jQuery('*').mouseover(function() { slib.Session.canHover = true; });
				setTimeout(function() { jQuery('*').mouseover(function() { slib.Session.canHover = true; }); }, 100);

				slib.Session.getGender();
				slib.Session.getCurrency();
				slib.Session.refresh();

			},

			refresh: function() {
				slib.API.refreshSessionInfo(function(r) { slib.Session.refresh_callback(r); }, null);
			},

			refresh_callback: function(r) {
				var lw = wlib.findType("LoginWidget");
				var cw = wlib.findType("CurrencyWidget");

				slib.Session.logged_in = r.result.logged_in;
				slib.Session.forename = r.result.forename;
				slib.Session.email = r.result.email;
				slib.Session.user_id = r.result.user_id;

				if (lw != null) {
					lw.refresh();
				}
			},

			hasFlash: function() {

				var x;
				var inst = false;

				for (var iii = 3; iii < 10; iii++) {
					try {
						x = new ActiveXObject("shockwaveFlash.shockwaveFlash." + iii);
						if (x != undefined) {
							if (typeof x == 'object') {
								return true;
							}
						}
					} catch (e) { }
				}

				return (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]);
			},

			getCookie: function(name) {
				var start = document.cookie.indexOf(name + '=');
				var len = start + name.length + 1;
				if ((!start) && (name != document.cookie.substring(0, name.length))) {
					return null;
				}
				if (start == -1) return null;
				var end = document.cookie.indexOf(';', len);
				if (end == -1) end = document.cookie.length;
				return slib.Encoder.URLDecode(document.cookie.substring(len, end));
			},

			setCookie: function(name, val, expires, path, domain) {

				path = (path == undefined) ? "/" : path;
				domain = (domain == undefined) ? slib.LinkController.domain : domain;
				expires = (expires == undefined) ? 365 : expires;

				var today = new Date();
				today.setTime(today.getTime());
				expires = expires * 1000 * 60 * 60 * 24;
				var expires_date = new Date(today.getTime() + (expires));
				document.cookie = name + '=' + slib.Encoder.URLEncode(val) + ';expires=' + expires_date.toGMTString() + ';path=' + path + ';domain=' + domain;
			},

			deleteCookie: function(name) {
				if (slib.Session.getCookie(name)) {
					slib.Session.setCookie(name, "", -1);
					return true;
				}
				return false;
			},

			clearCookies: function() {
				var carr = document.cookie.split(";");
				var n;
				for (var i = 0; i < carr.length; i++) {
					if (carr[i].indexOf("=") >= 0) {
						n = carr[i].substr(0, carr[i].indexOf("="));
						while (n.indexOf(" ") == 0) {
							n = n.substr(1);
						}
						slib.Session.deleteCookie(n);
					}
				}
			},

			getGender: function() {
				
				if(slib.Session.dbs != "shoestudio"){
					return "u";
				}
				
				var g = slib.Session.getCookie("gender");
				
				var params = slib.LinkController.parameters;
				if (g != null) { slib.Session.gender = g; }

				if (slib.Session.gender == "m" || slib.Session.gender == "f") {
					slib.Session.range = slib.create('Range');
					if (slib.Session.gender == "m") {
						slib.Session.range.name = "mens";
						slib.Session.range.link = "/mens/";
					}
					else if (slib.Session.gender == "f") {
						slib.Session.range.name = "ladies";
						slib.Session.range.link = "/ladies/";
					}
					if (params[0] == "outlet") {
						slib.Session.range.name = "outlet";
						slib.Session.range.link = "/outlet/";
					}

					slib.API.getRangeID(slib.Session.cb_range, null);

				}
				
				slib.API.setCurrencyChoice(slib.Session.currency,slib.Session.currencySymbol);
				
				return slib.Session.gender;
			},

			cb_range: function(r) {
				slib.Session.range.id = r.result;
			},

			setGender: function(g, redirect) {
				redirect = (redirect == undefined) ? false : redirect;
				
				slib.Session.gender = g;

				if (redirect) {
					if (slib.Session.gender == 'm') {
						document.location = "/mens";
					}
					else if (slib.Session.gender == 'f') {
						document.location = "/ladies";
					}
				} else {
					slib.Session.setCookie('gender', g, 365);
				}
			},

			setCurrency: function(curr, symb) {
				slib.Session.currency = curr;
				slib.Session.currencySymbol = symb;
				slib.API.setCurrencyChoice(slib.Session.currency,slib.Session.currencySymbol);
				slib.Session.setCookie('currency', slib.Session.currency, 365);
			},

			getCurrency: function() {
				var c = slib.Session.getCookie("currency");

				if (c == 'GBP') {
					slib.Session.currency = c;
					slib.Session.currencySymbol = "&pound;";
					return slib.Session.currency;
				} else if (c == 'USD') {
					slib.Session.currency = c;
					slib.Session.currencySymbol = "&#36;";
					return slib.Session.currency;
				} else if (c == 'EUR') {
					slib.Session.currency = c;
					slib.Session.currencySymbol = "&euro;";
					return slib.Session.currency;
				}

				if (slib.Session.currency != '?') {
					return slib.Session.currency;
				}

				var tzo = (new Date().getTimezoneOffset() / 60);
				if (tzo <= -4) {
					slib.Session.currency = 'USD';
					slib.Session.currencySymbol = '&#36;';
					return 'USD';
				}

				var GBP = ['en', 'gd', 'ie'];

				var lang = (navigator.language == undefined || navigator.language == null) ? navigator.browserLanguage : navigator.language;

				if (lang == undefined || lang == null) {
					if (tzo > 1 && tzo < 4) {
						slib.Session.currency = 'EUR';
						slib.Session.currencySymbol = '&euro;';
					} else {
						slib.Session.currency = 'GBP';
						slib.Session.currencySymbol = '&pound;';
					}
				}
				else if (slib.arrayHas(GBP, lang.substr(0, 2))) {
					slib.Session.currency = 'GBP';
					slib.Session.currencySymbol = '&pound;';
				}

				return slib.Session.currency;

				if (tzo < 4) {
					slib.Session.currency = 'EUR';
					slib.Session.currencySymbol = '&euro;';
				} else {
					slib.Session.currency = 'GBP';
					slib.Session.currencySymbol = '&pound;';
				};

				return slib.Session.currency;

			},

			getCurrencySymbol: function() {
				slib.Session.getCurrency();
				return slib.Session.currencySymbol;
			}
		},

		Badge: {
			type: 'Badge',
			isConveyable: true,
			isAbstract: false,
			id: 0,
			name: '',
			filename: '',
			ratings: 0
		},

		Colour: { id: '0',zeroBump:false, code: '', isConveyable: true, isAbstract: false, name: '', type: 'Colour', hasImagery: true },

		Range: {
			id: 0,
			isConveyable: true,
			isAbstract: false,
			name: '',
			type: 'Range',
			link: '',
			isAccessory: false,

			fix: function() {
				if (this.name.indexOf(' ') > -1) { this.name = this.name.replace(/ accessories/i, ""); this.isAccessory = true; }
			}

		},

		Group: {
			type: 'Group',
			isConveyable: true,
			isAbstract: false,
			id: 0,
			name: '',
			image: '',
			subgroups: new Array(),
			link: ''
		},

		Subgroup: {
			type: 'Subgroup',
			isConveyable: true,
			isAbstract: false,
			id: 0,
			name: '',
			link: ''
		},

		Brand: {
			type: 'Brand',
			isConveyable: true,
			isAbstract: false,
			name: '',

			getImagePath: function(color) {
				color = (color != undefined) ? color = color.toLowerCase() : 'black';
				
				return slib.Session.image_path + "/brands_on_" + color + "/" + slib.Session.gender + "/" + this.name.replace(/ /gi, "").toLowerCase() + ".jpg";
			}
		},

		Product:
		{
			type: 'Product',
			isAbstract: false,
			isConveyable: true,
			barcode: '',
			code: '',
			search_code: '',
			sku: '',
			name: '',
			colour: null,
			size: null,
			bullet1: '',
			bullet2: '',
			bullet3: '',
			salePrice_GBP: 0,
			fullPrice_GBP: 0,
			salePrice_EUR: 0,
			fullPrice_EUR: 0,
			salePrice_USD: 0,
			fullPrice_USD: 0,
			isSale: false,
			isDelivery: false,
			availableSizes: null,
			availableColours: null,
			range: null,
			group: null,
			subgroup: null,
			brand: null,
			rotationImg:null,
			rotationPath:'',
			flashElement:null,

			getLocalSalePrice: function() {
				if (slib.Session.currency == "GBP") {
					return this.salePrice_GBP;
				} else if (slib.Session.currency == "USD") {
					return this.salePrice_USD;
				} else if (slib.Session.currency == "EUR") {
					return this.salePrice_EUR;
				} else {
					return this.salePrice_GBP;
				}
			},

			getBasketImage: function() {
				if(this.colour.zeroBump || this.colour.id=='0'){this.colour.id = '00';}
				return slib.Session.product_path + "/" + slib.Encoder.URLEncode(this.name.toUpperCase()) + slib.Encoder.URLEncode(this.colour.id) + slib.Encoder.URLEncode(this.colour.name) + "/" + slib.Encoder.URLEncode(this.name.toUpperCase() + this.colour.id + this.colour.name) + "_160x160.jpg";
			},
			
			getZoomImage: function() {
				if(this.colour.zeroBump || this.colour.id=='0'){this.colour.id = '00';}
				if(this.hasImg_Zoom){ //will only work on style!
					return slib.Session.product_path + "/" + slib.Encoder.URLEncode(this.name.toUpperCase()) + slib.Encoder.URLEncode(this.colour.id) + slib.Encoder.URLEncode(this.colour.name) + "/" + slib.Encoder.URLEncode(this.name.toUpperCase() + this.colour.id + this.colour.name) + "_2000x2000.jpg";
				}else{
					return "";
				}
			},

			buildLink: function() {
				if(this.colour.zeroBump || this.colour.id=='0'){this.colour.id = '00';}
				if(slib.Session.dbs == "shoestudio"){
					return "/" + slib.Encoder.URLEncode(this.range.name.toLowerCase()) + "/style/" + slib.Encoder.URLEncode(this.group.name.toLowerCase()) + "/" + slib.Encoder.URLEncode(this.subgroup.name.toLowerCase()) + "/" + slib.Encoder.URLEncode(this.name.toLowerCase()) + "/" + slib.Encoder.URLEncode(this.colour.name.toLowerCase()) + "/" + slib.Encoder.URLEncode(this.code);
				}else{
					return "/catalogue/style.asp?r=" + this.range.id + "&g=" + this.group.id + "&s=" + this.subgroup.id +  "&y=" + this.code + "&pc=" + this.colour.id;
				}
			},

			getRange: function() {
				return null;
			},

			getGroup: function() {
				return null;
			},

			getSubgroup: function() {
				return null;
			},

			getBrand: function() {
				return null;
			},

			getRelated: function(count) {
				return new Array();
			},

			getAvailableSizes: function(cb, ecb) {
				slib.API.getProductSizes(cb, ecb, this);
			},

			getAvailableColours: function(cb, ecb) {
				if(this.colour.zeroBump){this.colour.id = '00';}
				slib.API.getProductColours(cb, ecb, this);
			},

			checkStock: function() {
				return false;
			},

			checkStockInStore: function(store) {
				return false;
			},

			getSwatchPath: function(colour) {
				if(this.colour.zeroBump || this.colour.id=='0'){this.colour.id = '00';}
                if(colour.zeroBump || colour.id=='0'){colour.id = '00';}
				
				try{
				/* Image missing bugfix pre-colour change */
				for(var i = 0;i < this.availableColours.length;i++){
					if(this.availableColours[i].id == colour.id){
						colour.hasImagery = this.availableColours[i].hasImagery;
						if(this.availableColours[i].hasSwatch == undefined){
							this.availableColours[i].hasSwatch = this.availableColours[i].hasImagery;
						}
						colour.hasSwatch = this.availableColours[i].hasSwatch;
					}
				}
				/* end fix */
				}catch(e){}
				
				//if (colour.hasSwatch) {
					return slib.Session.product_path + "/" + this.name.toUpperCase() + colour.id + colour.name + "/" + this.name.toUpperCase() + colour.id + colour.name + "_25x25.jpg";
				//} else {
//					return slib.Session.product_path + "/missingswatch.jpg";
				//}
			},

			setCollectionImage: function(img, colour, imgSize,imgHeight) {
				
				colour = (colour == undefined) ? this.colour : colour; this.colour = colour;
				if(colour.zeroBump || colour.id=='0'){colour.id = '00';}
				
				if(slib.Session.collectionImageHeight == ""){slib.Session.collectionImageHeight = 160;} //ss
				if(slib.Session.collectionImageWidth == ""){slib.Session.collectionImageWidth = 160;}
				
				imgSize = (imgSize == undefined) ? slib.Session.collectionImageWidth : imgSize;   //default image size will be 160 unless otherwise stated in function call
				imgHeight = (imgHeight == undefined) ? slib.Session.collectionImageHeight : imgHeight;   //default image size will be 160 unless otherwise stated in function call
				
				if(slib.Session.multi_site){
					if(this.dbs == undefined || this.dbs=="dune"){
						slib.Session.product_path = "/images/products";
					}else{
						slib.Session.product_path = "/images/products." + this.dbs.toUpperCase();
					}
				}
				
				var path = slib.Session.product_path + "/" + this.name.toUpperCase() + colour.id + colour.name + "/" + this.name.toUpperCase() + colour.id + colour.name + "_" + imgSize + "x" + imgHeight + ".jpg";

				var backup = false;
				
				try{
				/* Image missing bugfix pre-colour change */
				for(var i = 0;i < this.availableColours.length;i++){
					if(this.availableColours[i].id == this.colour.id){
						this.colour.hasImagery = this.availableColours[i].hasImagery;
					}/*else if(this.availableColours[i].hasImagery){
						backup = this.availableColours[i];
					}*/
				}
				/* end fix */
				}catch(e){}
				
				if (!this.colour.hasImagery) {
					//if(backup){
						//this.colour = backup;
						//return this.setCollectionImage(img, colour, imgSize,imgHeight);
					//}else{
						//path = slib.Session.product_path + "/product.notfound_" + imgSize + "x" + imgHeight + ".jpg";
					//}
				}

				img.attr('src', path); img.fadeIn();

			},

			
			setCollectionLink: function(a, link) {

				link = (link == undefined) ? this.link : link; this.link = link;

				a.attr('href', link);
			},

			
			//Set product code when this product has more than one product code for different colours.
			setCode: function(prodcode) {
				if (prodcode != undefined) {
					this.code = prodcode;
				}
			},


			setFlash: function(element) {
				if(this.colour.zeroBump || this.colour.id=='0'){this.colour.id = '00';}
				if (!jQuery.browser.msie || slib.Session.multi_site) {//non IE browsers
					
					
					
					if (this.hasImg_Rota) { //if image rotation found
						var rotPath;
						

						
						if(slib.Session.multi_site){
							rotPath = this.product_path  + this.name.toUpperCase() + this.colour.id + this.colour.name + "/A";
						}else{
							rotPath = slib.Session.product_path + "/" + this.name.toUpperCase() + this.colour.id + this.colour.name + "/A";
						}
						
						
						this.rotationPath = rotPath;
						element.css("width", "565px");
						element.css("height", "435px");
						element.css("position", "relative");

						var m;
						var img = jQuery(document.createElement("img"));
						var si;

						element.append(img);

						img.attr("src", rotPath + "01.jpg");

						var preImg;

						var preload = jQuery('#preload');

						if (preload.length == 0) {
							preload = jQuery(document.createElement("div")).attr("id", "preload");
						}

						
						for (var i = 0; i < 24; i++) {
							si = (i+1) + "";
							if (si.length == 1) {
								si = "0" + si;
							}

							preImg = jQuery(document.createElement("img")).attr("src", rotPath + si + ".jpg");
							preload.append(preImg);

							m = jQuery(document.createElement("div")).css("background-color","white").css("opacity","0").click(function(){void 0;}).mouseover(
								function() {

									var no = (1 + (parseInt(jQuery(this).css("left").replace("px", "")) / 24)) + "";
									if (no.length == 1) {
										no = "0" + no;
									}
									img.attr("src", rotPath + no + ".jpg").show();
								}
							);
							m.css("position", "absolute"); m.css("left", (i * 24) + "px"); m.css("top", "0px");
							m.css("height", "435px"); m.css("width", "24px"); m.css("z-index", "5");
							element.append(m);
						}
						
						this.rotationImg = img;
						
						if(slib.Session.multi_site){
							var leftArrow = $(document.createElement("div"));
							leftArrow.css('position','absolute').css('top','200px').css('left','-50px').css('z-index',999999);
							leftArrow.mousedown(function(){slib.gui.findType("MSProductDetailWidget").product.spinCW();});
							leftArrow.click(function(){slib.gui.findType("MSProductDetailWidget").product.spinCW(true);});
							leftArrow.mouseup(function(){slib.gui.findType("MSProductDetailWidget").product.stopSpin();});
							leftArrow.css('font-size','30px').css('cursor','pointer').css('padding','20px');
							leftArrow.html("&lt;&lt;");
							
							var rightArrow = $(document.createElement("div"));
							rightArrow.css('position','absolute').css('top','200px').css('right','-50px').css('z-index',999999);
							rightArrow.mousedown(function(){slib.gui.findType("MSProductDetailWidget").product.spinACW();});
							rightArrow.click(function(){slib.gui.findType("MSProductDetailWidget").product.spinACW(true);});
							rightArrow.mouseup(function(){slib.gui.findType("MSProductDetailWidget").product.stopSpin();});
							rightArrow.css('font-size','30px').css('cursor','pointer').css('padding','20px');
							rightArrow.html("&gt;&gt;");
							
							element.append(leftArrow);
							element.append(rightArrow);
						}

					} else if (this.hasImg_Main) { //if image main single found
						var img = jQuery(document.createElement("img"));
						img.attr('src', slib.Session.product_path + "/" + this.name.toUpperCase() + this.colour.id + this.colour.name + "/" + this.name.toUpperCase() + this.colour.id + this.colour.name + "_565x435.jpg");
						element.append(img);
						element.fadeIn();
					} else { //if no images found
						var img = jQuery(document.createElement("img"));
						img.attr('src', slib.Session.product_path + "/product.notfound_565x435.jpg");
						element.append(img);
						element.fadeIn();
					}

					return;

				}else{
				//IE browsers

				if ((slib.Session.hasFlash()) && (this.hasImg_Rota)) { //if image rotation found
					var path = slib.Session.product_path + "/" + this.name.toUpperCase() + this.colour.id + this.colour.name + "/" + this.name.toUpperCase() + this.colour.id + this.colour.name + "_565x435.jpg";

					element.hide();

					//if (slib.Session.hasFlash()) {						
                        //var so = new SWFObject("/flash/rotation/rotate.swf", "rotate", "565", "435", "8", "#FFFFFF");
						//so.addParam("quality", "high");
						//so.addParam("pluginspage", "http://www.macromedia.com/go/getflashplayer");
						//so.addParam("align", "middle");
						//so.addParam("play", "true");
						//so.addParam("loop", "true");
						//so.addParam("scale", "showall");
						//so.addParam("devicefont", "false");
						//so.addParam("id", "rotate");
						//so.addParam("bgcolor", "#ffffff");
						//so.addParam("name", "rotate");
						//so.addParam("menu", "true");
						//so.addParam("allowFullScreen", "false");
						//so.addParam("allowScriptAccess", "sameDomain");
						//so.addParam("movie", "rotate");
						//so.addParam("wmode", "transparent");
						//so.addVariable("prefix", slib.Session.product_path + "/" + this.name.toUpperCase() + this.colour.id + this.colour.name.toUpperCase());
						//so.addVariable("dir", "reverse");
						//so.write(element.attr("id"));
                        
                        var flashvars = {};
                        flashvars.prefix = slib.Session.product_path + "/" + this.name.toUpperCase() + this.colour.id + this.colour.name.toUpperCase();
                        flashvars.dir = "reverse";

                        var params = {};
                        params.quality = "high";
                        params.align = "middle";
                        params.id = "rotate";
                        params.bgcolor = "#ffffff";
                        params.menu = "true";
                        params.wmode = "transparent";

                        swfobject.embedSWF("/flash/rotation/rotate.swf", element.attr("id"), "565", "435", "9.0.0", "expressInstall.swf", flashvars, params);

						element.fadeIn();
					//} else {
					//    var img = jQuery(document.createElement("img"));

					//    img.attr('src', path);

					//    element.append(img);

					//    setTimeout(function() {
					//        jQuery.ajax({
					//            url: path,
					//            data: {},
					//            type: 'HEAD',
					//            error: function() { img.attr("src", "/images/products." + slib.Session.dbs + "/product.notfound_100x120.jpg"); }
					//        });
					//    }, 300);

					//    element.fadeIn();
					//}
				} else if (this.hasImg_Main) { //if image main single found
					var img = jQuery(document.createElement("a"));
					img.attr('src', slib.Session.product_path + "/" + this.name.toUpperCase() + this.colour.id + this.colour.name + "/" + this.name.toUpperCase() + this.colour.id + this.colour.name + "_565x435.jpg");
					element.append(img);
					element.fadeIn();
				} else { //if no images found
					var img = jQuery(document.createElement("a"));
					img.attr('src', slib.Session.product_path+ "/product.notfound_565x435.jpg");
					element.append(img);
					element.fadeIn();
				}
				
				}
				
				
			},
			
			spindex:0,
			CWTimeout:null,
			ACWTimeout:null,
			spinhalt:false,
			
			spinCW:function(stop){
				stop = stop==undefined ? false:stop;
				clearTimeout(this.ACWTimeout);
				this.spindex++;
				if(this.spindex>=25){this.spindex = 1;}
				
				var ts = this.spindex;
				ts = ts < 10 ? '0' + ts : ts;
				this.rotationImg.attr('src',this.rotationPath + ts + '.jpg');
				
				if(!stop && !this.spinhalt){
					this.CWTimeout = setTimeout('slib.gui.findType("MSProductDetailWidget").product.spinCW()',100);
				}else{
					this.spinhalt = false;
				}
			},
			
			spinACW:function(stop){
				stop = stop==undefined ? false:stop;
				clearTimeout(this.CWTimeout);
				this.spindex--;
				if(this.spindex<=0){this.spindex = 24;}
				
				var ts = this.spindex;
				ts = ts < 10 ? '0' + ts : ts;
				this.rotationImg.attr('src',this.rotationPath + ts + '.jpg');
				
				if(!stop && !this.spinhalt){
					this.ACWTimeout = setTimeout('slib.gui.findType("MSProductDetailWidget").product.spinACW()',100);
				}else{
					this.spinhalt = false;
				}
			},
			
			stopSpin:function(){
				clearTimeout(this.ACWTimeout);
				clearTimeout(this.CWTimeout);
				this.spinhalt = true;
			}

		},

		Helper:
		{
			activate: function() {
				var img = jQuery(document.createElement("img")).attr("src", "/images/shoestudio/ee/peek.png").css("position", "fixed").css("top", "-83px").css("left", "100px");
				jQuery(document.body).append(img).css("position", "relative");
				var hi = setInterval(function() { var t = parseInt(img.css("top").replace("px", "")); if (t < -53) { img.css("top", (t + 5) + "px"); } else { clearInterval(hi); } }, 100);
			}
		},

		Validation:
		{
			validateEmail: function(email) {
				var ere = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/;
				return (ere.test(email));
			}
		},

		Text:
		{
			cap: function(text) {
				text = text + "";
				result = "";
				var ta = text.replace(/&nbsp;/gi," ").toLowerCase().split(' ');
				for (var i = 0; i < ta.length; i++) {
					result += ta[i].charAt(0).toUpperCase() + ta[i].substring(1).toLowerCase() + " ";
				}
				return result;
			}
		}
	
    };

	wlib = slib.gui;
    slib.init();

});

function hideRegNews(){
    $('#popup_nreg').fadeOut();
    $('#fader').fadeOut();
}

function registerNewsletter(){
        
        
        if($('#nrclose').length==0){
            $('#popup_nreg').append('<div id="nrclose" onclick="hideRegNews()" style="cursor:pointer;position:absolute;top:15px;right:24px;color:white;font-size:20px;">x</div>');
        }

        $(document.body).css('position', 'relative').css('width', '100%').css('height', '100%').css('overflow', 'hidden');
        var w = $(window).width();
        var h = $(window).height();

        var form_w = 367;
        var form_h = 343;

        var x = Math.round((w - form_w) / 2);
        var y = Math.round((h - form_h) / 2) - 20;
        y = (y < 10) ? 10 : y;

        $('#fader').css('width', (w + 600) + 'px').css('height', (h + 200) + 'px').css('position', 'fixed').css('top', '0px').css('left', '0px').css('opacity', 0).show().animate({ opacity: 0.7 }).css('background-color', 'white');
        $('#fader').css('z-index', '99998');

        $('#popup_nreg').css('position', 'fixed').css('left', '0px').css('top', '0px').css('width', form_w + 'px').css('height', form_h + 'px');
        $('#popup_nreg').css('left', x + 'px').css('top', y + 'px').css('z-index', '99999');
        $('#popup_nreg').children("form").css('padding-left', '38px').children("label").css('line-height', '1.5').css('font-weight', 'normal');
	
		
					//$('#popup_nreg').css('left',(x-50) + 'px');
				
	
        $('#popup_nreg').fadeIn();
}
