var left_opened = false;
var right_opened = false;
var center_opened = false;

$(function () {
	if($("#scrollwrap").length){$("#scrollwrap").jScrollPane({scrollbarWidth:6, scrollbarMargin:10, showArrows:true});}
	
	$("#nav li div").each(function() {
		$(this).css('width',($(this).parent().width()+20));
	  });
	
	$("#nav li").mouseover(function(){
		if(!$(this).hasClass("curr_menu")) {
			$('div', this).stop().animate({opacity: 1}, 200);
		}
	})
	.mouseout (function(){
		if(!$(this).hasClass("curr_menu")) {
			$('div', this).stop().animate({opacity: 0}, 200);
		}
	});
	
	
	if($('.lightbox').length) {$('.lightbox').lightBox();}
	
	
	$("#book_room_ttl").click(function(){doleft(1)});
	$("#book_room_close").click(function(){doleft(2)});
	
	$("#offers_ttl").click(function(){doright(1)});
	$("#offers_wrap_close").click(function(){doright(2)});
	
	$("#topevents").click(function(){docenter(1)});
	$("#topevents_wrap_close").click(function(){docenter(2)});
});


function doleft(todo) {
	if (todo == 1) {//open
		if (right_opened == true) {
			doright(2);
		}
		if (center_opened == true) {
			docenter(2);
		}
		$("#sidebutt_left").stop().css('width','500px');
		$("#book_room").stop().animate({marginLeft: "0px"}, 1500);
		$("#book_room_ttl").stop().animate({opacity: 0}, 1500);
		$("#book_room_close").stop().animate({opacity: 1}, 500);
		$("#book_room_ttl").css('cursor','default');
		$("#book_room_close").css('z-index','20');
		$("#book_room_close").css('cursor','pointer');
		left_opened = true;
	}
	if (todo == 2) {//close
		$("#book_room").stop().animate({marginLeft: "-475px"}, 1500);
		$("#sidebutt_left").stop().animate({width: "48px"}, 3000);
		$("#book_room_ttl").stop().animate({opacity: 1}, 1500);
		$("#book_room_close").stop().animate({opacity: 0}, 500);
		$("#book_room_ttl").css('cursor','pointer');
		$("#book_room_close").css('z-index','1');
		$("#book_room_close").css('cursor','default');
		
		left_opened = false;
	}
}

function docenter(todo) {
	if (todo == 1) {//open	
		if (right_opened == true) {
			doright(2);
		}
		if (left_opened == true) {
			doleft(2);
		}
		$("#topevents_wrap").stop().slideDown('slow');
		$("#topevents").stop().animate({opacity: 0}, 1500);
		$("#topevents_wrap_close").animate({opacity: 1}, 1500);
		center_opened = true;
		if ($(".goback").length) {
			$(".goback").css('z-index','13');
		}
	}
	if (todo == 2) {//close
		$("#topevents_wrap").stop().slideUp('slow');
		$("#topevents").stop().animate({opacity: 1}, 1000);
		$("#topevents_wrap_close").animate({opacity: 0}, 1000,
		function(){
			if ($(".goback").length) {
				$(".goback").css('z-index','14');
			}	
		});
		center_opened = false;
	}
}

function doright(todo) {
	if (todo == 1) {//open		
		if (left_opened == true) {
			doleft(2);
		}
		if (center_opened == true) {
			docenter(2);
		}
		$("#offers_wrap").stop().animate({marginRight: "0px"}, 1500);
		$("#offers_ttl").stop().animate({opacity: 0}, 1500);
		$("#offers_wrap_close").stop().animate({opacity: 1}, 1500);
		$("#offers_ttl").css('cursor','default');
		$("#offers_wrap").css('z-index','20');
		$("#offers_wrap_close").css('cursor','pointer');
		right_opened = true;
	}
	if (todo == 2) {//close		
		$("#offers_wrap").stop().animate({marginRight: "-260px"}, 1500);
		$("#offers_ttl").stop().animate({opacity: 1}, 1500);
		$("#offers_wrap_close").stop().animate({opacity: 0}, 500);
		$("#offers_ttl").css('cursor','pointer');
		$("#offers_wrap").css('z-index','16');
		$("#offers_wrap_close").css('cursor','default');
		right_opened = false;
	}
}

function PNG(element){
	if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent)){
	var src;
	if (element.tagName=='IMG'){
			if (/\.png$/.test(element.src)){
				src = element.src;
				element.src = "/img/t.gif";
			}
		}
		else {
			src = element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i)
			if(src){
				src = src[1];
				element.runtimeStyle.backgroundImage="none";
			}
		}
	if (src) element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
	}
}
