var experience = {
	setGlobals: function() {
		adCampaignLi = jQuery('a#link-ad-campaign').parent('li');
		productVideosLi = jQuery('a#link-product-videos').parent('li');
		vidLi = jQuery('a#link-essence-video').parent('li');
		animateVisible = '0px';
		animateOffLeft = '-638px';
		animateOffRight = '738px';
		
		expPhotos = jQuery('div#experience-photos');
		campaignWindow = jQuery('div#campaign-window');
		productVideosWindow = jQuery('div#product-videos-window');
	},
	
	setBackLink: function() {
		campaignActive = 0;
		productVideosActive = 0;
		backLink = jQuery('a[rel="back"]');
		backLink.css({ opacity: 0 });
	},
	
	showBackLink: function() {
		if (campaignActive == 1 || productVideosActive == 1) {		
			backLink.css({ position: 'absolute', left: 0, top: '324px', opacity: 0, cursor: 'pointer' }).animate({ opacity: 1 }, 500);	
		}
	},
		
	autoOpen: function() {
		if((document.location.hash) && (document.location.hash === '#open-ad-campaign')) {
			experience.showCampaign();
		}
	},
	
	setVideo: function() {
		video.init();
	},
	
	setProductVideos: function() {
	
		// Variable assignment
		var productVideosLinks = jQuery('a[rel="open-product-videos"]');
		var navProductVideosLink = jQuery('a#link-product-videos');
		
		// Add video close action to Product Videos link
		productVideosLinks.attr('rel', 'close-video-window');		

		
		var videoCount = jQuery('div#product-videos-window ul li').length;
		
		
		// Add additional HTML/CSS
		productVideosWindow.css({ position: 'relative', width: '660px', height: '280px' });
		productVideosWindow.append(
			jQuery('<div />').attr({ id: 'tech-videos-pagination' }).text('1-3 of '+videoCount)
		);
		var videoPager = jQuery('#tech-videos-pagination', productVideosWindow);
		
		
		// functions for video carousel callbacks
		function videosCarousel_initCallback(carousel) {
			//alert('init callback');
		}
		function videosCarousel_itemFirstInCallback(carousel, li, index, state) {
			//alert(videoPager);
			videoPager.text(index+'-'+(index+2)+' of '+videoCount);
		}
		
		// Initialize video carousel
		jQuery('div#product-videos-window ul').jcarousel({
			initCallback: videosCarousel_initCallback,
			itemFirstInCallback: videosCarousel_itemFirstInCallback
		});

		//Video title rollover for IE6
		jQuery('li a', productVideosWindow).hover(
			function(){
				jQuery('.video-title', this).css({ backgroundPosition: '-200px 0' });
			},
			function(){
				jQuery('.video-title', this).css({ backgroundPosition: '0 0' });
			}	
		);

		// Slide Product Videos into view
		function showProductVideos() {
			productVideosActive = 1;
			
			// "Back" link functionality
			backLink.unbind();
			backLink.bind('click', function(){
				closeProductVideos();
				return false;
			});
			
			if(campaignActive == 1) {
				campaignActive = 0;
				campaignWindow.removeClass('campaign-activated');
			
				productVideosWindow.addClass('product-videos-activated');
				campaignWindow.animate({ left: -250, opacity: 0 }, 350, 'easeInBack', function(){
					campaignWindow.css({ left: animateOffRight });
				});
				productVideosWindow.animate({opacity: 0}, 200).animate({ left: animateVisible, opacity: 1 }, 350, 'easeOutExpo');
			
			} else {
				
				experience.showBackLink();
				productVideosWindow.addClass('product-videos-activated');
				expPhotos.animate({ left: animateOffLeft, opacity: 0 }, 350, 'easeInBack', function(){
					expPhotos.css({ top: '1500px' });
				});
				productVideosWindow.animate({opacity: 0}, 200).animate({ left: animateVisible, opacity: 1 }, 350, 'easeOutExpo');
			}
		}
		
		// Set up links which show Product Video Carousel
		productVideosLinks.bind('click', function(){
			// Set delay for campaign animation if needed
			var productVideosDelay = (jQuery('div#video-window').length && !jQuery('div.product-videos-activated').length) ? 275 : 0;

			setTimeout(function(){
				jQuery('#sidenav > li').removeClass('active');
				productVideosLi.addClass('active');
				// Make sure campaign window isn't already open
				if(!jQuery('div.product-videos-activated').length) {
					showProductVideos();
					return false;
				}
			}, productVideosDelay);
			return false;
		});
		
		function closeProductVideos() {
			productVideosActive = 0;
			navProductVideosLink.parent('li').removeClass('active');
			productVideosWindow.removeClass('product-videos-activated');
			expPhotos.css({ top: '62px' });
			brizo.hideBackLink();
			//expPhotos.animate({ opacity: 1 }, 350, 'easeOutExpo');
			productVideosWindow.animate({ left: animateOffRight, opacity: 0 }, 350, 'easeInBack');
			expPhotos.animate({opacity: 0}, 200).animate({ opacity: 1, left: animateVisible }, 350, 'easeOutExpo');
		}

	},

	urlOpenVideo: function(){
		if(document.location.hash.indexOf('smarttouch') != -1) {
			setTimeout(function(){
				jQuery('#product-videos-pic').click();
			}, 500);			
			setTimeout(function(){
				jQuery('#coll-smarttouch-technology').click();
			}, 1000);
		}
	}
};

// Initialize JS functions
$(document).ready(function(){
	experience.setGlobals();
	experience.setBackLink();
	experience.setVideo();
	experience.setProductVideos();
	experience.urlOpenVideo();
	//experience.autoOpen();
});
