$.fn.setAllToMaxHeight = function(){
return this.height( Math.max.apply(this, $.map( this , function(e){ return $(e).height() }) ) );
}

$(window).load( function() {
	
/*
bg = {

	shift : function() {

	     var ww = $(window).width();
	     var wh = $(window).height();

	     $('.bg').css({"width" : ww, "height" : wh});

	     rootElement = $(window);
	     imgRatio = $('.bg img').width() / $('.bg img').height();
                bgCSS = {left: 0, top: 0}
                bgWidth = rootElement.width();
                bgHeight = bgWidth / imgRatio;

	                // Make adjustments based on image ratio
	                // Note: Offset code provided by Peter Baker (http://ptrbkr.com/). Thanks, Peter!
	                if(bgHeight >= rootElement.height()) {
	                    bgOffset = (bgHeight - rootElement.height()) /2;
	                } else {
	                    bgHeight = rootElement.height();
	                    bgWidth = bgHeight * imgRatio;
	                    bgOffset = (bgWidth - rootElement.width()) / 2;           
	                }

                $(".bg img").width( bgWidth ).height( bgHeight ).css(bgCSS);
			
	},

	go : function(e) {
		$('.bg').fadeOut( function() {
			$('.canvas').attr("src", e);
			$('.bg').fadeIn('slow');
			bg.shift();
		});
	}
}; */

	function wrap() {
		var wh = $(document).height();
		$('#wrapper').css("min-height", wh);
	}

	function reset() {
		var wh = $(window).height();
		$('#wrapper').css("min-height", wh);
	}

	wrap();

	$(window).bind("resize", function() { wrap(); });


	$('.section').click(function() {

		//var id = '#' + $(this).attr("alt");
		//$(window).scrollTo(id,1200, {margin:true});

		var id = '#' + $(this).attr("alt");

		if ( $(id).is(":visible")  ) {

			$(id).fadeOut();
			$.backstretch('<img style="http://unicorn.supercoolgroovy.com/bg-uploads/unicorn-angledTable.jpg" ');
		} else {

		$('.bg').fadeOut();
		if ( id == "#751451757153" ) { 
			$.backstretch("images/bg7.jpg");
		};
		reset();
		$('.model').fadeOut();
		$(id).delay(1000).fadeIn();
		$('.item').setAllToMaxHeight();

	}

		return false;

	});

	$('.list').click(function() {

		$('.menu').slideUp( function() {
				$('.list').slideDown();
				$('.model').fadeOut();
				$('.bg').fadeOut();
		});

		return false;

	});

	$('.closemenu').click(function() {

		$('.list').slideUp( function() {
				$('.menu').slideDown();
				$('.model').fadeOut();
				reset();
		});

		return false;

	});


	// scrolling

	$('.menu-button').click(function() {

		$('.model').fadeOut();
		
		var id = '#' + $(this).attr("alt");

			$(id).delay(500).fadeIn(function() {
				reset();
				wrap();
			});
		
		return false;

	});

	$('.thumbimg').hover( function() {
		$(this).fadeTo("fast",0.8);
	}, function(){
		$(this).fadeTo("fast",1);
	});


	$(".thumbimg").fancybox({'overlayShow':true, 'titlePosition':'inside'});

function size () {
	var wh = $(window).height() - 60;
	var h = wh + "px";
	$('.model').css("min-height",h);
}

//size();

//$(window).bind('resize', function() { size(); });

	$('.logo').click( function() {
			$('.menu').slideDown();
			$('.model').fadeOut();
			$('.address').fadeIn();
			$('.phone').fadeIn();
			$('.subscribe').fadeIn();
			$('.logobg').fadeIn();
	});



	$('.buy').click( function() {

		var parent = $(this).parent().parent();

		var itemTitle = $('.itemTitle', parent).text();
		var itemDesc = $('.itemDesc', parent).text();
		var itemPrice = $('.itemPrice', parent).text().substr(1);
		//var itemTitle = $('.itemName', this).text();

		//alert(itemPrice);

		var url = "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_cart&upload=1&business=warrenhaskins@gmail.com&currency_code=EUR";

		var build = "&item_name_1=" + itemTitle + "&item_number_1=1&quantity_1=1&amount_1=" + itemPrice + "&on0_1=Options&os0_1";

		//var build = "&item_name_=" + itemTitle + "&quantity_1=1" + "&amount_1=" + itemPrice; 

		window.location = url + build;

		//alert(build);

	});


$('.home').delay(500).fadeIn();



});
