
var first_click=0;
var current_page = 1;
var tot = 0;
var current_slide = 0;
var _left = 0;
var slide = '';

var _lat2 = null;
var _lng2 = null;
var _msg2 = null;

function init_js(){
  var body_class = $('body').attr('class');
 if (body_class=='com_contact'){
    $('#sinistra').css('display', 'none');
    $('#destra').css('display', 'none');
    $('#box_slide').html('<div id="maps_contis" class="google_maps" style="width:432px;height:378px"><input type="hidden" name="lat" class="lat" value="39.560403"/><input type="hidden" name="lng" class="lng" value="8.90034"/> <input type="hidden" name="zoom" class="zoom" value="15"/><input type="hidden" name="msg" class="msg" value="Via Carlo Felice 128, Sanluri"/><input type="hidden" name="lat" class="lat2" value="39.553569"/><input type="hidden" name="lng" class="lng2" value="8.900292"/><input type="hidden" name="msg2" class="msg2" value="Laboratorio"/></div>'); 
}  
   $('body').find('.google_maps').each(function(){
  
   _title = $(this).attr('title'); 
    _id = $(this).attr('id');
    _lat = $(this).find('.lat').val();
    _lng = $(this).find('.lng').val();
    _zoom = $(this).find('.zoom').val();
   _msg = $(this).find('.msg').val();
      if (_msg==undefined){
      _msg = '';
    }
    if (_zoom!=undefined){
      _zoom = parseFloat(_zoom);
    }
     _lat2 = $(this).find('.lat2').val();
     _lng2 = $(this).find('.lng2').val();
    _msg2 = $(this).find('.msg2').val();
    $('.lng').remove();
    $('.lat').remove();
    $('.zoom').remove();      
    initialize(_id, _lng, _lat, _zoom, _msg);
  });
  if (body_class=='home'){  
    h_h = parseFloat($('window').css('height')) - 790;
  }else{
    h_h = parseFloat($('window').css('height')) - 790;
  }
  div = '<div style="background:#884008 ; height: ' + h_h + 'px"></div>';
  $('body').append(div);
  if (body_class=='com_contact'){
    $('#sinistra').css('display', 'none');
    $('#destra').css('display', 'none');
    //$('#box_slide').html('<iframe width="432" height="378" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.it/maps?f=q&amp;source=s_q&amp;hl=it&amp;geocode=&amp;q=Via+Carlo+Felice,+228+Sanluri&amp;sll=39.560132,8.900452&amp;sspn=0.007775,0.021136&amp;ie=UTF8&amp;hq=&amp;hnear=Via+Carlo+Felice,+228,+09025+Sanluri+Medio+Campidano,+Sardegna&amp;z=15&amp;ll=39.560132,8.900452&amp;output=embed"></iframe>');  

 
  }else{
      $('.content_article img').each(function(i){
          slide +='<li><img src="' + $(this).attr('src') + '">';
        $(this).remove();  
      }); 
      $('#slide_photo').html(slide);
      $('#slide_photo').addClass('slide_photo');
     if ($('.slide_photo li').size()==1){
         $('#destra').remove();
         $('#sinistra').remove();
      }
      tot = $('.slide_photo li').size();
      if (tot==1){
         window.clearInterval(_x)
      } 
  }
  
  if($('#gallery_box').html()!=undefined){
    list = $('#gallery_box').find('ul').html();
    //alert(list)
     page = $('#page_gallery').val();
     if (page==0){
       page=1;
     }
    table = '<table id="list-gallery"><tr>';
    if (page==1){
    link_1 = 'active'
    link_2 = 'inactive'
    for(i=1; i<=6; i++){
       table += '<td><a href="images/stories/gallery/' + i + '.jpg" rel="prettyPhoto[gallery]"><span><img src="images/stories/thumb/' + i + '.jpg"/></span></a></td>' 
    }
    table += '</tr><tr>';
    for(i=7; i<=12; i++){
       table += '<td style="vertical-align:top;"><a href="images/stories/gallery/' + i + '.jpg" rel="prettyPhoto[gallery]"><spam><img src="images/stories/thumb/' + i + '.jpg"/></span></a></td>' 
    }
    }else{
     link_2 = 'active'
     link_1 = 'inactive' 
     for(i=13; i<=18; i++){
       table += '<td><a href="images/stories/gallery/' + i + '.jpg" rel="prettyPhoto[gallery]"><span><img src="images/stories/thumb/' + i + '.jpg"/></span></a></td>' 
    }
    table += '</tr><tr>';
    for(i=1; i<=6; i++){
       table += '<td style="height:174px"> </td>' 
    }
    }
    
    table += '</tr></table>';
    table += '<div id="bottom-gallery"><p><span><a href="indexf129.html" class="' + link_1 + '">1</a> <a href="gallery2.html" class="' + link_2 + '">2</a></span><em>In questo spazio ci raccontiamo attraverso le immagini.</em></p></div>';
    
    $('#gallery_box').html('');
    $('#gallery_box').html(table);
  }
  

  $('#next-slide').click(function(){avanti()});
  
  _h = 378;
  if (body_class=='home'){
    $('#destra').css('height', _h);
  $('#sinistra').css('height', _h);
  $('#box_slide').css('height', _h);  
  }
  $('#destra').mouseover(function(){
      if (current_slide>0){
        $('#back-slide').stop().animate({"left":"0"}, {"duration":"500"})
      }
 			
		}).mouseout(function(){
			$('#back-slide').stop().animate({"left":"-67px"}, {"duration":"500"})
	});
	
	$('#sinistra').mouseover(function(){
      $('#next-slide').stop().animate({"right":"0"}, {"duration":"500"})
		}).mouseout(function(){
		  if(first_click){
			   $('#next-slide').stop().animate({"right":"-68px"}, {"duration":"500"})
			}
	});
	
	$('#back-slide').mouseover(function(){
 			$('#back-slide').css({"left":"0"})
		});
  
  
   
  $('#back-slide').click(function(){
    restart();
    page= Math.ceil(current_slide / tot);
    //alert(page)
    //alert(page)
    if (current_slide==0 && page==0){
      return false;
    }
    /*if (current_page==1){
      return false;
    } */
    current_page--;
   // alert(current_slide)
   
    current_slide--;
    _left = _left + 432;
    $('.slide_photo').stop().animate({
      'left':_left
    });
  });
  
  if ($('#current').attr('class')==undefined){
    _class = new Array();
    _class[1] = 'item6'
  }else{
    _class = $('#current').attr('class'); 
    _class = _class.split(' ');
  }
  

  if (_class[1]=='item1'){
    $('.menu li.item1 a').find('span').css({'background-position':"0px -31px"});
  }else{
    $('.menu li.item1 a').mouseover(function(){
			$(this).find('span').stop().animate({"backgroundPosition":"(0px -31px)"}, {"duration":"200"})
		}).mouseout(function(){
			$(this).find('span').stop().animate({backgroundPosition:"(0px 0px)"}, {duration:200});
	 });
  }
	
	
	if (_class[1]=='item2'){
    $('.menu li.item2 a').find('span').css({'background-position':"-69px -31px"});
  }else{
    $('.menu li.item2 a').find('span').stop().animate({backgroundPosition:"(-69px 0px)"}, {duration:200});
    $('.menu li.item2 a').mouseover(function(){
			$(this).find('span').stop().animate({'backgroundPosition':"(-69px -31px)"}, {duration:200})
		}).mouseout(function(){
			$(this).find('span').stop().animate({'backgroundPosition':"(-69px 0px)"}, {duration:200});
	 });
	} 
	
	if (_class[1]=='item3'){
    $('.menu li.item3 a').find('span').css({'background-position':"-138px -31px"});
  }else{
  	$('.menu li.item3 a').find('span').stop().animate({backgroundPosition:"(-138px 0px)"}, {duration:200});
  	$('.menu li.item3 a').mouseover(function(){
  			$(this).find('span').stop().animate({backgroundPosition:"(-138px -31px)"}, {duration:200})
  		}).mouseout(function(){
  			$(this).find('span').stop().animate({backgroundPosition:"(-138px 0px)"}, {duration:200});
  	});
	}
		
	if (_class[1]=='item4'){
    $('.menu li.item4 a').find('span').css({'background-position':"-207px -31px"});
  }else{
	 $('.menu li.item4 a').find('span').stop().animate({backgroundPosition:"(-207px 0px)"}, {duration:200});
	 $('.menu li.item4 a').mouseover(function(){
			$(this).find('span').stop().animate({backgroundPosition:"(-207px -31px)"}, {duration:200})
		}).mouseout(function(){
			$(this).find('span').stop().animate({backgroundPosition:"(-207px 0px)"}, {duration:200});
	 });
	} 
	
	if (_class[1]=='item5'){
    $('.menu li.item5 a').find('span').css({'background-position':"-276px -31px"});
  }else{
	 $('.menu li.item5 a').find('span').stop().animate({backgroundPosition:"(-276px 0px)"}, {duration:200});
	 $('.menu li.item5 a').mouseover(function(){
			$(this).find('span').stop().animate({backgroundPosition:"(-276px -31px)"}, {duration:500})
		}).mouseout(function(){
			$(this).find('span').stop().animate({backgroundPosition:"(-276px 0px)"}, {duration:200});
	 });
	} 
	
	$('#link_ricette').find('span').stop().animate({backgroundPosition:"(-0px 0px)"}, {duration:200});
	$('#link_ricette').mouseover(function(){
			$(this).find('span').stop().animate({backgroundPosition:"(0 -31px)"}, {duration:200})
		}).mouseout(function(){
			$(this).find('span').stop().animate({backgroundPosition:"(0 0px)"}, {duration:200});
	});
	
	$('#link_gallery').find('span').stop().animate({backgroundPosition:"(-107px 0px)"}, {duration:200});
	$('#link_gallery').mouseover(function(){
			$(this).find('span').stop().animate({backgroundPosition:"(-107px -31px)"}, {duration:200})
		}).mouseout(function(){
			$(this).find('span').stop().animate({backgroundPosition:"(-107px 0px)"}, {duration:200});
	});
	
	$('#link_banqueting').find('span').stop().animate({backgroundPosition:"(-214px 0px)"}, {duration:200});
	$('#link_banqueting').mouseover(function(){
			$(this).find('span').stop().animate({backgroundPosition:"(-214px -31px)"}, {duration:200})
		}).mouseout(function(){
			$(this).find('span').stop().animate({backgroundPosition:"(-214px 0px)"}, {duration:200});
	});

  
}

  var  _x = null;
  
  var speed = 7000;
  _x = window.setInterval("avanti_auto()", speed);
  
  function restart_intervall(){
       _x = null;
      _x = window.setInterval("avanti_auto()", speed);  
  }
  
  function restart(){
    window.clearInterval(_x)
    if (_x!=null){
      _x=null;
      window.setTimeout('restart_intervall()', 10000)  
    }
    //_x = window.setInterval("avanti_auto()", 5000);
  }
  
  var slide_auto = 0;
  function avanti(){
    if (slide_auto==1){
      restart()
    }
    if (!first_click){
       first_click = 1;
    }
    if (current_page==tot){
      current_page =0;
    }
    current_slide++;
    current_page++;
    //alert(tot)
     if (current_page==(tot - 1)){
        $('#slide_photo').append( slide );
    }
    page= Math.ceil(current_slide / tot);  
    _left = _left - 432;
    $('.slide_photo').stop().animate({
      'left': _left
    });
    slide_auto = 1;
  }
  
function avanti_auto(){
  slide_auto = 0;
  avanti();
}


 function initialize(id, lng, lat, zoom, msg) {
      if (GBrowserIsCompatible()) {   
        var map = new GMap2(document.getElementById(id));
        map.setCenter(new GLatLng(39.557403, 8.901025), zoom);
        map.setUIToDefault();
        var latlng = new GLatLng(lat, lng);
        map.addOverlay(new GMarker(latlng));
        if (msg!=undefined){
          map.addOverlay(createMarker(latlng, map, msg));
        }
        var latlng2 = new GLatLng(_lat2, _lng2);
        map.addOverlay(new GMarker(latlng2));
        map.addOverlay(createMarker(latlng2, map, _msg2)); 
      }
    }





function createMarker(latlng, map, msg) {
      var marker = new GMarker(latlng);
     /* GEvent.addListener(marker,"click", function() {
        map.openInfoWindowHtml(latlng, msg);
      });  */
       GEvent.addListener(marker, "click", function() {
           marker.openInfoWindowHtml(msg);
       });
      return marker;
	}

   var $buoop = {};$buoop.ol = window.onload;window.onload=function(){if ($buoop.ol) $buoop.ol();var e = document.createElement("script");e.setAttribute("type", "text/javascript");e.setAttribute("src", "../../browser-update.org/update.js");document.body.appendChild(e);} 


