$(function(){
	var dsAjax = new DS.SpecialsService(s);
	var newSpecials = dsAjax.getNew(20);
	var usedSpecials = dsAjax.getUsed(20);
	var themeName = "<li><div class='special'>"
								+ "<a href='${specialLink}'><img src='${imagePath}' alt='${title}' /></a>"
								+ "<h3 title='${title}'>${title}</h3>"
								+ "<p>SPECIAL OFFER</p>"
								+ "<span>${line1}</span>"
								+ "</div></li>";
	dsAjax.render("newSpBox",newSpecials,themeName);
	dsAjax.render("usedSpBox",usedSpecials,themeName);

	if (newSpecials.length)
		$("#newSpBox").show();
	if (usedSpecials.length)
		$("#usedSpBox").show();
		
	$(".special img").error(function(){
		$(this).attr('src','http://sitespecific.dealerskins.com/CarouselMotors/2011assets/no-vehicle-image-available.jpg');
	});
});

$(document).ready(function() {
	$('#slideshow').cycle({
		fx: 'fade',
		speed: 750,
		timeout: 5000,
		pause: 1,
		pager: '#controls'
	});
	// If more than 3 specials, initiat jCarousel, otherwise apply css
	if ($('#newSpBox').children().length > '3') {
		jQuery('#newSpBox').jcarousel({
			wrap: 'circular'
		});
	} else {
		$('#newSpBox').css({
			'width':'471px','height':'166px','margin-top':'41px','list-style':'none'
		});
		$('#newSpBox li').css({
			'width':'150px','margin-right':'10px','float':'left'
		});
		$('#newSpBox li:nth-child(3n)').css({
			'margin-right':'0px'
		});
	}
	if ($('#usedSpBox').children().length > '3') {
		jQuery('#usedSpBox').jcarousel({
			wrap: 'circular'
		});
	} else {
		$('#usedSpBox').css({
			'width':'471px','height':'166px','margin-top':'41px','list-style':'none'
		});
		$('#usedSpBox li').css({
			'width':'150px','margin-right':'10px','float':'left'
		});
		$('#usedSpBox li:nth-child(3n)').css({
			'margin-right':'0px'
		});
	}
	$("ul.jcarousel-list li:nth-child(3n)").css('background','none');
});

var thisURL = location.protocol + "//" + document.location.hostname + "/";
params_carousel2011 = {menu:'false',allowscriptaccess:'always',wmode:'transparent'};
flashvars_carousel2011 = {siteid:s,servername:thisURL};
attributes_carousel2011 = {};
swfobject.embedSWF("/sitespecific/CarouselMotors/inventory-search.swf", "invSearch", "330", "310", "9.0.0",false,flashvars_carousel2011,params_carousel2011,attributes_carousel2011);

