$.extend($.ford.pages, {index: { }});
$.extend($.ford.pages, {Index: $.ford.pages.index});
$.extend($.ford.pages.index, {_init: function() {
		if ($.flash.available){
			var flashvars = {
				locale: _F.lang + '-CA',
				lang: _F.lang,
				isDC: _F.dc
			};
			var sidekick = $("#flashContent").data("sidekick");
			if(sidekick) {
				flashvars.diffSide = sidekick;
			}
			homepage = $.flash.create({ 
				swf:'/flash/redesign/Homepage.swf',
				height:377,
				width:960,
				bgcolor:'#ffffff',
				wmode: 'transparent',
				flashvars: flashvars,
				hasVersion:9,
				hasVersionFail:function(){
						return false;
				}
			});
			$('#flashContent').html(homepage);
		} else {
			$('#flashContent, #sliderContent').addClass('noFlashContent');
			$('.noFlash').show();
		};
		
		
		/* new espot rotator - no flash */
		if ($('#espotSlides').find('.slides_control').length <= 0){
			$('#espotSlides').html(espotSlides);
			
			$('#espotSlides .slide div').bind('click', function() { 
				$.ford.common.url.goTo($(this).data('href'), $(this).data('target'));
			});
			
		}
		if ($('#slides').find('.slides_control').length <= 0){
			$('#slides').html(slides);
		}
		$('html').bind('postalChange', function() {
			Ford.Page.Index.Flash.refresh();
		});
		
		
}});
Ford.Page.Index = {
	Flash: {
		msrp: function(acode) {
			if($.ford.common.hasLocation() == false) {
				$('html').trigger('getPostal');
			}
			return $.ford.Vehicle.Msrp.get(acode).display;
		},
		callback: function(value) {
			try {
				$.ford.common.flash.getMovie($(homepage).attr('id')).callback();
			} catch (e) { }
		},
		refresh: function() {
			try {
				$.ford.common.flash.getMovie($(homepage).attr('id')).refresh();
			} catch (e) { }
		}
	}
};
// Work around for old code
Ford.Flash = {
	HomePage: {
		object: null,
		Msrp: {
			display: function(acode) {
				return $.ford.pages.Index.Flash.msrp(acode);
			}
		}
	}
};
var homepage;

/*var companion = $.flash.create({
	swf:"/flash/home/companion_" + _F.lang + ".swf",
	height:333,
	width:184,
	bgcolor:'#ffffff',
	wmode: 'transparent',
	hasVersion:9,
	hasVersionFail:function(){
		return false;
	}
});*/




/*function loadVoken () {
	if ($.flash.available){
		$('#flashCompanion').html(companion);
	}
		
}

function closeVoken () {
	$('#flashCompanion').hide();
}*/

var espotSlides = function()
{
	// Set starting slide to 1
	var startSlide = 1;
	
	// Get slide number if it exists
	if (window.location.hash) 
	{
		startSlide = window.location.hash.replace('#','');
	}
	
	// Initialize Slides
	$('#espotSlides').slides({
		preload: true,
		generateNextPrev: true,
		generatePagination: true,
		play: 8000,
		pause: 60000,
		hoverPause: true,
		// Get the starting slide
		start: startSlide,
		animationComplete: function(current)
		{
			// Set the slide number as a hash
			//window.location.hash = '#' + current;
			
		}
	});
};


var slides = function()
{
	// Set starting slide to 1
	var startSlide = 1;
	
	// Get slide number if it exists
	if (window.location.hash) 
	{
		startSlide = window.location.hash.replace('#','');
	}
	
	// Initialize Slides
	$('#slides').slides({
		preload: true,
		generatePagination: true,
		generateNextPrev: true,
		// Get the starting slide
		start: startSlide,
		animationComplete: function(current)
		{
			// Set the slide number as a hash
			//window.location.hash = '#' + current;
			
		}
	});
};

$(function(){
	$.ford.pages.index._init();
});
