/*
 * File: ajax.js
 * Vers:  1.0
 * Auth: Fabio Memoli - www.opcode.it
 * Date: 24 Nov 2010
 * ----------------------------------
 * 
 */

function MyFadeIn() {
   $('#content').fadeIn(1000);
   return true;
}

/* --- Ajax --- */

$(document).ready(function(){

   $('#content').fadeIn(1000, function(){ 
      $('#content').load('home.html');
      }
   );

   $('#home').click(function() {
      $('#content').fadeOut(1000, function(){
         $('#content').load('home.html', MyFadeIn());
         }
      );
      return false;
   });

   $('#description').click(function() {
      $('#content').fadeOut(1000, function(){ 
         $(this).load('description.html', MyFadeIn());
         }
      );
      return false;
   });

   $('#services').click(function() {
      $('#content').fadeOut(1000, function(){ 
         $(this).load('services.html', MyFadeIn());
         }
      );
      return false;
   });
   
   $('#photos').click(function() {
      $('#content').fadeOut(1000, function(){ 
         $(this).load('photos.html', MyFadeIn());
         }
      );
      return false;
   });

   $('#videos').click(function() {
      $('#content').fadeOut(1000, function(){ 
         $(this).load('videos.html', MyFadeIn());
         }
      );
      return false;
   });
   
   $('#location').click(function() {
      $('#content').fadeOut(1000, function(){ 
         $(this).load('location.html', MyFadeIn());
         }
      );
      return false;
   });
   
   $('#guestbook').click(function() {
      $('#content').fadeOut(1000, function(){ 
         $('#content').load('guestbook.html', MyFadeIn());
         }
      );
      return false;
   });
   
   $('#booking').click(function() {
      $('#content').fadeOut(1000, function(){ 
         $(this).load('booking.html', MyFadeIn());
         }
      );
      return false;
   });
   
   $('#contacts').click(function() {
      $('#content').fadeOut(1000, function(){ 
         $(this).load('contacts.html', MyFadeIn());
         }
      );
      return false;
   });
   

});

function history(){
      $('#content').fadeOut(1000, function(){ 
         $(this).load('history.html', MyFadeIn());
         }
      );
}

function cars(){
      $('#content').fadeOut(1000, function(){ 
         $(this).load('cars.html', MyFadeIn());

         }
      );
}

function ZoomVideo(video) {
   document.getElementById('zoom').style.display = 'block';
   document.getElementById('container').style.display = 'none';
   var txt = '<div id="video">'
      + '<object style="height: 100%; width: 100%">\n'
      + '<param name="movie" value="http://www.youtube.com/v/' + video + '?version=3&autoplay=1">\n'
      + '<param name="allowFullScreen" value="true">\n'
      + '<param name="allowScriptAccess" value="always">\n'
      + '<embed src="http://www.youtube.com/v/' + video 
         + '?version=3&autoplay=1" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="100%" height="100%">\n'
      + '</object>\n'
      + '</div>\n'
      + '<p><a href="#" onClick="ZoomOff();">Click here for close</a></p>';
   document.getElementById('zoom').innerHTML = txt;
}


function ZoomImage(image) {
   document.getElementById('zoom').style.display = 'block';
   document.getElementById('container').style.display = 'none';
   var begin = image.lastIndexOf("/") + 1;
   var end =  image.lastIndexOf(".");
   
   var path = image.slice(0,image.indexOf("/"));
   
   var photos = 0;
   switch(path){
      case "home": photos = 13; break;
      case "description": photos = 9; break;
      case "services": photos = 7; break;
      case "photos": photos = 53; break;
      case "location": photos = 19; break;
      case "guestbook": photos = 46; break;
   }
   
   var img = image.slice(begin,end);
   var id_img = parseInt(img);
   
   //window.alert(photos);
   var next = id_img + 1;
   var prev = id_img - 1;
   
   if(prev < 1) prev = photos;
   if(next > photos) next = 1;
   
   var txt = '<div id="leftbox"><a href="#" onclick="ZoomImage(\'' + path + '/large/' + prev + '.jpg\');"><img src="lib/prev.png" alt="preview" /></a></div>\n'
         + '<div id="centerbox"><img onClick="ZoomOff();" src="' + image + '" alt="' + image +'" /></div>\n'
         + '<div id="rightbox"><a href="#" onclick="ZoomImage(\'' + path  + '/large/' + next + '.jpg\');"><img src="lib/next.png" alt="next" /></a></div>\n'
         + '<div id="bottombox"><a href="#" onClick="ZoomOff();">Click here or on the photo for close</a></div>\n'
         + '<embed src="lib/bip.mp3" autostart="true" loop="false" width="0" height="0" controller="true" bgcolor="#FF9900"></embed>\n';
   document.getElementById('zoom').innerHTML = txt;
}

function ZoomOff() {
   document.getElementById('zoom').style.display = 'none';
   document.getElementById('container').style.display = 'block';
}


