// JavaScript Document

		$(document).ready( function(){
			var count = 0;
			
			$("#tabs").tabs();
			
			//$(".scrollable > div").scrollable();
			
			$(".scrollable").corner('5px');
			
			$("#tabs-header li").corner("top, 5px");
			
			$("#tabs-header li a").click( function () {
												
				var href = $(this).attr("href");			
				
				var src;
				
				$(href).find("div.items img").each( function () {
					$(this).removeClass("active");
					 count = count +1;
				});
				
				//alert(count);
				if(count > 7 )
					$(".scrollable > div").scrollable();
				
				count = 0;
				
				
				$("div.items").css("left","0");
				
				$(href).find("div.items img:first-child").each( function () {
					 src = $(this).attr("src");
					 $(this).addClass("active");
				});
				
				// calclulate large image's URL based on the thumbnail URL (flickr specific)
				var url = src.replace("TH_", "");
			 
				// get handle to element that wraps the image and make it semitransparent
				var wrap = $(".image_wrap").fadeTo("medium", 0.5);
			 
				// the large image from flickr
				var img = new Image();
			 
				// call this function after it's loaded
				img.onload = function() {
			 
					// make wrapper fully visible
					wrap.fadeTo("fast", 1);
			 
					// change the image
					wrap.find("img").attr("src", url);
			 
				};
			 
				// begin loading the image from flickr
				img.src = url;
				
			});
			
			
			$(".linkReservar").corner('5px');
			
			$(".items img").click(function() {
										   
				$("div.scrollable").find("div.items img").each( function () {
					 $(this).removeClass("active");
				});
				
				$(this).addClass("active");		
				
				
				// calclulate large image's URL based on the thumbnail URL (flickr specific)
				var url = $(this).attr("src").replace("TH_", "");
			 
				// get handle to element that wraps the image and make it semitransparent
				var wrap = $(".image_wrap").fadeTo("medium", 0.5);
			 
				// the large image from flickr
				var img = new Image();
			 
				// call this function after it's loaded
				img.onload = function() {
			 
					// make wrapper fully visible
					wrap.fadeTo("fast", 1);
			 
					// change the image
					wrap.find("img").attr("src", url);
			 
				};
			 
				// begin loading the image from flickr
				img.src = url;
			 
			// when page loads simulate a "click" on the first image
			}).filter(":first").click();

			
			var title = $("div.items img.active").attr("title");
			var desc = $("div.items img.active").attr("alt");
			
			if(desc=="" && title=="")
			{
				$('div.legend').hide();
			}
			else 
			{
				$('div.legend').show();
			}
			
			$("h4.title").text(title);
			$("p.description").text(desc);
			
			$("div.items img").click(function(){
				title = $(this).attr("title");
				desc = $(this).attr("alt");
				
				if(desc=="" && title=="")
				{
					$('div.legend').hide();
				}
				else 
				{
					$('div.legend').show();
				}
				
				$("h4.title").text(title);
				$("p.description").text(desc);
			});

		});
