$(document).ready(function() {
	$('a[rel=external]').each(function() {
		this.target = '_blank';
	});
});

var productImageToUrlMapping = {};

function addProductImage(product, perspective, size, color, url) {
	var productToPerspectiveMap = productImageToUrlMapping;

	if (! productToPerspectiveMap[product]) productToPerspectiveMap[product] = {};
	var perspectiveToSizeMap = productToPerspectiveMap[product];

	if (! perspectiveToSizeMap[perspective]) perspectiveToSizeMap[perspective] = {};
	var sizeToColorMap = perspectiveToSizeMap[perspective];

	if (! sizeToColorMap[size]) sizeToColorMap[size] = {};
	var colorToUrlMap = sizeToColorMap[size];

	var imageObj = {
		url: url
	};

	colorToUrlMap[color] = imageObj;
}

function getProductImageUrl(product, perspective, size, color)
{
	if (! perspective) perspective = getFirstKeyFromMap(productImageToUrlMapping[product]);
	if (! size) size = getFirstKeyFromMap(productImageToUrlMapping[product][perspective]);
	if (! color) color = getFirstKeyFromMap(productImageToUrlMapping[product][perspective][size]);

	return productImageToUrlMapping[product][perspective][size][color].url;
}

function getFirstKeyFromMap(map) {
	for (key in map) {
		return key;
	}
}


function launchHelp(newURL, newFeatures)
{
	launchHelpInShop(newURL, newFeatures);
}

function launchHelpInShop(newURL, newFeatures)
{
	if (window.HelpWindow) HelpWindow.close();
	HelpWindow = open(newURL, "HelpWindow", newFeatures + ",screenX=0,left=0,screenY=0,top=0,channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=0,status=0,toolbar=0,scroll=1");
	if (HelpWindow.opener == null) HelpWindow.opener = window;
	HelpWindow.focus();
}
