// JavaScript Document
// MENU

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function setLyr(obj,lyr,addleft,addtop)
{
	
	var coors = findPos(obj);
	if (addleft != '') coors[0] += addleft;
	if (addtop != '') coors[1] += addtop;
	document.getElementById(lyr).style.display = 'block';
	var x = document.getElementById(lyr);
	x.style.top = (coors[1] + 1) + 'px';
	x.style.left = (coors[0] + 165) + 'px';
	//x.style.left = (coors[0] + 110) + 'px';
}

function popup_display_image($element,$src, $caption){
  setLyr(document.getElementById($element),'popup',-410,-62);
  document.getElementById('popup').style.display = 'block';
  document.getElementById('popup').innerHTML = '<p>'+$caption+'</p><img src="'+$src+'" />';
}

function popup_display_image2($element,$src, $caption){
  setLyr(document.getElementById($element),'popup',-960,-62);
  document.getElementById('popup').style.display = 'block';
  document.getElementById('popup').innerHTML = '<p>'+$caption+'</p><img src="'+$src+'" />';
}

function close_popup_display_image(){
	document.getElementById('popup').style.display = 'none';
}

function dollars(number) {
	decimal_points = 2;
	if(!decimal_points) return Math.round(number);
	if(number == 0) {
		var decimals = "";
		for(var i=0;i<decimal_points;i++) decimals += "0";
		return "0."+decimals;
	}

	var exponent = Math.pow(10,decimal_points);
	var num = Math.round((number * exponent)).toString();
	return num.slice(0,-1*decimal_points) + "." + num.slice(-1*decimal_points)
	}

function calculate_total_price($id,$p1,$p2,$p3,$p4){
		$total = 0;
	if ($p1 == 'true'){ $total += document.getElementById('value1'+$id).innerHTML * document.getElementById('price1_'+$id).value }
	if ($p2 == 'true'){ $total += document.getElementById('value2'+$id).innerHTML * document.getElementById('price2_'+$id).value}
	if ($p3 == 'true'){ $total += document.getElementById('value3'+$id).innerHTML * document.getElementById('price3_'+$id).value}
	if ($p4 == 'true'){ $total += document.getElementById('value4'+$id).innerHTML * document.getElementById('price4_'+$id).value}
	
	document.getElementById('totalprice'+$id).innerHTML = dollars($total);
	
}

