﻿function button_switch(o, p, q){
    o.setAttribute('src', o.getAttribute('src').replace(p, q));
}

function setPano(i, s){
    var o=document.getElementById(i)
    o.src+=s;
}

function setCookie(name, value) {
    document.cookie = name + "=" + escape( value );
}

function setCookieEXP(name, value, min) {
    var now = new Date();
    now.setTime(now.getTime() + 1000 * 60 * min)
    document.cookie = name + "=" + escape( value )+ ";expires=" + now;
}

function getCookie(name) {
  var cookie=document.cookie;
  var start=cookie.indexOf(name+"=");
  if(start>1){if(cookie.substr(start-2,1)!=";")return null;}
  //if(start!=cookie.lastIndexOf(name+"="))return null;
  if(start>=0) 
  {
  	var end = document.cookie.indexOf(";", start);
    if (end == -1) end = cookie.length;
  	return unescape(cookie.substring(start + name.length+1,end));
  }
  return null;
}

function removeCookie(name) 
{ 
document.cookie = name + "=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT;"; 
} 

function sizeProductName(pn){ 
    var pix = 72;//default
    
    if(pn.length>13) pix=36;
    
    return pix;
}

function bannerModule(div) {
    var o = new Array();
    o.id = div;
    o.refresh = 8000;
    o.index = -1;
    o.timer = null;
    o.add = function(imgDefault,imgOver,Width,href,target,trackingFunction) {
        o[o.length] = {defaultImg:imgDefault,OverImg:imgOver,width:Width,Href:href,Target:target,trackInfo:trackingFunction }
    }
    o.imgSwitch = function() {
        $("#" + o.id + o.index).fadeOut(200,function() {
            o.index += 1;
            if (o.index > o.length -1) { o.index = 0 }
                var innerContent = "<div id='" + o.id + o.index + "' style='display:none;'><a href='" + o[o.index].Href + "' ";
                innerContent += "target='" + o[o.index].Target + "' ";
                innerContent += "onclick=\"" + o[o.index].trackInfo + '">';
                innerContent += "<img id='" + o.id + "img' src='" + o[o.index].defaultImg + "' style='border:0px;' />";
                innerContent += "</a></div>";
                $("#" + o.id).html(innerContent);
                $("#" + o.id + o.index).fadeIn(200);
                o.enable();
                o.hover();
        });
    }
    o.enable = function() {
        if ( o.length > 1 ) {
            o.timer = setTimeout(o.imgSwitch,o.refresh);
        }
    }
    o.disable = function() {
        clearTimeout(o.timer);
    }
    o.hover = function() {
        $("#" + o.id + " #" + o.id + "img").hover( 
        function() {
            $(this).attr("src",o[o.index].OverImg)
        }, 
        function() {
            $(this).attr("src",o[o.index].defaultImg)
        });
    }
    
    o.init = function() {
        o.index += 1;
        if (o.index > o.length -1) { o.index = 0 }
        var innerContent = "<div id='" + o.id + o.index + "'><a href='" + o[o.index].Href + "' ";
        innerContent += "target='" + o[o.index].Target + "' ";
        innerContent += "onclick=\"" + o[o.index].trackInfo + '">';
        innerContent += "<img id='" + o.id + "img' src='" + o[o.index].defaultImg + "' style='border:0px;' />";
        innerContent += "</a></div>";
        $("#" + o.id).html(innerContent);
        o.enable();
        o.hover();
    }
    return o;
}
