$(document).ready( function()
{
//---- ROLLOVER
	PEPS.rollover.init();

//----- DATEPICKERS

	$("#datepicker_in").datepicker({ dateFormat: 'dd/mm/yy' });	
	$("#datepicker_out").datepicker({ dateFormat: 'dd/mm/yy' });

//----- NAVIGATION
$('ul#nav > li').hover(function() {
    		$('ul:first', this).show();
  		},function(){
    			$('ul:first', this).hide();
		});

$('ul#nav li li').hover(function() {
    $('ul:first', this).each(function() {
      $(this).css('top', $(this).parent().position().top );
      $(this).css('left', $(this).parent().position().left + $(this).parent().width() );
      $(this).show();
    });},function(){
    $('ul:first', this).hide();
 	});

	
});

PEPS = {};
PEPS.rollover = {init: function()
   {
      this.preload();
     
      $(".ro").hover(
         function () { $(this).attr( 'src', PEPS.rollover.newimage($(this).attr('src')) ); },
         function () { $(this).attr( 'src', PEPS.rollover.oldimage($(this).attr('src')) ); }
      );
   },

   preload: function()
   {
      $(window).bind('load', function() {
         $('.ro').each( function( key, elm ) { $('<img>').attr( 'src', PEPS.rollover.newimage( $(this).attr('src') ) ); });
      });
   },
   
   newimage: function( src )
   {
      return src.substring( 0, src.search(/(\.[a-z]+)$/) ) + '_o' + src.match(/(\.[a-z]+)$/)[0];
   },

   oldimage: function( src )
   {
      return src.replace(/_o\./, '.');
   }
};
