/////////////////////////////////////////////////
//////// pop up window for detail images ////////
/////////////////////////////////////////////////
var newWin = null;
//function popup(url,name,h,w,toolbar,location,directories,status,menubar,scrollbars,resizable)
function popup(url)
{
	try
	{
		var w_name = "pics"
		var w_width = 350
		var w_height = 250
		var LeftPos = (screen.width) ? (screen.width-w_width)/2 : 0;
		var TopPos = (screen.height) ? (screen.height-w_height)/2 : 0;
		var settings = 'height='+w_height+',width='+w_width+',top='+TopPos+',left='+LeftPos+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes'
		
		newWin = window.open(url,w_name,settings);
		newWin.focus();
	}
	catch(err)
	{
		var txt = ""
		txt += "There was an error on this page.\n\n";
		txt += "Error description: " + err.description + "\n\n";
		txt += "Click OK to continue.\n\n";
		alert(txt);
	}
}

/////////////////////////////////////////////
//////// resize pop up window onload ////////
/////////////////////////////////////////////
function resize_window(img_src)
{
	//var image = new Image();
	//image.onload = function() {
	  	
		var img = document.getElementById('img_detail');
		var i_height = img.offsetHeight;
		var i_width = img.offsetWidth;
		var r_width = i_width + 150;
		var r_height = i_height + 225;
		window.resizeTo(r_width,r_height);
	
		var LeftPos = (screen.width) ? (screen.width-r_width)/2 : 0;
		var TopPos = (screen.height) ? (screen.height-r_height)/2 : 0;
		
		window.moveTo(LeftPos,TopPos)
	//};
	//image.src = img_src;
	
	
}


////////////////////////////////////////////////////////////////
//////// resize detail image to fit product detail page ////////
////////////////////////////////////////////////////////////////
function resize_img_detail(newPhoto)
{
	//resize image to make sure it fits in space allotted for it on product detail page.
	
	//document.getElementById("detail_img_holder").innerHTML = "<img src=\"/images/page_elements/loading.gif\" />"
	
	//document.getElementById("dimg").style.display = "block";
	var img = document.getElementById('img_detail');
	var height = img.offsetHeight;
	var width = img.offsetWidth;
	var newx = 275; // set to whatever you want the images max width to be.
	var newy = 275; // whatever you want the images maximum height to be.
	if(width >= height)
	{
		// landscape
		var tmpy = height * newx / width;
		if(tmpy <= newy)
		{
			newy = tmpy;
		}
		else
		{
			newx = width * newy / height;
		}
	}
	else
	{
		// portrait
		var tmpx = width * newy / height;
		if (tmpx <= newx)
		{
			newx = tmpx;
		}
		else
		{
			newy = height * newx / width;
		}
	}
	img.width = newx;
	img.height = newy;
	
	//document.getElementById("img_detail").style.display = "block";
	
	//alert(newx + " - " + newy)
	//alert(Math.round(newx) + " - " + Math.round(newy))
}


function enlarge_img(img_src)
{
	// enlarge the image and center it on screen
	var str = ""
	var div_img_enlarge = document.getElementById("img_enlarge")
	var screen_width = screen.availWidth
	var screen_height = screen.availHeight
	var image = new Image();
	
	image.onload = function() {
	  
		str += "<div style=\"text-align:right;padding:4px;background:#000;color:#fff;\"><a href=\"javascript:void(0);\" onclick=\"javascript:document.getElementById('img_enlarge').style.display='none';\" style=\"color:#ffffff;\">Close</a></div>"
		str += "<a href=\"javascript:void(0);\" onclick=\"javascript:document.getElementById('img_enlarge').style.display='none';\">"
		str += "<img id=\"img_loaded\" src=\""+img_src+"\" style=\"border:none;\" />"
		str += "</a>"
		str += "<div style=\"text-align:right;padding:4px;background:#000;color:#fff;\"><a href=\"javascript:void(0);\" onclick=\"javascript:document.getElementById('img_enlarge').style.display='none';\" style=\"color:#ffffff;\">Close</a></div>"
		
		div_img_enlarge.style.display = "block";
		div_img_enlarge.innerHTML = str;
		
		var img = document.getElementById('img_loaded');
		var img_height = img.offsetHeight;
		var img_width = img.offsetWidth;
		
		var div_top = 50
		//var div_top = Math.round((screen_height - img_height) / 2)
		var div_left = Math.round((screen_width - img_width) / 2)
		
		div_img_enlarge.style.position = "absolute";
		div_img_enlarge.style.top = div_top + "px"
		div_img_enlarge.style.left = div_left + "px"
	};
	image.src = img_src;
}

