﻿// -------------------------------------------------------------------
// JeffThink.com Interface Functions
// (1) getElementById Shortcut
// (2) hoverIcon/outIcon for top right toolbar
// (3) hoverButton/resetButtons for left circle nav
// (4) showWelcome for default right pane text
// -------------------------------------------------------------------

//if (document.location.href!="http://www.jeffthink.com/") document.location.href="http://www.jeffthink.com/";

function gei(id) {
	return document.getElementById(id);
}

function hoverIcon(txt,status) {
	try {
		window.clearTimeout(clientTimer);
	} catch (err) {}

	var obj = gei("toolbar");
	if (obj.style.visibility=="hidden") obj.style.visibility="visible";
	obj.innerHTML="&nbsp;"+txt+"&nbsp;";
	 
	var obj = gei("status");
	if (obj.style.visibility=="hidden") obj.style.visibility="visible";
	obj.innerHTML="&nbsp;"+status; 
	
	gei("tdtoolbar").style.backgroundColor="silver";
}

function outIcon() {	
	gei("toolbar").innerHTML="";gei("toolbar").style.visibility="hidden";
	gei("status").innerHTML="";gei("status").style.visibility="hidden";
	gei("tdtoolbar").style.backgroundColor="white";
}

/*
function hoverButton(imgObj) {
	resetButtons();
	var str = imgObj.src;
	var end = str.substr(str.length-6,str.length).replace("c","o");
	imgObj.src = "img/"+end;
	gei("rightPane").innerHTML = gei(end).innerHTML;
}
*/
function over(i) {
	try {
		window.clearTimeout(clientTimer);
	} catch (err) {}
	
	for (var j=0; j<8; j++) {
		if (j != i) gei('nav'+j).src="img/nav/b_"+j+".jpg";
	}
	gei('nav'+i).src="img/nav/o_"+i+".jpg";
	if (i == 0 || i == 6) gei('nav'+(i+1)).src="img/nav/o_"+(i+1)+".jpg";
	
	if (i == 0) gei("rightPane").innerHTML = gei("o1.png").innerHTML;
	if (i == 2) gei("rightPane").innerHTML = gei("o4.png").innerHTML;
	if (i == 3) gei("rightPane").innerHTML = gei("o2.png").innerHTML;
	if (i == 4) gei("rightPane").innerHTML = gei("o3.png").innerHTML;
	if (i == 5) gei("rightPane").innerHTML = gei("o5.png").innerHTML;
	if (i == 6) gei("rightPane").innerHTML = gei("o6.png").innerHTML;				

//	if (i == 2) clientTimer=window.setTimeout("clientTimerTick()",clientTimerMS);
}

//var clientTimer=null;
//var clientTimerCount=0;
//var clientTimerMS=2200;
//var clients=new Array();
//clients[0]="30-60-90";
//clients[1]="cthelper";
//clients[2]="services";


//function clientTimerTick() {
//	gei("rightPane").innerHTML = "<center><img src=\"/img/client/"+clients[clientTimerCount]+".png\" /></center>";
//	clientTimerCount++;
//	if (clientTimerCount>clients.length-1) clientTimerCount=0;
//	clientTimer=window.setTimeout("clientTimerTick()",clientTimerMS);
//}

function resetButtons() {
	try {
		for (i=1; i<=6; i++) {
			gei("c"+i).src = "img/c"+i+".png";
		}
		for (i=0; i<=9; i++) {
			var obj = gei("exp_"+i);
			if (obj != null) obj.parentNode.removeChild(obj);
		}
	} catch(err) {}
}

function showWelcome() {
	gei("rightPane").innerHTML = gei("divWelcome").innerHTML;
	resetButtons();
	outIcon();
}

// -------------------------------------------------------------------
// Preload images
// http://articles.techrepublic.com.com/5100-22-5214317.html
// -------------------------------------------------------------------
function preload() {
	preloader("img/o1.png");
	preloader("img/o2.png");
	preloader("img/o3.png");
	preloader("img/o4.png");
	preloader("img/o5.png");
	preloader("img/o6.png");	
}

function preloader(src) {
	heavyImage = new Image(); 
	heavyImage.src = src;
}

// -------------------------------------------------------------------
// Get, cache, and output contents of a RSS XML file
// Author: George at JavaScriptKit.com/ DynamicDrive.com
// Created: Feb 1st, 2006. Updated: Feb 1st, 2006
// -------------------------------------------------------------------
function createAjaxObj(){
	var httprequest=false
	if (window.XMLHttpRequest){ // if Mozilla, Safari etc
	httprequest=new XMLHttpRequest()
	if (httprequest.overrideMimeType)
	httprequest.overrideMimeType('text/xml')
	}
	else if (window.ActiveXObject){ // if IE
	try {
	httprequest=new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch (e){
	try{
	httprequest=new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch (e){}
	}
	}
	return httprequest
}

function ajaxshowme(){
	ajaxinstance=createAjaxObj()
	xmlindicator=(arguments.length>0)? 1 : 0
	ajaxinstance.onreadystatechange=alertcontents
	ajaxinstance.open('GET', "http://www.jeffthink.com/google_broadcast.xml", true)
	ajaxinstance.send(null)
}

function alertcontents(){
	if (ajaxinstance.readyState == 4){ //if request of file completed
	if (ajaxinstance.status==200){ //if request was successful
	if (xmlindicator)
	alert(ajaxinstance.responseXML)
	else
	alert(ajaxinstance.responseText)
	}
	}
}

// -------------------------------------------------------------------
// Main RSS Ticker Object function
// rss_ticker(RSS_id, cachetime, divId, divClass, delay, optionalswitch)
// -------------------------------------------------------------------
function rss_ticker(RSS_id, cachetime, divId, divClass, delay, optionalswitch){
	this.RSS_id=RSS_id //Array key indicating which RSS feed to display
	this.cachetime=cachetime //Time to cache feed, in minutes. 0=no cache.
	this.tickerid=divId //ID of ticker div to display information
	this.delay=delay //Delay between msg change, in miliseconds.
	this.logicswitch=(typeof optionalswitch!="undefined")? optionalswitch : -1
	this.mouseoverBol=0 //Boolean to indicate whether mouse is currently over ticker (and pause it if it is)
	this.pointer=0
	this.ajaxobj=createAjaxObj()
	document.write('<div id="'+divId+'" class="'+divClass+'">Initializing ticker...</div>')
	this.getAjaxcontent()
}

// -------------------------------------------------------------------
// getAjaxcontent()- Makes asynchronous GET request to "rssfetch.php" with the supplied parameters
// -------------------------------------------------------------------
rss_ticker.prototype.getAjaxcontent=function(){
	if (this.ajaxobj){
	var instanceOfTicker=this
	this.ajaxobj.onreadystatechange=function(){instanceOfTicker.initialize()}
	this.ajaxobj.open('GET', "http://www.jeffthink.com/google_broadcast.xml", true)
	this.ajaxobj.send(null)
	}
}

// -------------------------------------------------------------------
// initialize()- Initialize ticker method. Gets contents of RSS content and parse it using JavaScript DOM methods
// -------------------------------------------------------------------
rss_ticker.prototype.initialize=function(){
	if (this.ajaxobj.readyState == 4){ //if request of file completed
	if (this.ajaxobj.status==200){ //if request was successful
	var xmldata=this.ajaxobj.responseXML
	if (xmldata.getElementsByTagName("entry").length==0){ //if no <item> elements found in returned content
//	document.getElementById(this.tickerid).innerHTML="<b>Error</b> fetching remote RSS feed<br />"+this.ajaxobj.responseText
	document.getElementById(this.tickerid).innerHTML=""
	document.getElementById(this.tickerid).className=""
	return
}
var instanceOfTicker=this;
this.feeditems=xmldata.getElementsByTagName("entry");
//Cycle through RSS XML object and store each piece of the item element as an attribute of the element
for (var i=0; i<this.feeditems.length; i++){
	this.feeditems[i].setAttribute("ctitle", this.feeditems[i].getElementsByTagName("title")[0].firstChild.nodeValue)
	this.feeditems[i].setAttribute("clink", this.feeditems[i].getElementsByTagName("link")[0].getAttribute("href"))
	var temppubDate = this.feeditems[i].getElementsByTagName("published")[0].firstChild.nodeValue;
	this.feeditems[i].setAttribute("cpubDate", temppubDate.substr(0,10))
	
	}
	document.getElementById(this.tickerid).onmouseover=function(){instanceOfTicker.mouseoverBol=1}
	document.getElementById(this.tickerid).onmouseout=function(){instanceOfTicker.mouseoverBol=0}
	this.rotatemsg()
	}
	}
}

// -------------------------------------------------------------------
// rotatemsg()- Rotate through RSS messages and displays them
// -------------------------------------------------------------------
rss_ticker.prototype.rotatemsg=function(){
	var instanceOfTicker=this
	if (this.mouseoverBol==1) //if mouse is currently over ticker, do nothing (pause it)
	setTimeout(function(){instanceOfTicker.rotatemsg()}, 100)
	else{
	var tickerDiv=document.getElementById(this.tickerid)
	var tickercontent='&nbsp;Google Reader shared :&nbsp;&nbsp;&nbsp;<a href="'+this.feeditems[this.pointer].getAttribute("clink")+'">'+this.feeditems[this.pointer].getAttribute("ctitle")+'</a>'
	if (this.logicswitch=="showdescription")
	tickercontent+="<br />"+this.feeditems[this.pointer].getAttribute("cdescription")
	if (this.logicswitch=="showpubDate")
	tickercontent+="&nbsp;&nbsp;("+this.feeditems[this.pointer].getAttribute("cpubDate")+")"
	tickerDiv.innerHTML=tickercontent
	this.pointer=(this.pointer<this.feeditems.length-1)? this.pointer+1 : 0
	setTimeout(function(){instanceOfTicker.rotatemsg()}, this.delay) //update container every second
	}
}

// -------------------------------------------------------------------
// The JavaScript ticker object is invoked on the page as follows:
// rss_ticker(RSS_id, cachetime, divId, divClass, delay, optionalswitch)
// (1) RSS_id: "Array key of RSS feed in PHP script"
// (2) cachetime: Time to cache the feed in minutes (0 for no cache)
// (3) divId: "ID of DIV to display ticker in. DIV id dynamically created"
// (4) divClass: "Class name of this ticker, for styling purposes"
// (5) delay: delay between message change, in miliseconds
// (6) optionalswitch: "optional arbitrary" string to create additional logic in call back function
// -------------------------------------------------------------------
