/* Sweet Titles (c) Creative Commons 2005  http://creativecommons.org/licenses/by-sa/2.5/
Author: Dustin Diaz | http://www.dustindiaz.com */
function addEvent( obj, type, fn ){
	if (obj.addEventListener) {
		obj.addEventListener( type, fn, false );
	} else if (obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	} else {
		obj["on"+type] = obj["e"+type+fn];
	}
}

function processEvent( e, prevent ){
	e = e || window.event;
	var el = e.target || e.srcElement;
	if(prevent){
		e.preventDefault();
		e.returnValue = false;
	}
	return el;
}

var sweetTitles = {
	xCord : 0,		// @Number: x pixel value of current cursor position
	yCord : 0,		// @Number: y pixel value of current cursor position
	obj : Object,	// @Element: That of which you're hovering over
	tip : Object,	// @Element: The actual toolTip itself
	active : 0,		// @Number: 0: Not Active || 1: Active
	init : function() {
		if( !document.getElementById ||
			!document.createElement ||
			!document.getElementsByTagName ) {
			return;
		}
		var i,j;
		this.tip = document.createElement('div');
		this.tip.id = 'toolTip';
		document.getElementsByTagName('body')[0].appendChild(this.tip);
		this.tip.style.top = '-20em';
		this.tip.style.visibility = 'hidden';
		var aElTips = document.getElementsByTagName("a");
		for( j=0; j<aElTips.length; j++ ) {
			if(aElTips[j].className=="tip"){
				addEvent(aElTips[j],'mouseover',this.tipOver);
				addEvent(aElTips[j],'mouseout',this.tipOut);
				aElTips[j].setAttribute('tip',aElTips[j].title);
				aElTips[j].removeAttribute('title');
			}
		}
	},
	updateXY : function(e) {
		if ( document.captureEvents ) {
			sweetTitles.xCord = e.pageX;
			sweetTitles.yCord = e.pageY;
		} else if ( window.event.clientX ) {
			sweetTitles.xCord = 
				window.event.clientX + 
				document.documentElement.scrollLeft + 
				document.body.scrollLeft;
			sweetTitles.yCord =
				window.event.clientY + 
				document.documentElement.scrollTop + 
				document.body.scrollTop;
		}
	},
	tipOut: function() {
		if( window.tID ){ clearTimeout(tID); }
		if( window.opacityID ){ clearTimeout(opacityID); }
		sweetTitles.tip.style.visibility = 'hidden';
		sweetTitles.tip.style.top = '-10em';
	},
	tipOver : function(e){
		sweetTitles.obj = this;
		tID = window.setTimeout("sweetTitles.tipShow()",200);
		sweetTitles.updateXY(e);
	},
	tipShow : function() {
		var scrX = Number(this.xCord);
		var scrY = Number(this.yCord);
		var tp = parseInt(scrY+15);
		var lt = parseInt(scrX+10);
		var anch = this.obj;
		//addy = (anch.href.length > 50 ? anch.href.toString().split("out.php?")[1].substring(0,50)+"..." : anch.href);
		this.tip.innerHTML = "<p>"+anch.getAttribute('tip')+"</p>";
		/* var docEl = document.documentElement ? document.documentElement : document.body;
		if ( parseInt(docEl.clientWidth + docEl.scrollLeft ) <
			 parseInt(this.tip.offsetWidth+lt)
		) {	*/
		if ( parseInt(document.body.clientWidth +
				document.body.scrollLeft
			 ) < parseInt(this.tip.offsetWidth+lt)
		) {
			if(this.tip.offsetWidth < lt){
				this.tip.style.left = parseInt(lt-(this.tip.offsetWidth+10))+'px';
			} else {
				this.tip.style.left = '10px';
			}
		} else {
			this.tip.style.left = lt+'px';
		}
		if ( parseInt(document.documentElement.clientHeight + 
				document.documentElement.scrollTop) < parseInt(this.tip.offsetHeight+tp)
		) {
			this.tip.style.top = parseInt(tp-(this.tip.offsetHeight+10))+'px';
		} else {
			this.tip.style.top = tp+'px';
		}
		this.tip.style.visibility = 'visible';
		this.tip.style.opacity = '.1';
		this.tipFade(10);
	},
	tipFade: function(opac) {
		var passed = parseInt(opac);
		var newOpac = parseInt(passed+10);
		if ( newOpac < 80 ) {
			this.tip.style.opacity = '.'+newOpac;
			this.tip.style.filter = "alpha(opacity:"+newOpac+")";
			opacityID = window.setTimeout("sweetTitles.tipFade('"+newOpac+"')",20);
		}
		else { 
			this.tip.style.opacity = '.80';
			this.tip.style.filter = "alpha(opacity:80)";
		}
	}
};


//  ALTTXT V1.2 BY BRIAN GOSSELIN OF SCRIPTASYLUM.COM
//  ADDED FADING EFFECT FOR IE4+ AND NS6+ ONLY AND OPTIMIZED THE CODE A BIT.
var center=false;     // CENTERS THE BOX UNER THE MOUSE, OTHERWISE DISPLAYS BOX TO THE RIGHT OF THE MOUSE

var NS4 = ( navigator.appName.indexOf("Netscape") >= 0 &&
			!document.getElementById) ? true : false;
var IE4 = (document.all && !document.getElementById) ? true : false;
var IE5 = (document.getElementById && document.all) ? true : false;
var NS6 = (document.getElementById && navigator.appName.indexOf("Netscape") >= 0 ) ? true: false;
var W3C = (document.getElementById) ? true : false;
var w_y, w_x, navtxt, boxheight=0, boxwidth=0;
var ishover=false;
var isloaded=false;
var op_id=0;

function getwindowdims(){
	w_y = (NS4||NS6) ? window.innerHeight : (IE5||IE4) ? document.body.clientHeight : 0;
	w_x = (NS4||NS6) ? window.innerWidth  : (IE5||IE4) ? document.body.clientWidth  : 0;
}

function getboxwidth(){
	if(NS4)boxwidth=(navtxt.document.width)? navtxt.document.width : navtxt.clip.width;
	else if(IE4)boxwidth=(navtxt.style.pixelWidth)? navtxt.style.pixelWidth : navtxt.offsetWidth;
	else boxwidth=(navtxt.style.width)? parseInt(navtxt.style.width) : parseInt(navtxt.offsetWidth);
}

function getboxheight(){
	if(NS4)boxheight=(navtxt.document.height) ? navtxt.document.height : navtxt.clip.height;
	else if(IE4)boxheight=(navtxt.style.pixelHeight)? navtxt.style.pixelHeight : navtxt.offsetHeight;
	else boxheight=parseInt(navtxt.offsetHeight);
}

function movenavtxt(x,y){
	if(NS4){ navtxt.moveTo(x,y-10); }
	if(W3C||IE4){
		navtxt.style.left=x+'px';
		navtxt.style.top=y+'px';
	}
}

function getpagescrolly(){
	if(NS4||NS6){ return window.pageYOffset; }
	if(IE5||IE4){ return document.body.scrollTop; }
}

function getpagescrollx(){
	if(NS4||NS6){ return window.pageXOffset; }
	if(IE5||IE4){ return document.body.scrollLeft; }
}

function writeindiv(text){
	if(NS4){
		navtxt.document.open();
		navtxt.document.write(text);
		navtxt.document.close();
	}
	if(W3C||IE4){ navtxt.innerHTML=text; }
}

function writetxt(text){
if(isloaded){
if(text!=0){
	ishover=true;
	if(NS4)text='<div class="navtext">'+text+'</div>';
	writeindiv(text);
} else {
	if(NS4)navtxt.visibility = "hide";
	if(IE4||W3C){
		navtxt.style.visibility = "hidden";
	}
	writeindiv('');
	ishover=false;
}
}}

function moveobj(evt){
if(isloaded && ishover){
	margin=(IE4||IE5)? 1 : 23;
	if(NS4){ 
		if(document.height-window.innerHeight<0){ margin=10; }
		mx=evt.pageX;
		my=evt.pageY;
		mx-=getpagescrollx();
		my-=getpagescrolly();
	} else if (NS6){
		if(document.height+27-window.innerHeight<0) margin=15;
		mx=evt.clientX;
		my=evt.clientY;
	} else if (IE5){
		mx=event.clientX;
		my=event.clientY;
	} else if (IE4){
		mx=0;
		my=0;
	}
	xoff = center ? mx-boxwidth/2 : mx+5;
	yoff = (my+boxheight+30-getpagescrolly()+margin>=w_y) ? -15-boxheight: 30;
	movenavtxt( Math.min( w_x-boxwidth-margin, Math.max(2,xoff) ) + getpagescrollx(),
			my+yoff+getpagescrolly() );
	if(W3C||IE4){ navtxt.style.visibility="visible"; }
	else if(NS4){ navtxt.visibility="show"; }
}
}


function altTxtInit(){
  navtxt = document.getElementById('navtxt');
  if(!navtxt) return false;
  getboxwidth();
  getboxheight();
  getwindowdims();
  isloaded=true;
  if(W3C){ navtxt.style.padding='0px'; }
  if(NS4){ document.captureEvents(Event.MOUSEMOVE); }
  document.onmousemove=moveobj;
  window.onresize=getwindowdims;
}

function newWin(pageName,pageWidth,pageHeight){
  var options = "status=no,menubar=no,resizable=no,scrollbars=no,location=no,width=" + pageWidth + ",height=" + pageHeight;
  options += ",top=" + Math.floor( (screen.height - pageHeight) / 2) + ",left=" + Math.floor( (screen.width - pageWidth) / 2);
  myWin = window.open(pageName,"_blank", options);
}

function initComments(){
	
	var pid = document.getElementById("cmt-pid");
	var subj = document.getElementById("cmt-subj");
	var bd = document.getElementById("cmt-body");
	var msg = document.getElementById("cmt-msg");
	var links = document.getElementById("comments").getElementsByTagName("a");
	
	var reply = function(e){
		var el = processEvent(e);
		var psubj = el.parentNode.parentNode.getElementsByTagName('h3')[0].innerHTML;
		pid.value = el.rel;
		subj.value = "RE: "+psubj;
		add_reset_msg(psubj)
		setTimeout(function(){bd.focus();},100);
	}
	
	for( var i=0,ct=links.length; i<ct; i++ ){
		if(links[i].className=="reply"){
			addEvent(links[i],'click',reply);
		}
	}	
	links = null;
	
	function reset_form(e){
		processEvent(e,true);
		msg.innerHTML = msg.className = subj.value = "";
		pid.value = "0";
		subj.focus();
	}
	
	function add_reset_msg(subj){
		msg.innerHTML = "<strong>Note:</strong> You're replying to a comment, you can also ";
		var a = document.createElement("a");
		a.href = "New: Thread";
		a.innerHTML = "start a new thread.";
		addEvent(a,'click',reset_form);
		msg.appendChild(a);
		msg.className = "msg";
		a = null;
	}

}

addEvent(window,'load',altTxtInit);
addEvent(window,'load',function(){ sweetTitles.init(); });
