function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}
addLoadEvent(makeNiceTitles);
var XHTMLNS = "http://www.w3.org/1999/xhtml";
var CURRENT_NICE_TITLE;
var browser = new Browser();
function makeNiceTitles() {
    if (!document.createElement || !document.getElementsByTagName) return;
    if(!document.createElementNS)
    {document.createElementNS = function(ns,elt) {return document.createElement(elt);}}
    if( !document.links ){document.links = document.getElementsByTagName("a");}
    for (var ti=0;ti<document.links.length;ti++) {
        var lnk = document.links[ti];
        if (lnk.title) {
            lnk.setAttribute("nicetitle",lnk.title);
            lnk.removeAttribute("title");
            addEvent(lnk,"mouseover",showNiceTitle);
            addEvent(lnk,"mouseout",hideNiceTitle);
            addEvent(lnk,"focus",showNiceTitle);
            addEvent(lnk,"blur",hideNiceTitle);}}
    var instags = document.getElementsByTagName("ins");
    if (instags) {
    for (var ti=0;ti<instags.length;ti++) {
        var instag = instags[ti];
        if (instag.dateTime) {
            var strDate = instag.dateTime;
            var dtIns = new Date(strDate.substring(0,4),parseInt(strDate.substring(4,6)-1),strDate.substring(6,8),strDate.substring(9,11),strDate.substring(11,13),strDate.substring(13,15));
            instag.setAttribute("nicetitle","Added on "+dtIns.toString());
            addEvent(instag,"mouseover",showNiceTitle);
            addEvent(instag,"mouseout",hideNiceTitle);
            addEvent(instag,"focus",showNiceTitle);
            addEvent(instag,"blur",hideNiceTitle);}}}}
function findPosition( oLink ) {
  if( oLink.offsetParent ) {
    for( var posX = 0, posY = 0; oLink.offsetParent; oLink = oLink.offsetParent ) {
      posX += oLink.offsetLeft;
      posY += oLink.offsetTop;}
    return [ posX, posY ];} else {return [ oLink.x, oLink.y ];}}
function showNiceTitle(e) {
    if (CURRENT_NICE_TITLE) hideNiceTitle(CURRENT_NICE_TITLE);
    if (!document.getElementsByTagName) return;
    if (window.event && window.event.srcElement) {lnk = window.event.srcElement} else if (e && e.target) {lnk = e.target}
    if (!lnk) return;
    if (lnk.nodeName.toUpperCase() != 'A') {lnk = getParent(lnk,"A");}
    if (!lnk) return;nicetitle = lnk.getAttribute("nicetitle");    
    var d = document.createElementNS(XHTMLNS,"div");
    d.className = "nicetitle";
    tnt = document.createTextNode(nicetitle);
    pat = document.createElementNS(XHTMLNS,"p");
    pat.className = "titletext";
    pat.appendChild(tnt);
    d.appendChild(pat);
    if (lnk.href) {
        tnd = document.createTextNode(lnk.href);
        pad = document.createElementNS(XHTMLNS,"p");
        pad.className = "destination";
        pad.appendChild(tnd);
        d.appendChild(pad);}
    STD_WIDTH = 300;
    if (lnk.href) {h = lnk.href.length;} else { h = nicetitle.length; }if (nicetitle.length) {t = nicetitle.length;}
    h_pixels = h*6; t_pixels = t*10;
     if (h_pixels > STD_WIDTH) {w = h_pixels;} else if ((STD_WIDTH>t_pixels) && (t_pixels>h_pixels)) {w = t_pixels;} else if ((STD_WIDTH>t_pixels) && (h_pixels>t_pixels)) {w = h_pixels;} else {w = STD_WIDTH;}
    d.style.width = w + 'px';    
    mpos = findPosition(lnk);
    mx = mpos[0];
    my = mpos[1];
    d.style.left = (mx+15) + 'px';
    d.style.top = (my+35) + 'px';
    if (window.innerWidth && ((mx+w) > window.innerWidth)) {d.style.left = (window.innerWidth - w - 25) + "px";}
    if (document.body.scrollWidth && ((mx+w) > document.body.scrollWidth)) {d.style.left = (document.body.scrollWidth - w - 25) + "px";}
    document.getElementsByTagName("body")[0].appendChild(d);
    CURRENT_NICE_TITLE = d;}
function hideNiceTitle(e) {if (!document.getElementsByTagName) return;if (CURRENT_NICE_TITLE) {document.getElementsByTagName("body")[0].removeChild(CURRENT_NICE_TITLE);CURRENT_NICE_TITLE = null;}}
function addEvent(obj, evType, fn){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, false);
    return true;} else if (obj.attachEvent){var r = obj.attachEvent("on"+evType, fn);
    return r;} else {return false;}}
function getParent(el, pTagName) {
	if (el == null) return null;
	else if (el.nodeType == 1 && el.tagName.toLowerCase() == pTagName.toLowerCase())
		return el;
	else
		return getParent(el.parentNode, pTagName);}
function getMousePosition(event) {
  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;  }
  return [x,y];}
function Browser() {
  var ua, s, i;
  this.isIE    = false;
  this.isNS    = false;
  this.version = null;
  ua = navigator.userAgent;
  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;  }
  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;  }
   s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;}}

//** Tab Content script v2.0- © Dynamic Drive DHTML code library (http://www.dynamicdrive.com)

function ddtabcontent(tabinterfaceid){
    this.tabinterfaceid=tabinterfaceid 
	this.tabs=document.getElementById(tabinterfaceid).getElementsByTagName("a") 
	this.enabletabpersistence=true
	this.hottabspositions=[] 
	this.currentTabIndex=0 
	this.subcontentids=[] 
	this.revcontentids=[] 
	this.selectedClassTarget="link" }
ddtabcontent.getCookie=function(Name){ 
	var re=new RegExp(Name+"=[^;]+", "i"); 
	if (document.cookie.match(re))
		return document.cookie.match(re)[0].split("=")[1] 
	return ""}
ddtabcontent.setCookie=function(name, value){document.cookie = name+"="+value+";path=/" }
ddtabcontent.prototype={
	expandit:function(tabid_or_position){ 
		this.cancelautorun() 
		var tabref=""
		try{
			if (typeof tabid_or_position=="string" && document.getElementById(tabid_or_position).getAttribute("rel")) 
				tabref=document.getElementById(tabid_or_position)
			else if (parseInt(tabid_or_position)!=NaN && this.tabs[tabid_or_position].getAttribute("rel")) 
				tabref=this.tabs[tabid_or_position]	}
		catch(err){alert("Invalid Tab ID or position entered!")}
		if (tabref!="") 
			this.expandtab(tabref) },
	cycleit:function(dir, autorun){ 
		if (dir=="next"){
			var currentTabIndex=(this.currentTabIndex<this.hottabspositions.length-1)? this.currentTabIndex+1 : 0}
		else if (dir=="prev"){var currentTabIndex=(this.currentTabIndex>0)? this.currentTabIndex-1 : this.hottabspositions.length-1}
		if (typeof autorun=="undefined") 
			this.cancelautorun() 
		this.expandtab(this.tabs[this.hottabspositions[currentTabIndex]])},
	setpersist:function(bool){this.enabletabpersistence=bool},
	setselectedClassTarget:function(objstr){this.selectedClassTarget=objstr || "link"},
	getselectedClassTarget:function(tabref){return (this.selectedClassTarget==("linkparent".toLowerCase()))? tabref.parentNode : tabref},
	urlparamselect:function(tabinterfaceid){
		var result=window.location.search.match(new RegExp(tabinterfaceid+"=(\\d+)", "i")) 
		return (result==null)? null : parseInt(RegExp.$1)},
	expandtab:function(tabref){
		var subcontentid=tabref.getAttribute("rel") 
		var associatedrevids=(tabref.getAttribute("rev"))? ","+tabref.getAttribute("rev").replace(/\s+/, "")+"," : ""
		this.expandsubcontent(subcontentid)
		this.expandrevcontent(associatedrevids)
		for (var i=0; i<this.tabs.length; i++){ 
			this.getselectedClassTarget(this.tabs[i]).className=(this.tabs[i].getAttribute("rel")==subcontentid)? "selected" : ""}
		if (this.enabletabpersistence) 
			ddtabcontent.setCookie(this.tabinterfaceid, tabref.tabposition)
		this.setcurrenttabindex(tabref.tabposition)},
	expandsubcontent:function(subcontentid){
		for (var i=0; i<this.subcontentids.length; i++){
			var subcontent=document.getElementById(this.subcontentids[i]) 
			subcontent.style.display=(subcontent.id==subcontentid)? "block" : "none" }},
	expandrevcontent:function(associatedrevids){
		var allrevids=this.revcontentids
		for (var i=0; i<allrevids.length; i++){ 
			document.getElementById(allrevids[i]).style.display=(associatedrevids.indexOf(","+allrevids[i]+",")!=-1)? "block" : "none"}},
	setcurrenttabindex:function(tabposition){ 
		for (var i=0; i<this.hottabspositions.length; i++){
			if (tabposition==this.hottabspositions[i]){
				this.currentTabIndex=i
				break}}},
	autorun:function(){this.cycleit('next', true)},
	cancelautorun:function(){
	if (typeof this.autoruntimer!="undefined")
			clearInterval(this.autoruntimer)},
	init:function(automodeperiod){
		var persistedtab=ddtabcontent.getCookie(this.tabinterfaceid) 
		var selectedtab=-1
		var selectedtabfromurl=this.urlparamselect(this.tabinterfaceid) 
		this.automodeperiod=automodeperiod || 0
		for (var i=0; i<this.tabs.length; i++){
			this.tabs[i].tabposition=i 
			if (this.tabs[i].getAttribute("rel")){
				var tabinstance=this
				this.hottabspositions[this.hottabspositions.length]=i 
				this.subcontentids[this.subcontentids.length]=this.tabs[i].getAttribute("rel") 
				this.tabs[i].onclick=function(){
					tabinstance.expandtab(this)
					tabinstance.cancelautorun() 
					return false}
				if (this.tabs[i].getAttribute("rev")){this.revcontentids=this.revcontentids.concat(this.tabs[i].getAttribute("rev").split(/\s*,\s*/))}
				if (selectedtabfromurl==i || this.enabletabpersistence && selectedtab==-1 && parseInt(persistedtab)==i || !this.enabletabpersistence && selectedtab==-1 && this.getselectedClassTarget(this.tabs[i]).className=="selected"){
					selectedtab=i}}} 
		if (selectedtab!=-1) 
			this.expandtab(this.tabs[selectedtab])
		else 
			this.expandtab(this.tabs[this.hottabspositions[0]]) 
		if (parseInt(this.automodeperiod)>500 && this.hottabspositions.length>1){this.autoruntimer=setInterval(function(){tabinstance.autorun()}, this.automodeperiod)}}}
