// JavaScript Document

var count = 0;
var ajaxReturn = ''; 
var iframe;
var isLoaded = 0;
var ie7 = false;

function getWidget()
{
	var url = "http://www.expandomaha.com/events/mini/mini.php?plugin=true&source=" + escape(window.location.hostname) + "&" + window.location.search.substring(1);
	eo_get(url, 'eo_calendar');
}

function getEventDetails(id, x)
{
	
	var url = "http://www.expandomaha.com/events/mini/mini.php?plugin=true&source=" + escape(window.location.hostname) + "&eventID=" + id + 'date=' + x;
	eo_get(url, 'eo_calendar');
	return false;
}

function eo_get(url, id)
{
	var head = document.getElementsByTagName("head").item(0);
	var script = document.createElement("script");
	script.setAttribute("type", "text/javascript");
	script.setAttribute("src", url + '&eoID=' + id);
	head.appendChild(script);
	return ajaxReturn;
}

function lightBoxLoad()
{
	var documentBody = document.getElementsByTagName("body").item(0);
	
	var dim = document.createElement("div");
	dim.setAttribute("id", "eo_dim");
	documentBody.appendChild(dim);
	
	var lbClose = document.createElement("div");
	lbClose.setAttribute("id", "eo_close");
	lbClose.setAttribute("onclick", "closeLightBox();");
	documentBody.appendChild(lbClose);
	
	var lbBox = document.createElement("div");
	lbBox.setAttribute("id", "eo_lightbox");
	lbBox.setAttribute("onclick", "closeLightBox();");
	documentBody.appendChild(lbBox);
	
	iframe = document.createElement("iframe");
	iframe.setAttribute("src", "");
	iframe.setAttribute("id", "eoFrame");
	iframe.setAttribute("style", "display:none;");
	iframe.setAttribute("src", "http://www.expandomaha.com/events/submit/submit.php");
	document.getElementById('eo_lightbox').appendChild(iframe);
}

function getCSS()
{
	var header = document.getElementsByTagName("head").item(0);
	
	var ele = document.createElement("link");
	ele.setAttribute("rel", "stylesheet");
	ele.setAttribute("type", "text/css");
	ele.setAttribute("href", "http://www.expandomaha.com/events/css/v1/mini.css");
	header.appendChild(ele);
}


function openSubmitEvent()
{
	
	document.all.eoFrame.src = "http://www.expandomaha.com/events/submit/submit.php";
	document.getElementById('eoFrame').style.display = 'block';
	document.getElementById('eo_close').style.display = 'block';
	document.getElementById('eo_lightbox').style.display = 'block';
	document.getElementById('eo_dim').style.display = 'block';
	window.scrollTo(0,0);
	
	return false;
}

function openGetPlugin()
{
	
	
	document.all.eoFrame.src = "http://www.expandomaha.com/events/getPlugin.php";
	document.getElementById('eoFrame').style.display = 'block';
	document.getElementById('eo_close').style.display = 'block';
	document.getElementById('eo_lightbox').style.display = 'block';
	document.getElementById('eo_dim').style.display = 'block';
	window.scrollTo(0,0);
	
	return false;
}

function openFullCalendar()
{
	
	
	document.all.eoFrame.src = "http://www.expandomaha.com/events/mini/full.php";
	document.getElementById('eoFrame').style.display = 'block';
	document.getElementById('eo_close').style.display = 'block';
	document.getElementById('eo_lightbox').style.display = 'block';
	document.getElementById('eo_dim').style.display = 'block';
	window.scrollTo(0,0);
	
	return false;
}

function closeLightBox()
{
	document.getElementById('eoFrame').style.display = 'none';
	document.getElementById('eo_close').style.display = 'none';
	document.getElementById('eo_lightbox').style.display = 'none';
	document.getElementById('eo_dim').style.display = 'none';
}

function eoLoad()
{
	getCSS();
	setTimeout("getWidget()",600);
	setTimeout("lightBoxLoad()", 500);
}


if(!isLoaded)
{
	document.write('<div style="font-size:11px; font-weight:bold; text-align:right;"><a href="" onclick="openSubmitEvent(); return false;">Submit Event</a> | <a href="" onclick="openFullCalendar(); return false;">View Full Calendar</a></div>');
	document.write('<div id="eo_calendar">Loading...</div>');
	document.write('<div style="font-size:11px; font-weight:bold;"><a onclick="openGetPlugin(); return false;" href="">Put this calendar on your site.</a></div>');
	isLoaded = 1;
	eoLoad();
}
