<!--

	//================================================================================================
	// VARIABLES DECLARATION
	//================================================================================================
	var area;
	var MAX_HEIGHT = 860;
	var MIN_HEIGHT = 440;
	var search = "";
	var tabTo = "";
	var selectedPage = 0, selectedTab = "", once = false;

	//================================================================================================
	// AJAX FUNCTIONS
	//================================================================================================
	function showMenu(id, tab, keywords)
	{
		var url = "" + tab + "&pageID=" + id;
		var div = $('container_menu_' + tab);

		var req = new Request( {url: '' + url,

			onSuccess: function(txt) {
				$(div).set('html', txt);

				if (!blnFirst) {

					if (area != tab)
					{
						if (area == "work") {
							openPlay();
						} else if (area == "play") {
							openWork();
						}
					}

					showDetails(id, tab, keywords);

				} 

				if (tab == "work") {
					tabWork = id;
				} else if (tab == "play") {
					tabPlay = id;
				}

			},

			onFailure: function() {
				$(div).set('html', '');
			},

			onRequest: function() {
				$(div).set('html', '');
			}

		});

	
	}

	
	//================================================================================================
	// LAYOUT FUNCTIONS
	//================================================================================================
	

	function resetTabFloater()
	{
		area_h = window.getHeight() - 170;
		image_h = area_h - 38;

		if (image_h > MAX_HEIGHT) image_h = MAX_HEIGHT;
		if (image_h < MIN_HEIGHT) image_h = MIN_HEIGHT;

		$("container_work").setStyle('height', area_h);
		$$(".resizeable").setStyle('height', image_h);
		$$(".resizeable_text").setStyle('height', image_h - 2);

		if (area == "work") $("tab_floater").setStyle('top', area_h);
		if (area == "play") $("container_work").setStyle('top', -1 * area_h);
	}

	
	
	function setKeywords()
	{
		if ($chk($('keywords')))
		{
			search = $('keywords').get('text');
		}
	}

	function setTab(tab, pageID)
	{
		selectedTab = tab;
		selectedPage = pageID;
	}

	//================================================================================================
	// EVENTS FUNCTIONS
	//================================================================================================
	function setupActions()
	{
		$("work").addEvent('click', function(e) {
			if (area == "play") {
				e.stop();

				if (tabWork != 0) {
					showMenu(0, "work", "");
				} else {
					openWork();
				}

				trackPage("");

			} else if (area == "work") {

				if (tabWork != 0) {
					showMenu(0, "work", "");
				}

				trackPage("");
			}
		});

	  }
	
	
	
	function setupScrollSide()
	{
		var scrollWork = new ScrollSide($('container_work'));

	}	

	//================================================================================================
	// START THIS WHEN PAGE DOM READY
	//================================================================================================
	window.addEvents({

		'domready' : function() {
			setKeywords();
			setupScrollSide();
			
			h = new HistoryManager();

			h.addEvent('onHistoryChange', function() {
				if (h.getCurrentLocation() != "")
				{
					var state = h.getCurrentLocation().split('_');
					showMenu(state[1], '' + state[0], '');

				} else {

					if (search != "") {
						if (search != "hello") {
							showMenu(-1, "play", "");

							blnFinish = true;						
							showMenu(-1, "work", search);
						}
						else{
							showMenu(0, "work", "");
							toggleSwearJar();
						}
					} else {
						showMenu(0, "work", "");
					}

				}
			});

			//h.fireEvent('onHistoryChange', [h.getCurrentLocation()]);

			blnFirst = true;
			blnSwearJar = false;
			blnNewsletter = false;
			
			blnFinish = true;
			if (h.getCurrentLocation() != "")
			{
				var first_state = h.getCurrentLocation().split('_');

				if (first_state[0] == "play") {
					blnFinish = true;
					showMenu(-1, "work", '');		
				}
				else {
					blnFinish = true;
					showMenu(-1, "play", '');
				}

				blnFinish = true;
				showMenu(first_state[1], '' + first_state[0], '');

			} else {
				if (search != "") {
					if (search != "hello") {
						showMenu(-1, "play", "");

						blnFinish = true;
						(function () {
							showMenu(-1, "work", search);
						}).delay(200);
						
					}
					else {
						showMenu(0, "work", "");
						toggleSwearJar();
					}
				} else {
					if (selectedTab != ""){
						showMenu(-1, "play", "");
						
						blnFinish = true;
						(function () {
							showMenu(selectedPage, selectedTab, "");
						}).delay(200);						
					}
					else{
						showMenu(-1, "play", "");
					
						blnFinish = true;
						(function () {
							showMenu(0, "work", "");
						}).delay(200);							
					}
				}
			}

			$("container_play").setStyle('display', 'none');
			
			setupActions();

			if (tabTo != "") {
				area = tabTo;
			} else {
				area = "work";
			}
			resetTabFloater();

		},

		'resize' : function() {

			resetTabFloater();

		}

	});

//-->
