function popIt(width, height, scrollbars){ 
	if(!width) width = "335";
	if(!height) height = "460";
	var windowString = 'width=' + width + ',height=' + height + ',resizable=1,statusbar=0,toolbar=0,location=0,scrollbars=' + scrollbars + ',scrolling=auto';
	var popItWindow = window.open('',"popIt", windowString);
	return false;
}

function abbreviateDescription(description, endMarker, paragraphCount) {
	if(!endMarker) endMarker = "<br><br>";
	if(!paragraphCount) paragraphCount = 1;
	description = String(description);
	var searchText = description.toLowerCase();
	var firstParagraphEnd = 0;
	var tempEnd;
	for(var i=0;i<paragraphCount;i++) {
		tempEnd = searchText.indexOf(endMarker);
		if(tempEnd > -1) {
			firstParagraphEnd += tempEnd;
			searchText = searchText.substring(firstParagraphEnd += endMarker.length, searchText.length);
		}
	}
	if(firstParagraphEnd <= 0) firstParagraphEnd = description.length;
	else firstParagraphEnd -= endMarker.length; 
	description = description.substring(0, firstParagraphEnd);
	return description;
}

function showFullDescription() {
	document.getElementById("pageDescription").innerHTML = description;
	return false;
}

function trim (str) {
	str = String(str);
	return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

function popUpImage(img, name, wid, hi, autoSize){
	features = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,scrolling=yes,resizable=yes,width=" + wid + ",height=" + hi;
	dlg = window.open ("","Details",features);
	dlg.document.write('<html><head>');
	dlg.document.write('<title>' + name + ' Zoom</title>');
	dlg.document.write('<script>');
	dlg.document.write('function autoSizeWhenReady() {');
	dlg.document.write('if(document.images[0].complete) {');
	dlg.document.write(' autoSize();');
	dlg.document.write('}');
	dlg.document.write('else setTimeout(autoSizeWhenReady(), 500);');
	dlg.document.write('}');
	dlg.document.write('function autoSize() {');
	dlg.document.write('var width=document.images[0].width + 100;');
	dlg.document.write('var height=document.images[0].height + 100;');
	dlg.document.write('if(height > screen.availHeight ) height = screen.availHeight  - 100;');
	dlg.document.write('window.resizeTo(width, height);');
	dlg.document.write('}');
	dlg.document.write('</script>');
	dlg.document.write('</head>');
	dlg.document.write('<body bgcolor=white onload="self.focus();');
	if(autoSize == true && !browserIsSafari()) dlg.document.write('autoSizeWhenReady();');
	dlg.document.write('">');
	dlg.document.write('<table border="0" width="100%">');
	dlg.document.write('<tr><td align=center valign=top>');
	dlg.document.write('<a href=# onClick=window.close();>');
	dlg.document.write('<img src=' + img + ' border=0 alt="Click Image to Close">');
	dlg.document.write('<br>');
	dlg.document.write('<font face="arial" size="2">Click to Close</font>')
	dlg.document.write('</a></td></tr>');
	dlg.document.write('</table>');
	dlg.document.write('</body></html>');
	dlg.document.close();
}

var currentImage = "standard";
function swapCurrentImage() {
	if(currentImage == "standard") currentImage = "inset";
	else currentImage = "standard";

	if(browserIsSafari()) {
	
		//**** TEMP *****
		document.getElementById("currentImage").src = "/lib/duematernity/spacer.gif";
		document.getElementById("currentImage").alt = productImages[currentImage].title;
		document.getElementById("currentImage").src = productImages[currentImage].url;
		
		//**** SAFARI FIX REQUIRES JS FILE IN SAME DOMAIN ****		
		//document.getElementById("imageBuffer").src = productImages[currentImage].url;
		//document.getElementById("imageBuffer").alt = productImages[currentImage].title;
		//document.getElementById("currentImageDiv").innerHTML = document.getElementById("imageBufferDiv").innerHTML;
	
	} else {
		document.getElementById("currentImage").src = productImages[currentImage].url;
		document.getElementById("currentImage").alt = productImages[currentImage].title;
	}
}

function zoomCurrentImage() {
	var windowWidth = 500;
	var windowHeight = screen.availHeight - 100;
	popUpImage(productImages[currentImage].zoomUrl, productImages[currentImage].title, windowWidth, windowHeight, false);
}

function browserIsSafari() {
	var userAgent = navigator.userAgent.toLowerCase();
	if(userAgent.indexOf("safari") > -1) return true;
	else return false;
}

function jumpToUrl(url) {
	if(url != "" && String(url) != "undefined") {
		location = url;
	}
	return false;
}