$(function() {
		// Fake the idTabs 'selected tab' functionality. Look for body class, highlight corresponding tab
		if ($('body').hasClass('dealers')){
			$("a.dealer").closest('li').addClass('selected');
		}
		if ($('body').hasClass('contact-us')){
			$("a.contact").closest('li').addClass('selected');
		}
		if ($('body').hasClass('blog')){
			$("a.events").closest('li').addClass('selected');
		}
		// If the visitor clicks the Request Brochure, go ahead and show the mailing address section
		if(document.URL.indexOf("#request-brochure") >= 0){ 
			$("#sidebar-links").idTabs("photos"); 
			$("#mailingAddress").show().find('.ifyesrequire').addClass('needsfilled');
			$("#modelInterest").show();
			$("#brochure").attr('checked','checked');
		}

	}
);

$(window).load(function(){
	$('a.fancybox').each(function(){
		fancyHeight = $(this).children('img:eq(0)').attr('height')+10;
		fancyWidth = $(this).children('img:eq(0)').attr('width');
		$(this).append('<span class="clickenlarge">Click to Enlarge</span>').height(fancyHeight).width(fancyWidth);
		})
	}
);


	

$('#nav li:has(ul)').hover(
	function() { $('ul:first', this).css('display', 'block'); },
	function() { $('ul', this).css('display', 'none'); }
);


var accordion = $("#accordion h2");
$(accordion).prepend("<small></small>");
$(accordion).click(function(){
	$(this).toggleClass('open');
	$(this).children('small').toggleClass('arrowopen');
	$(this).next().slideToggle('slow');
});

$('#brochure').click(function(){
	if (($("#mailingAddress").is(":hidden")) && ($('#brochure').attr('checked') == true)){
		$("#mailingAddress").slideDown('slow').find('.ifyesrequire').addClass('needsfilled');
		$("#modelInterest").slideDown('slow');
	} else if ($('#brochure').attr('checked') == false) {
		$("#mailingAddress").slideUp().find('.ifyesrequire').removeClass('needsfilled');
		$("#modelInterest").slideUp();
	}
});


$(function(){
	$('.video_thumb').hover(function(){
		$(this).find('img').css('opacity','0.5');
	},function(){
		$(this).find('img').css('opacity','0.7');
	});	
	var fb_timeout = null;
	var fb_opts = { 'overlayShow' : true, 'centerOnScroll' : true, 'showCloseButton' : true, 'showNavArrows' : true, 'onCleanup' : function() { if(fb_timeout) { window.clearTimeout(fb_timeout); fb_timeout = null; } } };

	$('a.fancybox-youtube, area.fancybox-youtube').fancybox( $.extend({}, fb_opts, { 'type' : 'iframe', 'width' : 853, 'height' : 505, 'padding' : 0, 'autoScale' : false, 'titleShow' : false, 'titlePosition' : 'float', 'titleFromAlt' : true, 'onStart' : function(selectedArray, selectedIndex, selectedOpts) { selectedOpts.href = selectedArray[selectedIndex].href.replace(new RegExp('youtu.be', 'i'), 'www.youtube.com/embed').replace(new RegExp('watch\\?v=([a-z0-9\_\-]+)(&|\\?)?(.*)', 'i'), 'embed/$1?version=3&$3') } }) );
	/* Auto-click */ 
	$('#fancybox-auto').trigger('click');						
});
