var menuTimeout;

/**
 * Equal Heights Plugin
 * Equalize the heights of elements. Great for columns or any elements
 * that need to be the same size (floats, etc).
 * 
 * Version 1.0
 * Updated 12/10/2008
 *
 * Copyright (c) 2008 Rob Glazebrook (cssnewbie.com) 
 *
 * Usage: $(object).equalHeights([minHeight], [maxHeight]);
 * 
 * Example 1: $(".cols").equalHeights(); Sets all columns to the same height.
 * Example 2: $(".cols").equalHeights(400); Sets all cols to at least 400px tall.
 * Example 3: $(".cols").equalHeights(100,300); Cols are at least 100 but no more
 * than 300 pixels tall. Elements with too much content will gain a scrollbar.
 * 
 */

(function($) {
	$.fn.equalHeights = function(minHeight, maxHeight) {
		tallest = (minHeight) ? minHeight : 0;
		this.each(function() {
			if($(this).height() > tallest) {
				tallest = $(this).height();
			}
		});
		if((maxHeight) && (tallest > maxHeight)) tallest = maxHeight;
		return this.each(function() {
			 $(this).height(tallest).css();
		});
	}
})(jQuery);

function showMegaMenu(target){
	$(target).children('.menu').stop(true,true).slideDown(400, function(e){
	});
		if (!$(target).children('.menu').hasClass('even')){
			$(target).find('ul').equalHeights();
			$(target).children('.menu').addClass('even');
		}
}
function hideMegaMenu(target){
	$(target).children('.menu').stop(true,true).slideUp(200, function(e){
	});
}
function listenMegaMenu(){
	$('.megamenu>li').mouseenter(function(){ 
		var item = this; 
		menuTimeout = setTimeout(function(){ 
			showMegaMenu(item); 
		}, 250) 
	});
	$('.megamenu>li').mouseleave(function(){ 
		if (menuTimeout) clearTimeout(menuTimeout); 
		hideMegaMenu(this); 
	})
}
$(document).ready(function() {
	listenMegaMenu();
//	$('.products .quickview').click(function(e){
//		e.preventDefault();
//		$(this).parent().addClass('active');
//		var position = $(this).parent().position();
//		if(position.left > 460) {
//			$(this).parent().children('.view').addClass('right');
//		}
//		if(position.top > 500){
//			$(this).parent().children('.view').addClass('bottom');
//		}
//		$(this).parent().children('.view').show();	
//		$('.overlay').show();
//	});
//	$('.overlay, .toggle-close').click(function(e){
//		$('.view').removeClass('right').removeClass('bottom').hide();
//		$('.overlay').hide();
//		$('.products .active').removeClass('active');
//	});
	//$(".products>li:nth-child(4n):not(.special,.clearance)").addClass('clean');
	//$(".products>li:nth-child(4n).special").addClass('clean-special');
	//$(".products>li:nth-child(4n).clearance").addClass('clean-clearance');
	
	//$("ul.featured li").equalHeights();
	//$(".products>li").equalHeights(250);
	Cufon.replace('.megamenu>li>a');

});