$(window).load(function() {
	$('#specials').orbit({
		'bullets': false,
		'advanceSpeed': 5000,
		'timer' : true,
		'animation' : 'fade',
		'directionalNav': false
	});
	
	
	
	
	
	/**
	 * All the options of orbit
	$('#featured').orbit({
	     animation: 'fade',                  // fade, horizontal-slide, vertical-slide, horizontal-push
	     animationSpeed: 800,                // how fast animtions are
	     timer: true, 			 // true or false to have the timer
	     advanceSpeed: 4000, 		 // if timer is enabled, time between transitions 
	     pauseOnHover: false, 		 // if you hover pauses the slider
	     startClockOnMouseOut: false, 	 // if clock should start on MouseOut
	     startClockOnMouseOutAfter: 1000, 	 // how long after MouseOut should the timer start again
	     directionalNav: true, 		 // manual advancing directional navs
	     captions: true, 			 // do you want captions?
	     captionAnimation: 'fade', 		 // fade, slideOpen, none
	     captionAnimationSpeed: 800, 	 // if so how quickly should they animate in
	     bullets: false,			 // true or false to activate the bullet navigation
	     bulletThumbs: false,		 // thumbnails for the bullets
	     bulletThumbLocation: '',		 // location from this file where thumbs will be
	     afterSlideChange: function(){} 	 // empty function 
	});
	*/
	
	
	//auto populate make on year change
	$('#year').change( function(activateMake) {
		$('#make').empty();
		$('#model').empty();
		$('#vehOptions').empty();
		$('#sizeOptions').empty();
		$.ajax({
			url: 'retail/com/SearchFunctions.cfc?method=getMakeJSON',
			data: {
				vYear: $('#year').val()
			},
			success: function(data) {
				var ajxResponse = $.parseJSON(data);
				var html = '';
			    var len = ajxResponse.length;
			    for (var i = 0; i< len; i++) {
			        html += '<option value="' + ajxResponse[i][0] + '">' + ajxResponse[i][1] + '</option>';
			    }
			    $('#make').append(html);
			},
			error: function() {
				//alert('error will robinson error make');
			}		  			  		  
		});
	});
	
	//auto populate model on make change
	$('#make').change( function(activateMake) {
		$('#model').empty();
		$('#vehOptions').empty();
		$('#sizeOptions').empty();
		$.ajax({
			url: 'retail/com/SearchFunctions.cfc?method=getModelJSON',
			data: {
				vYear: $('#year').val(),
				vMake: $('#make').val()
			},
			success: function(data) {
				var ajxResponse = $.parseJSON(data);
				var html = '';
			    var len = ajxResponse.length;
			    for (var i = 0; i< len; i++) {
			        html += '<option value="' + ajxResponse[i][0] + '">' + ajxResponse[i][1] + '</option>';
			    }
			    $('#model').append(html);
			},
			error: function() {
				//alert('error will robinson error model');
			}		  			  		  
		});
	});
	
	//auto populate vehOptions on model change
	$('#model').change( function(activateMake) {
		$('#vehOptions').empty();
		$('#sizeOptions').empty();
		$.ajax({
			url: 'retail/com/SearchFunctions.cfc?method=getOptionsJSON',
			data: {
				vYear: $('#year').val(),
				vMake: $('#make').val(),
				vModel: $('#model').val()
			},
			success: function(data) {
				var ajxResponse = $.parseJSON(data);
				var html = '';
			    var len = ajxResponse.length;
			    for (var i = 0; i< len; i++) {
			        html += '<option value="' + ajxResponse[i][0] + '">' + ajxResponse[i][1] + '</option>';
			    }
			    $('#vehOptions').append(html);
			},
			error: function() {
				//alert('error will robinson error model');
			}		  			  		  
		});
	});
	
	//auto populate vehicleFormInfo on vehOptions change
	$('#vehOptions').change( function(activateMake) {
		$('#sizeOptions').empty();
		$.ajax({
			url: 'retail/com/SearchFunctions.cfc?method=getResultsJSON',
			data: {
				vYear: $('#year').val(),
				vMake: $('#make').val(),
				vModel: $('#model').val(),
				vOption: $('#vehOptions').val()
			},
			success: function(data) {
				var ajxResponse = $.parseJSON(data);
			    $('#sizeOptions').append(ajxResponse);
			},
			error: function(data) {
				//alert('error will robinson error vehicleFormInfo');
			}		  			  		  
		});
	});
	
	$.ajax({
		url: 'retail/com/SearchFunctions.cfc?method=getYearsJSON',
		success: function(data) {
			var ajxResponse = $.parseJSON(data);
			var html = '';
		    var len = ajxResponse.length;
		    for (var i = 0; i< len; i++) {
		        html += '<option value="' + ajxResponse[i][0] + '">' + ajxResponse[i][1] + '</option>';
		    }
		    $('#year').append(html);
		},
		error: function() {
			//alert('error will robinson error year');
		}		  			  		  
	});		
	
});

$(document).ready(function(){
	try {
		if (geoplugin_region() == 'WY' || geoplugin_region() == 'MT' || geoplugin_region() == 'ND' 
		  || geoplugin_region() == 'SD' || geoplugin_region() == 'ID') {
			window.location='indexDealer.cfm';
		}
	}
	catch (err) {
		//do nothing
	}
	
	$('#fbOneText').orbit({
		bullets: false,
		advanceSpeed: 4000,
		timer : true,
		animation : 'fade',
		directionalNav: false,
		pauseOnHover: true,
		startClockOnMouseOut: true
	});
	
	
	$("#accordion").accordion({ 
		header: "h2",
		animated: "bounceslide",
		clearStyle: true,
		autoHeight: false
	});	
	//$(".ui-accordion-content").css({ 'opacity' : 0.9});
	$(".ui-widget-content").css({ 'background' : 'none'});
	
	$('#submitVehicle').button();
	$('#submitSize').button();
	$('#submitQuick').button();
	
	$('#sizeForm').submit(function() {
		var canSubmit = false;
		if ($('#width').val() != 'All')
			canSubmit = true;
		if ($('#rim').val() != 'All')
			canSubmit = true;
		if ($('#aspect').val() != 'All')
			canSubmit = true;
		if (!canSubmit){
			$('#sizeFormInfo').show("fade", {}, 1500);
			$('#sizeForm select').effect("pulsate", {times:3}, 1300, function () {
				$('#sizeFormInfo').hide("fade", {}, 1500);
			});
		}			
		return canSubmit;
	});
	
	$('#vehicleForm').submit(function() {
		var canSubmit = false;
		if ($('#result1').length != 0)
			canSubmit = true;
		if (!canSubmit) {
			$('#vehicleFormInfo').show("fade", {}, 1500);
			$('#vehicleForm select').effect("pulsate", {times:3}, 1300, function () {
				$('#vehicleFormInfo').hide("fade", {}, 1500);
			});
		}
		return canSubmit;
	});
	
	$('#agSizeForm').submit(function() {
		var canSubmit = false;
		if ($('#agWidth').val() != 'All')
			canSubmit = true;
		if ($('#agRim').val() != 'All')
			canSubmit = true;
		if ($('#agAspect').val() != 'All')
			canSubmit = true;
		if (!canSubmit){
			$('#agSizeFormInfo').show("fade", {}, 1500);
			$('#agSizeForm select').effect("pulsate", {times:3}, 1300, function () {
				$('#agSizeFormInfo').hide("fade", {}, 1500);
			});
		}					
		return canSubmit;
	});
	
	$('#altSearchActivate').fancybox({
		onComplete: function() {
			$('#quickSearch').focus();
		}
	});
	
	/** $('#altSearchText').bt('Test text'); 
	$('.tooltip').each(function() {
		var myContent = '<div class="altSearchTip"><b>Alternate SEARCH:</b> <br />Alternate Search is the size without any slashes or dashes. <br />Alternate Search Example: SIZE: 235/75R15, <br />Would be Alternate SEARCH: 2357515</div>';
		//alert('attr = '+$(this).attr('href'));
		$(this).tipTip({
			defaultPosition: 'top',
			content: myContent,
			maxWidth: "300px"
		});
	 });
	*/
	
	/**
	$.fancybox({
		'padding'		: 0,
		'href'			: 'compareProducts.cfm?'+urlParams,
		'title'   		: 'Product Comparison',
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'type'          : 'iframe',
		'width'         : '75%',
        'height'        : '75%',
        'speedIn'       : 600,
        'speedOut'      : 200
	});	
	*/
	
	/**$('.tooltip').each(function() {
		$(this).bt({
			ajaxPath: ["$(this).attr('href')"],
			width: '400px',
			hoverIntentOpts: {
				interval: 500,
				timeout: 500
			},
			fill: 'rgba(209, 123, 25, .8)',
			strokeWidth: 3,
			strokeStyle: '#CC6D00',
			cssStyles: {
				color: '#FFF', 
				fontWeight: 'bold', 
				fontFamily: 'Arial, Helvetica, sans-serif'
			},
			activeClass: 'tt_active',
			shrinkToFit: true,
			spikeGirth: 15,
			spikeLength: 30
	 	});
	 });
	 **/
}); 
