// Submit contact form
function contactFormSubmit() {
    // send the request
    $.ajax({
      type: "POST", timeout: 15000, url: "contact.php", dataType: 'json', data: $("#contacts-form").serialize(), cache: false,
      success: function(data, status){
        if(data.error == true) {
          $('#contactFormError').html('<blockquote>'+data.msg+'</blockquote>');
          $('#contactFormError').show();
          }
        else {
          $('#contactFormDiv').hide();
          $('#contactFormOkDiv').show();
          }
        },
      error: function(data, status, e){
        $('#contactFormError').html('<blockquote>'+status+'</blockquote>');
        $('#contactFormError').show();
        }
      });
    }
 // Submit travel form
function travelFormSubmit() {
    $('#travelFormError').hide();
    // send the request
    $.ajax({
      type: "POST", timeout: 15000, url: "resa.php", dataType: 'json', data: $("#travel-form").serialize(), cache: false,
      success: function(data, status){
        if(data.error == true) {
          $('#travelFormError').html('<blockquote>'+data.msg+'</blockquote>');
          $('#travelFormError').show();
          }
        else {
          $('#travelFormDiv').hide();
          $('#travelFormOkDiv').show();
          }
        },
      error: function(data, status, e){
        $('#travelFormError').html('<blockquote>'+status+'</blockquote>');
        $('#travelFormError').show();
        }
      });
    }
// Submit comment form
function commentFormSubmit() {
    $('#commentFormError').hide();
    // send the request
    $.ajax({
      type: "POST", timeout: 15000, url: "comments.php", dataType: 'json', data: $("#comment-form").serialize(), cache: false,
      success: function(data, status){
        if(data.error == true) {
          $('#commentFormError').html('<blockquote>'+data.msg+'</blockquote>');
          $('#commentFormError').show();
          }
        else {
          $('#linkAddComments').hide();
          $('#commentFormDiv').hide();
          $('#commentFormOkDiv').show();
          }
        },
      error: function(data, status, e){
        $('#commentFormError').html('<blockquote>'+status+'</blockquote>');
          $('#commentFormError').show();
        }
      });
    }
var childData	= function(selector, arg) { return selector.find(arg).attr('data'); }
var getWeather =function(){
    $.ajax({
      type: "GET",timeout: 5000,data:"",url:"googleWeather.php",
      success: function(data){
        $('#loading').stop().hide('fast');
        forecast	= $(data).find('forecast_information');
        cCondition	= $(data).find('current_conditions');
        city	= childData(forecast, 'city');
        if(city!=undefined) {
          date	= childData(forecast, 'forecast_date');
          condition	= childData(cCondition, 'condition');
          tempC	= childData(cCondition, 'temp_c');
          humidity	= childData(cCondition, 'humidity');
          icon	= childData(cCondition, 'icon');
          $('#city').text(city);
          $('#date').text(date);
          $('#condition').text(condition);
          $('#tempC').text(tempC+' C');
          $('#humidity').text(humidity);
          $('#icon').attr({'src':'http://www.google.com'+icon})
          $('#data').stop().show('fast');
          }
      else {
          $('#error').stop().show('fast');
          }
      },
			error: function (data, status, e) {
          $('#loading').stop().hide('fast');
          $('#error').stop().show('fast');
          //alert(data.error+"\n"+status+"\n"+e);
        }
    });
  };

var doRollOvers = function() {
  // photo div loader
  $(".embed").live('click', function(event){
    event.preventDefault();
    var urlToLoad = 'index.php?page='+escape($(this).attr("href").replace(".html", ""))+'&type=embed';
    $.ajax({
    type: "GET",
    url: urlToLoad,
    cache: false,
    success: function(data){
        $(data).find('a[rel=lightbox]').lightBox().end().replaceAll('.embedContent');
        }
      });
    });
  // comments div loader
  $("#linkAddComments").live('click', function(event){
    event.preventDefault();
    $("#commentFormDiv").toggle();
    });
  // photo lightbox
  $('.lightbox a').lightBox();
}

