/*-------------------------------------------------------------------- 
 * JQuery Plugin: "EqualHeights" & "EqualWidths"
 * by:	Scott Jehl, Todd Parker, Maggie Costello Wachs (http://www.filamentgroup.com)
 *
 * Copyright (c) 2007 Filament Group
 * Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php)
 *
 * Description: Compares the heights or widths of the top-level children of a provided element 
 		and sets their min-height to the tallest height (or width to widest width). Sets in em units 
 		by default if pxToEm() method is available.
 * Dependencies: jQuery library, pxToEm method	(article: http://www.filamentgroup.com/lab/retaining_scalable_interfaces_with_pixel_to_em_conversion/)							  
 * Usage Example: $(element).equalHeights();
   						      Optional: to set min-height in px, pass a true argument: $(element).equalHeights(true);
 * Version: 2.0, 07.24.2008
 * Changelog:
 *  08.02.2007 initial Version 1.0
 *  07.24.2008 v 2.0 - added support for widths
--------------------------------------------------------------------*/

$.fn.equalHeights = function(px) {
	var currentTallest = 0;
	$(this).each(function(i){
		if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
	});
	// for ie6, set height since min-height isn't supported
	if ($.browser.msie && $.browser.version == 6.0) { $(this).css({'height': currentTallest}); }
	$(this).css({'height': currentTallest}); 
	return this;
};

function addRow() {
	var id = $(".row").size();
	$("#product_list").append("<div id=\"product-" + id + "\" class=\"row\"><input type=\"text\" name=\"product_num[]\" class=\"product_num indent\"/>&nbsp;<input type=\"text\" name=\"product_name[]\" class=\"product_name\"/>&nbsp;<input type=\"text\" name=\"product_qty[]\" class=\"product_qty\"/>&nbsp;<input type=\"text\" name=\"product_lb[]\" class=\"product_lb\"/>&nbsp;<input type=\"text\" name=\"product_gal[]\" class=\"product_gal\"/>&nbsp;<input type=\"text\" name=\"product_price[]\" class=\"product_price\"/></div>\n");
}

function calcFields() {	
	var product_num = document.getElementsByName('product_num[]');
	var product_name = document.getElementsByName('product_name[]');
	var product_qty = document.getElementsByName('product_qty[]');
	var product_lb = document.getElementsByName('product_lb[]');
	var product_gal = document.getElementsByName('product_gal[]');
	var product_price = document.getElementsByName('product_price[]');
	var product_hidden = document.getElementsByName('product_hidden')[0];

	var size = $(".row").size();
	var i;
	var count = 0;
	product_hidden.value = "<table width=500 border=1 cellpadding=3 cellspacing=0><tr><th>Product \#</th><th>Description</th><th>QTY</th><th>Lbs.</th><th>Gals</th><th>Quoted Price</th></tr>";
	
	for (i=0; i<size; i++) {
		if(product_num[i].value != '' || product_name[i].value != '') {
		product_hidden.value += "<tr><td>" + product_num[i].value + "</td><td>" + product_name[i].value + "</td><td>" + product_qty[i].value + "</td><td>" + product_lb[i].value + "</td><td>" + product_gal[i].value + "</td><td>" + product_price[i].value + "</td></tr>";
		count++;
		}		
	 }
	product_hidden.value += "</table>";
	 document.orderform.submit();
}

$(document).ready(function() {
	$(".homeentry").equalHeights();
	$(".pool-brands .intro").equalHeights();
	$("a[href^=http]").click(function(){ //find the links pointing to a URL
		if(this.href.indexOf(location.hostname) == -1) {  //check if they point outside
			window.open( $(this).attr('href') ); //force open the new window
		    return false;
		}
	});
	
	$("#pool-products .pool-categories a, #pool-products .open ul li a").colorbox({
		height: 535
	});
});
