/* 
	##############################
	##
	##		name: xtags.js
	##		author: Ivar Abrahamsen
	##		copyright: flurdy @ eray
	##		date: 2005
	##		desc: 
	##			randomised tiny tags 
	##			at the bottom of the 
	##			screen.
	##
	##############################
*/
function TagMng(){
	this.add = tagAdd;
	this.render = tagRender;
	this.renderAll = tagRenderAll;
	this.renderOne = tagRenderOne;
	this.write = tagWrite;
	this.insert = tagInsert;
	this.start = tagStart;
	this.stop = tagStop;
	this.show = tagShow;
	this.close = tagClose;
	this.togleShow = tagTogleShow;	
	this.interval = 1000;
	this.lastTogle = new Date();
	this.intObj = false;
	this.src = "";
	this.tags = new Array();
	this.fade = tagFade;
	this.fadeTime=2500;
	this.fadeInt=false;
	this.fadeUse=true;
	this.moveAll = tagMoveAll;
	this.hideAll=tagHideAll;
	this.showAll=tagShowAll;
	this.findLeft=tagFindLeft;
	this.findTop=tagFindTop;
	this.onAll=tagOnAll;
}
function TagEnt( name, imgsrc, url, title ){
	this.name = name;
	this.img = new Image();
	if( imgsrc.substring(0,4) =="http" )
		this.img.src = imgsrc;
	else
		this.img.src = "http://www.ivar.co.uk/" + imgsrc;
	this.url = url;
	this.title = title;
}
function tagAdd( name, imgsrc, url, title ){
	if( title )
		this.tags.push( new TagEnt( name, imgsrc, url, title ) );
	else
		this.tags.push( new TagEnt( name, imgsrc, url, name ) );
}
function tagRender(){
	this.ran = Math.floor(Math.random()*this.tags.length);
	this.tag = this.tags[this.ran];
	this.src = this.renderOne(this.tag);
	return this.src;
}
function tagRenderAll(){
	this.src = "";
	for( this.i in this.tags ){
		this.src += this.renderOne(this.tags[this.i]);
	}
	return this.src;
}
function tagRenderOne(tag){
	this.osrc = '<a href="' + tag.url + '">';
	this.osrc += '<img align="right" src="' + tag.img.src; 
	this.osrc += '" alt="" title="' + tag.title + '" />';
	this.osrc += '</a>';
	return this.osrc;
}
function tagWrite(src){
	if(src)
		document.write(src);
	else
		document.write(this.src);
}
function tagInsert(src){
	if(src)
		document.getElementById("tagstrips").innerHTML = src;
	else 
		document.getElementById("tagstrips").innerHTML = this.render();
}
function tagStart(){
	this.intObj = window.setInterval("tags.insert()",this.interval);
}
function tagStop(){
	window.clearInterval(this.intObj);
}
function tagShow(){
	//this.togleShow();	
	this.showAll();
	this.stop();
}
function tagClose(varName){
	if( this.lastTogle > (new Date().getTime() - this.interval + 200 ) && this.shown)
		this.fade(varName);
	else
		this.hideAll();
	this.start();
}
function tagTogleShow(){
	if( this.lastTogle < (new Date().getTime() - this.interval + 200 )){
		if(this.shown){
			this.hideAll();
		}else {
			this.showAll();
		}
		this.lastTogle = new Date();
	}
}
function tagShowAll(){
	if(!this.shown)
		this.lastTogle = new Date();
	if( this.fadeInt )
		window.clearInterval(this.fadeInt);
	this.moveAll();
	document.getElementById("alltagstrips").style.visibility= "visible";	
	this.shown=true;
}
function tagHideAll(){
	if(this.shown)
		this.lastTogle = new Date();
	if( this.fadeInt )
		window.clearInterval(this.fadeInt);
	document.getElementById("alltagstrips").style.visibility= "hidden";	
	this.shown=false;
}
function tagFade(varName){
	this.fadeInt = window.setInterval(
		varName+".hideAll()",this.fadeTime);
}
function tagMoveAll(){
	document.getElementById("alltagstrips").style.left =this.findLeft();	
	document.getElementById("alltagstrips").style.top =this.findTop();	
}
function tagFindLeft(){
	elem= document.getElementById("tagstrips");	
	if (elem.calcLeft)
		return elem.calcLeft;
	else
		elem.calcLeft=0;
	var oElem=elem;
	while(elem){
		if ((elem.currentStyle)&& (!isNaN(parseInt(elem.currentStyle.borderLeftWidth)))&&(oElem.calcLeft!=0))
			oElem.calcLeft+=parseInt(elem.currentStyle.borderLeftWidth);
		 oElem.calcLeft+=elem.offsetLeft;
		 elem=elem.offsetParent;
	} 
	oElem.calcLeft -= 40;
	return oElem.calcLeft;
}
function tagFindTop(){
	elem= document.getElementById("tagstrips");	
	if (elem.calcTop)
		return elem.calcTop;
	else
		elem.calcTop=0;
	var oElem=elem;
	while(elem){
		if ((elem.currentStyle)&& (!isNaN(parseInt(elem.currentStyle.borderTopWidth)))&&(oElem.calcTop!=0))
			oElem.calcTop+=parseInt(elem.currentStyle.borderTopWidth);
		 oElem.calcTop+=elem.offsetTop;
		 elem=elem.offsetParent;
	} 
	for( this.i in this.tags ){
		oElem.calcTop-=this.tags[this.i].img.height;
	}
	return oElem.calcTop;
}
function tagOnAll(){

}
function tagOffAll(){

}





