var carFirst = true;
var suvFirst = true;
var truckFirst = true;
var hybridFirst = true;

function bannerClick(url){
	location.href = url + "?user_id=" + user_id;
}
function change_case(what)
{
	what.value = toProperCase(what.value)
}
function toProperCase(s)
{
	return s.toLowerCase().replace(/^(.)|\s(.)/g, 
		function($1) { return $1.toUpperCase(); });
}

function animateit(obj, evoxImage) {
    if (obj == 'carSlide') {
        if ($('#carSlide').width() < "880") {
            $('#carSlide').animate({ 'width': '880px', 'opacity': 100 }, 1500, function (){
				if (carFirst){
					setSliderModels('car1', 'car', '2010', 'Toyota', 'Yaris');
					document.getElementById('car1').style.background = "url(" + evoxImage + ")";
					document.getElementById('car1').style.backgroundPosition = "0px -30px";
					document.getElementById('car1').style.backgroundRepeat = "no-repeat";
					carFirst = false;
				}
			});
            $('#tab1').css('zIndex', ++currentTab);
            $('#carSlideContent').show(1500);
            
        }
        else {
            $('#carSlide').animate({ 'width': '0px', 'opacity': 0 }, 1500,
                function() {
                    //document.getElementById(currentCar).innerHTML = currentCarHTML;
					$('#carSlideContent').hide(0);
                }
            );
            //$('#carSlideContent').toggleClass('closed').hide(1500);
            //$('#carSlideContent').hide(1500);
        }
    }
    if (obj == 'suvSlide') {
        if ($('#suvSlide').width() < "880") {
            $('#suvSlide').animate({ 'width': '880px', 'opacity': 100 }, 1500, function (){
				if (suvFirst){
					setSliderModels('suv1', 'suv', '2010', 'Toyota', 'RAV4');
					document.getElementById('suv1').style.background = "url(" + evoxImage + ")";
					document.getElementById('suv1').style.backgroundPosition = "0px -30px";
					document.getElementById('suv1').style.backgroundRepeat = "no-repeat";
					suvFirst = false;
				}
			});
            $('#tab2').css('zIndex', ++currentTab);
            $('#suvSlideContent').fadeIn(1500);
            
        }
        else {
            $('#suvSlide').animate({ 'width': '0px', 'opacity': 0 }, 1500,
                function() {
					$('#suvSlideContent').hide(0);
                }
            );
            //$('#suvSlide').animate({ 'width': '0px' }, 1500);
            //$('#suvSlideContent').fadeOut(1500);
            
        }
    }
    if (obj == 'truckSlide') {
        if ($('#truckSlide').width() < "880") {
            $('#truckSlide').animate({ 'width': '880px', 'opacity': 100 }, 1500, function (){
				if (truckFirst){
					setSliderModels('truck1', 'truck', '2010', 'Toyota', 'Tacoma');
					document.getElementById('truck1').style.background = "url(" + evoxImage + ")";
					document.getElementById('truck1').style.backgroundPosition = "0px -30px";
					document.getElementById('truck1').style.backgroundRepeat = "no-repeat";
					truckFirst = false;
				}
			});
            $('#tab3').css('zIndex', ++currentTab);
            $('#truckSlideContent').show(1500);
        }
        else {
            $('#truckSlide').animate({ 'width': '0px', 'opacity': 0 }, 1500,
                function() {
					$('#truckSlideContent').hide(0);
                }
            );
            //$('#truckSlide').animate({ 'width': '0px' }, 1500);
            //$('#truckSlideContent').hide(1500);
        }
    }
    if (obj == 'hybridSlide') {
        if ($('#hybridSlide').width() < "880") {
            $('#hybridSlide').animate({ 'width': '880px', 'opacity': 100 }, 1500, function (){
				if (hybridFirst){
					setSliderModels('hybrid1', 'hybrid', '2010', 'Toyota', 'Prius');
					document.getElementById('hybrid1').style.background = "url(" + evoxImage + ")";
					document.getElementById('hybrid1').style.backgroundPosition = "0px -30px";
					document.getElementById('hybrid1').style.backgroundRepeat = "no-repeat";
					hybridFirst = false;
				}
			});
            $('#tab4').css('zIndex', ++currentTab);
            $('#hybridSlideContent').show(1500);
        }
        else {
            $('#hybridSlide').animate({ 'width': '0px', 'opacity': 0 }, 1500,
                function() {
					$('#hybridSlideContent').hide(0);
                }
            );
            //$('#hybridSlide').animate({ 'width': '0px' }, 1500);
            //$('#hybridSlideContent').hide(1500);
        }
    }


}

var mycarousel_itemList = [
			{ url: 'http://mt0.bochstatic.com/toyotasouth/images/ticker11.JPG', title: 'New Inventory', href: 'toyota-inventory-new.asp?user_id=' + user_id },
			{ url: 'http://mt3.bochstatic.com/toyotasouth/images/last-chance-lot.jpg', title: 'Last Chance Lot', href: 'toyota-lastchance.asp?user_id=' + user_id },
			{ url: 'http://mt1.bochstatic.com/toyotasouth/images/certifiedticker.jpg ', title: 'Used Inventory', href: 'boch-certified-pre-owned-ma.asp?user_id=' + user_id },
			{ url: 'http://mt2.bochstatic.com/toyotasouth/images/ticker13.JPG', title: 'Monthly Incentives', href: 'toyota-incentives.asp?user_id=' + user_id },
			{ url: 'http://mt0.bochstatic.com/toyotasouth/images/trade-in-value-ticker.jpg', title: 'Trade In Value', href: 'toyota-vehicle-trade-value.asp?user_id=' + user_id },
			{ url: 'http://mt0.bochstatic.com/toyotasouth/images/ticker-tires-red.png', title: 'Boch Toyota South Tires', href: 'buy-toyota-dealer-tires-north-attleboro-ma.asp?user_id=' + user_id },
			{ url: 'http://mt3.bochstatic.com/toyotasouth/images/ticker14.JPG', title: 'Printed Ads', href: 'toyota-weekly-promotions.asp?user_id=' + user_id },
			{ url: 'http://mt0.bochstatic.com/toyotasouth/images/ticker15.JPG', title: 'Service Specials', href: 'toyota-service.asp?user_id=' + user_id },
			{ url: 'http://mt1.bochstatic.com/toyotasouth/images/ticker16.JPG', title: 'Parts Department', href: 'toyota-parts.asp?user_id=' + user_id },
			{ url: 'http://mt2.bochstatic.com/toyotasouth/images/ticker17.JPG', title: 'Get Pre Approved', href: 'toyota-finance.asp?user_id=' + user_id }
		];

function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt) {
    // The index() method calculates the index from a
    // given index who is out of the actual item range.
    var idx = carousel.index(i, mycarousel_itemList.length);
    carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[idx - 1]));
};

function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt) {
    carousel.remove(i);
};

/**
* Item html creation helper.
*/
function mycarousel_getItemHTML(item) {
    var href_m = item.href;
    //alert(href_m);
    var url_m = item.url.replace(/_s.jpg/g, '_m.jpg');
    return '<a href="' + href_m + '" title="' + item.title + '" target="_self"><img src="' + item.url + '" width="170" height="80" border="0" alt="' + item.title + '" /></a>';
};

jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel({
        scroll: 1,
        auto: 0,
        wrap: 'circular',
        itemVisibleInCallback: { onBeforeAnimation: mycarousel_itemVisibleInCallback },
        itemVisibleOutCallback: { onAfterAnimation: mycarousel_itemVisibleOutCallback }
    });
    $('#car1').animate({ 'width': '300px', 'left': '165px', 'height': '190px', 'top': '15px' }, 5);
    $('#car1 > img').hide("slow");
    $('#suv1').animate({ 'width': '300px', 'left': '165px', 'height': '190px', 'top': '15px' }, 750);
    $('#suv1 > img').hide("slow");
    $('#truck1').animate({ 'width': '300px', 'left': '165px', 'height': '190px', 'top': '15px' }, 750);
    $('#truck1 > img').hide("slow");
    $('#hybrid1').animate({ 'width': '300px', 'left': '165px', 'height': '190px', 'top': '15px' }, 750);    
    $('#hybrid1 > img').hide("slow");
    $('#carSlideContent').hide();
    $('#suvSlideContent').hide();
    $('#truckSlideContent').hide();
    $('#hybridSlideContent').hide();
	var carFirst = true;
	var suvFirst = true;
	var truckFirst = true;
	var hybridFirst = true;
	//setSliderModels('car1', 'car', '2010', 'Toyota', 'Yaris');
	//setSliderModels('suv1', 'suv', '2010', 'Toyota', 'RAV4');
	//setSliderModels('truck1', 'truck', '2010', 'Toyota', 'Tacoma');
	//setSliderModels('hybrid1', 'hybrid', '2010', 'Toyota', 'Prius');
});
currentCar = 'car1';
currentTopCar = '2px';
currentLeftCar = '10px';
currentSUV = 'suv1';
currentTopSUV = '2px';
currentLeftSUV = '10px';
currentTruck = 'truck1'
currentTopTruck = '2px';
currentLeftTruck = '10px';
currentHybrid = 'hybrid1';
currentTopHybrid = '2px';
currentLeftHybrid = '10px';
currentVehicle = '';
currentTop = '';
currentLeft = '';
currentTab = 9999;
currentCarHTML = '<img src="images/yarisIcon.jpg" width="60" />';
currentType = 'car';

function enlargeMe(thisVehicle, type, evoxImage, vehYear, vehMake, vehModel) {
	currentType=type;
	document.getElementById(thisVehicle).style.background = "url(" + evoxImage + ")";
	document.getElementById(thisVehicle).style.backgroundPosition = "0px -30px";
	document.getElementById(thisVehicle).style.backgroundRepeat = "no-repeat";
    switch (type) {
        case 'car':
            //currentCarHTML = document.getElementById(thisVehicle).innerHTML;
            currentVehicle = currentCar;
            currentCar = thisVehicle;
            currentTop = currentTopCar;
            currentLeft = currentLeftCar;
            break;
        case 'suv':
            currentVehicle = currentSUV;
            currentSUV = thisVehicle;
            currentTop = currentTopSUV;
            currentLeft = currentLeftSUV;
            break;
        case 'truck':
            currentVehicle = currentTruck;
            currentTruck = thisVehicle;
            currentTop = currentTopTruck;
            currentLeft = currentLeftTruck;
            break;
        case 'hybrid':
            currentVehicle = currentHybrid;
            currentHybrid = thisVehicle;
            currentTop = currentTopHybrid;
            currentLeft = currentLeftHybrid;
            break;
    }
    if ($('#' + thisVehicle).width() < "300") {
		document.getElementById(currentType + "VehicleModels").innerHTML = "";
        $('#' + thisVehicle).animate({ 'width': '300px', 'left': '165px', 'height': '190px', 'top': '15px' }, 750,
									 function(){
										 document.getElementById(currentType + "TitleText").innerHTML = '';
										 }
									 );
        $('#' + thisVehicle + '> img').hide("slow");
        
        //document.getElementById(currentVehicle).innerHTML = currentCarHTML;
        $('#' + currentVehicle).animate({ 'width': '50px', 'left': currentLeft, 'height': '50px', 'top': currentTop }, 750);
        $('#' + currentVehicle + '> img').show(750);
		
		switch (type) {
            case 'car':
                currentTopCar = $('#' + thisVehicle).css("top");
                currentLeftCar = $('#' + thisVehicle).css("left");
                break;
            case 'suv':
                currentTopSUV = $('#' + thisVehicle).css("top");
                currentLeftSUV = $('#' + thisVehicle).css("left");
                break;
            case 'truck':
                currentTopTruck = $('#' + thisVehicle).css("top");
                currentLeftTruck = $('#' + thisVehicle).css("left");
                break;
            case 'hybrid':
                currentTopHybrid = $('#' + thisVehicle).css("top");
                currentLeftHybrid = $('#' + thisVehicle).css("left");
                break;
        }
		
		setSliderModels(thisVehicle, currentType, vehYear, vehMake, vehModel);
    }
}


function setSliderModels(theVehicle, currentType, vehYear, vehMake, vehModel){
	document.getElementById(currentType + "VehicleModels").innerHTML = document.getElementById(currentType + "VehicleModels").innerHTML + "<div style='float:left; width:100%; margin-top:5px;'><div class='modelColorTitle'>Model Trims"
	var sURL = "include/functions.asp?action=getvinstylenameimage&year=" + vehYear + "&make=" + vehMake + "&model=" + vehModel;
	var htmlModels = "";
	//alert(vehModel);
	//alert(sURL);
	document.body.style.cursor = "wait";
	var aa = $.ajax({url: sURL, async: false }).responseText;
	document.body.style.cursor = "default";
	//alert(aa);
	htmlModels=aa.split("|");
	for(loop1 = 0; loop1 < htmlModels.length; loop1++){
		var trims = htmlModels[loop1].split("#");
		document.getElementById(currentType + "VehicleModels").innerHTML = document.getElementById(currentType + "VehicleModels").innerHTML + "<div onclick='switchModelImage(\"" + theVehicle + "\",\"" + trims[1] + "\",\"" + trims[0] + "\",\"" + vehYear + "\",\"" + vehMake + "\",\"" + vehModel + "\"); testing(\"" + vehYear + "\",\"" + vehMake + "\",\"" + vehModel + "\")' style='float:left;width:33%;text-align:center; padding-top:3px;'><img style='border:solid 1px #999; cursor:pointer;' src='" + trims[1] + "' width='60'></div>";
	}
	document.getElementById(currentType + "VehicleModels").innerHTML = document.getElementById(currentType + "VehicleModels").innerHTML + "</div>"
	
	document.getElementById(currentType + "VehicleModels").innerHTML = document.getElementById(currentType + "VehicleModels").innerHTML + "<div style='float:left; width:100%; margin-top:5px;'><div class='modelColorTitle'>Model Colors"
	var sURL = "include/functions.asp?action=getvincolors&year=" + vehYear + "&make=" + vehMake + "&model=" + vehModel;
	//alert(sURL);
	var htmlModels = "";
	document.body.style.cursor = "wait";
	var aa = $.ajax({url: sURL, async: false }).responseText;
	document.body.style.cursor = "default";
	htmlModels=aa.split("|");
	for(loop1 = 0; loop1 < htmlModels.length; loop1++){
		var colors = htmlModels[loop1].split("#");
		document.getElementById(currentType + "VehicleModels").innerHTML = document.getElementById(currentType + "VehicleModels").innerHTML + "<div onclick='switchModelImage(\"" + theVehicle + "\",\"" + colors[0] + "\",\"" + colors[2] + "\",\"" + vehYear + "\",\"" + vehMake + "\",\"" + vehModel + "\")' class='modelColor' style='background-color:#" + colors[1] + "'></div>";
	}
	document.getElementById(currentType + "VehicleModels").innerHTML = document.getElementById(currentType + "VehicleModels").innerHTML + "</div>"
}


function switchModelImage(divID, modelImage, modelText, carYear, carMake, carModel){
	document.getElementById(divID).style.background = "url(" + modelImage + ")";
	document.getElementById(divID).style.backgroundPosition = (modelImage.toLowerCase().indexOf("evox") > 0) ? "0px -20px" : "0px center"; 
	document.getElementById(divID).style.backgroundSize = (modelImage.toLowerCase().indexOf("evox") > 0) ? "100% 100%" : "80% 80%"; 
	document.getElementById(divID).style.backgroundRepeat = "no-repeat";
	document.getElementById(currentType + "TitleText").innerHTML = "<div style='width:100%; text-align:center; font-size:14px; font-weight:bold'>" + modelText + "</div>";
	document.getElementById(currentType + "InventoryLink").innerHTML = "<div style='width:120px; margin:0 auto; text-align:center; font-size:11px;'><a id='btnInventory' class='clickButtonSm' href='#' onclick=\"updateUserSearch('" + carYear + "','" +  carMake + "','" + carModel + "', '', 'N');return false\">View Inventory</a></div>";
}
