function set_hotel_details( hotel_to_find, elementID ){

  hotel_details = "";
  for (i in associativeArray) { 
    if( hotel_to_find == i ){
     hotel_details = associativeArray[i].split("#");
    }
    //document.writeln(i+':'+associativeArray[i]+', '); 
    // outputs: one:First, two:Second, three:Third
  };  

  if($(elementID).val() == "" ){
    $(elementID).val(hotel_details);
  }

}

var data = "<?= $hotels ?>".split("#");

var FROM_AIRPORT        = 1;
var FROM_SUBURB         = 4;
var JOURNEY_TYPE_FLEXI  = 3;

function center_element( element ){

  xpos = ( $("#wrapper").width() / 2 ) - ( $(element).width() / 2 );
  ypos = ( $(window).height() / 2 ) - ( $(element).height() / 2 );
    
  $(element).css("left" , xpos );
  $(element).css("top" , ypos );

}


$(document).ready(function() {

  // site specific (rio)
  $('.jq_detect_cruise_terminal').change( function(){
    if($('.jq_detect_cruise_terminal').val() == 33 ){
      if( $('[name=a_address1]').val() == "" ){
        $('[name=a_address1]').val('Cais do Porto');
      }
      if( $('[name=a_address2]').val() == "" ){
        $('[name=a_address2]').val('Pier Maua');
      }
	  //$('#jq_hotel_cruise_text').html( 'Cruise Ship' );	  	  
    } else {
	  //$('#jq_hotel_cruise_text').html( 'Hotel' );	  
	}
  });


  //alert(get_hotel_details("Apa Hotel"));

//  $('#blk_rio_booking').bind("click",function(){
//	set_hotel_details($("#blk_rio_booking #a_hotel").val(),"#add1");
//  });

  $( '.jq_fill_booking' ).bind("click", function(){			 
    $('[name=title]').val('Mr');
    $('[name=name]').val('testy');
    $('[name=surname]').val('tester');
    $('[name=email]').val('test@test.com');
    $('[name=confirm_email]').val('test@test.com');
    $('[name=tel_number]').val('tel_number');	
    $('[name=address1]').val('123 test street');
    $('[name=address2]').val('testsham');
    $('[name=town_city]').val('testville');
    $('[name=county_state]').val('testerset');
    $('[name=postal_code]').val('TT11 T12');
    $('[name=country]').val('United Kingdom');

	return false;
  });

  //=== tooltip 1
  $(".jq_tooltip1").hover(
    function () {
      $("#tooltip_text_1").fadeIn();
    }, 
    function () {
      $("#tooltip_text_1").fadeOut("fast");
    }
  );

  //=== tooltip 2
  $(".jq_tooltip2").hover(
    function () {
      $("#tooltip_text_2").fadeIn();
    }, 
    function () {
      $("#tooltip_text_2").fadeOut("fast");
    }
  );


  //=== tooltip 3
  $(".jq_tooltip3").hover(
    function () {
      $("#tooltip_text_3").fadeIn();
    }, 
    function () {
      $("#tooltip_text_3").fadeOut("fast");
    }
  );

  //=== date picker
	var pickerOpts = {
			dateFormat: "dd M y",
	    minDate: new Date(),
	    maxDate: "+1095"
	}; 
	$(".jq_datepicker").datepicker(pickerOpts);	
	

// no longer reuiqred on step 1, becuse you can;t change it.
//=== STEP 1 == change I want to go from.
//  $('#jq_booking_want_to_go').change( function(){
//    // show / hide flexi transfer
//    ja_jouney_typeID = $('.ja_jouney_typeID:checked')[0].value;
//    switch( ja_jouney_typeID ){
//      case "1":
//      case "2":
//      case "3":
//        $('.jq_return_journey').hide();
//        break;
//      case "4":
//        $('.jq_return_journey').show();
//        break;
//      default:
//        alert("One - way has not been selected.");
//        break;
//    }

// iwantto show / hide flexi transfer
//    switch( $(this).val() ){
//      case "1":
//        $('.jq_booking_from_airport').show();
//        $('.jq_booking_from_suburb').hide();
//        break;
//      case "4":
//        $('.jq_booking_from_suburb').show();
//        $('.jq_booking_from_airport').hide();
//        break;
//      default:
//        $('.jq_booking_from_suburb').hide();
//        $('.jq_booking_from_airport').hide();
//        break;
//    }
//  });

  //=== STEP 1 == show / hide return journey
  $( '.ja_jouney_typeID_one_way' ).bind("click", function(){
    $('.jq_return_journey').hide();
  });

  $( '.ja_jouney_typeID_return' ).bind("click", function(){
    $('.jq_return_journey').show();
  });

  $( '.ja_jouney_typeID_flexi' ).bind("click", function(){
    $('.jq_return_journey').show();
  });
  

  //=== block_fast_quote ( round trip / one way / flexi )
  $("input[name='jouney_typeID']").change( function(){
    ja_jouney_typeID = $(this).val();
    iwanttogo = $("#jq_want_to_go").val();

    if( iwanttogo == FROM_AIRPORT && ja_jouney_typeID == JOURNEY_TYPE_FLEXI ){
      $('.jq_option3').show();
      $('.jq_option4').hide();
    } else if ( iwanttogo == FROM_SUBURB && ja_jouney_typeID == JOURNEY_TYPE_FLEXI ) {
      $('.jq_option4').show();
    } else {
      $('.jq_option3').hide();
      $('.jq_option4').hide();
    }

  });

  
  //=== block_fast_quote - I want to go change
  $('#jq_want_to_go').change( function(){
    
    ja_jouney_typeID = $("input[name=jouney_typeID]:checked").val(); 
    iwanttogo = $("#jq_want_to_go").val();

    if( ja_jouney_typeID == JOURNEY_TYPE_FLEXI ){
      if( iwanttogo == FROM_AIRPORT ){
        $('.jq_option3').show();
        $('.jq_option4').hide();
      } else if ( iwanttogo == FROM_SUBURB ) {
        $('.jq_option4').show();
        $('.jq_option3').hide();
      } else {
        $('.jq_option3').hide();
        $('.jq_option4').hide();
      }
    }

    switch( $(this).val() ){
      case "1":
        $('.jq_option1').show();
        $('.jq_option2').hide();
        break;
      case "4":
        $('.jq_option1').hide();
        $('.jq_option2').show();
        break;
	  default:	    
        break;
    }

  });
    
});

