function getLeaf(url) {
	var splited=url.split('?');// remove all the parameter from url
	url=splited[0];
	return url.substring(url.lastIndexOf("/")+1);// return file name without domain and path
}

jQuery.fn.extend({
	enter: function() {//plugins creation
		return this.each(function() {
			var pth = $(this).find("img")[0];
			//alert($(this).children().attr("href"));
			if (!$(this).hasClass('menuactive')) {
				$(this).hover(function(){
					$(pth).attr("src",pth.src.replace(/.png/g, '_active.png'));// mouse over Image
				},function(){
					$(pth).attr("src",pth.src.replace(/_active.png/g, '.png'));// mouse out image
				});
			}
			
		});
	}
});

$(function(){ // Document is ready
	$("#menu ul#menu li").enter();// call the function
});

// JavaScript Document
$(document).ready(function(){
	
	$("#menu ul li").click(function(){
		if (!$(this).hasClass('menuactive') && $(this).hasClass('nellaslide')) {
			$("#menu ul#menu li").unbind('mouseenter mouseleave');
			var pth = $(this).find("img")[0];
			var pth1 = $('.menuactive img').attr("src");
			var identificativo = $(this).attr('id');
			$('.menuactive img').attr("src",pth1.replace(/_active.png/g, '.png'));
			$('.menuactive').removeClass('menuactive');
			$(this).addClass('menuactive');
			//$(pth).attr("src",pth.src.replace(/.png/g, '_active.png'));
			$("#menu ul#menu li").enter();
			$('#slideshow .container').load(identificativo + '.php', function() {		
				ThumbnailScroller("tsh_container","horizontal",0,900,"easeOutCirc",0.5,300);
				$('#slideshow .container').css('left', '0px');
				$("a[rel^='lightbox']").slimbox({/* Put custom options here */}, null, function(el) {
        	return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));		
				});
			});
		}
	  
	});
	
	$('#open-chisiamo').click(function() {
  		$('#linguetta1').animate({
		    top: '0',
	    }, 500, function() {
    		$("#toggle-chisiamo a").toggle();
  		});
	});
	
	$('#close-chisiamo').click(function() {
  		$('#linguetta1').animate({
		    top: '-500',
	    }, 500, function() {
    		$("#toggle-chisiamo a").toggle();
  		});
	});
	
	$('#open-dovesiamo').click(function() {
  		$('#linguetta2').animate({
		    top: '0',
	    }, 500, function() {
    		$("#toggle-dovesiamo a").toggle();
  		});
	});
	
	$('#close-dovesiamo').click(function() {
  		$('#linguetta2').animate({
		    top: '-500',
	    }, 500, function() {
    		$("#toggle-dovesiamo a").toggle();
  		});
	});	  
});


