//Author: Toby Travis
//Project: The Long Way Down
//Date: 29 March 2007

/*
name: addUnloadEvent()
description: Calls functions on body.unload
params: function to call
returns: none
*/
function addUnloadEvent(func){
	var oldonunload = window.unonload;
	if(typeof window.unonload != 'function'){
		window.unonload = func;
	}else{
		window.unonload = function(){
			oldonunload();
			func();
		}
	}
}

/*
name: mapUnload()
description: Unloads Google Map from memory
params: none
returns: none
*/
function mapUnload(){
	GUnload();
}

/*
name: String.prototype.supplant
description: Replaces {} variables in templates with object values
params: o
returns: formatted string
*/
String.prototype.supplant = function (o) { 
    return this.replace(/{([^{}]*)}/g,
        function (a, b) {  
            var r = o[b];
            return typeof r === 'string' ? 
                r : a; 
        }
    ); 
};

/*
name: initPanels
description: used to show/hide content of panels e.g. RSS, Latest Logs.
applies behaviour to all elements in document with a className of "panel" 
params: none
returns: none
*/
function initPanels(){
	if(!document.getElementById) return false;
	if(!document.getElementsByTagName) return false;
	var divs = document.getElementsByTagName("div");
	for(var i=0; i<divs.length; i++){
		if(divs[i].className == "panel"){
			var panelheader = divs[i].getElementsByTagName("h3");
			var panelcontent = panelheader[0].nextSibling;
			panelheader[0].visible = "true";
			while(panelcontent.nodeType!==1){
				panelcontent = panelcontent.nextSibling;
			}
			panelheader[0].content = panelcontent;
			panelheader[0].onclick = function(){
				if(this.visible === "false"){
					this.content.style.display = "block";
					this.visible = "true";
				}
				else{
					this.content.style.display = "none";
					this.visible = "false";
				}
			}
		}
	}		
}

function prepareRollOvers(){
	var imagepath = "/longwaydown/images/interface/buttons/";
	bbcjs.images.rolls["view_route_button"] = imagepath + "view_route_over.jpg";
	bbcjs.images.rolls["view_the_route_button"] = imagepath + "view_the_route_over.jpg";
	bbcjs.images.rolls["view_location_button"] = imagepath + "view_the_location_over.jpg";
	bbcjs.images.rollPrep();
}


var mediaSelector = new bbcjs.win.Window("",409,269);
mediaSelector.name = "avaccesswin";
mediaSelector.features.top = 50;
mediaSelector.features.left = 50;
mediaSelector.features.scrollbars = "yes";
mediaSelector.features.menubar = "no";
mediaSelector.features.location = "no";
