/*
 * global loader
 */

var Loader = {
	initialized: 0,
	stack: [],
	/**
	 * push function on stack
	 */
	push: function(funct) {
		this.stack.push(funct);
	},

	/**
	 * execute functions stored in stack
	 */
	start: function() {
		if (this.initialized == 0) {
			for (var i=0; i<this.stack.length; i++) {
				this.stack[i]();
				this.stack[i] = null;
			}
			this.stack = [];
		}
		this.initialized += 1;
	}
}

var True = true;
var False = false;

function readMap() {
	var map, mapbg, i;
	mapbg = document.getElementById('ImgCountrySelect');
	if(mapbg) {
		//mapbg.src = "/images/spacer.gif";

		map = document.getElementsByTagName('area');
		if (document.getElementById('map-links')) {
			linkColor = document.getElementById('map-links').getElementsByTagName('a');
		};
		
		if (document.getElementById('MapCountry')) {
			linkColor = document.getElementById('MapCountry').getElementsByTagName('a');
		};

		for(i=0;i<map.length;i++) {
			map[i].onmouseover=function() { change(this); };
			map[i].onmouseout=function() { change(this); };
		}

		for(i=0;i<linkColor.length;i++) {
			linkColor[i].onmouseover=function() { change(this,1); };
			linkColor[i].onmouseout=function() { change(this,1); };
		}
	}
}

Loader.push(function(){ readMap(); });


function change(o,linked) {
	var mapbg, id;
	id = o.id;

	mapbg = document.getElementById('ImgCountrySelect');

	if (linked == 1) {
		id = 'map' + id.substring(4,8);
		if (id == 'map-cym') id = 'map-wal';
	}

	if(id == mapbg.className) {
		mapbg.className='map-off';
		document.getElementById('link' +id.substring(3,7)).style.color = "#6f6352";
		if (id == 'map-wal') document.getElementById('link-cym').style.color = "#6f6352";
	}
	else {
		mapbg.className=id;
		document.getElementById('link' +id.substring(3,7)).style.color = "#d9c90a";
		if (id == 'map-wal') document.getElementById('link-cym').style.color = "#d9c90a";
	}
}

function linklight(act) {
	var mapsw, id;
	
}


function flashActivation() {
	
}

// global onload function
var _init = function() {
    Loader.start();
    GoogleTagAttachments();
}

window.onload = function() {
    _init();
}

var state = 'block'; 

function showhide(layer_ref) { 

if (state == 'block') { 
state = 'none'; 
} 
else { 
state = 'block'; 
} 
if (document.all) { //IS IE 4 or 5 (or 6 beta) 
eval( "document.all." + layer_ref + ".style.display = state"); 
} 
if (document.layers) { //IS NETSCAPE 4 or below 
document.layers[layer_ref].display = state; 
} 
if (document.getElementById &&!document.all) { 
hza = document.getElementById(layer_ref); 
hza.style.display = state; 
} 
}


function GoogleTagAttachments() {
	var hrefs = document.getElementsByTagName("a");
	for (var l = 0; l < hrefs.length; l++) {
	    //protocol, host, hostname, port, pathname, search, hash
	    if ((hrefs[l].href.indexOf('media/attachments/') >= 0) && (!hrefs[l].onclick)) {
	        hrefs[l].onclick = function() { urchinTracker("/" + this.href.substring(this.href.indexOf('media/attachments/'))); }	
		   }
	}
}


function returnObjById(id) {
    if (document.getElementById)
        var returnVar = document.getElementById(id);
    else if (document.all)
        var returnVar = document.all[id];
    else if (document.layers)
        var returnVar = document.layers[id];
    return returnVar;
}

function trackclick(name, url, obj) {
    var objImage = returnObjById('clicktracker');
    if (objImage) {
        (new Image()).src = "trackclick.aspx?url=" + url + "&obj=" + obj + "&name=" + name + "&loc=" + document.location; 
    } 
    return true;
}


