var vWidth = "368px";
var hWidth = "690px";
var img1;
var img2;
var actualPage = "Inici";
var transitioning = false;
var fadeSpeed = "medium";


$(document).ready(function(){
	$("#menu").ready(function(){
		$("#menu .boto").click(
		function () {
			if(!transitioning) {
				var newPage = $(this).attr("alt");
				var newContentSrc = $(this).attr("newContent");
				var actualContent = $("#centerScreen:first-child");
				if(actualPage != newPage) {
					transitioning = true;
					actualPage = newPage;
					$("#centerScreen").fadeOut(fadeSpeed, function() {
						$("#centerScreen").empty();
						if(actualPage != "Enllaços") {
							//Due to accordion issues with 'height'
							$("#centerScreen").css({height: "490px"});
							var newImg = $(new Image()).attr('src', newContentSrc);
							$(newImg).css({width: hWidth, height: "490px", right: "0px"});
							$(newImg).load(function() {
								$("#centerScreen").append($(newImg));
							});
						} else {
							//Due to accordion issues with 'height'
							$("#centerScreen").css({height: "270px"});
							$("#centerScreen").load(newContentSrc);
						}
						setTimeout('showCenterScreen()', 500);
					});
				}
			}
		   return false;
		});
		$("#menu .boto").hover(
		  function () {
			  img1 = $(this).attr("src");
			  img2 = img1.substr(0, img1.length-4)+ "2.gif";
			  $(this).attr({src: img2});
      }, 
		  function () {
			  $(this).attr({src: img1});
		  }
    );
	});
	$("#submenu").ready(function(){
		$("#submenu img").mouseover(function(){
			$(this).css({opacity:".0"}).stop().animate({opacity:"1.0"},500);
		});
		$("#submenu img").click(function(){
			if(!transitioning) {
				var newImgSrc = $(this).attr("src");
				newImgSrc = "photos/" + newImgSrc.substr(8, newImgSrc.length-11) + "jpg";
				var actualContent = $("#centerScreen img");
				var orientation = $(this).attr("orient");
				if($(actualContent).attr("src") != newImgSrc) {
					transitioning = true;
					$("#centerScreen").fadeOut(fadeSpeed, function() {
						$("#centerScreen").empty();
						var newImg = $(new Image()).attr('src', newImgSrc);
						if(orientation == "h") {
							$(newImg).css({width: hWidth, height: "490px", right: "0px"});
						} else {
							$(newImg).css({width: vWidth, height: "490px", right: "322px"});
						}
						$(newImg).load(function() {
							$("#centerScreen").append($(newImg));
							setTimeout('showCenterScreen()', 500);
						});
					});
					actualPage = "Galeria";
				}
			}
			return false;
		});
	});
});

function showCenterScreen() {
	$("#centerScreen").fadeIn(fadeSpeed);
	transitioning = false;
}


