	// German-Inc Site.Js
	// Copyright Hirbod

	// Variablen
	var isOpenDownloadBox = false;
	var managerIsOpen = false;
	var timerFunction1 = null;
	var timerFunction2 = null;
	var flashMusicPlayerInnerContent = null
	var lastPlayerId = null;
	var playerID;
	if (Cookie.read('manager') != 'open')
	{
		var manageCookie = null;
	}
	
	
	// Growl einbinden
	var roar = new Roar({
		position: 'upperRight'
	});
	


	// Shadowbox initialiseren. Todo: Fix Counter
	function initShadowbox() 
	{
	Shadowbox.init({
		useSizzle:	"false",
		language:   "de",
		player: ["img", "iframe", "html", "flv"],
		displayCounter:	"false",
		initialHeight:250,
		initialWidth:250
			
	});
	}
	
	function hideMusicPlayer() {
		if(lastPlayerId)
		{
			$(""+lastPlayerId+"").updateText();
		}
	}
	
	function registerMusicPlayer(playerID) {
		lastPlayerId = "songPlayer"+playerID+"";
	}
	

	
	// Add Event einbinden
	
	window.addEvent('domready', function()
		{
			
			if($('downloadsRight'))
			{
				$('downloadsRight').setStyle('visibility', 'hidden');
				$('downloadsRight').setStyle('display', 'none');
			}

			initShadowbox();
			initManager();

		}
	);
	
	function showDownloadPanel()
	{
		if(!isOpenDownloadBox) 
		{
			$('downloadsRight').setStyle('display', 'block');
			$('downloadTitleRight').innerHTML='Downloads verbergen';
			
		window.setTimeout(
				function()
				{
					
					$('downloadsRight').fade(1);
					isOpenDownloadBox = true;
				}, 100);
			
		} else {
		
			$('downloadsRight').fade(0);
			
			window.setTimeout(
				function()
				{
					$('downloadTitleRight').innerHTML='Downloads anzeigen';
					$('downloadsRight').setStyle('display', 'none');
					isOpenDownloadBox = false;
				}, 1000);
		}
	}
	
	
	
	// MANAGER //
	
	function updateActive(el){
		$$('#bottomContent tr').each(function(item, index){
	    		item.className='';
				item.setStyle('background-color','');
		});
		if(el)
			el.className='activeSongInManager';
	}
	
	
	// Funktion um Roar aufzurufen
	function makeANotice(title, text)
	{
		roar.alert(title,text); 
	}
	
	
	// Manager initalisieren
	function initManager()
	{
		$('fixedBottom').setStyle('display', 'block');
		$('bottomContentWrapper').fade('out');
		
		if (Cookie.read('manager') == 'open')
		{
			toggleManager('no');
		}
		
		updateManager("refresh", 0);
	}
	

	
	// File-Handling fuer Manager
	function manageFile(mode, id)
	{
		if(!managerIsOpen) toggleManager('yes');
			
			if(mode == "add")
			{
				updateManager("add", +id);
				makeANotice('Manager','Song zum Manager hinzugefügt'); 
			}
			
			if(mode == "remove")
			{
				updateManager("remove", id, "logContent");
				makeANotice('Manager','Song vom Manager entfernt'); 
			}
			
			if(mode == "removeAll")
			{
				updateManager("removeAll", +id);
				makeANotice('Manager','Liste wurde geleert');
				toggleManager(); 
			}

		
		return false;
	}
	
	function removeFromTable(i)
	{
		$('managerList').deleteRow(i);
		return true;
	}
	
	// Ajax Funktion für Upadates des Managers
	function updateManager(action, id, update)
	{
		
		if(update == undefined)
		{
			var updateBox = $('bottomContent');
		} else {
			var updateBox = $(update);
		}
		
		var url = "download-manager.html?action="+action+"&id="+id;

		var req = new Request.HTML({
			method: 'post',
			update: updateBox,
			evalScripts: true,
			url: url,
			onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript) {
				if($('managerFirst') && update == undefined) $('managerFirst').highlight('#FF2564');
			},

			onFailure: function() {
				$('bottomContent').set('html', 'The request failed.');
			}
		}).send();
		return false;
	}

	
	// Manager oeffnen / schließen (Toggle)
	function toggleManager(animate)
	{
		if(!managerIsOpen)
		{
			
			if(animate != 'no')
			{
				$('fixedBottom').morph({height: 150, opacity: 1});
				$('bottomContentWrapper').fade('in');
				//updateManager("refresh", 0);
				
			} else {
				$('fixedBottom').setStyles({height: 150, opacity: 1});
				$('bottomContentWrapper').fade('in');
				//updateManager("refresh", 0);
			}
			
			manageCookie  	= Cookie.write('manager', 'open', {path: '/', domain: 'german-inc.com', duration: 1});
			managerIsOpen 	= true;
			
		} else {
			
			$('fixedBottom').morph({height: 15, opacity: 0.6});
			$('bottomContentWrapper').fade('out');
			//$('bottomContent').empty();
			
			managerIsOpen = false;
			manageCookie.dispose('manager');
		}
		
	}
	

