        var year = [];
        var make = [];
        var model = [];
        var imageURL = [];				    
        var adURL = [];
        var askingPrice = []; 
        var x = 0; 
        var y = 0;
        var numLinks = 0;
        
        $(document).ready(function(){      
            
            $.ajax({
	            type: "GET",
	            url: "../../feat.xml",
	            dataType: "xml",
	            success: function(xml) {
    	        
	                $("#featuredVehicleBottom p").append('<a id="btnPrevious" href="javascript:void(0);"><span>Previous</span></a>');
    	            
		            $(xml).find("Advertisement").each(function(){
    		        
			            year.push($(this).find("year").text());
			            make.push($(this).find("make").text());
			            model.push($(this).find("model").text());
			            imageURL.push($(this).find("image_url_1").text());
				   		var url = 'http://www.1stopmotors.com/osm-vehicle/index.cfm/' + $(this).find("stockno").text()	    
				        adURL.push(url);
			            askingPrice.push($(this).find("asking_price").text());
    			        
		                $("#featuredVehicleBottom p").append('<a class="listingBtn" id="btn' + x + '" href="javascript:void(0);"><span>Featured Vehicle ' + x + '</span></a>');
		                x++;
    		            
		            });
    		        
		            $("#featuredVehicleBottom p").append('<a id="btnNext" href="javascript:void(0);"><span>Next</span></a>');
		            numLinks = $(".listingBtn").length;
		            if(numLinks > 0){
		                setVehicleValues(0);
		            }
	            }
            });
            
            $("#featuredVehicleBottom .listingBtn").live("click",function(e){
                e.preventDefault();
                var clickedImageNumber =  $(this).attr('id').substr(3,$(this).attr('id').length);
                y = clickedImageNumber;
                setVehicleValues(clickedImageNumber);
            });
            
            function setVehicleValues(id){
                $("#featuredVehicle > a").attr("href",adURL[id]);
                $("#featuredVehicle > img").attr("src",imageURL[id]);
                $("#featuredVehicleTop h1").text(year[id] + ' ' + make[id] + ' ' + model[id]); 
                $("#featuredVehicleTop p").text(formatCurrency(askingPrice[id])); 
                setSelected(id);  
            }
            
          function setSelected(btnId){
                $('.listingBtn').removeClass('selected');
                var thisId = '#btn' + btnId;
                $(thisId).addClass('selected');     
          }
	        
          function getNext(){
            if ($(':animated').length) {
                return false;
            } else {

                if(y==numLinks-1){
                  y=0;
                }else{
                  y++;
                }
                setVehicleValues(y);
            }
          }

          function getPrev(){
            if ($(':animated').length) {
                return false;
            } else {

                if(y==0){
                  y=numLinks-1;
                }else{
                  y--;
                }
                setVehicleValues(y);
            }
          }
          
        function formatCurrency(strValue)
        {
            strValue = strValue.toString().replace(/\$|\,/g,'');
            dblValue = parseFloat(strValue);

            blnSign = (dblValue == (dblValue = Math.abs(dblValue)));
            dblValue = Math.floor(dblValue*100+0.50000000001);
            intCents = dblValue%100;
            strCents = intCents.toString();
            dblValue = Math.floor(dblValue/100).toString();
            if(intCents<10)
	            strCents = "0" + strCents;
            for (var i = 0; i < Math.floor((dblValue.length-(1+i))/3); i++)
	            dblValue = dblValue.substring(0,dblValue.length-(4*i+3))+','+
	            dblValue.substring(dblValue.length-(4*i+3));
            return (((blnSign)?'':'-') + '$' + dblValue + '.' + strCents);
        }

        $('#btnNext').live("click",function(e){
            getNext();
        });

        $('#btnPrevious').live("click",function(e){
            getPrev();
        });
    	    
        });
