//Main Java Script for site
//Andrew Stickney 2008
//Feel free to use any of this code

//These next variables are for directories
var binDir = 'binary/';
var ssDir = 'images/screenshots/';
var tnDir = 'images/thumbnails/';

//These are just a simple initialization of download windows, which are used on several pages
var dlCount = 0;	//counter
var dlItem = new Array();	//initial array

//Side Bar Navigation menu, I put this here, so if I need to add or delete, I only have to do it once
var linkSide = new Array(5,		//number of links
	new Array('Games', 'games.html'),
	new Array('Developers', 'developer.html'),
	new Array('Projects', 'project.html'),
	new Array('The Gemini Project', 'gemini.html')
);

function writeMenu(activeLink)	{	//Function inserts menu into side bar, after window is created
	var index;
	for(index=1; index<=linkSide[0]; index++) {
		//check for active, and create accordingly
		if(index==activeLink) {
			document.write('<div class="nav_linkActive">' + linkSide[index][0] + '</div>');
		}
		else {	//isn't active, treat as link
			document.write('<a class="nav_link" href="' + linkSide[index][1] + '">' + linkSide[index][0] + '</a>');
		}
	}
}

//Top Menu Navigation
var linkTop = new Array(5, //Number of Links
	new Array('Home','index.html'),
	new Array('News','news.html'),
	new Array('Contact','contact.html'),
	new Array('Links','links.html'),
	new Array('Forum','http://dabooda.org/dabooda_village/index.php')
);

function writeTopMenu(title, active)
{
	document.write('<div id="title_bar"><div id="title_bar_caption">' + title + '</div>');
	var index;
	for(index=1; index<=linkTop[0]; index++) {
		//Check for active
		if(index==active) {		//Write Active
			document.write('<div class="top_linkActive">' + linkTop[index][0] + '</div>');
		} else {	//isn't active so write link
			document.write('<a class="top_link" href="' + linkTop[index][1] + '">' + linkTop[index][0] + '</a>');
		}
	}
	document.write('</div>');
}

//Window Toggle and functions
var winCount=0;	//keeps count of windows, for adding them dynamically
var winToggle=new Array(100); var winID=new Array(100);		//will hold information for windows, after creation
function winOver(obj) {	//Mouse over title
	obj.style.background="url(images/menu_hover.gif)";
	obj.style.color="rgb(0,255,0)";
}

function winOut(obj) { //Mouse moves out of title
	obj.style.background="url(images/window_bar.gif)";
	obj.style.color="rgb(0,192,0)";
}
function winAdd(toggle, ID, Caption)	{//Adds and opens a simple sub window
	//Set the toggle
	winToggle[winCount] = toggle;
	//Set the ID
	winID[winCount] = ID;
	//Create Window by Toggle
	if(toggle==0){	//window starts closed
		document.write('<div class="sub_window" id="' + ID + '" style="height: 16px;">');
	}
	else if(toggle==1) { //Window Starts Open
		document.write('<div class="sub_window" id="' + ID + '" style="height: auto;">');
	}
	//Write Title
	document.write('<div class="sub_window_title" onmouseover="winOver(this)" onmouseout="winOut(this)" onclick="winClick(' + winCount + ')">' + Caption + '</div>');
	//Increment Counter
	winCount++;
}

function winClick(index) {	//For when title is clicked, window toggles
	if(winToggle[index]==0) {	//Window is closed, so open it
		document.getElementById(winID[index]).style.height="auto";
		winToggle[index]=1;
	}
	else {	//Window is open, so close it
		document.getElementById(winID[index]).style.height="16px";
		winToggle[index]=0;
	}
}

//Time, Date, Status
var s_status='Online(100%)';

//Function that inits all functions
function initStatus() {	//just throw this in body onload
	dispDate();
	dispStatus();
	dispTime();
}

//Display Date Function(inline)
function dispDate() {
	ndate = new Date();
	month = ndate.getMonth() + 1;
	day = ndate.getDate();
	year = ndate.getFullYear();
	if(month<10) {month="0"+month;}
	if(day<10) {day="0"+day;}
	ndate=month+"/"+day+"/"+year;
	document.getElementById('jdate').innerHTML = ndate;
}

//Display Time Function(id based)
function dispTime() {
	time = new Date();
	hours = time.getHours();
	minutes = time.getMinutes();
	seconds = time.getSeconds();
	if(hours<12) { mm = " am"; }
		else { mm = " pm"; }
	if(hours>12) { hours-=12; }
	if(hours<10) { hours="0"+hours; }
	if(minutes<10) { minutes="0"+minutes; }
	if(seconds<10) { seconds="0"+seconds; }
	ntime=hours+":"+minutes+":"+seconds+mm;
	document.getElementById('jtime').innerHTML = ntime;
	delay = setTimeout('dispTime()', 1000);
}

//Display Status Function
function dispStatus() {
	document.getElementById('jstatus').innerHTML = s_status;
}

//Update
var updateDate='04/23/2009';
var updateText='<a class="form_link" href="project.html">FB DaBooda Turbo Wrapper</a> 95% Complete!';
function writeUpdate()	{	//Simple function that writes the update
	document.write('<div class="sub_center">' + updateDate + '</div>');
	document.write('<div class="sub_pu" style="text-indent: 0px;">' + updateText + '</div>');
}

//Image functions
function imgOver(obj) {	//Mouse over image
	obj.style.borderColor="rgb(0,255,0)";
}
function imgOut(obj) {	//Mouse out of image
	obj.style.borderColor="rgb(0,128,0)";
}
function imgClick(dl, ss)	{	//Opens new window to show full image
	window.open(ssDir + dlItem[dl][3][ss],'','');
}
function imgWrite(dl, ss) 	{	//writes the image to html
	document.write('<div class="sub_image" style="background: url(' + tnDir + dlItem[dl][3][ss] + ')" onmouseover="imgOver(this)" onmouseout="imgOut(this)" onclick="imgClick(' + dl + ',' + ss + ')"></div>');
}
//This function creates the download window, that is viewed on many pages
//dlItem structure break down
//dlItem[index][0] = Caption
//dlItem[index][1] = descriptive text, for information
//dlItem[index][2] = number of screenshots
//dlItem[index][3][0]-[2] = screenshot file names, note thumbnails carry same name except different directory
//dlItem[index][lindex][0]-[1] = Items for box, note as soon as null is encountered it quits(lindex starts a 4 naturally)
function dlWrite()	{//This functions parameters is actually defined within the pages java
	//loop through and write everywindow
	var index; var lindex;
	for(index=0; index<dlCount; index++) {
		document.write('<hr />');
		//add window to page
		winAdd(1, 'dl'+index, dlItem[index][0]);
			//create information div, and fill it, do it in one statement
			document.write('<div class="sub_div"><div class="sub_p">' + dlItem[index][1] + '</div></div>');
			//check for screenshot count and write accordingly, note if no screen shots, then nothing is written(duh)
			if(dlItem[index][2] == 1)	{	//1 screenshot
				document.write('<div class="sub_image_div"><div class="sub_image_center" style="width: 108px">');
				imgWrite(index, 0);
				document.write('</div></div>');
			} else if(dlItem[index][2] == 2) {	//2 screenshots
				document.write('<div class="sub_image_div"><div class="sub_image_center" style="width: 216px">');
				imgWrite(index, 0);	imgWrite(index, 1);
				document.write('</div></div>');
			} else if(dlItem[index][2] == 3) {	//3 screenshots(max)
				document.write('<div class="sub_image_div"><div class="sub_image_center" style="width: 324px">');
				imgWrite(index, 0); imgWrite(index, 1); imgWrite(index, 2);
				document.write('</div></div>');
			}
			//reset lindex and loop through items, there will always be items
			document.write('<table class="sub_table">');
			lindex=4; backdex=1;
			while(dlItem[index][lindex]!='null') {	//quit when 'null' is encountered
				
				document.write('<tr><td><table class="sub_table_div"><tr>');
				
				document.write('<td class="sub_table_div_a">');
				if(dlItem[index][lindex][0]=='Download') {
					document.write('<h1 class="sub_table_colc">' + dlItem[index][lindex][0] + '</h1>');
				} else if(backdex==1) {
					document.write('<h1 class="sub_table_cola">' + dlItem[index][lindex][0] + '</h1>');
				} else {
					document.write('<h1 class="sub_table_colb">' + dlItem[index][lindex][0] + '</h1>');
				}
				document.write('</td>');
					
				document.write('<td class="sub_table_div_b">');
				if(backdex==1) {
					document.write('<h2 class="sub_table_cola">' + dlItem[index][lindex][1] + '</h1>');
				} else {
					document.write('<h2 class="sub_table_colb">' + dlItem[index][lindex][1] + '</h1>');
				}
				document.write('</td>');

				document.write('</td></tr></table></tr>');
				
				lindex++; backdex^=1;
			}
			document.write('</table>');
			//write footer bar and place top button in it
			document.write('<div class="sub_footer" style="clear:both"><a class="to_top" href="#page_top"></a></div>');
		document.write('</div>')
	}
}

//Function just writes in the footer at the bottom of each page(this way I can update it here).
function footerWrite() { //No parameters, just does a document write
	document.write('<div id="footer">Site Designed and Maintained by Andrew Stickney 2009</div>')
	document.write('<br />')
	document.write('<center><a href="http://www.w3.org/Style/CSS/"><img src="images/cssos.png" border=0 alt="CSS">&nbsp</a>')
	document.write('<a href="http://jigsaw.w3.org/css-validator/check/referer"><img style="border:0;width:88px;height:31px" src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS!">&nbsp</a>');
	document.write('<a href="http://www.freebasic.net/"><img src="images/fb.png" border=0 alt="FreeBasic">&nbsp</a>')
	document.write('<a href="http://www.relishgames.com/"><img src="images/hge.png" border=0 alt="HGE">&nbsp</a>')
	document.write('</center><br />')
}