/* Initialize any JQuery Accordions */
$(document).ready(function() { $(".menu").accordion({ collapsible: true, header: "dt", autoHeight: false, active: ".open"});});

function openProductDetail(productId){

	var height = 660;
	var width = 600;
	var left = Math.floor( (screen.width - width) / 2);
  	var top = Math.floor( (screen.height - height) / 2);
	 
	var detailWindow = window.open('','ProductImageLarge', 'top=' + top + ',left=' + left + ',width=' + width + ',height=' + height + ',status=no,menubar=no,location=no,toolbar=no,directories=no,scrollbars=no');
	
	detailWindow.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">');
	detailWindow.document.write('<html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>DoulaShop.com: Product Image</title>');
	detailWindow.document.write('<link href="http://cdn.doulashop.com/style/main.css" rel="stylesheet" type="text/css"></head>');
	detailWindow.document.write('<body class="enlargedimage"><img src="http://cdn.doulashop.com/images/products/large/');
	detailWindow.document.write(productId);
	detailWindow.document.write('.jpg" width="550" height="600" alt=""><p><a href="javascript:self.close()">Close This Window</a></p></body></html>');
	detailWindow.document.close();
	
	detailWindow.focus();
}

function openPopup(height, width, url){

	var left = Math.floor( (screen.width - width) / 2);
  	var top = Math.floor( (screen.height - height) / 2);
	 
	var detailWindow = window.open(url, '', 'top=' + top + ',left=' + left + ',width=' + width + ',height=' + height +',status=no,menubar=no,location=no,toolbar=no,directories=no,scrollbars=no');
	
	detailWindow.focus();
	
}

function toggleDiv( layerId ) {
	
	var style;
	
	if ( document.getElementById( layerId ) ){
		style = document.getElementById( layerId ).style;
	} else if ( document.all ) {
		style = document.all[ layerId ].style;
	} else if (document.layers) {
		style = document.layers[ layerId ].style;
	}
	
	style.display = style.display ? "":"block";
}

function showDiv( layerId ) {

	var style;
	
	if ( document.getElementById( layerId ) ){
		style = document.getElementById( layerId ).style;
	} else if ( document.all ) {
		style = document.all[ layerId ].style;			
	} else if (document.layers) {
		style = document.layers[ layerId ].style;
	}
	
	style.display = "block";
}

function showBigSwatches() {
	showDiv('bigswatches');
}

function setBigSwatch( url ) {
	if (document.images.bigswatch){
		document.images.bigswatch.src = url;
	}
}

function runSlideShow() {
	if (document.all) {
		document.images.SlideShow.style.filter="blendTrans(duration=2)";
		document.images.SlideShow.filters.blendTrans.Apply();
	}
	document.images.SlideShow.src = preLoad[j].src;
	if (document.all) {
		document.images.SlideShow.filters.blendTrans.Play();
	}
	
	j = j + 1;
	if (j > (p - 1)) j = 0;
	setTimeout('runSlideShow()', 5000);
}


function pause(millis) {
	var date = new Date();
	var curDate = null;
	do { curDate = new Date(); } while(curDate-date < millis);
} 

function changeToBeta(theElement){
	
	var beginningText = theElement.href.substring(0,11);
	
	if ( beginningText == "http://www." ){
		//theElement.href = "http://beta." + theElement.href.substring(11);
	}
}

function showCheapShipping(weight){
	if (weight < 1){ toggleDiv('cheapshipping'); }
}

function putSpanAroundCents(priceSpan){
	
	var priceText = priceSpan.innerText + "";
	
	var dotspot = priceText.indexOf(".");
	
	if (dotspot == -1){ return; }
	
	priceSpan.innerText = priceText.substring(0,dotspot);
	
	spannode = document.createElement("span"); 
	spannode.setAttribute("class", "cents");
	spannode.innerText = priceText.substring(dotspot,dotspot + 3);
	
	priceSpan.appendChild( spannode );
}

function displayCents ( value ){
	value = Math.round( value*100 )/100;
	return ( value == Math.floor( value )) ? value + '.00' : ( (value * 10 == Math.floor( value * 10 )) ? value + '0' : value);
}

function writeYouSave( basePrice, salePrice ){
	
	if (basePrice.length < 1) { return; }
	if (isNaN(basePrice) || isNaN(salePrice)) { return; }

	basePrice -= 0;
	salePrice -= 0;
	
	var discount = basePrice - salePrice;
	
	var discountPercent = discount / basePrice * 100;
	
	document.write("<span class=\"price\">$" + displayCents(discount) + "</span> (" + Math.round(discountPercent) + "%)");
}

function writeStockStatus( yahooText ){

	if ((yahooText == "Usually ships the same business day")||(yahooText == "Usually ships the next business day")){
		document.write("In Stock, Ships Today");
	} else {
		document.write(yahooText);
	}
}

function initializeBoldChat() {

	try {
		var pageViewer = _bcvm.getPageViewer("7746757330145273614"); pageViewer.setParameter("WebsiteDefID", "1955238913888664788");
		pageViewer.setParameter("ChatWindowDefID", "4279435195046390697");
		pageViewer.setParameter("ChatWidth", "640");
		pageViewer.setParameter("ChatHeight", "480");
		pageViewer.setParameter("CallWidth", "480");
		pageViewer.setParameter("CallHeight", "360");
		pageViewer.setParameter("CallWindowDefID", "3738474055364478798");
		pageViewer.setParameter("InvitationDefID", "7558489404639720602");
		pageViewer.setParameter("WindowScheme", "https");
		pageViewer.pageViewed();
	} catch(error) {}
}
