window.onload = init;
// include("functions2.js"); // not necessary; it's included from the page head

function init() {
	linkPop();
	dynDiv();
	createBannerDiv();
	}

var bannerCurPos = 0;
// the banner div starts at zero
var bannerHeight = 100;
var bannerRange = (allBanners.length * (0 - bannerHeight)) - bannerHeight;
// how far does it have to drop? (with extra for repeated first image at end)
var bannerChangeInt = 6000;
// time for each banner display
var bannerNewPos;

function changeImage() {
	var div = document.getElementById("banners");
	var bannerChangeIntOp;
// this lets us avoid doubling the time for the repeat 1st image
	bannerCurPos = parseInt(div.style.top);
	bannerNewPos = bannerCurPos - bannerHeight;
	if (bannerNewPos > bannerRange) {	// if there's more room to scroll...
		bannerScroll();
		bannerChangeTimer = setTimeout("changeImage()", bannerChangeInt);
	} else {							// ... otherwise we've reached the end
		div.style.top = "0px";
		bannerCurPos = 0;
		changeImage();
	}
}

function createBannerDiv() {
	if (document.getElementById("show_ads")) {
// only if we want to show ads, that is
		var image = document.getElementById("show_ads");
		var bannerDiv = document.createElement("div");
		bannerDiv.setAttribute("id", "banners");
		bannerDiv.style.width = "500px";
		bannerDiv.onmouseover = pauseScroll;
		bannerDiv.onmouseout = resumeScroll;
		var bannerDivContent = "";
		for (c = 0; c < allBanners.length; c++) {
			bannerDivContent += '<a href="'+allBanners[c][2]+'" title="'+allBanners[c][0]+'"><img src="http://www.ebizq.net/web_images/ebizqinaction/banners/'+allBanners[c][1]+'" alt="'+allBanners[c][0]+' banner" /></a> ';
		}
// add the extra 1st image to the end for rollover
		bannerDivContent += '<a href="'+allBanners[0][2]+'" title="'+allBanners[0][0]+'"><img src="http://www.ebizq.net/web_images/ebizqinaction/banners/'+allBanners[0][1]+'" alt="'+allBanners[0][0]+' banner" /></a>';
		bannerDiv.innerHTML = bannerDivContent;
		image.appendChild(bannerDiv);
		bannerChangeTimer = setTimeout("changeImage()", bannerChangeInt);
	}
}

function bannerScroll() {
	var id = document.getElementById("banners");
	bannerCurPos-=10;
	id.style.top = bannerCurPos+"px";
	if (bannerCurPos > bannerNewPos) {
		bannerScrollTimer = setTimeout("bannerScroll()",40);
	} else {
		clearTimeout(bannerScrollTimer);
	}
}

function pauseScroll() {
	clearInterval(bannerChangeTimer);
}

function resumeScroll() {
	bannerChangeTimer = setTimeout("changeImage()", bannerChangeInt);
}




// creats the div used for the dynamic content
function dynDiv() {
	var sec = document.getElementById("toppage");
	var div=document.createElement("div");
	div.setAttribute("id","acontent")
	sec.appendChild(div);
	div.style.top = "20px";
	div.style.left = "200px";
//	changeOpac(0, "acontent");
}


// takes anything with the class popup and links it to events/calendar/<id>/text/
function linkPop () {
	var sec = document.getElementById("toppage");
	ids = document.getElementsByTagName("a");
	for (c=0; c<ids.length; c++) {
		if (ids[c].className.match("popup")) {
			ids[c].onclick = loadurl;
			ids[c].setAttribute("title", "View event details in a window");
		}
	}
}

// toggles the windows on the front page
function toggle(id) {
	var
	ids = new Array("d1","d2","d3","d4"),
	n = "";
	
	if (document.getElementById && document.createTextNode) {
		for (c=0;c<ids.length;c++) {
			if (id == ids[c]) {
				document.getElementById(id).className='on';
			} else {
				document.getElementById(ids[c]).className='off';
			}
		}
	}
	return;
}

// closes them
function toggleOff(id) {
	if (document.getElementById) {
		document.getElementById(id).className='off';
	}
	return false;
}


// resizes the floating windows by giving them class "flow"
function fwindowsize() {
	var idDiv = "big_panel";
	if (document.getElementById && document.createTextNode) {
		var n = document.getElementById(idDiv);
		if(n) {
			if (n.className == "tabs") {
				n.className='tabs flow';
			} else if (n.className == "tabs flow") {
				n.className='tabs';
			} else if (n.className == "tabs_") {
				n.className='tabs_ flow';
			} else if (n.className == "tabs_ flow") {
				n.className='tabs_';
			}
		}
	}
}


// creates tab-based floating window for any #big_panel
function tabsinit() {
	
	var ids = findTabs();
	if (ids.length > 1) {
		var panel = document.getElementById("big_panel")
		panel.className = "tabs";
		var tabBarText ="";
		for (c=0;c<ids.length;c++) {
			var thisId = ids[c];
			var tabTitle = "";
			if (thisId == "speakers") {
				tabTitle = "Speaker Bios";
			} else if (thisId == "register") {
				tabTitle = "Register to Attend";
			} else {
				tabTitle = thisId.replace("_"," ");
				tabTitle = uc(tabTitle);
			}
			tabBarText += '<a id="'+thisId+'_tab" class="tab_head" onclick="toggleTab(\''+thisId+'\')">'+tabTitle+'</a>';
		}
		tabBarText += '<a class="extra" onclick="fdeTab()">Show all content</a>'
		document.getElementById("tab_bar").innerHTML = tabBarText;
// this allows us to link to specific tabs
		var url = window.location.href;
		if ((a = url.indexOf('#')) > 0) {
			var loc = url.substring(a+1);
		}
// show one tab, hide the rest
		if (document.getElementById) {
			for (c=0;c<ids.length;c++) {
				document.getElementById(ids[c]).className='tab_page';
				var tabId = ids[c]+"_tab";
				var item=document.getElementById(ids[c]);
				if (item.className == "tab_page_") {
					item.className == "tab_page";
				}
				if (loc) {
					item.className += (ids[c]==loc) ? " shown" : " hidden";
					document.getElementById(tabId).className = (loc == ids[c]) ? "tab_head selected" : "tab_head unselected";
				} else {
					item.className += (c > 0) ? " hidden" : " shown";				document.getElementById(tabId).className = (c > 0) ? "tab_head unselected" : "tab_head selected";
				}
			}
		}
// create inter-tab links for those using ajah
	var links = panel.getElementsByTagName("a");
	var toggleTo = "";
		for (c=0;c<links.length;c++) {
			if (links[c].className.match("toggle_tab")) {
				links[c].onclick = toggleTab;
			}
		}
// not more than one tab, no need for tab bar
	} else {
		document.getElementById("big_panel").className = "tabs_";
	}
// moveable window
	var theHandle = document.getElementById("window_title");
	var theRoot   = document.getElementById("acontent");
	Drag.init(theHandle, theRoot);
}

// dynamically finds the tabs by looking for .tab_page
function findTabs(windowId) {
	var tabs = new Array();
	if (windowId) {
		windowId = document.getElementById(windowId);
	} else {
		windowId = document.getElementById("big_panel");
	}
	ids = windowId.getElementsByTagName("div");
	for (c=0;c<ids.length;c++) {
		if (ids[c].className.search("tab_page") > -1) {
			if (ids[c].getAttribute("id")) {
				tabs.push(ids[c].getAttribute("id"));
			}
		}
	}
	return tabs;
}

function toggleTab(id) {
	if (typeof(id) != 'string') {
		if ((a = this.href.indexOf('#')) > 0) {
			id = this.href.substring(a+1);
		} else {
			id = "information";
		}
	}
	if (document.getElementById("big_panel")) {
		var ids = findTabs();
		if (document.getElementById) {
			for (c=0;c<ids.length;c++) {
				var tabId = ids[c]+"_tab";
				if (id == ids[c]) {
					document.getElementById(id).className='tab_page shown';
					document.getElementById(tabId).className='tab_head selected';
				} else {
					document.getElementById(ids[c]).className='tab_page hidden';
					document.getElementById(tabId).className='tab_head unselected';
				}
					
			}
		}
	}
	return false;
}

function fdeTab() {
	var ids = findTabs();
	for (c=0;c<ids.length;c++) {
		document.getElementById(ids[c]).className='tab_page_';
	}
	document.getElementById("big_panel").className = "tabs_ flow";
	document.getElementById("tab_bar").innerHTML = '<a class="extra" onclick="freTab()">Show content in tabs</a>';
}

function freTab() {
	document.getElementById("big_panel").className = "tabs";
	tabsinit();
}


function loadurl(e) {
//	var targ;
//	if (!e) var e = window.event;
//	if (e.target) targ = e.target;
//	else if (e.srcElement) targ = e.srcElement;
//	if (targ.nodeType == 3) {
//		targ = targ.parentNode;
//	}
//	var dest = "/events/calendar/"+targ.getAttribute("id")+"/text/";
	var dest = "/events/calendar/"+this.getAttribute("id")+"/text/";
	
	try {
		xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");
	} catch (e) {
		return true;		// no ajax?
	}
	
	xmlhttp.onreadystatechange = triggered;
	xmlhttp.open("GET", dest, true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.send(null);
	return false;
}


function triggered() {
	if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {
		document.getElementById("acontent").innerHTML = xmlhttp.responseText;
		tabsinit();
	}
}

function windowclose() {
	document.getElementById("acontent").innerHTML = "";
}

function uc(str) {  // quick! from http://www.java2s.com/Code/JavaScript/Language-Basics/Stringutilitywordcountreplaceandcapitalize.htm
	var tempArray = str.split(' ');
	for (var i = 0; i < tempArray.length; i++) {
    	tempArray[i] = tempArray[i].charAt(0).toUpperCase() + tempArray[i].substring(1);
	}
	return tempArray.join(' ');
}


// ---------------------------------- //

/* drag code proved beyond my ability to write at this point, so: */

/**************************************************
 * dom-drag.js
 * 09.25.2001
 * www.youngpup.net
 **************************************************
 * 10.28.2001 - fixed minor bug where events
 * sometimes fired off the handle, not the root.
 **************************************************/

var Drag = {

	obj : null,

	init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
	{
		o.onmousedown	= Drag.start;

		o.hmode			= bSwapHorzRef ? false : true ;
		o.vmode			= bSwapVertRef ? false : true ;

		o.root = oRoot && oRoot != null ? oRoot : o ;

		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";

		o.minX	= typeof minX != 'undefined' ? minX : null;
		o.minY	= typeof minY != 'undefined' ? minY : null;
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;

		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;

		o.root.onDragStart	= new Function();
		o.root.onDragEnd	= new Function();
		o.root.onDrag		= new Function();
	},

	start : function(e)
	{
		var o = Drag.obj = this;
		e = Drag.fixE(e);
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		o.root.onDragStart(x, y);

		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;

		if (o.hmode) {
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
		}

		if (o.vmode) {
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
		}

		document.onmousemove	= Drag.drag;
		document.onmouseup		= Drag.end;

		return false;
	},

	drag : function(e)
	{
		e = Drag.fixE(e);
		var o = Drag.obj;

		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		var nx, ny;

		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

		if (o.xMapper)		nx = o.xMapper(y)
		else if (o.yMapper)	ny = o.yMapper(x)

		Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
		Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
		Drag.obj.lastMouseX	= ex;
		Drag.obj.lastMouseY	= ey;

		Drag.obj.root.onDrag(nx, ny);
		return false;
	},

	end : function()
	{
		document.onmousemove = null;
		document.onmouseup   = null;
		Drag.obj.root.onDragEnd(	parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), 
									parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
		Drag.obj = null;
	},

	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};

function include(jsFile) {
	document.write('<script type="text/javascript" src="' + jsFile + '"></scr' + 'ipt>'); 
}