$(document).ready(function() {

	if ($('#home_logo').length != 0) {
		$('#home_logo img').mouseenter(function() {
			$(this).stop().animate({ width: 190, height: 190, 'margin-left': -20, 'margin-top': -20 }, 300);
		}).mouseleave(function() {
			$(this).stop().animate({ width: 150, height: 150, 'margin-left': 0, 'margin-top': 0 }, 300);
		});
	}

	if ($('#gallery').length != 0) {
	
		// gallery
		var zoomFunc = function(dimension) {
	        return dimension * 2;
	    };
	    var shrinkFunc = function(dimension) {
	        return dimension * 0.5;
	    };
	    $('#gallery img').slidingGallery({ container: $('#gallery'), 'Lheight': 250, 'Lwidth': 350, 'Lzoom': zoomFunc, 'Pzoom': zoomFunc, 'Lshrink': shrinkFunc, 'Pshrink': shrinkFunc });

	    // autoscroll
	    var inte = {};
	    function shownext() {
	    	fin = 0;
	    	$('#gallery img').each(function(i, ind) {
	    		if ($(ind).height() == '250') { fin = i; }
	    	});
	    	inde = $('#gallery img').eq(fin).attr('next');
	    	$('#gallery img').eq(inde).trigger('click');
	    }
	    $('#gallery').mouseover(function() {
	        clearInterval(inte);
	    }).mouseleave(function() {
	        inte = setInterval(shownext, 2000);
	    }).trigger('mouseleave');
	    
	}

	if ($('#gallery_prima-dopo').length != 0) {
	    $('#gallery_prima-dopo a').colorbox();
	}

	if ($('.colorbox').length != 0) {
	    $('.colorbox').colorbox();
	}
    
	if ($('#map_canvas').length != 0) {
        var geocoder;
        var map;
        var query = "Via Cavalieri di Malta 70, Putignano";
        function initialize() {
          geocoder = new google.maps.Geocoder();
          var myOptions = {
            zoom: 14,
            mapTypeId: google.maps.MapTypeId.ROADMAP
          };
          map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
          codeAddress();
        }
    
        function codeAddress() {
          var address = query;
          geocoder.geocode( { 'address': address}, function(results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
              map.setCenter(results[0].geometry.location);
              var marker = new google.maps.Marker({
                  map: map, 
                  position: results[0].geometry.location
              });
            } else {
              alert("Geocode was not successful for the following reason: " + status);
            }
          });
        }
        initialize();
    }
	
});
