var activeRoom = 0;

var roomsR = new Array(0,573,1800,875,1000);
var roomsL = new Array(1000,573,1800,875,0);

function startRoutinen() {
	showOverlay();
	calContentWidth();
	loadContent();
	setTimeout('$(".loadInfos").append("<br/>Willkommen auf dem H&uuml;gel.")',4000);
	setTimeout('hideOverlay()',6000);


}

function calContentWidth() {
	var winWidth = window.innerWidth;
	$("#contentWrapper").css('width',winWidth);

}

function loadContent() {
	setTimeout('$(".loadInfos").append("Lade Meta-Informationen..<br/>")',500);
	setTimeout('$("#headWrapper").fadeIn(1000)',1000);
	setTimeout('$(".loadInfos").append("Lade Galerie-Men&uuml;..<br/>")',1500);
	setTimeout('$("#contentWrapper").fadeIn(1000)',2000);
	setTimeout('$(".loadInfos").append("Lade Galerie-R&auml;ume..<br/>")',2500);
	setTimeout('loadNavigation()',3000);
	setTimeout('$(".loadInfos").append("Lade Galerie-Informationen..<br/>")',3500);
	setTimeout('$("#footer").fadeIn(1000)',4000);

    if (specialMove) {
        specialJump(movePoint);
    }
}

function loadNavigation() {
	$(".navMoveRooms").fadeIn(1000);
	//$(".navMoveRight").fadeIn(1000);
}

function showOverlay() {
	var winWidth = window.innerWidth;
	var winHeight = window.innerHeight;
	$(".loadInfos").css({
		'opacitiy': 0.8
	});
	$(".mainOverlay").css({
		'width' : winWidth,
		'height' : winHeight,
		'background-color' : '#333',
		'opacity': 0.6
	});

	$(".mainOverlay").show();
    
    var infoLeft = (winWidth / 2) - (172 / 2);
    $(".loadInfos").css({
        'left' : infoLeft
    });

    $(".loadInfos").show(500);
}

function hideOverlay() {
    $(".loadInfos").fadeOut(800);
	$(".mainOverlay").fadeOut(1000);
}

//function moveRoomRight() {
//	var nextRoom = activeRoom + 1;
//	activeRoom = nextRoom;
//
//	//$("#innerContentWrapper").css('left','-200px');
//	var newLeft = '-='+rooms[activeRoom]+'px';
//	//alert(nextRoom + " ## " + newLeft + " ## " + rooms.length);
//	$("#innerContentWrapper").animate({'left': newLeft}, 2000);
//	if (activeRoom>0) {
//		$(".navMoveLeft").show();
//	}
//	if (activeRoom>=rooms.length-1) {
//		$(".navMoveRight").hide();
//	}
//}
//
//function moveRoomLeft() {
//	if (activeRoom>0) {
//		var nextRoom = activeRoom - 1;
//		activeRoom = nextRoom;
//
//		//$("#innerContentWrapper").css('left','-200px');
//		var newLeft = '+='+rooms[activeRoom+1]+'px';
//		//alert(nextRoom + " ## " + newLeft + " ## " + rooms.length);
//		$("#innerContentWrapper").animate({'left': newLeft}, 2000);
//		if (activeRoom==0) {
//			$(".navMoveLeft").hide();
//		}
//		if (activeRoom<rooms.length-1) {
//			$(".navMoveRight").show();
//		}
//	}
//}

function jumpToRoom(roomId) {
	//alert(roomId + "--" + activeRoom);
	if (roomId<activeRoom) {
		var moveLeft = 0;
        var newRoomLeft = 0;
		for (var k=0;k<=roomId;k++) {
            newRoomLeft += roomsR[k];
		}
        var actualLeft = parseInt($("#innerContentWrapper").css('left'));

        moveLeft = actualLeft + newRoomLeft;
        
        if (roomId==0) {
            moveLeft -= 30;
        }

		var newLeft = '-=' + moveLeft + 'px';
		//alert(roomId + " ## " + newLeft + " ## " + actualLeft + " ## " + newRoomLeft);
		$("#innerContentWrapper").animate({'left': newLeft}, 1000);
		activeRoom = roomId;
		if (activeRoom>0) {
			$(".navMoveRooms").css('left','119px');
			$(".jumpToRoom#jump_room_1").fadeIn(2000);
		} else if (activeRoom==0) {
			$(".jumpToRoom#jump_room_1").fadeOut(2000, function() {
				$(".navMoveRooms").css('left','145px')
			});
		}
	} else if (roomId>activeRoom) {
		var moveRight = 0;
		for (var j=activeRoom+1;j<=roomId;j++) {
			moveRight += roomsR[j];
		}
		var newLeft = '-=' + moveRight + 'px';
		//alert(nextRoom + " ## " + newLeft + " ## " + rooms.length);
		$("#innerContentWrapper").animate({'left': newLeft}, 1000);
		activeRoom = roomId;
		if (activeRoom>0) {
			$(".navMoveRooms").css('left','119px');
			$(".jumpToRoom#jump_room_1").fadeIn(2000);
		} else if (activeRoom==0) {
			$(".jumpToRoom#jump_room_1").fadeOut(2000, function() {
				$(".navMoveRooms").css('left','145px')
			});
		}
	}
}


function specialJump(movePoint) {
    
    var newLeft =  '-=' + movePoint + 'px';
    $("#innerContentWrapper").animate({'left': newLeft}, 1000);
}

function loadRoomContent(contentUrl) {
	$.post(contentUrl, function(roomContent){
		$('#raum2inhalt').html(roomContent);
		//console.log(roomContent);
	});
}

$(document).ready( function() {
	$(window).bind('resize',function() {
		calContentWidth();
	});
	$(".navMoveRight").hover( function() {
		$(this).css('cursor', 'pointer');
		$(this).css('background-image','url(../GALERIEmenu/ggruenrechts.jpg)');
	}, function() {
		$(this).css('cursor', 'normal');
		$(this).css('background-image','url(../GALERIEmenu/graurechts.jpg)');
	});

	$(".navMoveLeft").hover( function() {
		$(this).css('cursor', 'pointer');
		$(this).css('background-image','url(../GALERIEmenu/ggruenlinks.jpg)');
	}, function() {
		$(this).css('cursor', 'normal');
		$(this).css('background-image','url(../GALERIEmenu/graulinks.jpg)');
	});

//	$(".navMoveRight").click(function() {
//		moveRoomRight();
//	});
//
//	$(".navMoveLeft").click(function() {
//		moveRoomLeft();
//	});

	//$(".roommenu").click(function() {
//		var myId = $(this).attr('id');
//		var hrefUrl = $(this).attr('href');
//		loadRoomContent(hrefUrl);
//		return false;
	//});

	$(".jumpToRoom").click(function() {
		var jumpId = $(this).attr('id');
		var tmpArr = jumpId.split('_');
		jumpToRoom(tmpArr[2]-1);
		var linkHref = $(this).children('a').attr('href');
		if (linkHref!="#") {
			$("iframe#gallery").attr('src', linkHref);
		}
		return false;
	});

	//$(".artistPoint").mouseenter(function() {
		//$(this).data('mouseisda',true);
		//settimeout('function() { if ($(this).data("mouseisda")) { alert($(this).data("mouseisda"); $(this).children("a").children(".artistImg").stop(true,true).slideDown(250); }}',500);
		
	//	$(this).children("a").children(".artistImg").stop(true,true).slideDown(250);
		//$(this).children("a").children(".artistImg").stop().show().animate({height: '90px'},{queue: false,duration: 250});
	//}, function() {
	//	$(this).children("a").children(".artistImg").stop(true,true).slideUp(350);
		//$(this).children("a").children(".artistImg").stop().show().animate({height: '0px'},{queue: false,duration: 250});
	//});

	$(".artistPoint").mouseleave( function() {
		if (!$(this).children("a").children(".artistImg").hasClass('active')) {
			$(".artistPoint").children("a").children(".artistImg").stop(true,true);
			$(this).children("a").children(".artistImg").slideUp(350);
		}
	});
	
	$(".artistPoint").click(function() {
		var linkHref = $(this).children('a').attr('href');
		if (linkHref!="#") {
			$("iframe#artists").attr('src', linkHref);
		}
		jumpToRoom(1);

		return false;
	});

	$(".galeryPoint").hover(function() {
		$(this).children("a").children(".galeryImg").stop(true,true).slideDown(250);

		//$(this).children("a").children(".artistImg").stop().show().animate({height: '90px'},{queue: false,duration: 250});
	}, function() {
		$(this).children("a").children(".galeryImg").stop(true,true).slideUp(350);
		//$(this).children("a").children(".artistImg").stop().show().animate({height: '0px'},{queue: false,duration: 250});
	});

	$(".galeryPoint").click(function() {
		var linkHref = $(this).children('a').attr('href');
		if (linkHref!="#") {
			$("iframe#gallery").attr('src', linkHref);
		}
		jumpToRoom(2);

		return false;
	});
});



