// browser detection
var firefox = navigator.userAgent.indexOf("Firefox") != -1
var explorer = navigator.userAgent.indexOf("MSIE") != -1
var explorer7 = navigator.userAgent.indexOf("MSIE 7.0") != -1
var netscape = navigator.userAgent.indexOf("Netscape") != -1
var safari = navigator.userAgent.indexOf("Safari") != -1
var opera = navigator.userAgent.indexOf("Opera") != -1
var camino = navigator.userAgent.indexOf("Camino") != -1
var macintosh = navigator.platform.indexOf("Mac") != -1

// fix for transparent .png on IE6
function correctPNG() {
	for(var i=0; i<document.images.length; i++) {
		var img = document.images[i]
		var imgName = img.src.toUpperCase()
		if (imgName.substring(imgName.length-3, imgName.length) == "PNG") {
			//alert(img.src)
			var imgID = (img.id) ? "id='" + img.id + "' " : ""
			var imgClass = (img.className) ? "class='" + img.className + "' " : ""
			var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
			var imgStyle = "display:block;" + img.style.cssText 
			if (img.align == "left") imgStyle = "float:left;" + imgStyle
			if (img.align == "right") imgStyle = "float:right;" + imgStyle
			if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
			var strNewHTML = "<span class=\"pngFix\" " + imgID + imgClass + imgTitle
			+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
			+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
			img.outerHTML = strNewHTML
			i = i-1
		}
	}
}
if (explorer && !explorer7) {
	window.attachEvent("onload", correctPNG);
}

// embed a flash file
function insertFlash(path, id, width, height, flashvars, description, parent) {
	document.write('<object width="' + width + '" height="' + height + '" id="' + id + '" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0">\n');
	document.write('<![CDATA[<p>' + description + '</p>]]>\n');
	document.write('<param name="allowScriptAccess" value="always" />\n');
	document.write('<param name="movie" value="' + path + '" />\n');
	document.write('<param name="menu" value="false" />\n');
	document.write('<param name="allowFullScreen" value="true" />\n');
	document.write('<param name="flashvars" value="' + flashvars + '">\n');
	document.write('<param name="quality" value="high" />\n');
	document.write('<param name="scale" value="noscale" />\n');
	document.write('<param name="bgcolor" value="transparent" />\n');
	document.write('<param name="wmode" value="transparent" />\n');
	document.write('<embed width="' + width + '" height="' + height + '" name="' + id + '" src="' + path + '" flashvars="' + flashvars + '" wmode="transparent" menu="false" quality="high" scale="noscale" allowFullScreen="true" bgcolor="transparent" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>\n');
}

// images rollover (3 states: of, on, in)
function changeImage(which) { 
	var sr = $(which);
	var st = sr.src.substring(sr.src.length -6,sr.src.length -4);
	var e = sr.src.substring(sr.src.length -3,sr.src.length);
	if (st == 'of') sr.src = sr.src.substring(sr.src.length -6,0)+'on.'+e;
	else if (st == 'on') sr.src = sr.src.substring(sr.src.length -6,0)+'of.'+e;
}

// change an iframe's src
function changeFrame(frameId, url) {
	var oIframe = document.getElementById([frameId]);
	oIframe.src = url;
}

// put an image over sifr elements
function getPositionObject(obj) {
	var obj = $(obj);
	var o = function(){var curtop = 0; var curleft = 0;};
	o.curleft = 0;
	o.curtop = 0;
	if (obj.offsetParent) {
		o.curleft = obj.offsetLeft
		o.curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			o.curleft += obj.offsetLeft
			o.curtop += obj.offsetTop
		}
	}
	return o;
}

function createDiv(itm) {
	if (!explorer) {
		var itm = $(itm).id;
		var e = $('container');
		var p = getPositionObject(itm); 
		var d = Element.getDimensions(itm);
		var w = d.width+'px'; var h = d.height+'px';
		var l = p.curleft+'px'; var t = p.curtop+'px';
		var lnk = $(itm+'_alternate').select('a');
		if(lnk != "") { var img = '<a href="'+lnk+'"><img src="/store/images/common/spacer.gif" style="position:relative; width:'+w+'; height:'+h+'; border:solid 0px #666;" /></a>'; }
		else {var img = '<img src="/store/images/common/spacer.gif" style="position:relative; width:'+w+'; height:'+h+'; border:solid 0px #666;" />'; }
		Insertion.Top(e,'<div style="position:absolute; left:'+l+'; top:'+t+'; width:'+w+'; height:'+h+'; z-index:100000;">'+img+'</div>');
	}
}

// hide the search tips over the textbox in the header and set the focus on the textbox
function searchBox() {
	$('examples').hide();
	$('txt_searchBox').focus();
}

// hide and show the lightbox
function lightBox(url, title) {
	var lbPos = (document.viewport.getDimensions().height / 2).ceil() + document.viewport.getScrollOffsets().top - 340 + 'px';
	$('lb_player').setStyle({'top':lbPos});
	if ($('lb_background').visible()) {
		top.changeFrame('moviePlayer', '/store/html/emptyLB.html');
		$('lb_title').innerHTML = '';
		Effect.Fade('lb_player', {duration:0.5, from:1, to:0, queue: {position:'end', scope:'lightbox', limit:2}});
		Effect.Fade('lb_background', {duration:1.0, from:0.92, to:0, queue: {position:'end', scope:'lightbox', limit:2}});
		
		if (explorer){
			var selList = $$('select');
			for(i=0;i<selList.length;i++){
				mySel = selList[i];
				mySel.show();
			}
		}
		
		
	}
	else {
		//alert(lbPos);
		var url = url.replace(/&amp;/g,'&');
		top.changeFrame('moviePlayer', url);
		$('lb_title').innerHTML = title;
		Effect.Appear('lb_background', {duration:1.0, from:0, to:0.92, queue: {position:'end', scope:'lightbox', limit:2}});
		Effect.Appear('lb_player', {duration:0.5, from:0, to:1, queue: {position:'end', scope:'lightbox', limit:2}});
		if (explorer){
			var selList = $$('select');
			for(i=0;i<selList.length;i++){
				mySel = selList[i];
				mySel.hide();
			}
		}
	}
}

// hide and show the lightbox
function openLightbox3(whichLB, url, title) {
	var lbPos = (document.viewport.getDimensions().height / 2).ceil() + document.viewport.getScrollOffsets().top - 340 + 'px';
	var playerL = $$('#' + whichLB  + " .player");
	playerL[0].setStyle({'top':lbPos});
	top.changeFrame('loginBox2', url);
	$('lb_loginTitle2').innerHTML = title;
	var th = $('container').getHeight() + 'px';
	$('lb_background2').setStyle({'height':th});
	
	$(whichLB).setStyle({'display':'block'});
	
	if (explorer){
		var selList = $$('select');
		for(i=0;i<selList.length;i++){
			mySel = selList[i];
			mySel.hide();
		}
	}
	
	
}


function closeLightboxIframe(whichLB){
	top.document.getElementById(whichLB).hide();
	top.changeFrame('loginBox2', '/store/html/emptyLB.html');
	
}

function closeLightbox3(whichLB){
	$(whichLB).setStyle({'display':'none'});
	top.changeFrame('loginBox2', '/store/html/emptyLB.html');
	if (explorer){
		var selList = $$('select');
		for(i=0;i<selList.length;i++){
			mySel = selList[i];
			mySel.show();
		}
	}
}

function lightBoxLogin(url, title) {
	var lbPos = (document.viewport.getDimensions().height / 2).ceil() + document.viewport.getScrollOffsets().top - 340 + 'px';
	$('lb_login').setStyle({'top':lbPos});
	if ($('lb_loginBackground').visible()) {
		//top.changeFrame('loginBox', '/store/html/emptyLB.html');
		$('lb_loginTitle').innerHTML = '';
		// location.reload(true);
		Effect.Fade('lb_login', {duration:0.5, from:1, to:0, queue: {position:'end', scope:'lightboxLogin', limit:2}});
		Effect.Fade('lb_loginBackground', {duration:0.5, from:0.92, to:0, queue: {position:'end', scope:'lightboxLogin', limit:2}});
		//to show select
		if (explorer){
			var selList = $$('select');
			for(i=0;i<selList.length;i++){
				mySel = selList[i];
				mySel.show();
			}
		}
	}
	else {
		top.changeFrame('loginBox', url);
		$('lb_loginTitle').innerHTML = title;
		Effect.Appear('lb_loginBackground', {duration:0.5, from:0, to:0.92, queue: {position:'end', scope:'lightboxLogin', limit:2}});
		Effect.Appear('lb_login', {duration:0.5, from:0, to:1, queue: {position:'end', scope:'lightboxLogin', limit:2}});
		//to hide select
		if (explorer){
			var selList = $$('select');
			for(i=0;i<selList.length;i++){
				mySel = selList[i];
				mySel.hide();
			}
		}
	}
}


function lightBoxCart(url, title) {
  // add lightboxCart to the class for the light box login container
  $('lbLogin').addClassName('lightboxCart');

  // create light box
  return lightBoxLogin(url, title);
}

function closeLightbox(whichLightbox){
	Effect.Fade(whichLightbox, {duration:0.5, from:1, to:0, queue: {position:'end', scope:'lightboxLogin', limit:2}});
	Effect.Fade('lb_loginBackground', {duration:0.5, from:0.92, to:0, queue: {position:'end', scope:'lightboxLogin', limit:2}});
}

function postLightBoxLogin() {
	lightBoxLogin();
	location.href = location.href;
}

function postLightBoxCheckout() {
	lightBoxLogin();
	$('cart').submit();
}

function postShoppingCart() {
	lightBoxLogin();
	location.href = "/store/cart/shoppingCart.jsp";
}

function doRefresh() {
	document.billingForm.submit();
}

function doShippingRefresh() {
	document.shippingForm.submit();
}

function sifrLoad() {
	//sIFR.replace(imagoBook,{selector:'.content .right .cart p',transparent:'true',css:['.sIFR-root{color:#ffffff; font-size:17px; leading:0px;}, a{color:#ffffff; text-decoration:none;}, a:hover{color:#ffffff; text-decoration:underline;}'],onReplacement:function(obj){createDiv(this);}});
	//sIFR.replace(imagoMed,{selector:'.content .right .context p.title',transparent:'true',css:['.sIFR-root{color:#747474; font-size:14px; leading:0px;},a{color:#747474; text-decoration:none;},a:hover{color:#747474; text-decoration:underline;}'],onReplacement:function(obj){createDiv(this);}});
	//sIFR.replace(imagoBook,{selector:'.content .right .context .infos p',transparent:'true',css:['.sIFR-root{color:#747474; font-size:14px; leading:0px;},a{color:#747474; text-decoration:none;},a:hover{color:#747474; text-decoration:underline;}'],onReplacement:function(obj){createDiv(this);}});
}

function popUp(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,width=800,height=600,left = 440,top = 225');");
}