var multipleoptions = false;
var optionselection = false;
var price = 0.00;
var currency_symbol = "&euro;";
var currency_decimal_symbol = ".";
var currency_thousands_separator= ",";
var popups = new Array();

function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+currency_thousands_separator+
	num.substring(num.length-(4*i+3));
	
	return (((sign)?'':'-') + currency_symbol + ' ' + num + currency_decimal_symbol + cents);
}

function updatePrice () {
	if (optionselection) {
		if (multipleoptions) {
			var currentprice = price;
			
			for (var i=0; i < optionselection.length; i++) {
				if (!isNaN(parseFloat(optionselection[i].options[optionselection[i].selectedIndex].getAttribute('price'))))
					currentprice += parseFloat(optionselection[i].options[optionselection[i].selectedIndex].getAttribute('price'));
			}
			document.getElementById('price').innerHTML = formatCurrency(currentprice);
		} else {
			var currentprice = price;
			if (!isNaN( parseFloat(optionselection.options[optionselection.selectedIndex].getAttribute('price'))))
				currentprice +=  parseFloat(optionselection.options[optionselection.selectedIndex].getAttribute('price'));
			document.getElementById('price').innerHTML = formatCurrency(currentprice);
		}
	}
}

/* ------------------ */

function swapImage (imgObject) {
	if (imgObject && imgObject.tagName.toLowerCase()=="img") {
		if (imgObject.getAttribute('overSrc')) {
			
			if (!imgObject.getAttribute('originalSrc'))
				imgObject.setAttribute('originalSrc', imgObject.src);
				
			imgObject.src=imgObject.getAttribute('overSrc');
		}
	}
}

function restoreImage (imgObject) {
	if (imgObject && imgObject.tagName.toLowerCase()=="img") {
		if (imgObject.getAttribute('originalSrc')) {
			imgObject.src=imgObject.getAttribute('originalSrc');
		}
	}
}
	
function preloadImages () {
	if (!document.getElementById) return;
  
	var items = document.getElementsByTagName('img');
	var images=new Array();
	
	for (var i=0; i<items.length; i++) {
		if (items[i].getAttribute('overSrc')) { 
			images[i]=new Image; 
			images[i].src=items[i].getAttribute('overSrc');
		}
	}
}

function openPopup (url, windowname,width, height) {
	
	var isNN=(navigator.appName=="Netscape") ? 1:0;
	var isIE=(navigator.appName.indexOf("Microsoft")!=-1) ? 1:0;
	
	if (!popups[windowname]) {
		if (isNN) {
			popups[windowname] = window.open(url,windowname ,'scrollbars=no,menubar=no,innerHeight='+height+',innerWidth='+width+',resizable=no,toolbar=no,location=no,status=no');
		} else {
			popups[windowname] = window.open(url,windowname ,'scrollbars=no,menubar=no,height='+height+',width='+width+',resizable=no,toolbar=no,location=no,status=no');
		}
	}
	
	//if (window.focus)
		popups[windowname].focus();
}

function trim (str) {
    return (str.replace(/\s+$/,"").replace(/^\s+/,""));
}


function preloadScreenshotImages () {
	var i=0; var images = new Array();
	
	for (var j=0; j<screenshot_images.length; j++) {
		if (screenshot_images[j].src) { 
			i=i++;
			images[i]=new Image; 
			images[i].src=screenshot_images[j].src;
		}
	}
}

function setScreenshotControl () {
	
	if (document.getElementById("navigation_next")) {
		if (screenshot_images[current_image_index+1]) {
			document.getElementById("navigation_next").style.visibility="visible";
		} else {
			document.getElementById("navigation_next").style.visibility="hidden";
		}
	}
	
	if (document.getElementById("navigation_prev")) {
		if (screenshot_images[current_image_index-1]) {
			document.getElementById("navigation_prev").style.visibility="visible";
		} else {
			document.getElementById("navigation_prev").style.visibility="hidden";
		}
	}
}

function nextScreenshotImage () {
	if ( screenshot_images[current_image_index+1])
		current_image_index++;
	else
		current_image_index=0;
		
	setScreenshotImage(current_image_index);
}

function prevScreenshotImage () {
	if ( screenshot_images[current_image_index-1])
		current_image_index--;
	else
		current_image_index = screenshot_images.length-1
	
	setScreenshotImage(current_image_index);
}

function setScreenshotImage(image_id) {
	
	current_image_index=parseInt(image_id);
	
	if (document.getElementById("screenshotimage")) {
		var imageobject = document.getElementById("screenshotimage")
		imageobject.src = screenshot_images[image_id].src;
		imageobject.width = screenshot_images[image_id].width;
		imageobject.height = screenshot_images[image_id].height;
	}
	
	if (document.getElementById("selectImagePreview")) {
		document.getElementById("selectImagePreview").value=image_id;
	}
	
	//setScreenshotControl();
}