$(document).ready(function(){
			
	// INTRO EFFECT -------------------------------------------->
	$("#alertJS").remove();
	$("#wrapper").fadeIn(2000,function(){
		$("#bBox").animate({"width":1024},500,function(){						
			$("#slideConcepte").slideshow({
				type:"up",
				speed:10000
			});
		});
	});		
	
	// CHANGE FLAPS -------------------------------------------->
	$("#mainNav a, a.button").live("click",function(){
		var actFlap = $(".nav_selected").attr("title");
		var flap = $(this).attr("title");     
		// NOT ACTUAL FLAP CLICKED
		if(flap!=actFlap) {        			            			
  			// MENU SELECTED
   			$("#mainNav a").removeClass("nav_selected");
   			$(this).addClass("nav_selected");            			         
   			// SMALL FLAP -->
   			$("#sBox").fadeOut(500,function(){
       			$("#sBox").load("flaps.php #s"+flap,function(){
           			$(this).fadeIn(500);
       			});
   			});            			                        			
   			// BIG FLAP -->            			
   			// Stop slideshow
   			$("ul.slideBG, #slideConcepte").slideshow({stop:true});
       		//Remove thumbnails
     		$("#thumbs ul").fadeOut(500,function(){$(this).remove()}); 
       		// Show loading wheel
			$("#loadingWheel").show();
       		// Hide Content						
			$("#bBoxContent").fadeOut(500,function(){
			    // Load content
           		$("#bBoxContent").load("flaps.php #b"+flap,function(){
            		// Hide loading wheel
            		$("#loadingWheel").hide();                    			
            		// Show content
            		$(this).fadeIn(500);                    			
            		// Active Slideshows
            		$("ul.slideBG").slideshow({thumbs:true,reset:true});
					$("#slideConcepte").slideshow({
						type:"up",
						speed:10000
					});						
					$("#reserva").validate();							
           		});
       		});
       		
       		// BUTTONS BANNERS -->
       		if(actFlap=='Concepte') $("#buttons").load("flaps.php #buttonsSmall");
       		else if(flap=='Concepte') $("#buttons").load("flaps.php #buttonsBig");       		
       	           			
   		}
   		return false;

	});
    			
    			
	// SECOND NAVIGATION
	$("#secNav a").live("click", function(){
   		var flap = $(this).attr("title");        			            			
      	// MENU SELECTED
       	$("#secNav a").removeClass("nav_selected");
       	$(this).addClass("nav_selected");            			                     			                        	
       	// BIG FLAP -->            			
       	// Stop slideshow
       	$("ul.slideBG").slideshow({stop:true});
       	//Remove thumbnails
       	$("#thumbs ul").fadeOut(500,function(){$(this).remove()});            			            		
       	// Show loading wheel
		$("#loadingWheel").show();
       	// Hide Content						
		$("#zonaHabs").fadeOut(500,function(){
		    // Load content
        	$(this).load("flaps.php #"+flap,function(){
           		// Hide loading wheel
              	$("#loadingWheel").hide();                    			
               	// Show content
               	$(this).fadeIn(500);                    			
              	// Active Slideshows
               	$("ul.slideBG").slideshow({thumbs:true,reset:true});													
           	});
       	});
   		return false;
	});
		
	// COLLAPSE BOXES ------------------------------------------------->
	$(".collapse").live("click",function(){
		$(this).prev("p").slideToggle(500);
		return false;
	});
    			
	// BANNER --------------------------------------------------------->
	$("#banners a").live("click", function(){
		var banner = $(this).attr("title");
 		$("#bannerBox").fadeOut(500,function(){
  			$(this).load("flaps.php?banner="+banner+" #banner",function(){
   				$(this).fadeIn(500);
   			});
   		});
   		return false;
   	});
    			
   	// POPUP ------------------------------------------------------>
   	// OPEN POPUP -->
   	$("a.popup").live("click",function(){
   		var popup = $(this).attr("title");
   		$("#fade").fadeIn(500,function(){
   			$("#popup").load("flaps.php #"+popup);
   		});
   		return false;
   	});
    			
   	// CLOSE POPUP -->
   	$("#closePopup").live("click", function(){
   		$("#fade").fadeOut(500,function(){
   			$("#popup").html("");
   		});
   		return false;
   	});
   	
   	// SEND MAIL ------------------------------------------------->
   	$("#reservaForm").live("submit", function(){
		
		// 'this' refers to the current submitted form
		var str = $(this).serialize();
		$.ajax({
			type: "POST",
			url: "sendmail.php",
			data: str,
			success: function(msg){
				$("#note").ajaxComplete(function(event, request, settings){					
					$(this).html(msg);
				});
			}	
 		});
		return false;
	});
    			
});
