
$(document).ready(function(){

$("body").removeAttr('contenteditable'); //because of some weird code inserted into Booths

//if this is the sitemap page, clone top menu to fake a sitemap
if ($('html').is('.sitemap')) {   

$('div.menuVehicles > ul').clone().prependTo('.sitemapMenu');
$('#TopMenuBar ul.rootGroup').clone().appendTo('.sitemapMenu');

}

//smaller logo if two email addresses in header
if ($('.dealer_details ul').next().is('ul')) { 
$('#dealer_header').addClass('two');	
  }
  
else{	
$('#dealer_header').removeClass('two');	
}


//empty promos
//$("h1:contains('Promotions')").parent('div.article_text').addClass('promoPage');
//$('.promoPage').has('img').addClass('hasPromo');

//if ($('.promoPage').is('.hasPromo')) { 
//$('h4.noPromo').remove();	
 // }
  
//else{	
//$('.promoPage').append('<h4 class="noPromo">No current promotions</h4>');
//}
						    
//VEHICLES MEGA MENU

$('div.menuVehicles div').hide(); //hide all mega menu divs on load
$('div.menuVehicles ul ul').hide(); //hide all uls on load

$("div.menuVehicles > ul").addClass("vehicles");
$("div.menuVehicles > ul > li > ul").addClass("bodyTypes");
$("ul.bodyTypes li").removeClass();
$("ul.bodyTypes > li").addClass(function(i){return "body bodyType" + (i + 1);});
$(".bodyType1").children("ul").children("li").addClass(function(i){return "small" + (i + 1);});
$(".bodyType2").children("ul").children("li").addClass(function(i){return "medium" + (i + 1);});
$(".bodyType3").children("ul").children("li").addClass(function(i){return "suv" + (i + 1);});
$(".bodyType4").children("ul").children("li").addClass(function(i){return "people" + (i + 1);});
$(".bodyType5").children("ul").children("li").addClass(function(i){return "commercial" + (i + 1);});
$(".bodyType6").children("ul").children("li").addClass(function(i){return "coming" + (i + 1);});


$(".typeSmall").addClass(function(i){return "small" + (i + 1);});
$(".typeMedium").addClass(function(i){return "medium" + (i + 1);});
$(".typeSUV").addClass(function(i){return "suv" + (i + 1);});
$(".typePeople").addClass(function(i){return "people" + (i + 1);});
$(".typeCommercial").addClass(function(i){return "commercial" + (i + 1);});
$(".typeComing").addClass(function(i){return "coming" + (i + 1);});

$('div.menuVehicles div ul li:last-child').addClass('last');

$('li.body:first-child').addClass('first');
$('li.body:last-child').addClass('last');

   $('li.body > ul > li').mouseover(function(e){
        e.preventDefault();
	$('div.menuVehicles div:visible').hide();
    });
	
	$('ul.bodyTypes li.last').mouseover(function(e){
      
    });
		
		
	$('div.menuVehicles .vehicles > li > a').mouseover(function(e){
		$('li.body > ul').hide();													
      	 $('div.menuVehicles div').hide();
		 $('span.blank').hide(); //blank space for divs to sit on as they fade in/out
    });
	
	
	
	$('.typeSmall').appendTo('.bodyType1');
	$('.typeMedium').appendTo('.bodyType2');
	$('.typeSUV').appendTo('.bodyType3');
	$('.typePeople').appendTo('.bodyType4');
	$('.typeCommercial').appendTo('.bodyType5');
	$('.typeComing').appendTo('.bodyType6');

   
	$('li.body').mouseover(function(e){
		$(this).children('ul').css('display','block');
		$(this).siblings('li').children('ul').css('display','none');
		 $(this).siblings('li').children('div').css('display','none');
		 $(this).siblings('li').children('span.blank').css('display','none');
		 $(this).children('div:nth-child(3)').css('display','block').fadeTo(10, 1); //show first vehicle div on load
		 $(this).children('span.blank').css('display','block');
    });


$("li.body:has(ul)").addClass('expand').append('<span class="blank"></span>');
	
// hover delay 

$("li.body > ul > li").hoverIntent({ 
sensitivity: 1,		
interval: 20,
over: appear,
timeout: 10,
out: disappear
});
});

function appear (){  
$('div.menuVehicles .' + $(this).attr('class')).fadeTo(500, 1); 
$('div.menuVehicles .' + $(this).attr('class')).siblings('div').fadeTo(500,0);	
}
function disappear (){  
$('div.menuVehicles div:visible').hide();
$('div.menuVehicles .' + $(this).attr('class')).show();
} 


$(document).ready(function() {

if ($('div').is('#section_subnav')) { 
// add class to vehicle sub navs to style selected tab on vehicle model pages
var path = location.pathname; 
var home = "/";
$("a[href='" + [path || home] + "']").parents("li").each(function() {   
$(this).addClass("selected");
		
});
}

// fix image gallery widget to show large image rather than small thumbnail
$('.promo a').each(function() {
var newsrc = $(this).attr('href');
$(this).children('img').attr('src',newsrc).attr('align','center');
});

if ($('.left_dealer_map a').parent().is('p')) {   //unwrap unecess paragraphs
  $('.left_dealer_map p a').unwrap('p');
}

// add lightbox to dealer map and append necessary query
$('.left_dealer_map h4').next('a[href]').addClass('nyroModal').addClass('large').attr('href', function(index, attr) {
       return attr + "&output=embed";
  });

$('.left_dealer_map li').children('a[href]').addClass('nyroModal').attr('href', function(index, attr) {
       return attr + "&output=embed";
  });



//just in case another <ul> is created inside the article
$('ul#footer-ticker ul li').appendTo('ul#footer-ticker'); 
$('ul#footer-ticker ul').remove();
$('ul#footer-ticker br').remove();

if ($('ul#footer-ticker').children().is('li')) {   

        $('ul#footer-ticker').cycle({
            fx: 'fade'
        });
}

  
//if edit page, show wallpaper div  
  if ($('div').is('.ZoneControls')) {   
    $('#wallpaper').css('display','block').css('height', '200px').css('overflow','hidden');
}

//if logged in, add logout link to admin toolbar
if ($('a').is('.dashboard-button')) {   
$('body').addClass('loggedIn');
}

if ($('div').is('#AdminBar')) {   
$('#AdminBar ul.rootGroup').append('<li class="item"><a href="/logout.aspx"><span class="text">Logout</span></a></li>');
$('#AdminBar ul.rootGroup ul').addClass('vertical').removeClass('horizontal');
}

$('.promoSlide img').attr('align','center');
	   $('.promoSlide a').each(function() {
        var newsrc = $(this).attr('href');
        $(this).children('img').attr('src',newsrc);
        //$(this).attr('href','');	
		$(this).removeAttr('href');			
    });



if ($('div').is('.promoSlide')) { //

    $('#pagecontent').addClass('promoSlideContainer');
	
//$('div.promoSlide img').appendTo($('div.promoSlide'));
//$('div.promoSlide div').remove();

$('div.promoSlide div.allsubItems > div').appendTo($('div.promoSlide'));
    $('div.promoSlide > div').addClass('mainItem');
	$('div.promoSlide div.allsubItems').remove();
	
$('.widgetPageLinks').remove();
$('.promoSlide h1').remove();
$('.promoSlide h2').remove();
	

    $('.article_text').prepend('<div class="navSlide">');
	//$('div.promoSlide h1').prependTo('.article_text');
    $('.promoSlide').wrapAll('<div class="promoContainer"></div>');


    $('.promoSlide')
    .cycle({
		fx: 'fade',
                timeout: 12000,
                next:   '#next',
                prev:   '#prev',
                pager:  '.navSlide',
     before: function(){
         $(this).siblings('div').css('position','absolute');
               //    $(this).siblings('img').css('position','absolute');
		  $(this).css('position','relative');
     }
		
	});
}

							


if ($('.generalContent #page_feature img').parent().is('p')) {   
  $('.generalContent #page_feature img').unwrap('p');
}

if ($('#page_feature').contents().is('img')) { 
  }
else { 
$('#page_feature').addClass('noBanner');
  }


if ($('div').is('.ZoneControls')) { 
$('.generalContent #page_feature').show();
  }
  
else{	
   $('.generalContent #page_feature img').nextAll('img').remove();  
   $('.generalContent #page_feature img').siblings().remove();  
}

});


//refer a friend
function ReferFriendOpen(strURL, intArticleID, strPageToOpen)
{
	window.open(strPageToOpen + '?Article=' + intArticleID + '&' + strURL, 'Help', 'toolbar=no,width=580,height=420,resize=no, scrollbar=no');
}



/* ########################################################################### *
	/* ##### HOVER INTENT INCLUDE
	/* ########################################################################### */

	/**
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne <brian@cherne.net>
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);






















































