jQuery.fn.cycle.defaults.speed   = 900;
jQuery.fn.cycle.defaults.timeout = 6000;

(function(jQuery) {
jQuery.fn.fadeInSequence = function(fadeInTime, timeBetween)
{
	//Default Values
	timeBetween = typeof(timeBetween) == 'undefined' ? 0 : timeBetween;
	 fadeInTime = typeof(fadeInTime) == 'undefined' ? 500 : fadeInTime;

	//The amount of remaining time until the animation is complete.
	//Initially set to the value of the entire animation duration.
	var remainingTime = jQuery(this).size() * (fadeInTime+timeBetween);

	var i=0; //Counter
	return jQuery(this).each(function()
	{
		//Wait until previous element has finished fading and timeBetween has elapsed
		jQuery(this).delay(i++*(fadeInTime+timeBetween));

		//Decrement remainingTime
		remainingTime -= (fadeInTime+timeBetween);

		if(jQuery(this).css('display') == 'none')
		{
			jQuery(this).fadeIn(fadeInTime);
		}
		else //If hidden by other means such as opacity: 0
		{
			jQuery(this).animate({'opacity' : 1}, fadeInTime);
		}

		//Delay until the animation is over to fill up the queue.
		jQuery(this).delay(remainingTime+timeBetween);

	});	

};

})(jQuery);

jQuery.noConflict();

jQuery(function($) {
	/* Click Events */
	$('div.logo').css('cursor','pointer').click(function() {
		window.location='./';
	});
	$('button.contact-us').click(function() {
		window.location='contactus.aspx';
	});
	$('div.s-bottom').click(function() {
		window.location='currentpromotions.aspx';
	});
	$('button.find-dealer').click(function() {
		window.location='./dealerlocator.aspx';
	});
	$('button.find-a-location').click(function() {
		window.location='dealerlocator.aspx';
	});
	$('button.sign-up').click(function() {
		window.location='emailupdateinfo.aspx';
	});
	$('button.view-promos').click(function() {
		window.location='currentpromotions.aspx';
	});
	$('button.resources').click(function() {
		window.location='resources.aspx';
	});
	$('button.admin-find-dealer').click(function() {
		window.location='../dealerlocator.aspx';
	});
	$('button.view-trucks').click(function() {
		window.location='ViewPackages.aspx';
	});
    
    // Give Slideshow a Curosr and Action
	$('#map').click(function(){
		window.location = 'dealerlocator.aspx';
	}).css('cursor','pointer');
	
	$('#logo').click(function(){
		window.location = 'InventorySearch.aspx?Search=1';
	}).css('cursor','pointer');
	
	// Slide One Controls
	var slideOne = function() {
		$("div#centers").delay(1000).fadeIn(1000);
		$("div.loc").delay(1000).fadeInSequence(1000, -500);
		$("div#gonow").delay(10500).fadeIn(1000);
	}
	
	// Slide Two Controls
	var slideTwo = function() {
		$("div#logo").delay(16500).fadeIn(1000);
		$("div#twinkle1").delay(18000).fadeIn(250).fadeOut(250);
		$("div#twinkle2").delay(18500).fadeIn(250).fadeOut(250);
		$("div#searchnow").delay(19000).fadeIn(1000);
	}
	
	// Restart the Slide
	var doRestart = function() {
		$("div#centers,div.loc,div#gonow,div#twinkle1,div#twinkle2").hide();
		$("div#searchnow,div#logo").fadeOut(1000);
	}
	
	// Start the Slideshow
	var startShow = function() {
		slideOne();
		slideTwo();
	}
	
	/* Initiate Slideshow */
	setInterval(function() {
		doRestart();
		setTimeout(function(){startShow();},1000);
	}, 27000);
	
	startShow();
	
	$('div.truck-button').hover(function() { $("div", this).fadeIn(100)}, function() { $("div", this).fadeOut(100) });
	/**
	* Click Throughs
	**/
	var url = 'ViewPackageDetails.aspx?Gallery=';
	$('#9400i').click(function(){window.location = url + '9400&TruckId=700024593';});
	$('#4300').click(function(){window.location= url + '4300&TruckId=700017306';});
	$('#century').click(function(){window.location= url + 'Cent&TruckId=700017311';});
	$('#cl12064st').click(function(){window.location= url + 'CLST&TruckId=700017315';});
	$('#prostar').click(function(){window.location= url + 'Pros&TruckId=700017319';});
	$('#freightliner').click(function(){window.location= url + 'Cove&TruckId=700017318';});
	
	$('#ss_cus').each(function() {
        eval($(this).text());
    });
	
	
	/**
	* Begin: Dealer Locator
	**/
	$('#Map_img').maphilight(
	{
	  fill: true,
	  fillColor: 'ff9200',
	  fillOpacity: 0.8,
	  stroke: true,
	  strokeColor: 'ffffff',
	  strokeOpacity: 1,
	  strokeWidth: 2,
	  fade: true,
	  alwaysOn: false,
	  neverOn: false,
	  groupBy: false
	});

	$('area').each(function()
	{
	   this.title=this.alt+" AOR - Click For More Info";
	   this.href="DealerLocatorMini.aspx?Name="+this.id;
	});

	$('area').tooltip({
	  delay: 0,
	  track: true,
	  showURL: false,
	  showBody: " - "
	});
	
	$('area').fancybox({
	  overlayShow: false,
	  centerOnScroll: true,
	  transitionIn: 'fade',
	  transitionOut: 'fade'
	});
	/**
	* End: Dealer Locator
	**/
});
