	var $j = jQuery.noConflict();
	var savedSKU = '';
	var opac = 100;
	var fadetimer = null;
    var msgtimer = null;
    var timer = 1000;
    var ie = (navigator.userAgent.indexOf("MSIE") > 0) ? true:false;
    var version = document.getElementById('quicklookversion');
    var bgcolor = document.getElementById('quicklookbgcolor');
    var msgcolor = document.getElementById('quicklookcolor');
    
    $j(document).ready(function () {	
        updateswatchesid();
    });
	function updateswatchesid() { 
		$j('.prod-swatch').each(function (i) {
        $j(this).find('a').each(function () {
            var href = $j(this).attr('href').replace('swatches', '-' + i + 'swatches');
            $j(this).attr('href', href);
        });
      });
	}
        
    function showExpressBtn(id, show) {
        var btnContainer = document.getElementById('quickViewBtn_' + id);
        if (!btnContainer)
            return;
     
        if (show) {

            if(version.value == "1")
                btnContainer.innerHTML = '<img id="btn_' + id + '" src="/layout/tsak/images/titles/quick_view_ts.png" border="0" style="cursor:pointer;" onmouseover="this.src=\'/layout/tsak/images/titles/quick_view_over_ts.png\'" onmousedown="this.src=\'/layout/tsak/images/titles/quick_view_ts.png\'" onmouseup="this.src=\'/layout/tsak/images/titles/quick_view_over_ts.png\'" onclick="showPopUp(\'' + id.split('-')[0] + '\',\'' + btnContainer.title.split('-')[0] + '\'); var s = s_gi(\'onestoptsak\'); s.linkTrackVars=\'prop7,eVar12\'; s.prop7=\'ajaxproductdetail\'; s.eVar12=\'ajaxproductdetail\'; s.tl(this,\'o\',\'ajaxproductdetail\'); s.linkTrackVars=\'None\'; s.prop7=\'\'; s.eVar12=\'\'; setValue(\'' + id.split('-')[0] + '\',\'' + btnContainer.title.split('-')[0] + '\')" />';
            
            if(version.value == "2")
                btnContainer.innerHTML = '<img id="btn_' + id + '" src="/layout/sakr/images/titles/quick_view_sr.png" border="0" style="cursor:pointer;" onmouseover="this.src=\'/layout/sakr/images/titles/quick_view_sr.png\'" onmousedown="this.src=\'/layout/sakr/images/titles/quick_view_sr.png\'" onmouseup="this.src=\'/layout/sakr/images/titles/quick_view_sr.png\'" onclick="showPopUp(\'' + id.split('-')[0] + '\',\'' + btnContainer.title.split('-')[0] + '\'); var s = s_gi(\'onestoptsak\'); s.linkTrackVars=\'prop7,eVar12\'; s.prop7=\'ajaxproductdetail\'; s.eVar12=\'ajaxproductdetail\'; s.tl(this,\'o\',\'ajaxproductdetail\'); s.linkTrackVars=\'None\'; s.prop7=\'\'; s.eVar12=\'\'; setValue(\'' + id.split('-')[0] + '\',\'' + btnContainer.title.split('-')[0] + '\')" />';

            if(version.value == "3")
                btnContainer.innerHTML = '<img id="btn_' + id + '" src="/layout/elli/images/ql/quick_view.gif" title="quick view" border="0" style="cursor:pointer;" onmouseover="this.src=\'/layout/elli/images/ql/quick_view_over.gif\'" onmousedown="this.src=\'/layout/elli/images/ql/quick_view_down.gif\'" onmouseup="this.src=\'/layout/elli/images/ql/quick_view_over.gif\'" onclick="showPopUp(\'' + id.split('-')[0] + '\',\'' + btnContainer.title.split('-')[0] + '\'); var s = s_gi(\'onestopelli\'); s.linkTrackVars=\'prop7,eVar12\'; s.prop7=\'ajaxproductdetail\'; s.eVar12=\'ajaxproductdetail\'; s.tl(this,\'o\',\'ajaxproductdetail\'); s.linkTrackVars=\'None\'; s.prop7=\'\'; s.eVar12=\'\'; setValue(\'' + id.split('-')[0] + '\',\'' + btnContainer.title.split('-')[0] + '\')" />';
        }
     
        if (!show) {
            btnContainer.innerHTML = '';
        }

        return;
    }

    function mouseEventHandler(mEvent) {
        var id, currentSKU;
     
        if (mEvent.srcElement) {
            id = mEvent.srcElement.id;
        }    
        else if (mEvent.target) {
            id = mEvent.target.id;
        }
       
        var prod_image = /^[a-zA-Z0-9-]+$/.test(id);
        var quickView_image = /^btn_[a-zA-Z0-9-]+$/.test(id);
        var quickView_container = /^quickViewBtn_[a-zA-Z0-9-]+$/.test(id);
     
        if (prod_image)
            currentSKU = id;
        else if (quickView_image) {
            var temp = id.split('_');
            currentSKU = temp[1];
        }
        else if (quickView_container) {
            var temp = id.split('_');
            currentSKU = temp[1];
        }
     
        if (savedSKU != currentSKU) {
            showExpressBtn(savedSKU, false)
		}
        if (prod_image || quickView_image || quickView_container) {
            if (prod_image)
                showExpressBtn(id, true);
				savedSKU = currentSKU;
        }
        return;
    } 

    function setValue(sku, color) {
        current_sku = sku;
        current_color = color;
        
        return;
    }

    var Drag = { obj: null, init: function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
    { o.onmousedown = Drag.start; o.hmode = bSwapHorzRef ? false : true; o.vmode = bSwapVertRef ? false : true; o.root = oRoot && oRoot != null ? oRoot : o; if (o.hmode && isNaN(parseInt(o.root.style.left))) o.root.style.left = "0px"; if (o.vmode && isNaN(parseInt(o.root.style.top))) o.root.style.top = "0px"; if (!o.hmode && isNaN(parseInt(o.root.style.right))) o.root.style.right = "0px"; if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px"; o.minX = typeof minX != 'undefined' ? minX : null; o.minY = typeof minY != 'undefined' ? minY : null; o.maxX = typeof maxX != 'undefined' ? maxX : null; o.maxY = typeof maxY != 'undefined' ? maxY : null; o.xMapper = fXMapper ? fXMapper : null; o.yMapper = fYMapper ? fYMapper : null; o.root.onDragStart = new Function(); o.root.onDragEnd = new Function(); o.root.onDrag = new Function(); }, start: function(e) {
        var o = Drag.obj = this; e = Drag.fixE(e); var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom); var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right); o.root.onDragStart(x, y); o.lastMouseX = e.clientX; o.lastMouseY = e.clientY; if (o.hmode) { if (o.minX != null) o.minMouseX = e.clientX - x + o.minX; if (o.maxX != null) o.maxMouseX = o.minMouseX + o.maxX - o.minX; } else { if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x; if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x; }
        if (o.vmode) { if (o.minY != null) o.minMouseY = e.clientY - y + o.minY; if (o.maxY != null) o.maxMouseY = o.minMouseY + o.maxY - o.minY; } else { if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y; if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y; }
        document.getElementById('container').style.opacity = '.50'; document.getElementById('container').style.filter = 'alpha(opacity=50)'; document.onmousemove = Drag.drag; document.onmouseup = Drag.end; return false;
    }, drag: function(e) {
        e = Drag.fixE(e); var o = Drag.obj; var ey = e.clientY; var ex = e.clientX; var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom); var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right); var nx, ny; if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX); if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX); if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY); if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY); nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1)); ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1)); if (o.xMapper) nx = o.xMapper(y)
        else if (o.yMapper) ny = o.yMapper(x)
        Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px"; Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px"; Drag.obj.lastMouseX = ex; Drag.obj.lastMouseY = ey; Drag.obj.root.onDrag(nx, ny); return false;
    }, end: function()
    { document.getElementById('container').style.opacity = '1'; document.getElementById('container').style.filter = 'alpha(opacity=100)'; document.onmousemove = null; document.onmouseup = null; Drag.obj.root.onDragEnd(parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"])); Drag.obj = null; }, fixE: function(e)
    { if (typeof e == 'undefined') e = window.event; if (typeof e.layerX == 'undefined') e.layerX = e.offsetX; if (typeof e.layerY == 'undefined') e.layerY = e.offsetY; return e; }
    };

          
    function BuildQuicklookJs() {
        var content = document.getElementById("jLoader").innerHTML;
        var head = document.getElementsByTagName("head");
        var script = document.createElement("script");
        head[0].appendChild(script);
        script.type = "text/javascript";
        script.text = content;
    }
        
    function showPopUp(productid, color) {
        var box = document.getElementById('ql-main-container');
        var container = document.getElementById('ql-container');
         

        where = where.replace('&', ' and ');
        where = where.replace('&', ' and ');
        where = where.replace('%', '[perc]');
 
        var xmlHttp = ajaxFunction();
        var params = 'productid=' + productid + '&color=' + color + '&action=1&where=' + where;
 
        xmlHttp.onreadystatechange = function() {
            if (xmlHttp.readyState == 4) {
                if (document.all) {
                    var result=xmlHttp.responseText;
                     result=result.replace(/<[//]{0,1}(form|Form)[^><]*>/g, ""); 
                     box.innerHTML = result;  
                }
                else
                {
                    box.innerHTML = xmlHttp.responseText;
                } 
                
                getPopupPosition();
                
                if(document.getElementById("jLoader")!= null && document.getElementById("jLoader").innerHTML!= "")
                   BuildQuicklookJs();
                   
                change_unitcost(productid);
                init();
                    
                initializeAllProducts('true');
               
                if (container.style.display == 'none') {
                    container.style.display = 'block';
                }
                
                if (typeof document.body.style.maxHeight == "undefined") {
                  hideSelects('hidden');
                }
               
                down = false;
            }
        }
  
        if(version.value == "1")
            xmlHttp.open("POST", "/ajaxpopup.aspx", true);
        else if(version.value == "2")
            xmlHttp.open("POST", "/ajaxpopup2.aspx", true);
        else if(version.value == "3")
            xmlHttp.open("POST", "/ajaxpopup3.aspx", true);
        
        xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttp.setRequestHeader("Content-length", params.length);
        xmlHttp.setRequestHeader("Connection", "close");
        xmlHttp.send(params);

        return;
    }
    
    function hidePopUp() {
		$j('#ql-container').hide();
		$j('#ql-main-container').empty();
        down = false;
        return;
    }
    
    function trackme(url,query) { 
      if (window.XMLHttpRequest) {
          request = new XMLHttpRequest();
 
      } else if (window.ActiveXObject) {
          request = new ActiveXObject("Microsoft.XMLHTTP");
      }
      if (request) {
          request.onreadystatechange = function() { 
              return false; 
          };
          request.open("get", url, true);
          request.send(query);
      }
    }
    
    function getPopupPosition() {
        var width, scrollY;
        var IE = /*@cc_on!@*/false;
 
        var container = document.getElementById('ql-container');
 
        if (window.innerWidth)
            width = window.innerWidth;
        else if (document.body.clientWidth)
            width = document.body.clientWidth;
 
        if (window.pageYOffset || window.pageYOffset == 0)
            scrollY = window.pageYOffset;
        else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) )
            scrollY = document.body.scrollTop;
        else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) )  
            scrollY = document.documentElement.scrollTop;
        else if (document.body.scrollTop || document.body.scrollTop == 0)
            scrollY = document.body.scrollTop;
 
        var posx, posy;
        
        if(version.value == "3")
            posx = (width/2)-533;
        else
            posx = (width/2)-233;
		
        if(version.value == "3")
            posy = scrollY;
        else
            posy = scrollY + 250;
 
        var tmp = container.style.top.split('px');
        var position = tmp[0];
        if (container.style.display == 'none' || position < scrollY) {
            container.style.left = posx + 'px';
            if(IE){
             container.style.top = posy-15 + 'px';
            }else{
             container.style.top = posy + 'px';
            }
        }
        else {
            container.style.left = posx + 'px';
            container.style.top = posy + 'px';
        }
        return;
    }
 
    function ajaxFunction() {
        var xmlHttp;

        try {
            xmlHttp = new XMLHttpRequest();
        }
        catch (e) { 
            try {
                xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch (e) {
                try {
                    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch (e) {
                    alert("Your browser does not support AJAX!");
                    return false;
                }
            }
        }
        return xmlHttp;
    } 
    
    function addToCart(productid) {
        var qty = document.getElementById('qty_sel_ddl').value;
        var productid = document.getElementById('ProductIDHidden').value;
        var color = document.getElementById('ProductColors').value;
        var size = document.getElementById('ProductSizes').value;
        var modelname = document.getElementById('ModelName').innerHTML;
        var price = document.getElementById('UnitCostSpan').innerHTML;
        
        init();
        
        if (color == '-1') {
            $('message').style.padding = "5px";
	        $('message').style.color = msgcolor.value;
	        $('message').style.display = "block";
	        $('message').style.background = bgcolor.value;
	        $('message').innerHTML = "Please select a color!";
	        $('message').style.fontSize = "10px";
	        $('message').style.fontFamily = "Lucida Grande, Verdana, Arial, tahoma";
	        timer = 2000;
            fadeAddtoCartMsg(); 
            return false;
        }
 
        if (size == '-1') {
            $('message').style.padding = "5px";
	        $('message').style.color = msgcolor.value;
	        $('message').style.display = "block";
	        $('message').style.background = bgcolor.value;
	        $('message').innerHTML = "Please select a size!";
	        $('message').style.fontSize = "10px";
	        $('message').style.fontFamily = "Lucida Grande, Verdana, Arial, tahoma";
	        timer = 2000;
            fadeAddtoCartMsg(); 
            return false;
        }
                 
        if (!qty.match(/^[0-9]+$/) || qty == 0) {
            alert('quantity is Invalid');
            return false;
        }
 
        var xmlHttp = ajaxFunction();
        var params = '?productid=' + productid + '&colorid=' + color + '&sizeid=' + size + "&quantity=" + qty + "&ajax-add=1";
        var prodPlacementMember = -1;
	    if (prodPlacementJSON && prodPlacementJSON.ProductPlacement) {
	    
	        for (var index = 0; index < prodPlacementJSON.ProductPlacement.length; index++) {
	            if (prodPlacementJSON.ProductPlacement[index].ProductID == productid) {
	                if (prodPlacementJSON.ProductPlacement[index].ColorID > 0) {
	                    if (prodPlacementJSON.ProductPlacement[index].ProductID == productid && prodPlacementJSON.ProductPlacement[index].ColorID == color) {
	                        prodPlacementMember = prodPlacementJSON.ProductPlacement[index].PlacementMemberID;
	                        break;
	                    }
	                    continue;
	                } else {
	                    prodPlacementMember = prodPlacementJSON.ProductPlacement[index].PlacementMemberID
                    }
                }
            }
        }
	    if (prodPlacementMember > 0) {
	        params += "&placementMemberID=" + prodPlacementMember;
	    }
        
        document.getElementById('productid').value = productid;
        document.getElementById('colorid').value = color;
        document.getElementById('sizeid').value = size;
        document.getElementById('params').value = params;
        
        var url = '/store/os/addtocart.aspx';
        url += params;
        
        $('message').innerHTML = "processing...";
        $('message').style.padding = "5px";
        $('message').style.color = msgcolor.value;
        $('message').style.background = bgcolor.value;
		$('message').style.display = "block";
		$('message').style.fontSize = "10px";
		$('message').style.fontFamily = "Lucida Grande, Verdana, Arial, tahoma";
        
        new Ajax.Request(url,{
          method:'post',
          onSuccess: function(transport){
           var notice = $('message');
           var checkout = $('checkout');
            notice.update(qty + ' ' + modelname + ' has been added to your bag!');
            checkout.setStyle({ display: 'block' });
            addtobagUniTag(productid, modelname);
            UpdateShoppingBag(qty, price);
            timer = 4000;
            fadeAddtoCartMsg();
          },
            onFailure: function(){ 
            notice.update('item has not been added!').setStyle({ background: '#dfd' }); 
          }
        });
        
        return false;     
    }
    
    // wait x number of secs before fading out message
    function fadeAddtoCartMsg() {
	    // fade message out
	    msgtimer = setTimeout("fadeMessageAway()",timer);
    }

    // decrements opacity by 1 until reaches 0
    function fadeMessageAway() {
	    var ie = (document.all) ? true : false;
	    if (msgtimer != null) {
		    clearTimeout(msgtimer);
		    msgtimer = null;
	    }
	    if (opac > 0) {
		    // decrement var
		    opac--;
		    // update styles
		    if (ie) {
			    $('message').style.filter = "alpha(opacity=" + opac + ")";
		    } else {
			    $('message').style.opacity = opac/100;
		    }
		    // set timer
		    fadetimer = setTimeout("fadeMessageAway()",10);	
	    } else {
		    // reset timer
		    resetTimer();
	    }	
    }

    // resets msg styles + fade timers + global var
    function resetTimer() {
	    clearTimeout(fadetimer);
	    fadetimer = null;
	    // reset display
	    $('message').style.display = "none";
	    // reset opacity
	    if (ie) {
		    $('message').style.filter = "alpha(opacity=100)";
	    } else {
		    $('message').style.opacity = 1.0;
	    }
	    // reset opac var
	    opac = 100;
    }
    
    function UpdateShoppingBag(qty, price) {          
      var CartItems;
      var CartTotal;
      var CartItemsHidden;
      var CartTotalHidden;
      var Amount = 0;
      
      CartItems = getElementByID_Master("ctl00_ShoppingBag1_CartItemsLB");
      CartTotal = getElementByID_Master("ctl00_ShoppingBag1_CartTotalLB"); 
      CartItemsHidden = getElementByID_Master("ctl00$ShoppingBag1$CartItemsHidden");
      CartTotalHidden = getElementByID_Master("ctl00$ShoppingBag1$CartTotalHidden");
             
      Amount = parseDecimal(CartTotal.innerHTML) + parseDecimal(price);
                                               
      if (CartTotal != null)
          CartTotal.innerHTML =  '$' + Amount.toFixed(2);

      if (CartItems != null)
          CartItems.innerHTML =  parseInt(CartItems.innerHTML) + parseInt(qty) + ' ITEMS';           
    }
            
    function parseDecimal(d, zeros, trunc) {
	    d=d.replace(/[a-zA-Z\!\@\#\$\%\^\&\*\(\)\_\+\-\=\{\}\|\[\]\\\:\"\;'\<\>\?\,\/\~\`]/g,"");
	    while (d.indexOf(".") != d.lastIndexOf("."))
		    d=d.replace(/\./,"");
	    if (typeof zeros == 'undefined' || zeros == "") {
		    return parseFloat(d);
		    }
	    else {
		    var mult = Math.pow(10,zeros);
		    if (typeof trunc == 'undefined' || (trunc) == false)
			    return parseFloat(Math.round(d*mult)/mult);
		    else
			    return parseFloat(Math.floor(d*mult)/mult);
		    }
	  }
      
    function hideSelects(action) {
    if (action!='visible'){action='hidden';}
      if (navigator.appName.indexOf("MSIE")) {
        for (var S = 0; S < document.forms.length; S++){
          for (var R = 0; R < document.forms[S].length; R++) {
            if (document.forms[S].elements[R].options) {
              document.forms[S].elements[R].style.visibility = action;
              }
            }
          }
        }
      }
    
    function getItemColor(productid) { 
        if (!document.getElementById('quickViewBtn_' + productid))
            skuColor = '';
        else
            skuColor = document.getElementById('quickViewBtn_' + productid).title;

        return skuColor;
    }   
    
  var tabLinks = new Array();
  var contentDivs = new Array();

  function init() {

    // Grab the tab links and content divs from the page
    var tabListItems = document.getElementById('tabs').childNodes;
    for (var i = 0; i < tabListItems.length; i++) {
      if (tabListItems[i].nodeName == "LI") {
        var tabLink = getFirstChildWithTagName(tabListItems[i], 'A');
        var id = getHash(tabLink.getAttribute('href'));
        tabLinks[id] = tabLink;
        contentDivs[id] = document.getElementById(id);
        var tabbg = $("tabs");
		if(version.value == "3")
            tabbg.style.background ="url(/layout/elli/images/ql/tab-sizecolor.gif)";
        else
            tabbg.style.background ="url(/layout/ql/images/tab-sizecolor.gif)";
      }
    }

    // Assign onclick events to the tab links, and
    // highlight the first tab
    var i = 0;

    for (var id in tabLinks) {
      tabLinks[id].onclick = showTab;
      tabLinks[id].onfocus = function() { this.blur() };
      if (i == 0) tabLinks[id].className = 'selected';
      i++;
    }

    // Hide all content divs except the first
    var i = 0;

    for (var id in contentDivs) {
      if (i!= 0) contentDivs[id].className = 'tabContent hide';
      i++;      
    }    
    
    contentDivs["sizecolor"].className = 'tabContent';
  }

  function showTab() {
    var selectedId = getHash(this.getAttribute('href'));

    // Highlight the selected tab, and dim all others.
    // Also show the selected content div, and hide all others.
    for (var id in contentDivs) {
      if (id == selectedId) {
        tabLinks[id].className = 'selected';
        contentDivs[id].className = 'tabContent';
        var tabbg = $("tabs");
        if(version.value == "3")
            tabbg.style.background ="url(/layout/elli/images/ql/tab-"+selectedId+".gif)";
        else
		    tabbg.style.background ="url(/layout/ql/images/tab-"+selectedId+".gif)";
      } else {
        tabLinks[id].className = '';
        contentDivs[id].className = 'tabContent hide';
      }
    }

    // Stop the browser following the link
    return false;
  }

  function getFirstChildWithTagName(element, tagName) {
    for (var i = 0; i < element.childNodes.length; i++) {
      if (element.childNodes[i].nodeName == tagName) return element.childNodes[i];
    }
  }

  function getHash(url) {
    var hashPos = url.lastIndexOf('#');
    return url.substring(hashPos + 1);
  }
     
