// +----------------------------------+
// | Product namespace                |
// | Copyright (C) 2007 Craig Manley  |
// +----------------------------------+
// $Id: Product.js,v 1.10 2011-12-18 14:13:03 cmanley Exp $

// Make sure the required scripts are loaded.
// /js/i18n/??.js (Strings object)
// overlib


/***
 * Product namespace.
 */
var Product = new (function() {
	this.showLegend = function () {
		var html = [
				'<table cellpadding="3" cellspacing="0">',
    			' <tr>',
    	 		'  <th valign="top" align="center"><img src="/img/icons/new.gif" width="16" height="16" alt="" /><' + '/th>',
    	 		'  <td valign="top">:<' + '/td>',
    	 		'  <td valign="top">' + Strings['legend_new'] + '<' + '/td>',
    			' <' + '/tr>',
				' <tr>',
    	 		'  <th valign="top" align="center"><img src="/img/icons/stock_y.gif" width="11" height="11" alt="" /><' + '/th>',
    	 		'  <td valign="top">:<' + '/td>',
    	 		'  <td valign="top">' + Strings['legend_stock_y'] + '<' + '/td>',
    			' <' + '/tr>',
				' <tr>',
    	 		'  <th valign="top" align="center"><img src="/img/icons/stock_n.gif" width="11" height="11" alt="" /><' + '/th>',
    	 		'  <td valign="top">:<' + '/td>',
    	 		'  <td valign="top">' + Strings['legend_stock_n'] + '<' + '/td>',
    			' <' + '/tr>',
    	    	' <tr>',
				'  <th valign="top" align="center"><img src="/img/icons/limited.gif" width="12" height="16" alt="" /><' + '/th>',
				'  <td valign="top">:<' + '/td>',
				'  <td valign="top">' + Strings['legend_limited'] + '<' + '/td>',
				' <' + '/tr>',
				' <tr>',
				'  <th valign="top" align="center"><img src="/img/icons/photo.gif" width="16" height="16" alt="" /><' + '/th>',
				'  <td valign="top">:<' + '/td>',
				'  <td valign="top">' + Strings['legend_photo'] + '<' + '/td>',
				' <' + '/tr>',
				' <tr>',
				'  <th valign="top" align="center"><img src="/img/icons/i.gif" width="12" height="12" alt="" /><' + '/th>',
				'  <td valign="top">:<' + '/td>',
				'  <td valign="top">' + Strings['legend_info'] + '<' + '/td>',
				' <' + '/tr>',
				' <tr>',
				'  <th valign="top" align="center"><img src="/img/addToCart.gif" width="24" height="16" alt="" /><' + '/th>',
				'  <td valign="top">:<' + '/td>',
				'  <td valign="top">' + Strings['legend_addToCart'] + '<' + '/td>',
				' <' + '/tr>',
				'<' + '/table>'
		];
		overlib(html.join("\n"), CAPTION,  Strings['legend_caption'], BGCOLOR, '#0066ff', FGCOLOR,'#EEF7F4', BORDER, 2, WIDTH, 400, HAUTO, VAUTO, SHADOW);
	};

	this.showPhoto = function(code, dims) {
		//Photo art.nr
	  	if (!dims.match(/^(\d+)x(\d+)$/)) {
	  		return false;
	  	}
	  	var w = parseInt(RegExp.$1);
	  	var h = parseInt(RegExp.$2);
	  	var uri = '/photos/' + code.substr(code.length - 2) + '/' + code + '.jpg';
		var html = [
			'<div style="text-align: center">',
	    	' <img src="' + uri + '" width="' + w + '" height="' + h + '" alt="" />',
			'<' + '/div>'
		];
		//OFFSETY, parseInt(-h/2),
		overlib(html.join("\n"), CAPTION, Strings['photo_caption'] + ' ' + code, BGCOLOR, '#0066ff', FGCOLOR,'#EEF7F4', BORDER, 2, HAUTO, VAUTO, WIDTH, w + 10, HEIGHT, h, SHADOW);
		return false;
	};

	this.showInfo = function(code) {
		var url = '/dialogs/productInfo.php?code=' + escape(code);
		if (Site.language != 'nl') {
			url = '/' + Site.language + url;
		}
		var width  = 600;
		var height = 400;
		var ua_chrome_2 = navigator.userAgent.indexOf(' Chrome/2.0') > -1; // Chrome 2.0's support of window.showModalDialog is broken: http://code.google.com/p/chromium/issues/detail?id=4202
		if (window.showModelessDialog && !ua_chrome_2) {
			window.showModelessDialog(url, {}, 'dialogWidth: ' + width + 'px; dialogHeight: ' + height + 'px; center: 1; resizable: 1; status: 0; unadorned: 1');
		}
		else if (window.showModalDialog && !ua_chrome_2) {
			window.showModalDialog(url, {}, 'dialogWidth: ' + width + 'px; dialogHeight: ' + height + 'px; center: 1; resizable: 1; status: 0; unadorned: 1');
		}
		else {
			/*
			screenX,screenY
			*/
			var left   = (screen.width  - width)/2;
			var top    = (screen.height - height)/2;
			window.open(url, 'productInfo', 'left=' + left + ',top=' + top + ',width=' + width + ',height=' + height + ',scrollbars=1,resizable=1,alwaysRaised=1;status=0');
		}
	 	return false;
	};

})();

