$(document).ready(function(){ 
	$(".bottone-menu").click(function () {
		var str = $(this).attr("id");
		var array=str.split("_");
		if($(this).hasClass("bottone-menu-open")) {
			$(this).removeClass("bottone-menu-open");
			$(this).addClass("bottone-menu-close");
			$(".parent_but_"+array[1]).show("slow");		
			$(".child_"+array[1]).hide("slow");			
		 } else {
			$(this).removeClass("bottone-menu-close");
			$(this).addClass("bottone-menu-open");
			$(".parent_but_"+array[1]).hide("slow");		
			$(".child_"+array[1]).show("slow");		 
		 }
		$(".bottone-menu").each(function (i) { 
			var tmpbut = $(this).attr("id");
			var tmparray=tmpbut.split("_");
			if(array[1] != tmparray[1]) {
				$(".parent_but_"+tmparray[1]).show("slow");		
				$(".child_"+tmparray[1]).hide("slow");
				$(this).removeClass("bottone-menu-open");
				$(this).addClass("bottone-menu-close");					
			}
		});
	});
	
  var currentPosition4 = 0;
  var slide4Width = 130;
  var slides4 = $('.slide4');
  var numberOfSlides4 = slides4.length;

  /*Remove scrollbar in JS*/
  $('#slidesContainer4').css('overflow', 'hidden');

 /* Wrap all .slides4 with #slide4Inner div*/
  slides4
    .wrapAll('<div id="slide4Inner"></div>')
   /* Float left to display horizontally, readjust .slides width*/
	.css({
      'float' : 'left',
      'width' : slide4Width
    });

 /* Set #slideInner width equal to total width of all slides*/
  $('#slide4Inner').css('width', slide4Width * numberOfSlides4);

 /* Insert controls in the DOM*/
  $('#slideshow4')
    .prepend('<span class="control4" id="leftControl4">&nbsp;</span>')
    .append('<span class="control4" id="rightControl4">&nbsp;</span>');

 /* Hide left arrow control on first load*/
  manageControls4(currentPosition4);

 /* Create event listeners for .controls clicks*/
  $('.control4')
    .bind('click', function(){
   /* Determine new position*/
	currentPosition4 = ($(this).attr('id')=='rightControl4') ? currentPosition4+6 : currentPosition4-6;
    
	/* Hide / show controls*/
    manageControls4(currentPosition4);
   /* Move slideInner using margin-left*/
    $('#slide4Inner').animate({
      'marginLeft' : slide4Width*(-currentPosition4)
    });
  });

  $('.thumbnail').bind('click', function(){
	   $('#body-cappuccini-foto').addClass('loading');
	   $.ajax({ url: '${path}/templates/skin/cappuccini/imagepreview.jsp', 
		   dataType: 'html',
		   data: "img="+$(this).attr('srcfront'),
		   success: function (html) {  
		   		$('#body-cappuccini-foto').fadeOut();
				$('#body-cappuccini-foto').removeClass('loading').html(html);   
				$('#body-cappuccini-foto').fadeIn();
			} 
	   });
	  
  });
  
 /* manageControls: Hides and Shows controls depending on currentPosition*/
  function manageControls4(position4){
   /* Hide left arrow if position is first slide*/
	if(position4==0){ $('#leftControl4').hide() } else{ $('#leftControl4').show() }
	/* Hide right arrow if position is last slide*/
    if(position4>=numberOfSlides4-6){ $('#rightControl4').hide() } else{ $('#rightControl4').show() }
  }	
  	
	
});
