// Launch effects when the DOM is ready
$(document).ready(function() {
	/*
	Background Image Load (Wordmark)
	*/	
	var img = new Image();
    $(img).load(function() {
        
        if(navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i)) {
	        var wm = $('#wordmark');
	        wm.before( wm.clone(true) ).remove();
	        $('#wordmark').append(this);
	        $('#wordmark').css({ '-webkit-animation': 'wordmarkFadeIn 2s' });
	        $('#iPhoneSlides').fadeIn(2000).delay(2000).queue(function() {
	        	$('#wordmark').css({ '-webkit-animation': 'wordmarkFadeOut 3s' });
	        	$('#wordmark').fadeOut(2000).queue(function() {
		        	$('#menu').animate({opacity:1},1000);
				});
	        	
	        	$('#iPhoneSlides').css({ '-webkit-animation': 'iPhoneFadeIn 4s' });
				$('#iPhoneSlides img').css({ '-webkit-animation-iteration-count': 'infinite',
											 '-webkit-animation-duration': '60s'
											 });
	
		        $('#iPhoneSlides img.image1').css({	'-webkit-animation-name': 'image1' });
		        $('#iPhoneSlides img.image2').css({	'-webkit-animation-name': 'image2' });
		        $('#iPhoneSlides img.image3').css({	'-webkit-animation-name': 'image3' });
		        $('#iPhoneSlides img.image4').css({	'-webkit-animation-name': 'image4' });
		        $('#iPhoneSlides img.image5').css({	'-webkit-animation-name': 'image5' });
		        $('#iPhoneSlides img.image6').css({	'-webkit-animation-name': 'image6' });
		        $('#iPhoneSlides img.image7').css({	'-webkit-animation-name': 'image7' });
		        $('#iPhoneSlides img.image8').css({	'-webkit-animation-name': 'image8' });
	        });
	        
		} else {
	        $(this).css('display', 'none'); // .hide() doesn't work in Safari when the element isn't on the DOM already
	        $(this).hide();
	        $('#wordmark').append(this);
			$(this).fadeIn(2000).delay(300).queue(function() {				
				$('#wordmark').blur();
				$('#wordmark').fadeOut(2000);
				$('#supersized').animate({opacity:1},2000, function() {
					$('#menu').animate({opacity:1},1000);
				});
			});
		}
		        
    }).error(function () {
        // notify the user that the image could not be loaded
    }).attr('src', './wordpress/images/labelkings_wordmark.gif');
    
    /*
	Background Image Centering (Wordmark)
    */ 
    $(window).resize(function() {
    	$('.wordmark').css({
			position:'absolute',
			left: ($(window).width() - $('.wordmark').outerWidth())/2,
			top: ($(window).height() - $('.wordmark').outerHeight())/2
		});
		
		if ($('#product-menu').hasClass('active') == false) {
			var newScrollY = 210 - $(this).scrollTop() + 'px';
		} else {
			var newScrollY = 240 + $('#product-menu').outerHeight() - $(this).scrollTop() + 'px';
		}
		
		positionFooter();
	});
	$(window).resize();
		
	function positionFooter(){
		/*if($(window).height() <= 500) {
			$('#menu').css({ position: 'absolute', top: 210 });
		} else {
			$('#menu').css({ position: 'absolute', top: ($(window).scrollTop() + $(window).height() - 210) });
		}*/
		
		if (navigator.userAgent.match(/iPhone/i))
		{
			if ( orientation == 0 ) { //Portrait Mode, Home Button bottom
				$('#menu').css({ position: 'absolute', top: 850 });
			}  
			else if ( orientation == 90 ) { //Landscape Mode, Home Button right
				$('#menu').css({ position: 'absolute', top: 310 });
			}  
			else if ( orientation == -90 ) { //Landscape Mode, Home Button left
				$('#menu').css({ position: 'absolute', top: 310 });
			}  
			else if ( orientation == 180 ) { //Portrait Mode, Home Button top
				$('#menu').css({ position: 'absolute', top: 850 });
			}
		} else if (navigator.userAgent.match(/iPad/i))
		{
			if ( orientation == 0 ) { //Portrait Mode, Home Button bottom
				$('#menu').css({ position: 'absolute', top: 1024 });
			}  
			else if ( orientation == 90 ) { //Landscape Mode, Home Button right
				$('#menu').css({ position: 'absolute', top: 510 });
			}  
			else if ( orientation == -90 ) { //Landscape Mode, Home Button left
				$('#menu').css({ position: 'absolute', top: 510 });
			}  
			else if ( orientation == 180 ) { //Portrait Mode, Home Button top
				$('#menu').css({ position: 'absolute', top: 1024 });
			}
		} else {
			$('#menu').css({ position: 'absolute', top: ($(window).scrollTop() + $(window).height() - 210) });
		}
	}
    
    if(navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i)) {
		$('#iPhoneSlides').resizenow();
    } else {
		$('#iPhoneSlides').remove();
	    jQuery(function($){
			$.supersized({
			
				//Functionality
				slideshow               :   1,		//Slideshow on/off
				autoplay				:	1,		//Slideshow starts playing automatically
				start_slide             :   1,		//Start slide
				slide_interval          :   6000,	//Length between transitions
				transition              :   1, 		//0-None, 1-Fade, 2-Slide Top, 3-Slide Right, 4-Slide Bottom, 5-Slide Left, 6-Carousel Right, 7-Carousel Left
				transition_speed		:	500,	//Speed of transition
				new_window				:	0,		//Image links open in new window/tab
				pause_hover             :   0,		//Pause slideshow on hover
				keyboard_nav            :   0,		//Keyboard navigation on/off
				performance				:	1,		//0-Normal, 1-Hybrid speed/quality, 2-Optimizes image quality, 3-Optimizes transition speed // (Only works for Firefox/IE, not Webkit)
	
				//Size & Position
				min_width		        :   0,		//Min width allowed (in pixels)
				min_height		        :   0,		//Min height allowed (in pixels)
				vertical_center         :   1,		//Vertically center background
				horizontal_center       :   1,		//Horizontally center background
				fit_portrait         	:   0,		//Portrait images will not exceed browser height
				fit_landscape			:   0,		//Landscape images will not exceed browser width
				
				//Components
				navigation              :   0,		//Slideshow controls on/off
				thumbnail_navigation    :   0,		//Thumbnail navigation
				slide_counter           :   0,		//Display slide numbers
				slide_captions          :   0,		//Slide caption (Pull from "title" in slides array)
				slides 					:  	[		//Slideshow Images
													{image : './wordpress/images/home/home1.jpg'},
													{image : './wordpress/images/home/home2.jpg'},  
													{image : './wordpress/images/home/home3.jpg'},
													{image : './wordpress/images/home/home4.jpg'},
													{image : './wordpress/images/home/home5.jpg'},
													{image : './wordpress/images/home/home6.jpg'},
													{image : './wordpress/images/home/home7.jpg'},
													{image : './wordpress/images/home/home8.jpg'}  
											]
											
			}); 
	    });
	}
    
    /*
    Adjust the position of the Floating Nav if the content was scrolled
    */
    $(function() {
		//var originalTop = $('#menu').offset().top; // store original bottom position
		
		$(window).scroll(function(e) {
			if ($(this).scrollTop() > 0) {
				$('#menu').css({ position: 'fixed', bottom: '210px' });
			}
		}); 
	});
        
});
