/*Cufon.replace('.navbtn >  a', {
	textShadow: '1px 1px #c2b498'
});*/
Cufon.replace('.box2 h3', {
	textShadow: '1px 1px #341f06'
});
Cufon.replace('.description h3');
Cufon.replace('.font');





$(function(){
	//  Blinking fields
	
	if ($.browser.msie && parseInt($.browser.version, 10) == 9) {
		$('.navbtn > a').css({
			'float' : 'left',
			'padding-top' : '7px',
			'padding-bottom' : '8px'
		});
	};
	
    $('.blink').
        focus(function() {
            if(this.title==this.value) {
                this.value = '';
            }
        }).
        blur(function(){
            if(this.value=='') {
                this.value = this.title;
            }
        });
        

	
//  colors popup


	$('a.colors').live('click', function() {
		$(this).addClass('active');
		$(this).parent().parent().children('div.colors').fadeIn();
		$(this).parent().parent().addClass('relative');
	
		return false;
	});

	$('img.colorclose').live('click', function() {
		$(this).parent().hide();
		$(this).parent().parent().children().children('a.colors').removeClass('active');
		$(this).parent().parent().removeClass('relative');
		return false;
	});

	
//  Popup align and ignition


	$('a[rel=popup]').live('click', function() {
		// since there are multiple popups on one page, copy the content of one clicked on to the popup div
		$('.popup').html($('#popup-content-'+$(this).attr('id')).html());
		var href = $(this).attr('href');
		var $this = $(this);
		show_overlay();
		
		$('.popup').fadeIn();
		$('.popup').center();
		//$('.popup').corner();
		setup_overlay_height();
		
		return false;
	});

	$('#overlay, .popup a.close').live('click', function() {
		hide_popups();
		
		return false;
	});
	
	$(document).keypress(function(e){  
		if(e.keyCode==27){
			hide_popups();
		}
	});
	
//	Navigation dropdown

	$('.navbtn').hover(function() {
			$(this).addClass('hover');
			$(this).find('.dropdown').show();
			$(this).append('<span class="deco"><!-- --></span>');

		}, function() {
			$(this).removeClass('hover');
			$(this).find('.dropdown').hide();
		});

	
// submenu slide
	$('.dropdown> ul > li').hover(function() {
			$(this).addClass('hover');
			$(this).find('.submenu').show();
		}, function() {
			$(this).removeClass('hover');
			$(this).find('.submenu').hide();
		});
	
	// equal height columns 
	/*function equalHeight(group) {
	   tallest = 0;
	   group.each(function() {
		  thisHeight = $(this).height();
		  if(thisHeight > tallest) {
			 tallest = thisHeight;
		  }
	   });
	   group.height(tallest);
	}
	$(document).ready(function() {
	   equalHeight($(".submenu .column"));
	});*/

	$(document).ready(function() {
		var submenus = $(".submenu");
		submenus.each(function() {
			var columnWides = 0;
			var columns = $(this).find('.column');
			var hasColumn = false;
			columns.each(function(){
				columnWides += 126;
				hasColumn = true;
			});
			columnWides += 1;	// add 1 extra pixel: when zoom out once on firefox, 3rd column goes to next line, this fixes that
			var lastColumn = $(this).children()[$(this).children().length-1];
            if (lastColumn) lastColumn.className += ' columnNoBar';
            if(hasColumn){
            	$(this).width(columnWides);
            }
		});
	    
	});
	
	
})

function show_overlay() {
	hide_overlay();
	$('body').prepend('<div id="overlay">&nbsp;</div>');
	setup_overlay_height();
	$('#overlay').show().css({ 'opacity': 0.5 });
}
function hide_overlay() {
	$('#overlay').remove();
}
function setup_overlay_height() {
	body_height = $(document).height();
	$('#overlay').css('height', body_height);
}
function hide_popups() {
	if ($('.popup').length) { $('.popup').fadeOut('fast') };
	hide_overlay();
}
jQuery.fn.center = function(loaded) {
    var obj = this;
    body_width = parseInt($(window).width());
	body_height = parseInt($(window).height());
	block_width = parseInt(obj.width());
	block_height = parseInt(obj.height());
	
	left_position = parseInt((body_width/2) - (block_width/2)  + $(window).scrollLeft());
	if (body_width<block_width) { left_position = 0 + $(window).scrollLeft(); };
	
	top_position = parseInt((body_height/2) - (block_height/2) + $(window).scrollTop());
	if (body_height<block_height) { top_position = 0 + $(window).scrollTop(); };
	
    if(!loaded) {
    	
    	obj.css({'position': 'absolute'});
		obj.css({'left': left_position, 'top': top_position});
    	
    } else {
        obj.stop();
        obj.css({'position': 'absolute'});
        obj.animate({'left': left_position, 'top': top_position}, 200, 'linear');
    }
}




// filled in content of popup then call this
function show_popup(){
	show_overlay();
	
	$('.popup').fadeIn();
	$('.popup').center();
	//$('.popup').corner();
	setup_overlay_height();
}

//used on solr paginated page to check off product(s) selected in product comparison
$('a.paging_link').live('click', function() {
	setTimeout('checkedProductMarkedForComparison();',1000);
	return false;
});
