$(function(){

	//layout hack to center images and keep text left-aligned
	$('.front_page_product_cell_inner_wrap img').load(function(){
		var img = $(this);
		var width = img.width();
		var div = img.parents('.front_page_product_cell_inner_wrap');
		var css = {'width': width};
		
		if(width < img.height()){
			div.addClass('tall_image');

			if($('div.tall_image').length == 2){
				//if they're both tall, leave them centered
				$('div.tall_image').css({'float': '', 'margin': ''});
			}else{
				if(img.hasClass('this_thumb')){
					css['float'] = 'left';
					css['margin-left'] = '4px';
				}else{
					css['float'] = 'right';
					css['margin-right'] = '4px';
					
				}
			}
		}
		
		div.css(css);
	});
	
	
	//trigger load event for cached images
	$(".front_page_product_cell_inner_wrap img").not(function() {
		return !this.complete;
	}).trigger('load');

	
	$('#logo_above_click').click(function(){
		location.href = '/';
	});
	
	$('#add_to_cart_button').click(function(){
		$('#cart_wrapper form').submit();
	});

	$('#view_cart_button').click(function(){
		$('#view_cart_form_wrapper form').submit();
	});

	
	//serious paypal hacking
	var form = $('#cart_wrapper form');
	
	//hide ugly button
	form.find("input[type=image]").hide();
	
	//hide repetitive "choose size" text
	form.find('td').each(function(){
		var td = $(this);
		if(td.find('select').length == 0 && td.text().match(/Choose/)){
			td.hide();
		}			
	});
	

	$('a[href^="http://"]').attr("target", "_blank");

	if($('#table_wrapper select').length) $('#table_wrapper select').dropp({});
});
