 $(document).ready(function(){

    // clear form default elements
    $("input.clearDefault").each(function(){
	$(this).click(function(){
	    if (this.value == this.defaultValue)
		this.value = '';
	});
	$(this).blur(function(){
	   if (this.value == '')
	       this.value = this.defaultValue;
	});
    });
    
 });


// image gallery
 $(document).ready(function(){
     var truckGallery = $('#truckGallery');
     if (truckGallery.length) {
         // got a gallery to initialise

         // attach to the various images
         truckGallery.find('.truckThumbnail').each(function(){
             $(this).hover(function(){
                 var thumbSrc = this.children[0].src;
                 if (thumbSrc) {
                     var matches = /.*?(\d+)/i.exec(thumbSrc);
                     if (matches.length == 2) {
                         mediaId = matches[1];
                         truckGallery.find('#mainImageImg')[0].src = '/media/' + mediaId;
                     }
                    
                 }
             }, function(){});
         });

         // simulate a hover for the first element so we get it in the big image
         truckGallery.find('.truckThumbnail').first().trigger('mouseenter');

         // hide all the fallback big images
         truckGallery.find('#fallBackImages')[0].style.display = "none";

         // show the gallery
         truckGallery.find('#javascriptGallery')[0].style.display = "block";
     }
 });
