function addBookmark() {
    if (window.sidebar) { // firefox
    	window.sidebar.addPanel(window.document.title, window.document.location, "");
    } else if(window.opera && window.print) { // opera
    	var elem = document.createElement('a');
    	elem.setAttribute('href',window.document.location);
    	elem.setAttribute('title',window.document.title);
    	elem.setAttribute('rel','sidebar');
    	elem.click();
    } else if(document.all) {// ie
    	window.external.AddFavorite(window.document.location, window.document.title);
    }
}

var fontIndex = 1;
var fontSizes = [.85,1,1.15];
function loadFontSize() {
    setFontSize(readCookie('font-index') || fontIndex);
}
function setFontSize(idx) {
    createCookie('font-index',idx);
    fontIndex = idx;
    $('body').setStyle({fontSize: fontSizes[idx]+'em'});

    $('text-toggle').innerHTML = '';
    for(var i=0;i<fontSizes.length;i++) {
        var elem = document.createElement('span');
        Element.setStyle(elem,{fontSize: Math.floor(10*fontSizes[i])+'px', backgroundColor: (idx == i ? '#e8e8e8' : ''), color: (idx == i ? '#8c8c8c' : '')});
        elem.innerHTML = 'A';
        $('text-toggle').appendChild(elem);
    }
}
function toggleFontSize() {
    setFontSize((fontIndex + 1) % fontSizes.length);
}


function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name) {
	createCookie(name,"",-1);
}

function editChunk(in_id) {
    window.open('/page/chunkedit/'+in_id+'/','editPage','width=700,height=550,resizable=yes,scrollbars=yes');
    return false;
}
function editPage(in_id) {
    window.open('/page/seo/'+in_id+'/','editPage','width=550,height=550,resizable=yes,scrollbars=yes');
    return false;
}
function chunkClose() {
    window.opener.location.reload(true);
    window.close();
}
function email(in_id) {
    window.open('/home/email/'+in_id+'/','emailPage','width=450,height=400');
}

document.getElementsByClassName = function(className) {
  var children = document.getElementsByTagName('*') || document.all;
  var elements = new Array();

  for (var i = 0; i < children.length; i++) {
    var child = children[i];
    var classNames = child.className.split(' ');
    for (var j = 0; j < classNames.length; j++) {
      if (classNames[j] == className) {
        elements.push(child);
        break;
      }
    }
  }
  return elements;
}

document.addEvent = function(object, eventType,fn, useCapture) {
	if (object.addEventListener) {
		object.addEventListener(eventType, fn, useCapture);
		return true;
	} else {
		if (object.attachEvent) {
			var r = object.attachEvent("on"+eventType, fn);
			return r;
		}
	}
};

var clickmessage="Right click has been disabled.";
function associateimages(){
	//function from dynamicdrive.com
	for(i=0;i<document.images.length;i++)
	document.images[i].onmousedown=disableclick;
}

function disableclick(e) {
if ( document.domain.indexOf('pelagodesign.com') != -1 ) return;
if ( (navigator.appName == 'Netscape' && (e.which == 2 || e.which == 3 || e.ctrlKey || e.altKey) && e.target.tagName!='A' ) || (navigator.appName != 'Netscape' && (event && (event.button==2||event.button==3||event.ctrlKey||event.altKey) && event.srcElement.tagName=='IMG')) ) {
	alert(clickmessage);
	return false;
}
	return true;
}

function protectImages() {
	if ( (/pelago/gi).test(document.domain) ) return false;
	if (document.all)
		document.onmousedown=disableclick
	else if (document.getElementById)
		document.onmouseup=disableclick
	else if (document.layers)
		associateimages();
	window.onmousedown=disableclick;

}

function rollover() {
	//if ( !this.src ) return;
	this.oldsrc = this.src;
	this.src = this.imgOn.src;
}

function rollout() {
	//if ( !this.oldsrc ) return;
	this.src = this.oldsrc;
}

function switchImage(href) {
	var img = href.getElementsByTagName('IMG')[0];
	if (img == null) return false;
	var canvas = document.getElementById('product_image_display');
	if (canvas == null) return false;
	canvas.src = img.src
	return false;
}

function video(url) {
	var winWidth = 500;
	var winHeight = 350;
   	var left = Math.floor( (screen.width - winWidth) / 2);
    var top = Math.floor( (screen.height - winHeight) / 2);
	var g = window.open(url,'VideoWindow',"scrollbars=no,resizable=yes,width="+winWidth+",height="+winHeight+",left="+left+",top="+top);
	g.focus();
	return false;
}

function cvv_win() {
	var thewin = window.open("/cart/cvv/","cvv","height=450,width=550,toolbar=no,statusbar=no,scrollbars=yes");
	thewin.focus();
	return false;
}
//popup window for viewing image
function showPicture(imageName) {
    var img = new Image();
    img.src = imageName;
    if (img.complete) {
        showPictureProceed(imageName,img.width,img.height);
    } else {
        img.onload = function () { eval('showPictureProceed("'+imageName+'",'+img.width+','+img.height+')'); }
    }
}

function showPictureProceed(imageName,imageWidth,imageHeight) {

   	var left = Math.floor( (screen.width - imageWidth) / 2);
    var top = Math.floor( (screen.height - imageHeight) / 2);
	newWindow = window.open("","imageWindow","scrollbars=0,width="+(imageWidth+20)+",height="+(imageHeight+20)+",left="+left+",top="+top);
	newWindow.document.open();
	newWindow.document.write('<html><title></title>');
	newWindow.document.write('<head>');
	//newWindow.document.write('<link rel="stylesheet" type="text/css" href="/css/screen.css" media="screen,print,handheld" />');
	newWindow.document.write('<style>body { background-color: #fff; }</style>');
	newWindow.document.write('</head>');
	newWindow.document.write('<body style="background: #fff; margin: 10px;">');
	//newWindow.document.write('<center><p class="strong"><br />'+caption+'</p>');
	newWindow.document.write('<img src="'+imageName+'" alt="'+imageName+'" ></center>');
	newWindow.document.write('</body></html>');
	newWindow.document.close();
	newWindow.focus();
	newWindow.onblur = function() { newWindow.close(); };
}

function preload(imgObj,imgSrc) {
	if (document.images) {
		eval(imgObj+' = new Image()');
		eval(imgObj+'.src = "'+imgSrc+'"');
	}
}

function changeImages() {
  if (document.images) {
    for (var i=0; i<changeImages.arguments.length; i+=2) {
	  document[changeImages.arguments[i]].src = eval(changeImages.arguments[i+1] + ".src");
    }
  }
}

Event.observe(window,'load',function() {
    // this makes sure the content in the left-main table-row is at max for IE
    if (Prototype.Browser.IE && $('main-table') && $('left-main')) {
        var c = Element.getHeight($('main-table'));
        Element.setStyle($('left-main'), {height: c+'px'});

        var h = 0;
        if ($('left-banner')) h += Element.getHeight($('left-banner'));
        if ($('left-video')) h += Element.getHeight($('left-video'));
        Element.setStyle($('left-main'), {height: (c-h)+'px'});
    }
});
