$(document).ready(function() {
	$(".scrollable .content").jScrollPane({ reinitialiseOnImageLoad: true });
	
	$.activeLayer = true;
	
	$.navigation = {
		root : $(".roll_menu"),
		init : function() {
			var self = this;
			this.root.click(function() {
				if (self.isOpen() == true) {
					self.close();
				}
				else {
					self.open();
				}
			});
			
			return this;
		},
		isOpen : function() {
			if (this.root.hasClass("active")) {
				return true;
			}
			else {
				return false;
			}
		},
		open : function() {
			if (this.isOpen() == false) {
				$.layer.deactivate();
				$.activeLayer = true;
				
				this.root.addClass("active");
				this.root.prev().animate( { opacity: 'toggle', width: 'toggle'}, 500);
			}
		},
		close : function() {
			if (this.isOpen() == true) {
				if ($.isFunction($.gallerySlider)) {
					$.layer.activate();
				}	
				$.activeLayer = false;
				
				this.root.removeClass("active");
				this.root.prev().animate( { opacity: 'toggle', width: 'toggle'}, 500);
			}
		}
	};
	
	$.navigation.init();
	$.layer = {
		showcase : $("#showcase"),
		activate : function() {
			if (!$.activeLayer && $.isFunction($.gallerySlider)) {
				this.showcase.css("z-index","3");
			}
		},
		deactivate : function() {
			if ($.isFunction($.gallerySlider)) {
				this.showcase.css("z-index","1");
			}
		}
	};

	$("#newsletter_form").formPost( { text : ['name', 'email', 'repeat_email'], email : ['email'], repeat : ['email']}, true);
});
