Ford.Vehicle = {
	init: function() {
		
		
		//set new metatags with WT group/subgroup data.  Used by the layout_fo.jsp base _tag.
		$.ford.common.WT.metatag.set('WT.cg_n', $('#vpContent').data('wtgroup') );
		$.ford.common.WT.metatag.set('WT.cg_s', $('#vpContent').data('vehicle') );//notify kiki of all these new names!
		
		$.ford.common.postalCode.updateInputs();
		$('.js_specs').bind('click', function() {
			$('#vpMainTabs li[data-key="specs"]').trigger('click');
		});
		$('html').bind('postalChange', function() {
			var acodes = new Array();
			$.each($('.js_msrp'), function(index, obj) {
				acodes[index] = $(obj).data('acode');
			});
			$.ajax({
				  url: _F.root + '/' + _F.lang + '/' + _F.prov + '/acode/' + acodes.join("|") + '/msrp.json',
				  async: false,
				  dataType: 'json',
				  success: function(data) {
					  $.each(data.msrps, function(index, obj) {
						  $('.js_msrp[data-acode="' + obj.aCode + '"]').html(obj.msrp);
					  });
				  }
			});
		});
		/* new espot rotator - no flash */
		if ($('#vpEspotSlides').find('.slides_control').length <= 0){
			$('#vpEspotSlides').html(vpEspotSlides);
		}
		
		// may need to make this smarter : example buzz:youtub
		var hash = location.hash.substring(1);
		var hashArray = hash.split(':');
		
		var deepLinkArray = ['transmission', 'torque', 'interior', 'touch', 'sync', 'epas', 'park', 'wipers'];

		if(hashArray[0]) {
			$.each(deepLinkArray, function(index, data) {
				if(hashArray[0] == this) {
					location.hash = '#features:' + data;
					return;
				}
			});
		}
		
		$('#vpPromoTabs li').ford('tabs', {defaultTab:1});
		$('#vpMainTabs li').ford('tabs', {
			showMethod: function() {
				if($("#vpContent #vpMain #tab_"+ $(this).data('key')).length > 0) {
					$("#vpContent #vpMain #tab_loadable").hide();
					$("#vpContent #vpMain #tab_"+ $(this).data('key')).show();
				} else {
					$("#vpContent #vpMain #tab_loadable").html('');
					$.ajax({
						url: _F.root + '/' + _F.lang + '/' + _F.prov + '/year/' + $('#vpContent').data('year') + '/vehicle/' + $('#vpContent').data('vehicle') + '/' + $(this).data('key') + '.html',
						dataType: 'html',
						success: function(data, textStatus, jqXHR) {
							$("#vpContent #vpMain #tab_loadable").html(data);
							$("#vpContent #vpMain #tab_loadable").show();
						}
					});
				}
			}
		});
		
		//the unbinding/rebinding of these mouse events is required for IE, RB.
		function showSocial(){
			$('.socialLinks').unbind('mouseenter');
			$('div.socialLinks_Text').stop(true,true);
			$('div.socialLinks_Text').show("slide", {direction: "right"}, 400, function(){ $('.socialLinks').bind('mouseenter', showSocial); } );
		}
		function hideSocial(){
			$('.socialLinks').unbind('mouseleave');
			$('div.socialLinks_Text').stop(true,true);
			$('div.socialLinks_Text').hide("slide", {direction: "right"}, 200, function() { $('.socialLinks').bind('mouseleave', hideSocial); } );
		}
		$('div.socialLinks').bind('mouseenter', function(e) {
			showSocial();
		});
		$('div.socialLinks').bind('mouseleave', function(e) {
			hideSocial();
		});
		
		
		$('div.ipadLinks').bind('mouseenter',function() {
			$('div.ipadLinksText').show("slide", {direction: "right"}, 1000); 
		});
		$('div.ipadLinks').bind('mouseleave',function() {
			$('div.ipadLinksText').hide("slide", {direction: "right"}, 1000); 
		});
		if($.ford.common.hasLocation() === false) {
			$('html').trigger('getPostal');
		}
	}
};

var vpEspotSlides = 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
	$('#vpEspotSlides').slides({
		preload: true,
		generateNextPrev: false,
		generatePagination: false,
		play: 8000,
		pause: 1500,
		hoverPause: true,
		// Get the starting slide
		start: startSlide,
		animationComplete: function(current)
		{
			// Set the slide number as a hash
			//window.location.hash = '#' + current;
			
		}
	});
};
