function trackHash(){
	try{
		piwikTracker.trackLink( window.location.hash.substr(1),'url');
		switch( window.location.hash.substr(1) ){
			case 'home':
				fireTag(2204.1);
				break;
			case 'dark-ride':
				fireTag(2205.1);
				window.location = 'http://www.lexusdarkride.com';
				break;
			case 'events':
				fireTag(2206.3);
				break;
			case 'gallery-/-specs':
				fireTag(2207.1);
				break;
			case 'get-updates':
				fireTag(2208.1);
				break;
			case 'win-a-ct-200h':
				fireTag(2209.1);
				break;
			case 'legalterms':
				fireTag(2221.1);
				break;
			case 'privacy':
				fireTag(2221.2);
				break;
			case 'rules':
				fireTag(2209.5);
				break;
			case 'dark-ride-card':
				fireTag(2257.1);
				break;
		}
	}catch(e){}
}
function validateCode() {
	if( $.cookies.get( "vip_code" ) == null || $.cookies.get( "vip_code" ).length < 5 ) {
		var cusCode = prompt( 'Please enter the code found on your VIP card.' );

		if( cusCode == null || cusCode.length < 5 ) {
			alert( "Invalid code. (Internet Explorer users may need to click on the yellow bar to allow security settings)" );
		}
		else {
			$.cookies.set( "vip_code", cusCode, {expiresAt: new Date( 2025, 1, 1 )} );
			document.location = "partners.html#dark-ride-card";
		}
	}
	else {
		document.location = "partners.html#dark-ride-card";
	}
}
(function($) {
	$.fn.elevator = function( userOptions ) {
		var defaultOptions = {
			holderH: 900,
			start:""
		}
		var uO = $.extend( defaultOptions, userOptions );

		var self = this;
	
		return this.each(function() {
			var $this = $( this );
			var $contentHolders = $( "#content_holders" );
			var $contentHolder = $contentHolders.find( ".content_holder" );
			var contentIndex;
			var currentHash;

			function restartTimeout() {
				$this.doTimeout( "hash", 250, function() {
					checkHash();
					if( !$contentHolders.data( "inAnimation" ) ) return true;
					else restartTimeout();
				});
			}
			function checkHash() {
				if( !$contentHolders.data( "inAnimation" ) && (window.location.hash != ""  || uO.start != '')) {
					if (window.location.hash != '' ) contentIndex = $this.find("li[rel='" + window.location.hash.substr( 1 ).toLowerCase() + "']").index();
					else contentIndex = $this.find("li[rel='" + uO.start + "']").index();
					if( contentIndex < 0 ) contentIndex = 0;
					activeIndex = $this.find( "li.active" ).index();
					if( contentIndex == activeIndex ) return true;
					$this.find( "li" ).removeClass( "active" );
					$contentHolders.data( "inAnimation", true );
					translateHolders();		
					trackHash();
				}
			}
			function translateHolders() {
				$('.scrollable .close:visible').click(); // remove all overlays before proceeding
				var topOffset = 0 - uO.holderH * contentIndex;
				var currentDistance = activeIndex - contentIndex;
				var currentDuration = ( currentDistance * currentDistance ) + ( 300 * Math.abs( currentDistance ) ) + 100;
				$contentHolders.animate({top:topOffset}, currentDuration, function() {
					$this.find( "li:eq(" + contentIndex + ")" ).toggleClass( "active" );
					$contentHolders.data( "inAnimation", false );
					$( window ).trigger( 'hashchange' );
				});
			}
			function initialize() {
				if (document.location.hostname == 'lexusdarkride.com' || document.location.hostname.substring(4) == 'lexusdarkride.com'){
					$('#nav_right_header').bind('click',function(){window.location='http://www.darkersideofgreen.com'});
					$('#nav_top_left').bind('click',function(){window.location='http://www.lexus.com'});
					$('.nav_right_item').click(function(){window.location = $(this).children('a').attr('href');});
					return true; //no need for fancy nav on dark ride
				}
				currentHash = window.location.hash.substr( 1 ).toLowerCase();
				if( $this.find("li[rel='" + currentHash + "']").length > 0 ) {
					$this.find("li[rel='" + currentHash + "']").addClass( "active" );
					activeIndex = $this.find( ".active" ).index();
				}
				else if( uO.start != "" ) {
					$this.find("li[rel='" + uO.start + "']").addClass( "active" );
					activeIndex = $this.find( ".active" ).index();
				}
				else {
					$this.find("li:eq(0)").addClass( "active" );
					activeIndex = 0;
				}

				restartTimeout();

				topOffset = 0 - uO.holderH * activeIndex;
				$contentHolders.css({top:topOffset});
				$contentHolders.data( "inAnimation", false );

				$('#nav_right_header').bind( "click", function(){
					window.location='#home';
				});
				$( "#nav_top_left" ).bind( "click", function() {
					window.location='#home';
					fireTag(2204.6);
					if ( $("#nav_top_right > ul > li.right").eq(0).attr('innerHTML') == 'SHOW MENU') $("#nav_top_right li.right").click();
				});
				$('.nav_right_item').bind( "click", function(){
					window.location='#' + $(this).attr('rel');
				});
				$('.nav_right_item > a').bind( "click", function(){
					$(this).parents('li').click();
					return false;
				});
				$( window ).bind( "hashchange", function() {
					$this.doTimeout( "hash" );
					checkHash();
				});
				$('.event_moreInfo').bind('click', function(){
						fireTag(2206.4,{'<eventTitle>':$(this).attr('rel')});
						return true;
						});
			}

			initialize();
		}); // end return this
	}; // end plugin
})(jQuery);

