// JQUERY CUSTOM COMMANDS
$(document).ready( function() {  // start javascript when document is loaded
	
	// ADD CLASSES FOR LAYOUT STYLING
	
	
	// HEADER VISUAL CYCLE (uses Cycle plugin)
	$('#headerVisual').cycle({ 
	    fx:    'fade', 
	    speed:  2500,
		pause:  3,
		random:  1 
	 });
	

	// INPUT FOCUS & BLUR
	$('input.textfield, textarea.textarea, select.select').focus(function() {
	    $(this).addClass("focus");
	});
	$('input.textfield, textarea.textarea, select.select').blur(function() {
	    $(this).removeClass("focus");
		$(this).removeClass("error");
		$(this).parents("li").find("div.error").empty();
	});
	
	
	// LISTER
	$("tbody tr:odd").addClass('odd');
	$("tbody tr:even").addClass('even');
	$("tbody tr:first").addClass('first');
	$("tbody tr:last").addClass('last');
	$('tbody tr').hover(function() {
	    $(this).addClass('hover');
	}, function() {
	    $(this).removeClass('hover');
	});
	// remove onclick
	$('tbody tr a').click(function(){
		$(this).parents('tr').removeAttr('onclick');
	})
	
	
	// DEALER MAP
	$('#dealerMap li').hover(function() {
		$('#dealerMap .dealer').hide('fast');
		$(this).find('.dealer').show('fast');
		$(this).css('z-index', '2');
	}, function() {
		$(this).find('.dealer').hide('fast');
		$(this).css('z-index', '1');
	});

	
	// ROLLOVER IMAGES (1/2)
	IMAGE.rollover.init();
   
}); // end ready function




// ROLLOVER IMAGES (2/2)
IMAGE = {};
IMAGE.rollover = {
   init: function() {
      this.preload();
      $(".rollover").hover(
         function () { $(this).attr( 'src', IMAGE.rollover.newimage($(this).attr('src')) ); },
         function () { $(this).attr( 'src', IMAGE.rollover.oldimage($(this).attr('src')) ); }
      );
   },
   preload: function() {
      $(window).bind('load', function() {
         $('.rollover').each( function( key, elm ) { $('<img>').attr( 'src', IMAGE.rollover.newimage( $(this).attr('src') ) ); });
      });
   },
   newimage: function( src ) {
      return src.substring( 0, src.search(/(\.[a-z]+)/) ) + '_on' + src.match(/(\.[a-z]+)/)[0];
   },
   oldimage: function( src ) {
      return src.replace(/_on/, '');
   }
};