function load() {
  if(document.getElementById('catalog_graph')) {
    var el = $('graph_data')?$('graph_data'):$('product_div');
    var cg = $('catalog_graph');
    var xy = Position.cumulativeOffset(el);
    var wh = el.getDimensions();
    var wh2 = cg.getDimensions();
    var offset = $('graph_data')?102:0;

    setElementWidth(el, wh2.width + 20);
    
    document.getElementById('autoscroll_up').style.left = xy[0] + offset + "px";
    document.getElementById('autoscroll_up').style.top = xy[1] + "px";
    document.getElementById('autoscroll_up').style.zIndex = 800;
    
    document.getElementById('autoscroll_down').style.left = xy[0] + offset + "px";
    document.getElementById('autoscroll_down').style.top = xy[1] + wh.height - 16 + "px";
    document.getElementById('autoscroll_down').style.zIndex = 801;
    
    
  }
}




function indexMouseOver(w) {
  if (typeof document.body.style.maxHeight == "undefined") {
    document.getElementById('circle_'+w).style.display='block';
  }
}

function indexMouseOut(w) {
  if (typeof document.body.style.maxHeight == "undefined") {
    document.getElementById('circle_'+w).style.display='none';
  }
}

function display_demo(id) {
  window.open('/files/demos/demo_view.php?id='+id,'demo_view','width=800,height=660');
}


function handleMainMenuClick(w) {
  if(document.getElementById('menu_' + w) != undefined) {
    var curStyle = document.getElementById('menu_' + w).style.display;
    if(curStyle == 'none') {
      document.getElementById('menu_' + w).style.display = 'block';
    }
    else {
      document.getElementById('menu_' + w).style.display = 'none';
    }
  }
}

function openAnimation(anim) {
  var ov_window = window.open('/animation/' + anim + '.html', 'ov_window', 'height=600,width=800');
  ov_window.focus();
  return false;
}



function printEmailAddress(encAddr) {
  var decAddr = decode64(encAddr);
  return decAddr;
}

function printEmailAddressLink(encAddr, class_name) {
  var html;
  if(class_name == undefined) { class_name = 'emaillink'; }
  html = "<span class='" + class_name + "' onClick='document.location=\"mailto:" + printEmailAddress(encAddr) + "\"'>";
  html = html + printEmailAddress(encAddr);
  html = html + "</span>";
  document.write(html);
}

function decode64(inp) {
  var out = ""; //This is the output
  var chr1, chr2, chr3 = ""; //These are the 3 decoded bytes
  var enc1, enc2, enc3, enc4 = ""; //These are the 4 bytes to be decoded
  var i = 0; //Position counter
  var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

  // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
  var base64test = /[^A-Za-z0-9\+\/\=]/g;

  inp = inp.replace(/[^A-Za-z0-9\+\/\=]/g, "");

  do { //Here.s the decode loop.

    //Grab 4 bytes of encoded content.
    enc1 = keyStr.indexOf(inp.charAt(i++));
    enc2 = keyStr.indexOf(inp.charAt(i++));
    enc3 = keyStr.indexOf(inp.charAt(i++));
    enc4 = keyStr.indexOf(inp.charAt(i++));

    //Heres the decode part. There.s really only one way to do it.
    chr1 = (enc1 << 2) | (enc2 >> 4);
    chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
    chr3 = ((enc3 & 3) << 6) | enc4;

    //Start to output decoded content
    out = out + String.fromCharCode(chr1);

    if (enc3 != 64) {
      out = out + String.fromCharCode(chr2);
    }
    if (enc4 != 64) {
      out = out + String.fromCharCode(chr3);
    }

    //now clean out the variables used
    chr1 = chr2 = chr3 = "";
    enc1 = enc2 = enc3 = enc4 = "";

  } while (i < inp.length); //finish off the loop

  //Now return the decoded values.
  return out;
}


BookmarkApp = function () {
    var isIEmac = false; /*@cc_on @if(@_jscript&&!(@_win32||@_win16)&& 
(@_jscript_version<5.5)) isIEmac=true; @end @*/
    var isMSIE = (-[1,]) ? false : true;
    var cjTitle = document.title;
    var cjHref = location.href;

    function hotKeys() {
        var ua = navigator.userAgent.toLowerCase();
        var str = '';
        var isWebkit = (ua.indexOf('webkit') != - 1);
        var isMac = (ua.indexOf('mac') != - 1);

        if (ua.indexOf('konqueror') != - 1) {
            str = 'CTRL + B'; // Konqueror
        } else if (window.home || isWebkit || isIEmac || isMac) {
            str = (isMac ? 'Command/Cmd' : 'CTRL') + ' + D'; // Netscape, Safari, iCab, IE5/Mac
        }
        return ((str) ? 'Press ' + str + ' to bookmark this page.' : str);
    }

    function isIE8() {
        var rv = -1;
        if (navigator.appName == 'Microsoft Internet Explorer') {
            var ua = navigator.userAgent;
            var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
            if (re.exec(ua) != null) {
                rv = parseFloat(RegExp.$1);
            }
        }
        if (rv > - 1) {
            if (rv >= 8.0) {
                return true;
            }
        }
        return false;
    }

    function addBookmark(a) {
        try {
            if (typeof a == "object" && a.tagName.toLowerCase() == "a") {
                a.style.cursor = 'pointer';
                if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) {
                    window.sidebar.addPanel(cjTitle, cjHref, ""); // Gecko
                    return false;   
                } else if (isMSIE && typeof window.external == "object") {
                    if (isIE8()) {
                        window.external.AddToFavoritesBar(cjHref, cjTitle); // IE 8                    
                    } else {
                        window.external.AddFavorite(cjHref, cjTitle); // IE <=7
                    }
                    return false;
                } else if (window.opera) {
                    a.href = cjHref;
                    a.title = cjTitle;
                    a.rel = 'sidebar'; // Opera 7+
                    return true;
                } else {
                    alert(hotKeys());
                }
            } else {
                throw "Error occured.\r\nNote, only A tagname is allowed!";
            }
        } catch (err) {
            alert(err);
        }

    }

    return {
        addBookmark : addBookmark
    }
}();

