$(function (){
	
	// LOGIN FIELDS
	$("#loginFields .input input, #footer .input input").each(function() {
		if ($(this).val() == 0) {
			$(this).parent(".input").css({ backgroundPosition: "left top" });
		} else {
			$(this).parent(".input").css({ backgroundPosition: "left bottom" });
		};
	}).keydown(function() {
		$(this).parent(".input").css({ backgroundPosition: "left bottom" });
	}).blur(function() {
		if ($(this).val() == 0) {
			$(this).parent(".input").css({ backgroundPosition: "left top" });
		} else {
			$(this).parent(".input").css({ backgroundPosition: "left bottom" });
		};
	});
	
	// CUSTOMSELECT
	$(".customSelect").click(function() {
		$(this).addClass("customSelectHover");
	}).mouseleave(function() {
		$(this).removeClass("customSelectHover");
	});

//	$(".customSelect li a").click(function() {
//		var selectedText = $(this).html();
//		$(this).parents('div.customSelect').removeClass("customSelectHover").find('div.selected').text(selectedText);
//		return false;
//	});
	
	// EQUAL HEIGHTS
	function equalHeight(group) {
		tallest = 0;
		group.each(function() {
			thisHeight = $(this).height();
			if(thisHeight > tallest) {
				tallest = thisHeight;
			}
		});
		group.height(tallest);
	}
	equalHeight($(".duoBoxes .column"));
	equalHeight($(".tripleBoxes .column"));
	equalHeight($("#catPromos li"));
	equalHeight($(".related li.product "));
	
	// RESIZE COLUMNS (1/2)
	setTimeout("extendSide();", 500);
	
	// ROLLOVER IMAGES (1/2)
	DNZ.rollover.init();
	
});


// PAGEMASK
// Resize pageMask to html-size
function pageMask() {
	var htmlHeight = $(document).height();
	$('#pageMask').height(htmlHeight);
}

// LAYER POSITIONING IE6
function layerPosIE() {
	if ($.browser.msie && $.browser.version == 6.0) {
		var scrollTopPosition = $(window).scrollTop();
		var windowHeight = $(window).height();
		var layerHeight = $('#addedToWishlist').height();
		var offset = (windowHeight / 2) - (layerHeight / 2);
		$('#addedToWishlist, #addedToCart').css({'top': scrollTopPosition + offset}); // Set height for IE6
	}
}

// RESIZE COLUMNS (2/2)
function extendSide() 
{
	var mainHeight = $('#main').height();
	var sideHeight = $('#side').height();
	if (mainHeight > sideHeight) 
    {  
		// Set height of content container
		$('#side').css({'min-height': mainHeight - 32}); // Set new min-height
		if ($.browser.msie && $.browser.version == 6.0) 
        {
			$('#side').css({'height': mainHeight - 32}); // Set height for IE6
        }
    }
    if (sideHeight < 600) {
        $('#side').css({ 'min-height': 600 }); // Set new min-height
        if ($.browser.msie && $.browser.version == 6.0) {
            $('#side').css({ 'height': 600 }); // Set height for IE6
        }
    }

	if (sideHeight > mainHeight) {  
		// Set height of content container
		$('#fullContentBox').css({'min-height': sideHeight - 6}); // Set new min-height
		if ($.browser.msie && $.browser.version == 6.0) {
			$('#fullContentBox').css({'height': mainHeight - 6}); // Set height for IE6
		}
	}
}

// ROLLOVER IMAGES (2/2)
DNZ = {};
DNZ.rollover = {
   init: function() {
      this.preload();
      $(".rollover").hover(
         function () { $(this).attr( 'src', DNZ.rollover.newimage($(this).attr('src')) ); },
         function () { $(this).attr( 'src', DNZ.rollover.oldimage($(this).attr('src')) ); }
      );
   },
   preload: function() {
      $(window).bind('load', function() {
         $('.rollover').each( function( key, elm ) { $('<img>').attr( 'src', DNZ.rollover.newimage( $(this).attr('src') ) ); });
      });
   },
   newimage: function( src ) { return src.substring( 0, src.search(/(\.[a-z]+)/) ) + '_on' + src.match(/(\.[a-z]+)/)[0]; },
   oldimage: function( src ) { return src.replace(/_on/, ''); }
};
