﻿function ddtabcontent(tabinterfaceid){
	this.tabinterfaceid=tabinterfaceid //ID of Tab Menu main container
	this.tabs=document.getElementById(tabinterfaceid).getElementsByTagName("a") //Get all tab links within container
	this.enabletabpersistence=false
	this.hottabspositions=[] //Array to store position of tabs that have a "rel" attr defined, relative to all tab links, within container
	this.currentTabIndex=0 //Index of currently selected hot tab (tab with sub content) within hottabspositions[] array
	this.subcontentids=[] //Array to store ids of the sub contents ("rel" attr values)
	this.selectedClassTarget="link" //keyword to indicate which target element to assign "selected" CSS class ("linkparent" or "link")
}

ddtabcontent.prototype={

	cycleit:function(dir, autorun){ //PUBLIC function to move foward or backwards through each hot tab (tabinstance.cycleit('foward/back') )
		if (dir=="next"){
			var currentTabIndex=(this.currentTabIndex<this.hottabspositions.length-1)? this.currentTabIndex+1 : 0
		}
		this.expandtab(this.tabs[this.hottabspositions[currentTabIndex]])
	},

	getselectedClassTarget:function(tabref){ //Returns target element to assign "selected" CSS class to
		return (this.selectedClassTarget==("linkparent".toLowerCase()))? tabref.parentNode : tabref
	},

	expandtab:function(tabref){
		var subcontentid=tabref.getAttribute("rel") //Get id of subcontent to expand
		this.expandsubcontent(subcontentid)
		for (var i=0; i<this.tabs.length; i++){ //Loop through all tabs, and assign only the selected tab the CSS class "selected"
			this.getselectedClassTarget(this.tabs[i]).className=(this.tabs[i].getAttribute("rel")==subcontentid)? "selected" : ""
		}
		this.setcurrenttabindex(tabref.tabposition) //remember position of selected tab within hottabspositions[] array
	},

	expandsubcontent:function(subcontentid){
		for (var i=0; i<this.subcontentids.length; i++){
			var subcontent=document.getElementById(this.subcontentids[i]) //cache current subcontent obj (in for loop)
			subcontent.style.display=(subcontent.id==subcontentid)? "block" : "none" //"show" or hide sub content based on matching id attr value
		}
	},

	setcurrenttabindex:function(tabposition){ //store current position of tab (within hottabspositions[] array)
		for (var i=0; i<this.hottabspositions.length; i++){
			if (tabposition==this.hottabspositions[i]){
				this.currentTabIndex=i
				break
			}
		}
	},

	autorun:function(){ //function to auto cycle through and select tabs based on a set interval
		this.cycleit('next', true)
	},

	cancelautorun:function(){
		if (typeof this.autoruntimer!="undefined")
			clearInterval(this.autoruntimer)
	},

	init:function(automodeperiod){
		var selectedtab=-1 //Currently selected tab index (-1 meaning none)
		this.automodeperiod=automodeperiod || 0
		for (var i=0; i<this.tabs.length; i++){
			this.tabs[i].tabposition=i //remember position of tab relative to its peers
			if (this.tabs[i].getAttribute("rel")){
				var tabinstance=this
				this.hottabspositions[this.hottabspositions.length]=i //store position of "hot" tab ("rel" attr defined) relative to its peers
				this.subcontentids[this.subcontentids.length]=this.tabs[i].getAttribute("rel") //store id of sub content ("rel" attr value)
				this.tabs[i].onclick=function(){
					tabinstance.expandtab(this)
					tabinstance.cancelautorun() //stop auto cycling of tabs (if running)
					return false
				}
				if (this.enabletabpersistence && selectedtab==-1 || !this.enabletabpersistence && selectedtab==-1 && this.getselectedClassTarget(this.tabs[i]).className=="selected"){
					selectedtab=i //Selected tab index, if found
				}
			}
		} //END for loop
		if (selectedtab!=-1) //if a valid default selected tab index is found
			this.expandtab(this.tabs[selectedtab]) //expand selected tab (either from URL parameter, persistent feature, or class="selected" class)
		else //if no valid default selected index found
			this.expandtab(this.tabs[this.hottabspositions[0]]) //Just select first tab that contains a "rel" attr
		if (parseInt(this.automodeperiod)>500 && this.hottabspositions.length>1){
			this.autoruntimer=setInterval(function(){tabinstance.autorun()}, this.automodeperiod)
		}
	} //END int() function

} //END Prototype assignment










$(document).ready(function(){
    if($("img#mainProductImage").hasClass("frescaZoom"))
    {
        $("img#mainProductImage").frescaZoom()
    }
    alternativeViews();
    qtyModifyActions();
    addToWishlist()}
);
(function(){
    jQuery.fn.frescaZoom=function(){
        $("div#mainImageCont").unbind("mousemove");
        $("div#mainImageCont").unbind("hover");
        $("div#zoomCont").unbind("mouseover");
        $("div#zoomCont, div#mouseWindow, img#zoomProductImg, iframe#zoomFrame").remove();
        $("<div id='zoomCont'></div>").css({position:"absolute",top:"-5000px"}).appendTo("div#mainImageCont");
        $("<div id='mouseWindow'></div>").appendTo("div#mainImageCont");
        var c=$(this).attr("src");
        var b=c.split("large");
        var a=b[0]+"zoom"+b[1];
        $("<img id='zoomProductImg'>").attr("src",a).appendTo($("div#zoomCont"));
        $("img#zoomProductImg").load(function(){
            var e=parseFloat($("img#zoomProductImg").height())/parseFloat($("img#mainProductImage").height());
            var f=-(parseFloat($("img#zoomProductImg").width())-parseFloat($("div#zoomCont").width()));
            var d=-(parseFloat($("img#zoomProductImg").height())-parseFloat($("div#zoomCont").height()));
            $("div#mouseWindow").css({height:(parseFloat($("div#zoomCont").height())/e+"px"),width:(parseFloat($("div#zoomCont").width())/e+"px")}).hide();
            $("div#zoomCont").hide().css({position:"absolute",top:"0px"});
            $("div#mainImageCont").mousemove(function(m){var k=this.offsetTop;var l=this.offsetLeft;var h=this.offsetParent;while(h!=null){k+=h.offsetTop;l+=h.offsetLeft;h=h.offsetParent}var g=(m.pageX-l-(parseFloat($("div#mouseWindow").width())/2));
            var n=(m.pageY-k-(parseFloat($("div#mouseWindow").height())/2));
            var j=-(m.pageX-l-(parseFloat($("div#mouseWindow").width())/2))*e;var i=-(m.pageY-k-(parseFloat($("div#mouseWindow").height())/2))*e;if(j>0){j=0;g=0}else{if(j<f){g=-f/e;j=f}}if(i>0){n=0;i=0}else{if(i<d){n=-d/e;i=d}}$("img#zoomProductImg").css({top:i,left:j});$("div#mouseWindow").css({top:n,left:g})});$("div#mainImageCont").hover(function(g){$("div#mouseWindow, iframe#zoomFrame, div#zoomCont").show();
            if($.browser.msie&&$.browser.version==="6.0"){$("#selectSize").css("visibility","hidden")}},function(g){$("div#mouseWindow, iframe#zoomFrame").hide();
            $("div#zoomCont").hide();if($.browser.msie&&$.browser.version==="6.0"){$("#selectSize").css("visibility","visible")}});$("div#zoomCont").mouseover(function(){$("div#mouseWindow, div#zoomCont").hide()})})}}
)(jQuery);

function alternativeViews()
{
    var a=$("img.alternativeView");
    $.each(a,function(c,e){var d=$(e).attr("src");
    var b=d.split("thumbnail");
    this.largeSrc=b[0]+"large"+b[1];
    this.zoomSrc=b[0]+"zoom"+b[1];
    $("<img>").attr("src",this.mediumSrc);
    $(e).click(function()
    {
        $("<img>").attr("src",this.zoomSrc);
        $("img#mainProductImage").attr("src",this.largeSrc).frescaZoom()
    }).css("cursor","pointer")})
}

function qtyModifyActions(){var a="";if($("body.libertyoflondon").length>0){a="_LOL"}$("div#qtyElement").append('<img id="btnDec" src="/pws/images/btn_Minus'+a+'.jpg" alt="minus" /><img id="btnInc" src="/pws/images/btn_Plus'+a+'.jpg" alt="Plus" />');$("img#btnDec").click(function(b){var c=parseInt($("input#selectQuantity").val());if(c>1){c--}else{c=1}$("input#selectQuantity").val(c)});$("img#btnInc").click(function(b){var c=parseInt($("input#selectQuantity").val());if(c<99){c++}else{c=1}$("input#selectQuantity").val(c)})}function addToWishlist(){$("a#addToWishlist").click(function(a){$("form#addToBag").attr("action","/pws/secure/AddToWishList.ice?accountparameter=true");$("form#addToBag").submit()})};