$extend(App, {
	_currentContent: false,
	
	start: function() {
		$E("li.contact", "main-navigation").addEvents({
			"mouseenter": function() {
				this.addClass("hover");
			},
			"mouseleave": function() {
				this.removeClass("hover");
			},
			
			"click": this._showContactForm.bind(this)
		});
		
		var boxes = $ES("div.box", "content-part");
		if (boxes.length > 0)
		{
			boxes.each(function(box) {
				var fx = box.getFirst().effect("height", {
					"duration": 1000,
					"transition": Fx.Transitions.Expo.easeOut,
					"wait": false
				});
				
				box.addEvents({
					"mouseenter": function(event) {
						fx.start(150);
						
						if (this._currentContent)
						{
							if (this._currentContent == box.getProperty("id").slice(4))
								return;
						}
						else
						{
							$("content-board").setStyle("display", "none");
							$("content-board-2").setStyle("display", "");
						}
						
						this._renderContent(box.getProperty("id").slice(4));
					}.bind(this),
					
					"mouseleave": function() {
						fx.start(100);
						
						if (this._currentContent)
							this._renderContent(this._currentContent);
						else
						{
							$("content-board").setStyle("display", "");
							$("content-board-2").setStyle("display", "none");
						}
					}.bind(this)
				});
				
				$E("div.bContent", box).addEvent("click", function() {
					this._currentContent = box.getProperty("id").slice(4);
					this._highlightBox(this._currentContent);
				}.bind(this));
			}, this);
		}
		
		return this;
	},
	
	_renderContent: function(id) {
		var contentID = "content-" + id;
		var showContent = function() {
			$ES("div.content", "content-board-2").each(function(content) {
				content.setStyle("display", content == $(contentID) ? "" : "none");
			});
		};
		
		if ($(contentID))
		{
			if ($(contentID).getStyle("display") != "")
				showContent();
		}
		else
			new Ajax("box-" + id + ".htm", {
				method: "get",
				onComplete: function(response) {
					var contentEl = new Element("div", {
						"id": contentID,
						"class": "content"
					}).setHTML(response);
					
					$E("#content-board-2 .cbBody .cbLEdge .cbIFrame").adopt(contentEl);
					
					$ES(".ticker", contentEl).each(function(ticker) {
						new Ticker(ticker, {speed: 1000, delay: 3000});
					});
					
					showContent();
				}
			}).request({nocache: Math.random()});
		
		return this;
	},
	
	_highlightBox: function(id) {
		var boxID = "box-" + id;
		
		if ($(boxID).getStyle("opacity") != 0.7)
			$ES("div.box", "content-part").each(function(box) {
				box.setOpacity(box == $(boxID) ? 0.7 : 1);
			});
		
		return this;
	}
});

window.onunload = function() {
	try {
		if (App.contactForm) {
			App.contactForm.destroy();
			
			delete App.contactForm;
			App.contactForm = null;
		}
	}
	catch (e) {
	}
};