function getE(name) {
    if (document.getElementById)
        var elem = document.getElementById(name);
    else if (document.all)
        var elem = document.all[name];
    else if (document.layers)
        var elem = document.layers[name];
    return elem;
}

function OpenWindow(query, w, h, scroll) {
    var l = (screen.width - w) / 2;
    var t = (screen.height - h) / 2;

    winprops = 'resizable=1, height=' + h + ',width=' + w + ',top=' + t + ',left=' + l + 'w';
    if (scroll) winprops += ',scrollbars=1';
    var f = window.open(query, "_blank", winprops);
}
/**
 *
 * Copyright (c) 2007 Tom Deater (http://www.tomdeater.com)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 * 
 */
 
(function($) {
	 
	$.fn.equalizeCols = function(){
		var height = 0,
			reset = $.browser.msie && $.browser.version < 7 ? "1%" : "auto";
  
		return this
			.css("height", reset)
			.each(function() {
				height = Math.max(height, this.offsetHeight);
			})
			.css("height", height)
			.each(function() {
				var h = this.offsetHeight;
				if (h > height) {
					$(this).css("height", height - (h - height));
				};
			});
			
	};
	
})(jQuery);

jQuery(document).ready(function ($) {
	
	$(".ContentColumnOne:eq(0), .ContentColumnTwo:eq(0), .ContentColumnThree:eq(0), .ContentColumnTwo_Full:eq(0), .ContentColumnTwo_Small:eq(0)").equalizeCols();
	$(".ContentColumnOne:eq(1), .ContentColumnTwo:eq(1), .ContentColumnThree:eq(1), .ContentColumnTwo_Full:eq(1), .ContentColumnTwo_Small:eq(1)").equalizeCols();
	
	$(".CategoryBreadcrumb a:last").wrap(function() {
	  return '<span>' + $(this).text() + '</span>';
	}).hide();
	
	$('.storefrontButton, .GridImageInner, .ProductImageLink')
	.live("mouseover",function(){
		$(this).addClass('mouseover');
	})
	.live("mouseout",function(){
		$(this).removeClass('mouseover').removeClass('mousedown');
	})
	.live("mousedown",function(){
		$(this).addClass('mousedown');
	})
	.live("mouseup",function(){
		$(this).removeClass('mousedown');
	});
	
	//Photo grid - Fudala fixed this
	function AnimatePhoto(Obj, Val){
		$(Obj).stop().animate({opacity: Val}, {duration: 150});
		$(Obj).dequeue();
	}
	
	$('.ProductImageLink').css({opacity: '0.85'});
	$('.ProductImageLink').mouseenter(function(){
		$(this).queue(function(){AnimatePhoto($(this), '1');});
	}).mouseleave(function(){
		$(this).queue(function(){AnimatePhoto($(this), '0.85');});
	});
	
	//Product showcase page, thumbnail interactions
	$('.ProductThumbContainer .ProductThumbnailInner').eq(0).addClass('selected');
	$('.ProductImageLinkThumb').live("click",function(){
		$('.ProductThumbContainer .ProductThumbnailInner').removeClass('selected');
		$(this).parent().removeClass('selected');
	});
	
	//Form submits, to replace our dodgy buttons...
	$("span.ui-submit-form").click(function () {
		$('input.' + $(this).attr('id')).trigger('click');
	});
	$('.item_replace').click(function(){
		$(this).parent().children('input.'+$(this).attr('rel')).trigger('click');
	});
	
	$('a.ToggleZoom').click(function(){
		if ($(this).hasClass('Enabled'))
		{
			$(this).removeClass('Enabled');
			$('div.mousetrap').hide();
			$('div.productDetailsWrapper').removeClass('ZoomEnabled');
		}
		else{
			$(this).addClass('Enabled');
			$('div.mousetrap').show();
			$('div.productDetailsWrapper').addClass('ZoomEnabled');
		}
	});

	// 
	$('input[type=submit]').click(function () {
		$('div.errorWrapper').each(function (i, item) {
			var $wrapper = $(item);
			var $error = $wrapper.find('span.errorSummary');
			if ($error.size() > 0) {
				var summary = $error.html().trim();
				$wrapper.show();
				var visible = $error.find('div').is(':visible');
				$wrapper.hide();
				if (summary == "" || !visible) {
					$wrapper.hide();
				} else {
					$wrapper.show();
				}
			}
		});
	});

});
