/* Note functions here use MooTools. Be sure it's included! */

function preloadImages(path) {
	var kFilenames = ['raspberry.jpg', 'lime.jpg', 'giraffe.jpg', 'charcoal_damask.jpg', 'ocean_damask.jpg', 'charcoal_diamondweave.jpg', 'black.jpg', 'olive.jpg', 'ocean.jpg', 'modern_chain.jpg', 'pink.jpg', 'navy.jpg', 'circles_kelly_green.jpg', 'giraffe_pink_trim.jpg', 'avian_coral.jpg', 'stripes_sky.jpg', 'ribbons_candy.jpg'];
	kFilenames.each(function(filename) {
		var image = new Image();
		image.src = '/skin/frontend/default/neela/images/products/' + path + '/thumbnail/' + filename;
	});
}

function setColorTooltip(text, productName, imageName, swatchID) {
	swatch = $(swatchID);
	// Set text of tooltip and update product image
	// (Commented out lines where used with MooTools before.)

	// $('tooltip').setHTML(text);
	$('tooltip').update(text);

	// $('product_shot').setProperty('src', '/skin/frontend/default/neela/images/products/' + productName + '/thumbnail/' + imageName);
	$('product_shot').src = '/skin/frontend/default/neela/images/products/' + productName + '/thumbnail/' + imageName;
	
	// Calculate width of tooltip to determine amount of offset
	// required so that the tooltip is centered under the swatch
	
	// var swatchWidth = swatch.getSize().size.x;
	var swatchWidth = swatch.getWidth();

	// var textWidth = $('tooltip').getSize().size.x;
	var textWidth = $('tooltip').getWidth();

	var offset = (swatchWidth - textWidth) / 2;
	
	// var leftValue = swatch.getLeft() + offset;
	var leftValue = Position.cumulativeOffset(swatch)[0] + offset;

	// $('color_tooltips').setStyle('left', leftValue + 'px');
	$('color_tooltips').setStyle({left: leftValue + 'px'});
}

function clearColorTooltip() {
	// Clear the text in the tooltip and reset the 
	// product image to a default one.
  	// $('tooltip').setHTML("&nbsp;");
	$('tooltip').update("&nbsp;");
}

function validateForm() {
	var color = $('color').getValue();
	if (color == '') {
		// User did not pick a color
		$("color_warning").setStyle("display", "block");
		return false;
	}
	return true;
}

var newwindow;
function poptastic(url)	{
	newwindow=window.open(url,'name','height=396,width=600');
	if (window.focus) {newwindow.focus()}
}
