	var ie = (navigator.appName.indexOf("Explorer")!=-1) ? true : false;
	Event.observe(window,'load',initAnova);
	var jsReady = false; // Used for the main player
	var mainPlayer;
	// New release variables:
	var mp3Path;
	var textToShow;
	var imgToLoad;
	var currHash;
	var firstHash;
	var timer;
	
function initAnova() {
	// First initialization
	jsReady = true;
	initTopNavigator();
	initAfterAjaxUpdate(document.getElementsByTagName("body")[0].className);
 	//add iframe nav fixer for IE
	if(ie){
		var iframe = document.createElement('iframe');
		iframe.height = 0;
		iframe.width = 0;
		iframe.frameBorder = 0;
		iframe.src = "navFixer.php";
		iframe.id = "NavFixer";
		document.getElementsByTagName("body")[0].appendChild(iframe);
	}
 	// Init Hash Checker
	if(document.location.hash == ""){
		var parts = document.location.href.split(Path);
		firstHash = parts[1] != "" ? parts[1] : "#home.php";
	}
	else
		firstHash = document.location.hash;
	timer = window.setInterval(checkHash,300);

}

function initAfterAjaxUpdate(pageId) {
	updateLinks();
	externalLinks();
	initFlashPlayers(pageId);
	document.getElementsByTagName("body")[0].className = pageId;
	var l = document.getElementsByClassName("tooltipTrigger");
	l.each(function(el){
	xoffset = ($(el.id).rel);
	
  		 new Control.Modal(el.id,{
			position: 'mouse',
			offsetTop: (1*xoffset),
			offsetLeft: 25,
			contents: function(){return ($(el.id+'_div').value);}
		});
 	});
	var la = document.getElementsByClassName("container");
	la.each(function(el){
  		el.style.height="auto";
 	});
 	//google analytics stats:
 	pageTracker._trackPageview("/" + pageId + "/");
}

function eventsScroll(eventId) {
	window.scroll(0,$('event_'+eventId).offsetTop+115);
	var la = document.getElementsByClassName("clickedEvent");
	la.each(function(el){
  		el.className="";
 	});
	$('eventH3_'+eventId).className="clickedEvent";

}

function checkHash(){
	if(document.location.hash != "#" && document.location.hash != currHash && document.location.hash != "#" + currHash){
		window.clearInterval(timer);
		var p;
		var dh = document.location.hash;
		if(dh != currHash && document.location.hash != ""){
			var p = new String(document.location.hash);
		} else if(document.location.hash == "" && currHash != firstHash && currHash != undefined){
			var p = new String(firstHash);
		}
		if(p != undefined){
			if (p.indexOf('#') != -1)
				p = p.substr(1,p.length);
			currHash = "#"+p;
			ajaxLoadPage(p.replace("~","?"));
		}
		timer = window.setInterval(checkHash,300);
	}
}

function externalLinks() {
		if (!document.getElementsByTagName) return;
			var anchors = document.getElementsByTagName("a");
			for (var i=0; i<anchors.length; i++) {
				var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
			anchor.target = "_blank";
		}
}
function initTopNavigator() {
	// Adding the Ajax listener event to each of the buttons on the top navigator:
	var l = document.getElementsByClassName("topNavigation","header");
	l.each(function(el){
		el.observe('click',function(e){
 			ajaxLoadPage(Event.element(e).href);
 			Event.stop(e);
 			});
 	});
}

function updateLinks() {
	// Adding the Ajax listener event to each ajaxed link in the page:
	//.getElementsByTagName('a')).each(function(el){
	var l = document.getElementsByClassName("ajLink");
	l.each(function(el){
		el.observe('click',function(e){
 			ajaxLoadPage(Event.element(e).href);
 			Event.stop(e);
 			});
 	});
	var l = document.getElementsByClassName("ajImgLink");
	l.each(function(el){
		el.observe('click',function(e){
 			ajaxLoadPage(Event.element(e).id);
 			Event.stop(e);
 			});
 	});
 	
}

function externalLinks() {
		if (!document.getElementsByTagName) return;
			var anchors = document.getElementsByTagName("a");
			for (var i=0; i<anchors.length; i++) {
				var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
			anchor.target = "_blank";
		}
}


function parseURL(url) {
 return parameters;
}

function placepic(divID, pic) {
	document.getElementById(divID).innerHtml = '<img src="'+pic+'">';
}

function ajaxLoadPage(href) {
	var urlParts = href.split('/');
	var urlAction = urlParts[urlParts.length-1].split('.');
	if (urlAction[1]==undefined)
		urlAction[1] = urlAction[0];
	var params = '';
	var l = document.getElementsByClassName("container");
	l.each(function(el){
  		el.style.height="600px";
 	});
	if (urlAction[1].indexOf('?') != -1) {
		 params = (urlAction[1].split('?'))[1];
		 params += '&';
	 }
	 params += "proccess=" + urlAction[0];
	 params += "&showPreviewStatused=" + $('showPreviewStatused').innerHTML;
	 new Ajax.Updater('xmlContainer', 'ajaxLoader.php',
		{method: 'get', evalScripts: true, parameters: params});
 	//Hash:
 	 if(firstHash != urlAction){
		 document.location.hash = urlAction[0] + "." +  urlAction[1].replace("?","~");
		 currHash = urlAction[0] + "."+  urlAction[1].replace("?","~");
		 //if(ie && urlAction != "") $('NavFixer').src = "navFixer.php?hash="+urlAction[0] + "." + urlAction[1].replace("?","~");
	 }
	 timer = window.setInterval(checkHash,10000);
	window.scroll(0,0);
	return false;
}

/**
*	This function updates the flash ojects on the page, should be run after each ajax update
*	It switches diffrent flash objects for each page.
*   It always tries to put the main player flash object only once when the page is loaded or refreshed (F5).
**/
function initFlashPlayers(pageId) {
	// Initializing main mp3 player, only once, no matter what page is beeing viewed first:
	var playerCol = document.getElementById('playerCol');
	if (playerCol.name != 'playerInitialized') {
		if (swfobject.hasFlashPlayerVersion("9.0.115")) {
		    var fn = function(){
		        var att = {
		            data: "assets/mainPlayer.swf",
		            width: "525",
		            height: "180",
		            id: "musicPlayer",
		            name: "musicPlayer"
		        };
		        
		        var par = {
		            wmode: "transparent",
		            quality: "best",
		            scale: "noscale",
		            swliveconnect: "true",
		            allowscriptaccess: "always",
		            allownetworking: "all",
		            flashvars:"whichArtist=xml/playlist.php"
		        };
		        
		        var id = "f2";
		        mainPlayer = swfobject.createSWF(att, par, id);
		        
		    };
		    
		    swfobject.addDomLoadEvent(fn);
			playerCol.name = 'playerInitialized';
		}
	}	
	
	function isReady(){
	    return jsReady;
	}
	//this embeds the MAIN STORY FLASH using valid markup
	var flashvars = {};
	var params = {};
	params.play = "false";
	params.menu = "true";
	params.quality = "best";
	params.scale = "noscale";
	params.wmode = "transparent";
	params.bgcolor = "#FFFFFF";
	params.allowfullscreen = "true";
	params.allowscriptaccess = "always";
	params.allownetworking = "all";

	// Anova radio parameters:
	 var flashvars2 = {};
	 flashvars2.airversion =  "1.0"; // version of AIR runtime required
	 flashvars2.appname =  "Anova Radio"; // application name to display to the user
	 flashvars2.appurl =  "http://www.anovamusic.com/anovaRadio/Anova-Radio-1.air"; // absolute URL (beginning with http or https) of the application ".air" file
	// these parameters are required to support launching apps from the badge (but optional for install):
	 flashvars2.appid =  "com.anovamusic.anovaradio.v1.0"; // the qualified application ID (ex. com.gskinner.air.MyApplication)
	 flashvars2.pubid =   "Amit"; // publisher id
	// this parameter is required in addition to the above to support upgrading from the badge:
	 flashvars2.appversion =   "1.0"; // AIR application version
	// these parameters are optional:
	 flashvars2.imageurl =   "http://www.anovamusic.com/anovaRadio/radioImage.jpg"; // URL for an image (JPG, PNG, GIF) or SWF to display in the badge (205px wide, 170px high)
	 flashvars2.appinstallarg =   "installed from web"; // passed to the application when it is installed from the badge
	 flashvars2.applauncharg =   "launched from web"; // passed to the application when it is launched from the badge
	 flashvars2.helpurl =   "http://www.adobe.com/products/air/"; // optional url to a page containing additional help, displayed in the badge's help screen
	 flashvars2.hidehelp =   "false"; // hides the help icon if "true"
	 flashvars2.skiptransition =   "false"; // skips the initial transition if "true"
	 flashvars2.titlecolor =   "#B9131A"; // changes the color of titles
	 flashvars2.buttonlabelcolor =   "#B9131A"; // changes the color of the button label
	 flashvars2.appnamecolor =   "#B9131A"; // changes the color of the application name if the image is not specified or loaded
	 var parameters = {};
	 parameters.play = "false";
	 parameters.menu = "true";
	 parameters.quality = "best";
	 parameters.scale = "noscale";
	 parameters.allowscriptaccess = "always";
	 parameters.allownetworking = "all";
	 var attributes2 = {};
	
	
	// different flash for each page:
	switch(pageId) {
		
		 case 'events':
		 	 swfobject.embedSWF("anovaRadio/AIRInstallBadge_"+langCode+".swf", "anovaRadioObject", "525", "180", "9.0.115", "anovaRadio/expressinstall.swf",  flashvars2, parameters, attributes2);
		 break;
		 
		case 'home':
			var mainPlayerDiv = document.getElementById('mainPlayer');
			if (swfobject.hasFlashPlayerVersion("9.0.0")) {
			    var fn = function(){
			        var att1 = {
			            data: "assets/mainStory.swf?",
			            width: "420",
			            height: "335",
			            id: "mainstory",
			            name: "mainstory"
			        };
			        
			        var par = {
						play : "false",
			            wmode: "transparent",
			            quality: "best",
			            scale: "noscale",
			        	time:  (new Date().getTime()),
			            flashvars:"whichArtist=xml/mainStory.php?"
			        };
			        
			        var id = "f1";
			        var mainStory = swfobject.createSWF(att1, par, id);
			    };
			    
			    swfobject.addDomLoadEvent(fn);
			}
				swfobject.embedSWF("anovaRadio/AIRInstallBadgeMedium_"+langCode+".swf", "anovaRadioObjectMedium", "300", "280", "9.0.115", "anovaRadio/expressinstall.swf",  flashvars2, parameters, attributes2);
		break;
		
		case 'newsArchive':
			 swfobject.embedSWF("anovaRadio/AIRInstallBadge_"+langCode+".swf", "anovaRadioObject", "525", "180", "9.0.115", "anovaRadio/expressinstall.swf",  flashvars2, parameters, attributes2);		
		break;
		case 'about':
		 	swfobject.embedSWF("anovaRadio/AIRInstallBadgeMedium_"+langCode+".swf", "anovaRadioObjectMedium", "300", "280", "9.0.115", "anovaRadio/expressinstall.swf",  flashvars2, parameters, attributes2);
		 break;
		case 'artists':
		 	swfobject.embedSWF("anovaRadio/AIRInstallBadgeMedium_"+langCode+".swf", "anovaRadioObjectMedium", "300", "280", "9.0.115", "anovaRadio/expressinstall.swf",  flashvars2, parameters, attributes2);
		 break;
		
		case 'artist':
			var attributes = {};
			attributes.id = "main-story";
			attributes.name = "mainstory";
			if ($('f3_param'))
				flashvars.whichArtist = "xml/artistMedia.php?artistUid=" + $('f3_param').value + "";
			swfobject.embedSWF("assets/mediaViewer.swf", "f3", "525", "465", "9.0.0", false, flashvars, params, attributes);
		break; 

		case 'studio':
			var attributes = {};
			attributes.id = "main-story";
			attributes.name = "mainstory";
			flashvars.whichArtist = "xml/studioMedia.php";
			swfobject.embedSWF("assets/mediaViewer.swf", "f3", "525", "465", "9.0.0", false, flashvars, params, attributes);
		break; 

		case 'press':
		 	 swfobject.embedSWF("anovaRadio/AIRInstallBadge_"+langCode+".swf", "anovaRadioObject", "525", "180", "9.0.115", "anovaRadio/expressinstall.swf",  flashvars2, parameters, attributes2);
			var attributes = {};
			var flashvars = {};
			var params = {};
			params.play = "true";
			params.menu = "true";
			params.quality = "best";
			params.scale = "noscale";
			params.wmode = "transparent";
			params.bgcolor = "#FFFFFF";
			params.allowscriptaccess = "always";
			params.allownetworking = "all";
			flashvars.whichArtist = "xml/pressKit.php";
			swfobject.embedSWF("assets/pressBar.swf", "f8", "525", "100", "9.0.28", false, flashvars, params, attributes);			
		break;
		 
		}
}

function newRelease(mp3Path, textToShow, imgToLoad) {
    if (mainPlayer && typeof mainPlayer.sendPathToSwf != "undefined") {
        mainPlayer.sendPathToSwf(mp3Path, textToShow, imgToLoad);
    }
}

/*
 * Enables/disables a document element
 * @param id the id of the element
 * @param endisable when this parameter is ommited the element visibility is negated
 */
function endisableElement(id, endisable) {
	var element = document.getElementById(id);
	if (element) {
		var visibility;
		if (endisable == true) 
			visibility = "block";
		else if (endisable == false)
			visibility = "none";
		else 
			visibility = (element.style.display == "block" ? "none" : "block");
			
		element.style.display = visibility;
	} else
		alert("Error: element with id '" + id + "' doesn't exist");
}

function signNewsletter() {
	var formData=$('mailingListForm');
	var params="";
	for (var i=0;i<formData.length;i++)
	{
		params += formData.elements[i].name + "=" + formData.elements[i].value + "&";
	} 
	 new Ajax.Updater('xmlContainer', 'newsletterSignin.php',
		{method: 'get', evalScripts: true, parameters: params
			});	
	return false;
}

