var j = jQuery;
jQuery(document).ready(function() {
j('body').addClass('landing-bg');
j('#landing-page-title')
	.css('opacity',0)
	.delay(2000)
	.fadeTo(400,1);
j('#strapline')
	.css('opacity',0)
	.delay(6500)
	.fadeTo(400,1);
j('.quick-view')
	.css('opacity',0)
	.delay(6800)
	.fadeTo(400,1);
j('.nav')
	.css('opacity',0)
	.delay(7000)
	if (j.browser.msie) {
	j('.nav').fadeIn(400,function() {
		this.style.removeAttribute('filter');	// Remove MSIE's 'filter' attribute and allow child elements to display.  
	})											// IE won't display child elements with the 'filter' attribute
	} else {
	j('.nav').fadeTo(400,0.8);
	};
j('#menu-logo, #show-all, #sixtwo')
	.css('opacity',0)
	.delay(7300)
	.fadeTo(400,1);
j('.border').css('left','-500px');
j('.border')
	.delay(5000)
	.animate({
		left: '+=500px'
		}, 1500);
j('#main-bg-image').css('opacity',0)
	.delay(3000)
	.fadeTo(2000,1);
setTimeout(function() {
	j('body').removeClass('landing-bg');
	}, 5000);
j('.nav a, #menu-logo, .content a, .quick-lens a').click(function() {
	j('.border').animate({
		left: '-1000px'
		}, 400);
	j('.quick-view').animate({
		right: '-1000px'
		}, 400);
	j('#main-bg-image, .content, #landing-page-title')
		.fadeTo(1500,0)
		.delay(600);
});
j('#show-all').hover(function(){
	j('.nav, #landing-page-title, .border, .quick-view, #sixtwo')
	.fadeTo(350,0);
	}, function() {
	j('#landing-page-title, .border, .quick-view')
	.fadeTo(200,1);
	j('.nav')
	.fadeTo(200,0.8);
	j('#sixtwo')
	.fadeTo(200,0.8);
	});
	// ############ Adjust background image size #########
	// ######
	// ###### Props to Sam Dunn as this is a slightly reworked
	// ###### and cut down version of the image resizing that
	// ###### he used on his Supersized Slideshow plugin:
	// ###### http://buildinternet.com/2009/02/supersized-full-screen-backgroundslideshow-jquery-plugin/
	// ###### Full Project here: http://www.buildinternet.com/project/supersized/
	// ######
	// ########################################
				$().ready(function() {
			$('#main-bg-image').resizenow(); 
		});
		$(window).bind("resize", function(){
    		$('#main-bg-image').resizenow(); 
		});
		
	$.fn.resizenow = function() {
		
//		var options = $.extend($.fn.supersized.defaults, $.fn.supersized.options);
		
	  	return this.each(function() {
	  		
			//Define image ratio & minimum dimensions 
			var minwidth = 1024;
			var minheight = 757;
			var ratio = 1.352708058124174;
			
			//Gather browser and current image size
			var imagewidth = $(this).width();
			var imageheight = $(this).height();
			var browserwidth = $(window).width();
			var browserheight = $(window).height();
		//	alert('Window width: '+browserwidth+' Window height: '+browserheight);
			//Check for minimum dimensions
			if ((browserheight < minheight) && (browserwidth < minwidth)){
				$(this).height(minheight);
				$(this).width(minwidth);
			}
			else{	
				//When browser is taller	
				if (browserheight > browserwidth){
				    imageheight = browserheight;
				    $(this).height(browserheight);
				    imagewidth = browserheight*ratio;
				    $(this).width(imagewidth);
				    
				    if (browserwidth > imagewidth){
				    	imagewidth = browserwidth;
				    	$(this).width(browserwidth);
				    	imageheight = browserwidth / ratio;
				    	$(this).height(imageheight);
				    }
				
				}
				
				//When browser is wider
				if (browserwidth >= browserheight){
				    imagewidth = browserwidth;
				    $(this).width(browserwidth);
				    imageheight = browserwidth/ratio;
				    $(this).height(imageheight);
				    
				    if (browserheight > imageheight){
				    	imageheight = browserheight;
				    	$(this).height(browserheight);
				    	imagewidth = browserheight*ratio;
				    	$(this).width(imagewidth);
				    }
				}
			}
			return false;
		});
	};
});
