		Array.prototype.array_assoc = function() {
			var a = arguments[0];
			if(typeof(a)=='object' && a.length<this.length) {
				return false;
			}
			for(var y=0,x=0; x<this.length; ++x,++y) {
				this[((typeof(a)=='string') ? a+''+(y) : ((typeof(a)=='object') ? a[y] : this[x]))] = this[x];
			}
		}
		
		Array.prototype.make_assoc = function() {
			var _tmp = new Array();
			for(var i = 0, loops = this.length; i < loops; i++) {
				_tmp[this[i]] = i;
			}
			return _tmp;
		}
		
		function delay(the_func, the_delay) {
			var nox = 0;
			var exp = function() {
				if(nox == 1) {
					the_func();
					clearInterval(someInt);
				}
				nox = nox + 1;
			}
			var someInt = setInterval(exp, (the_delay / 2));
		}
		
		
		
		
		var ACTIVE_SECTION = null,
			ACTIVE_SUB_SECTION = null,
			ACTIVE_SUB_SUB_SECTION = null,
			
			ACTIVE_SUB,			// elem
			ACTIVE_SUB_SUB,		// elem
			
			SUBMENU_ACTIVE,
			TEXT_ACTIVE,		// Boolean
			SAMPLE_ACTIVE;		// Boolean
			
		// google urchin-tracker	
		_uacct = "UA-546711-3";

			
		// init SWF-Obj	
		var playerSWF = new SWFObject("swf/player.swf", "player", "283", "54", "8", "#fff");
			playerSWF.addParam("scale", "noscale");
			playerSWF.addParam("menu", "false");	
		
		function GetSubMenu(SECTION_ID) {
				
			SUBMENU_ACTIVE = true;
			ACTIVE_SECTION = SECTION_ID;
			
			UnsetText();
			UnsetSample();
			
			var url = "php/submenu.php";
			new Ajax(url, {
				method: 'get',
				data: { 'section': SECTION_ID },
				update: $('submenu'),
				onComplete: function() {
					// console.log(this.running);
					// $('submenu').innerHTML = this.response.text;
					// StyleBtns();
					
					$$('#sub-navigation li').each(function(_elem) {
														   
						var ID = _elem.getFirst().getProperty('href');
						_elem.getFirst().setProperty('href', 'javascript:void(0)');
						
						if( window.ie ) {
							// ID = _elem.getFirst().getProperty('href');
							ID = ID.split("/");
							ID = ID[ID.length - 1];
							// alert(ID);
						}
							
						// 	console.info(ACTIVE_SUB);
						// console.info(_elem.getFirst());
						
						_elem.getFirst().addEvent('click', function(e) {
							if( ACTIVE_SUB != _elem.getFirst() ) {
								e = new Event(e).stop();	
							// 	alert(ID);
								SetThumb(ID);
								GetText(ID);
								SetDeepLink(GetFullDeepLink()[0] + "/" + SUB_ITEMS[ID], ACTIVE_SECTION, ID, null);
							}
						});
					});
					
					// $('submenu').innerHTML = this.response.text;
					
				}
			}).request();
			
		}
	
		
		function UnsetSubMenu() {
			SUBMENU_ACTIVE = false;
			$('submenu').setHTML('&nbsp;');
		}
	
	
		function GetText(TEXT_ID) {

			if(TEXT_ID != null) {
				
				ACTIVE_SUB_SECTION = TEXT_ID;
				
				if(TEXT_ACTIVE) UnsetText();
				TEXT_ACTIVE = true;
				
				if(SAMPLE_ACTIVE) UnsetSample();
				
				UnsetActiveButton();
				// UnsetActiveSubButton();
				
							
				var url = "php/text.php";
				new Ajax(url, {
					method: 'get',
					data: { 'text': TEXT_ID },
					update: $('text'),
					onComplete: function() {
						// StyleBtns();					
						SetActiveButton( $('id_' + TEXT_ID) );
						// console.info("SetActiveButton(" + TEXT_ID +") inside GetText()");
						
						$$('#sub-sub-navigation li').each(function(_elem) {
							var ID = _elem.getFirst().getProperty('href');
							_elem.getFirst().setProperty('href', 'javascript:void(0)');
							
							// ie: getProperty("href") returns whole path to root-folder
							if( window.ie ) {
								// ID = _elem.getFirst().getProperty('href');
								ID = ID.split("/");
								ID = ID[ID.length - 1];
								// alert(ID);
							}
							
							_elem.addEvent('click', function(e) {
								if( ACTIVE_SUB_SUB != _elem.getFirst() ) {
									e = new Event(e).stop();	
									GetSample(ID);						
									SetDeepLink(GetFullDeepLink()[0] + "/" + GetFullDeepLink()[1] + "/" + SAMPLE_ITEMS[ID], ACTIVE_SECTION, ACTIVE_SUB_SECTION, ID);
								}
							});
						});
					}
				}).request();
			
			}
		}
		
		
		function UnsetText() {
			TEXT_ACTIVE = false;
			$('text').setHTML('');
		}
		
		
		function GetSample(SAMPLE_ID) {
			
			if(SAMPLE_ID != null) {
				
				ACTIVE_SUB_SUB_SECTION = SAMPLE_ID;
				SAMPLE_ACTIVE = true;
				if(!TEXT_ACTIVE) UnsetText();
				
				UnsetActiveSubButton();
			
				var url = "php/sample.php";
				new Ajax(url, {
					method: 'get',
					data: { 'sample': SAMPLE_ID },
					update: $('sample'),
					onComplete: function() {
												
						SetActiveSubButton( $('subid_' + SAMPLE_ID) );
						
						var playerElem = $('music-player'),
							SAMPLE_TITLE = playerElem.getChildren()[0].innerHTML,
							SAMPLE_SRC = playerElem.getChildren()[1].getProperty('href'),
							SAMPLE_DURATION = String(playerElem.getChildren()[1].getProperty('id')).substr(4, String(playerElem.getChildren()[1].getProperty('id')).length - 4);
						
						playerSWF.addVariable("SOUND_SRC", SAMPLE_SRC);
						playerSWF.addVariable("SOUND_DURATION", SAMPLE_DURATION);
						playerSWF.addVariable("SOUND_TITLE", SAMPLE_TITLE);
						playerSWF.write("music-player");
						
						// because of a nasty flickering
						playerElem.setStyle('visibility', 'visible');
						
						// if player is out of sight, then scroll to top of page
						if(window.getScrollTop() > 275) {
							var scroll = new Fx.Scroll(window, {
								wait: false,
								duration: 850,
								offset: {'x': 0, 'y': 0},
								transition: Fx.Transitions.Quad.easeInOut
							});
							scroll.toTop();
						}
						
					}
				}).request();
			
			}
		}
		
		
		function GetPage(PAGE_ID) {
			if(PAGE_ID != null) {
				ACTIVE_SECTION = 5;				
				TEXT_ACTIVE = true;
				UnsetSample();
				UnsetSubMenu();				
				
				var url = "php/page.php";
				new Ajax(url, {
					method: 'get',
					data: { 'page': PAGE_ID },
					update: $('text')
				}).request();
				
			}
		}
	
		
		function UnsetSample() {
			SAMPLE_ACTIVE = false;
			$('sample').setHTML('');
		}
	
	
		function SetActiveButton(_elem) {
			if(_elem) {
				ACTIVE_SUB = _elem;
				ACTIVE_SUB.className = "active";
			}
		}
		
		
		function UnsetActiveButton() {
			if(ACTIVE_SUB) ACTIVE_SUB.className = "menu";
			ACTIVE_SUB = null;
		}
		
		
		function SetActiveSubButton(_elem) {
			if(_elem) {
				ACTIVE_SUB_SUB = _elem;
				ACTIVE_SUB_SUB.className = "active";
			}
		}
		
		
		function UnsetActiveSubButton() {
			if(ACTIVE_SUB_SUB) ACTIVE_SUB_SUB.className = "menu";
			ACTIVE_SUB_SUB = null;
		}
		
		
		function SetThumb(ENTRY_ID) {
			if( FLASH("menu").LoadThumb )
				FLASH("menu").LoadThumb(ACTIVE_SECTION, MEDIA_STORAGE.thumbs + ITEM_THUMBS[ENTRY_ID]);
		}
		
		
		/*function // StyleBtns() {
			$$('.button').addEvents({
				'mouseover': function(e) {
					e = new Event(e).stop();	
					if(ACTIVE_SUB != this && ACTIVE_SUB_SUB != this) this.className = "button-over";
				},
				'mouseout': function(e) {
					e = new Event(e).stop();
					if(ACTIVE_SUB != this && ACTIVE_SUB_SUB != this) this.className = "button";
				}
			});
		}*/
		
		
		// flashmovie reference
		function FLASH(movieName) {
			if(navigator.appName.indexOf("Microsoft") != -1) {
				if( window[movieName] )
					return window[movieName]
				 else return false;
			} else {
				if( document[movieName] )
					return document[movieName]
				else return false;
			}
		}
	
	
		function GetFullDeepLink() {
			return dhtmlHistory.getCurrentLocation().split("/");
		}
		
		
		function HandleHistoryChange(newLocation, historyData) {
			
			// console.info("HandleHistoryChange");
			// console.debug("historyData = " + historyData.sectionID);
			delay(function() {	
			
				if(historyData != null) {
					
					SetTitle(newLocation);
								   
					if( historyData.sectionID != null ) {
						
						if( historyData.sectionID != ACTIVE_SECTION ) {
							if( FLASH("menu").SetSection )
								FLASH("menu").SetSection(historyData.sectionID, true);
						}
						
					} /* else {
						
						if(historyData.sectionID != ACTIVE_SECTION) {
							
							if( FLASH("menu").SetSection )
								FLASH("menu").SetSection(historyData.sectionID);
							// else console.info("fuck");
							
						}
						
					}	 */		
				
				
					if( historyData.storyID != null ) {
						
						SetThumb(historyData.storyID);
						GetText(historyData.storyID);		
						
					//	UnsetActiveButton();
					//	UnsetActiveSubButton();
											
					} else UnsetText();
					
					
					if ( historyData.sampleID != null )
						GetSample(historyData.sampleID);
					
					
					if ( historyData.storyID == null && historyData.sampleID == null ) {
						
						// console.info("bla");
						
						/*if ( historyData.sectionID == null )
							UnsetSubMenu();*/
						
						if ( FLASH("menu").UnloadThumb )
							FLASH("menu").UnloadThumb();
							
						UnsetActiveButton();
						
					}
						
				} else {
					// if just main-section is selected and you push backward-button
					// reset website to default position
					UnsetSubMenu();
					UnsetText();
					UnsetSample();
					if( FLASH("menu").UnsetSection )
						FLASH("menu").UnsetSection(true);
				
					ACTIVE_SECTION = null;
				
				}
			
			}, 500);
				
		}
		
		function SetDeepLink(newLocation, _sectionID, _storyID, _sampleID) {	
			var historyData = {
				sectionID:	_sectionID,
				storyID: 	_storyID,
				sampleID:	_sampleID
			}
			
			// never-ending loading-bug umgehen in safari 2.0
			if( !window.webkit419 ) {
				SetTitle(newLocation);
				dhtmlHistory.add(newLocation, historyData);
			}
			
			// track site stats
			urchinTracker();
		}
		
		function SetTitle(fullURL) {
			var urlItems = fullURL.split("/"),
				sep = " | ",
				titleFragment;
				
			window.document.title = sep + "sascha selke composer" + sep;
			
			if ( typeof urlItems[0] != "undefined" )
				window.document.title += urlItems[0].replace("_", " ");
			
			if ( typeof urlItems[1] != "undefined" ) {
				titleFragment = urlItems[1].split("_").join(" ");
				window.document.title += sep + titleFragment;
			}
			
			if ( typeof urlItems[2] != "undefined" ) {
				titleFragement = urlItems[2].split("_").join(" ");
				window.document.title += sep + titleFragement;
			}
		}
		
		
		function ShowIntro( clearCookie ) {
			
			// if intro-link has been clicked
			if ( clearCookie ) {
				Cookie.remove('hasViewedIntro');
				window.location.hash = "";
				window.location.href = "";
				// window.location.reload();
				// return;
			}
			
			// if intro has been watched return
			if ( Cookie.get('hasViewedIntro') == 'true') {
				
				return;
				
			}
			
			var introDIV = new Element('div', {
				'styles': {
					'position': 'absolute',
					'top': '0px',
					'left': '0px',
					'width': window.getWidth() + 'px',
					'height': window.getHeight() + 'px',
					'z-index': 25,
					'background-color': 'transparent'
				},
				'id': 'intro'
			});
			
			
			// inject as 1st element in body
			introDIV.injectBefore('credits');
			
			$('navigation').setStyle('visibility', 'hidden');
			
			// swfObject intro
			var introSWF = new SWFObject("swf/intro.swf", "player", "99%", "99%", "8", "#fff");
				introSWF.addParam("scale", "noscale");
				introSWF.addParam("menu", "false");	
				introSWF.addParam("salign", "t");
				introSWF.write("intro");
		}
		
		
		function RemoveIntro() {
			Cookie.set('hasViewedIntro', 'true', {duration:365});
			
			// IE bug
			/* if ( !window.ie6 ) {
				$('navigation').setStyle('visibility', 'visible');
				$('intro').getFirst().remove();
				var myFx = new Fx.Style('intro', 'opacity', { duration:1000, onComplete: function() {
					$('intro').remove();
				}}).start(1, 0);
			
			} */
			
			$('intro').remove();
			$('navigation').setStyle('visibility', 'visible');
		}
		
		
		function popUp(name, w, h, src) {
			var winl = (screen.width - w) / 2,
				wint = (screen.height - h) / 2,
				settings = 'height=' + h + ', width=' + w + ', top=' + wint + ', left=' + winl + ', scrollbars=no, toolbar=no, location=no, status=no, menubar=no, resizable=no, dependent=no';
				
			var win = window.open(src, name, settings);
		}	
	
	
		// DDL
		var loadType = "load";
		if( window.webkit) loadType = "domready";
		
		window.addEvent(loadType, function() {
			
			// credits links
			var a = $('credits').getChildren(), l = a.length;
			for ( var i = 0; i < l; i++ ) {
				a[i].setAttribute("href", "javascript:void(0);");
			}			
			
			// detect flash-version of user
			var pv = deconcept.SWFObjectUtil.getPlayerVersion();
			// Boolean
			var IsValidFlash = pv.versionIsValid( new deconcept.PlayerVersion([8,0,0]) );	
			
			if ( !IsValidFlash ) return;
										   			
			// set up dhtmlHistory
			dhtmlHistory.initialize();
			dhtmlHistory.addListener(HandleHistoryChange);
						
			// credit-links
			$('credits').setOpacity(0.7);			
						
			// init start-up URL
			if ( dhtmlHistory.isFirstLoad() ) {
				
				// console.info("dhtmlHistory.isFirstLoad()");
				
				var initURL = GetFullDeepLink(),
					urlTitle = dhtmlHistory.getCurrentLocation(),
					a = null, b = null, c = null;
				
				if ( urlTitle != "" ) {
				
					// delay actions for 1 second, until flash-menu is available
					delay(function() {
								   
						if ( typeof initURL[0] != 'undefined' ) {
							a = initURL[0];
							// troubles wenn FLASH noch nicht erreichbar!
								if( FLASH("menu").SetSection )
									FLASH("menu").SetSection(MAIN_SECTIONS[a], true);	  			
						}
							
						if ( typeof initURL[1] != 'undefined' ) {
							b = initURL[1];
							GetText(SUB_ITEMS.make_assoc()[b]);
							SetThumb(SUB_ITEMS.make_assoc()[b]);		
						}
							
						if ( typeof initURL[2] != 'undefined' ) {
							c = initURL[2];
							GetSample(SAMPLE_ITEMS.make_assoc()[c]);	
						}
						
						SetDeepLink(urlTitle,
									MAIN_SECTIONS[a], SUB_ITEMS.make_assoc()[b], SAMPLE_ITEMS.make_assoc()[c]);
					
					}, 1000);
					
				} else {
					// intro					
					if ( IsValidFlash ) {
						
						ShowIntro();
										
					}

				}
				
			}
		});