// garuda.js

///alert('garuda.js');

var rollover = {

	ids : [], // array of iktem ID's, built during page construction
	prefixPath : 'abc', // to be set upon init
	imgs : {}, // holds src's keyed on <img ID> plus '_on' and '_off' suffixes
	
	// adds a button and its images to rollover scheme:
	//
	// usage in html page: 
	//   rollover.add( <elementID>, <imgPath for OFF image>, <imgPath for ON image>
	//
	set : function(id, imgA, imgB, idGlow) {
		this.ids[this.ids.length] = [ id, imgA, imgB, idGlow ];
	},
	
	// @preload
	//
	preload : function (imgSpec) {
		this.addImgSource( imgSpec[0] + '_off', imgSpec[1] );
		this.addImgSource( imgSpec[0] + '_on', imgSpec[2] );
		that = this;
		
		el = $( '#' + imgSpec[0] );
		el.bind( 'mouseover', { imgId : imgSpec[0], idGlow : imgSpec[3] }, function(event) {
			$(this).attr('src', that.imgs[ event.data.imgId + '_on'].src );
			if (event.data.idGlow != '') {
				$('#'+event.data.idGlow).show();
			}
		});
		el.bind( 'mouseout', { imgId : imgSpec[0], idGlow : imgSpec[3] }, function(event) {
			$(this).attr('src', that.imgs[ event.data.imgId + '_off'].src );
			if (event.data.idGlow != '') {
				$('#'+event.data.idGlow).hide();
			}
		});
	},

	// @addImgSource
	//
	addImgSource : function( sourceName, fileName) {
		imgPath = this.prefixPath + fileName;
		this.imgs[sourceName] = this.newImage(imgPath);
	},
	
	// @newImage
	//
	newImage : function( path ) {
		// TODO if path exists in current array/object/collection of images, then return that reference
		//else make a new one and add to collection
		
		var i = new Image();
		i.src = path;
		return i;
	}

}

umemail = [
1734439541,
1684105317,
1634494830,
1732278625,
1752133422,
1668246846,
1044266044,
1013408114,
1969512808,
1700883561,
1852260473,
1634234223,
778268525
];
function doEmLink(emarray,linkid) {
	setMailLink( emarray, linkid, 'xx'+linkid ); 
}


function setMailLink(erp, idPhlink, idLink) {
	var em = '';
	var tmp;
	for(i=0;i<erp.length;i++){
		tmp = erp[i];
		if(Math.floor((tmp/Math.pow(256,3)))>0){
			em += String.fromCharCode(Math.floor((tmp/Math.pow(256,3))));
		};
		tmp = tmp - (Math.floor((tmp/Math.pow(256,3))) * Math.pow(256,3));
		if(Math.floor((tmp/Math.pow(256,2)))>0){
			em += String.fromCharCode(Math.floor((tmp/Math.pow(256,2))));
		};
		tmp = tmp - (Math.floor((tmp/Math.pow(256,2))) * Math.pow(256,2));
		if(Math.floor((tmp/Math.pow(256,1)))>0){
			em += String.fromCharCode(Math.floor((tmp/Math.pow(256,1))));
		};
		tmp = tmp - (Math.floor((tmp/Math.pow(256,1))) * Math.pow(256,1));
		if(Math.floor((tmp/Math.pow(256,0)))>0){
			em += String.fromCharCode(Math.floor((tmp/Math.pow(256,0))));
		};
	};
	var tmp = new Array;
	tmp = em.split('>>><<<');
	em = tmp[0];
	var an = tmp[1];
	var nl = document.createElement('a');
	nl.setAttribute('id', idLink);
	nl.setAttribute('href', 'mailto:' + em);
	document.getElementById(idPhlink).appendChild(nl);
	document.getElementById(idLink).innerHTML = an;
}

$(document).ready( function () {
	for (i in rollover.ids) {
		//s += 'image to store: ' + YAHOO.roll.imgs[i][0] + '\n' + YAHOO.roll.imgs[i][1] + '\n' + YAHOO.roll.imgs[i][2] + '\n';
		rollover.preload( rollover.ids[i] );
	}
	doEmLink( umemail, 'ghemlink' );
});

