// If you want the quotebox to be hidden until the user scrolls the
// page down past a certain element, then set this variable to the
// id of that element.  Otherwise set it to null ('').
//
var element_below_which_quotebox_will_be_displayed = 'sidebar';

var quotebox_display_time = 9000; // in milliseconds.


// Don't change these a, b, and c variables until after you've got
// the quotebox working properly.
//
var a = '<div class="quote">';
var b = '</div><div class="author">&#8211; ';
var c = '</div>';


// You can specify different quotes for different pages on your site,
// or just delete these if/else lines leaving only the quotes.push()
// lines -- then all your quotes will be the same on all pages of your
// site.
//
var quotes = new Array;
if(location.pathname == '/product_X/')
{
	quotes.push(a + "Product X is great!" + b + "John Doe" + c);
	quotes.push(a + "Product X is the best." + b + "Jack Jones" + c);
}
else if(location.pathname == '/product_Y/')
{
	quotes.push(a + "We love Product Y." + b + "Jane Smith" + c);
	quotes.push(a + "Product Y for President!" + b + "Sue Johnson" + c);
}
else
{
	quotes.push(a + "OnSched solved our shift scheduling and staffing problems. Great Support Team also!" + b + "Jesse Salen (VP Sales and Technology) Online Radiology" + c);
	quotes.push(a + "Running a staff placement agency lends challenges with employee scheduling and staffing. OnSched was the reliable and low cost solution we were looking for.  " + b + "Alonzo G. Lively (CEO) KapAlon Technologies" + c);
	quotes.push(a + "My DCA software is good to go. It works, and I don.t require any further assistance at this time. Thanks again for all your help and excellent support." + b + "Robert Miller (Loblaw.ca)" + c);
	quotes.push(a + "My Office Manager purchased DCA today. Success yeah!! Thanks for the support!" + b + "Jason Moore (Network Engineer) Clear Channel Communications" + c);
	quotes.push(a + "DCA is working for us. Thank you very much." + b + "Bopitt Chianok (hutch.co.th)" + c);
	quotes.push(a + "[DCA] affords me a manageable way to maintain lab equipment when I'm setting up test environments for various projects. I like that and I can't wait to see what you guys come up with next." + b + "Kyle Chrisman (Manager) Global Net Access" + c);
}


//
// You probably don't need to change anything below here.
//

var curquote = -1;

function findPos(obj)
{
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent)
		{
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function topOfElement(eID)
{
	var i = findPos(document.getElementById(eID));
	return i[1];
}

function position_quotebox()
{
	if(document.body)
	{
		var disp = '';
		if(navigator.userAgent.indexOf("MSIE 5") > -1 || navigator.userAgent.indexOf("MSIE 6") > -1)
		{
			// IE <7 don't support position:fixed.
			disp = 'block';
		}
		else
		{
			var scrollpos = window.pageYOffset ? window.pageYOffset : document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
			if(element_below_which_quotebox_will_be_displayed != ''   &&   document.getElementById(element_below_which_quotebox_will_be_displayed)   &&   scrollpos < topOfElement(element_below_which_quotebox_will_be_displayed))
			{
				disp = 'none';
			}
			else
			{
				disp = 'block';
			}
		}
		document.getElementById("quotebox").style.display = disp;
	}
}

function init_quotebox()
{
	display_quote();
	position_quotebox();
	setInterval("rotate_quotebox()", quotebox_display_time);
}

function rotate_quotebox()
{
	if(document.getElementById("quotebox").style.display == 'none')
		return;
	for(i=90; i>=0; i-=10)
	{
		var delay = (100 - i) * 10;
		setTimeout("set_opacity('quotebox'," + i + ")", delay);
	}
	setTimeout("display_quote()", 1050);
	setTimeout("set_opacity('quotebox',100)", 1060);
}

function display_quote()
{
	curquote++;
	if(curquote >= quotes.length) { curquote = 0; }
	document.getElementById("quotebox-inner").innerHTML = quotes[curquote];
}

function set_opacity(eID,opVal)
{
	var newvalue = opVal == 100 ? opVal : '.' + opVal;
	document.getElementById(eID).style.opacity = newvalue;
}


function schedule_onload_action(newfunc)
{
	var already_scheduled = window.onload;
	if(typeof window.onload != 'function')
	{
		window.onload = newfunc;
	}
	else
	{
		window.onload = function()
		{
			already_scheduled();
			newfunc();
		}
	}
}

function schedule_onresize_action(newfunc)
{
	var already_scheduled = window.onresize;
	if(typeof window.onresize != 'function')
	{
		window.onresize = newfunc;
	}
	else
	{
		window.onresize = function()
		{
			already_scheduled();
			newfunc();
		}
	}
}

function schedule_onscroll_action(newfunc)
{
	var already_scheduled = window.onscroll;
	if(typeof window.onscroll != 'function')
	{
		window.onscroll = newfunc;
	}
	else
	{
		window.onscroll = function()
		{
			already_scheduled();
			newfunc();
		}
	}
}

schedule_onload_action(init_quotebox);
schedule_onresize_action(position_quotebox);
schedule_onscroll_action(position_quotebox);

