$(document).ready(function(){
	//centered container and back image
	var viewportHeight = window.innerHeight ? window.innerHeight : $(window).height();
	var centerVertical = Math.ceil(viewportHeight/2) - Math.ceil($("div#container").height()/2);
	var viewportWidth = window.innerWidth ? window.innerWidth : $(window).width();
	var centerHorisontal = Math.ceil(viewportWidth/2) - Math.ceil($("div#container").width()/2);
	$("#container").css("margin-top", centerVertical);
	$("#container").css("margin-left", centerHorisontal);
	$("#back_image").css("margin-top", centerVertical);
	$("#back_image").css("margin-left", centerHorisontal);
	//initialization
	$("div[id^='menu_']").hide();
	$("div[id^='content_']").hide();
	$.cookie("page_opened", "hotel");
	transparant_hide_show("show");
	$("#content_hotel p:eq(1)").css("margin-top", 40);
	//marquee
	$jScroller.add("#scroller_container","#scroller","up",1,true);
	$jScroller.start();
	//function menu hide/show
	function menu_hide_show(hideshow, menu_eq){
		if (hideshow=="hide"){
			$("#content_" + $.cookie("page_opened")).fadeOut("slow");
			$("div[id^='menu_']:eq(" + menu_eq + ")").animate({
				"padding-top"	: "30px"
			 }, {
				"duration": 500,
				"complete": function(){
					$(this).hide("slow");
					if (menu_eq>0){
						menu_eq = menu_eq-1;
						menu_hide_show("hide", menu_eq);
					} else {
						transparant_hide_show("hide");
					}
				}
			 });
		} else {
			$("div[id^='menu_']:eq(" + menu_eq + ")").show("slow");
			$("div[id^='menu_']:eq(" + menu_eq + ")").animate({
				"padding-top"	: "0"
			 }, {
				"duration": 300,
				"complete": function(){
					if (menu_eq<6){
						menu_eq = menu_eq+1;
						menu_hide_show("show", menu_eq);
					}
					else
					{
						$("div#menu_" + $.cookie("page_opened")).trigger("click");
					}
				}
			 });
		}
	}
	//function transparant hide/show
	function transparant_hide_show(hideshow){
		if (hideshow=="hide"){
			$("#close-transparant").hide();
			$("#transparant").animate({
				"width" 		: "110px"
			}, {
				"duration"		: 2000,
				"complete"		: function(){
					$("#open-transparant").fadeIn("slow");
				}
			});
			$("#logo").animate({
				"margin-left" 	: "5px"
			}, 500);
		} else {
			$("#open-transparant").hide();
			$("#transparant").animate({
				"width" : "669px"
			}, {
				"duration"		: 2000,
				"complete"		: function(){
					$("#close-transparant").fadeIn("slow");
					menu_hide_show("show", 0);
				}
			});
			$("#logo").animate({
				"margin-left" : "25px"
			}, 500);
		}
	}
	//load menu
	$("div[id^='menu_'], a[id^='smnu_']").click(function(e){
		e.preventDefault();
		$("#content_" + $.cookie("page_opened")).fadeOut("slow");
		var content=$(this).attr("id").substring(5);
		if (($(this).attr("id").substring(0,4))=="smnu" && $("#transparant").width()==110){
			transparant_hide_show("show");
		}
		$.cookie("page_opened", content);
		if ($("#back_image").attr("class")!="back_" + content){
			$("#back_image").animate({
				"opacity"	: 0
			}, {
				"duration": 1000,
				"complete": function(){
					$("#back_image").attr("class", "back_" + content);
					$("#back_image").animate({
						"opacity"	: 100
					}, {
						"duration"	: 1000,
						"complete"	: function(){
							$("#content_" + $.cookie("page_opened")).fadeIn("slow");
						}
					});
				}
			});
		} else {
			$("#content_" + $.cookie("page_opened")).fadeIn("slow");
		}
	});
	//left transparant on/off
	$("#open-transparant").mouseover(function(){
		$(this).css("background-position", "right");
	});
	$("#open-transparant").mouseout(function(){
		$(this).css("background-position", "left");
	});
	$("#close-transparant").mouseover(function(){
		$(this).css("background-position", "right");
	});
	$("#close-transparant").mouseout(function(){
		$(this).css("background-position", "left");
	});
	//animate transparant
	$("#open-transparant").click(function(){
		transparant_hide_show("show");
	});
	$("#close-transparant").click(function(){
		menu_hide_show("hide", 6);
	});
	//show picture
	$("span[id^='des_']").hide();
	$("a[id^='open_']").click(function(e){
		e.preventDefault();
		$("img[id^='thumb_']").slideUp("slow");
		$("span[id^='des_']").fadeOut("fast");
		var open_thumb = $(this).attr("id").substring(5);
		$("#thumb_" + open_thumb).slideDown("slow");
		$("#des_" + open_thumb).fadeIn("slow");
	});
	//show large image
	$("img[id^='thumb_']").click(function(e){
		e.preventDefault();
		$("#back_image").attr("class", ($(this).attr('id').substring(6)));
	});
	//fancybox
	$(".fancybox").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	false
	});
	$('#back_music').flash({
		src: 'assets/frontend/simple_theme/sounds/back_music.swf',
		width: 90,
		height: 20
	},
	{
		version: 8
	});
	
	//links
	$('a[id^="link_"]').mouseover(function(e){
		e.preventDefault();
		
		var tt = $(this).attr('id').substring(5);
		
		$('#span_' + tt).fadeIn('slow');
	});
	
	$('a[id^="link_"]').mouseout(function(e){
		e.preventDefault();
		
		var tt = $(this).attr('id').substring(5);
		
		$('#span_' + tt).fadeOut('slow');
	});

//external links
	$('div[id^="link_j"]').mouseover(function(e){
		e.preventDefault();
		var tooltip = $(this).attr('id').substring(5);
		$('#span_' + tooltip).fadeIn('slow');
	});
	$('div[id^="link_j"]').mouseout(function(e){
		e.preventDefault();
		var tooltip = $(this).attr('id').substring(5);
		$('#span_' + tooltip).fadeOut('slow');
	});
	$('div[id^="link_j"]').click(function(e){
		e.preventDefault();
		var ext_link = $(this).attr('id').substring(5);
		switch (ext_link){
			case 'jatrahotelpekanbaru':
				window.open('http://www.jatrahotelpekanbaru.com/');
				break;
			case 'jboutique':
				window.open('http://www.jboutiquehotel.com/');
				break;
		}
	});
});
