jQuery.extend({
   urlParam: function(urlParam)
   {
      var search = window.location.search.replace("?", "");
      var params = search.split("&");
      
      for(var i = 0; i<params.length; i++)
      {
         var param = params[i].split("=");
         if (param[0] == urlParam)
         {
            return param[1];
         }
      }
      return null;
   }
});

$(document).ready(function(){

   $('#events').accordion({ collapsible: true, active: false, animated: 'slide', autoHeight: false });

   // We only want these styles applied when javascript is enabled
   $('div.navigation').css({'width' : '300px', 'float' : 'left'});
   $('div.gallerycontent').css('display', 'block');

   var onMouseOutOpacity = 0.67;
   $('#thumbs ul.thumbs li').opacityrollover({
      mouseOutOpacity:   onMouseOutOpacity,
      mouseOverOpacity:  1.0,
      fadeSpeed:         'fast',
      exemptionSelector: '.selected'
   });

   if($('#lightbox').length != 0)
   {
      $('#lightbox a').lightBox();
   }
   
   if($("#gallery").length != 0)
   {
      $("#gallery").treeview({ animated: "fast", collapsed: true, unique: true });
   }
});

function OpenGalleryClick(url)
{
   location.href = url;
}

function SendReservationRequest(url)
{
   var data = { 
                send: true,
                name: $('#fullname').val(),
                mail: $('#mail').val(),
                count: $('#count').val()
              };

   $.ajax({ type: "POST", url: url, data: data, dataType: "json",
            success: function (request, textStatus) {
               if(request.error)
               {
                  ErrorCallback(request, textStatus);
               }
               else
               {
                  document.getElementById("resform").reset();
                  $("#success").fadeIn();
               }
            },
            error: ErrorCallback });
   
}

function ErrorCallback(request, textStatus, errorThrown)
{
   $("#error").html(request.error ? request.error : request.responseText);
   $("#errordialog").dialog({ bgiframe: true, resizable: false, title: "Fehler", height:140, modal: true,
                         buttons: { 
                                    Ok: function() 
                                       {
                                          $(this).dialog('destroy');
                                       }
                                 }
                        });
}

function SendContact(url)
{
   var data = { 
                send: true,
                name: $('#name').val(),
                email: $('#email').val(),
                subject: $('#subject').val(),
                body: $('#body').val()
              };

   $.ajax({ type: "POST", url: url, data: data, 
            success: function (request, textStatus) {
               if(request.error)
               {
                  ErrorCallback(request, textStatus);
               }
               else
               {
                  ResetContact();
                  $('#success').fadeIn();
               }
            },
            error: ErrorCallback });
}

function ResetContact()
{
   $('input:text').val("");
   $('#body').val("");
}

function RecalculatePrices(price)
{
   var total = price * $('#count').val();
   
  $('#totalPrice').text(total);
}
