// This is for car show page.
// DEPRECATED. use imageChanger
var count = 1;
var imax = 67;
var imageperpage = 15;

//way 1 = back, 2 = forward
function changeImages(name, way){
	
	if (count == imax - imageperpage + 1 && way == 2) count = 1;
	else if (count > imax - imageperpage*2 + 1 && way == 2) count = imax - imageperpage +1;
	else if (way ==2 ) count += imageperpage;
	if (count == 1 && way == 1) count = imax - imageperpage + 1;
	else if (count < imageperpage + 1 && way == 1) count = 1;
	else if (way ==1) count -=  imageperpage;
		
	var doc=document.getElementById(name).rows
	
	var x = 0;
	for (var i = 0; i < 3; i++ ) {
		for (var j = 0; j < 5; j++ ) {
			var y = doc[i].cells;
			y[j].innerHTML = '<a href="images/carshow2008/carshow'+(count+x)+'.jpg" rel="lightbox[carshow2008]"><img src="images/carshow2008/carshow'+(count+x)+'_tn.jpg" width="100" height="100" border="0" /></a>';
			x ++;
		}
	}
}

function imageChanger(id, goto, dimx, dimy, maxCount) {
	if (goto <= 0 || dimx <= 0 || dimy <= 0 || maxCount <= 0) {
		document.write("A fatal error has occured, please contact the web administrator");
		return;
		//TODO ERROR PAGE!
	}
	if (id == null) {
		document.write("A fatal error has occured, please contact the web administrator");
		return;
		//TODO Error page!
	}
	var numsPerPage = dimx * dimy;
	var numPages = Math.ceil(maxCount / numsPerPage);
	if (goto > numPages) {
		document.write("A fatal error has occured, please contact the web administrator");
		return;
		//TODO Error page!
	}
	var doc = document.getElementById(id).rows;
	var x = dimx * dimy * (goto-1);
	
	var row;
	for (var i = 0; i < dimy; i++) {
		row = doc[i].cells;
		for (var j =0; j < dimx; j++) {
			x ++;
			if (x > maxCount) {
				row[j].innerHTML = "&nbsp;";
			} else {
				row[j].innerHTML = '<a href="images/' + id + '/' + id + x + '.jpg" rel="lightbox['+id+']"><img src="images/' + id + '/t_' + id + x + '.jpg" width="100" height="100" border="0" /></a>';
			}
		}
	}
	
	// Buttons
	row = doc[dimy].cells;
	
	// Prev button
	if (goto > 1) {
		row[0].innerHTML = '<a href="javascript:void('+(goto-1)+');" onclick="imageChanger(\''+id+'\', '+(goto-1)+', '+dimx+', '+dimy+', '+maxCount+')" onmouseover="this.style.cursor=\'hand\'" class="nounderline">&laquo; Prev Page</a>';
	} else {
		row[0].innerHTML = "&nbsp;"; //blank
	}
	
	// Page buttons
	
	var contents = "";
	for (var i = 0; i < numPages; i++) {
		if (goto == (i+1)) {
			contents = contents + "<b>" 
		}
		contents = contents + '<a href="javascript:void('+(i+1)+');" onclick="imageChanger(\''+id+'\', '+(i+1)+', '+dimx+', '+dimy+', '+maxCount+')" onmouseover="this.style.cursor=\'hand\'" class="nounderline">'+(i+1)+'</a> ';
		if (goto == (i+1)) {
			contents = contents + "</b>"
		}
	}
	row[1].innerHTML = contents;
	
	// Next button
	if (x >= maxCount) {
		row[2].innerHTML = "&nbsp;"; //blank
	} else {
		row[2].innerHTML = '<a href="javascript:void('+(goto+1)+');" onclick="imageChanger(\''+id+'\', '+(goto+1)+', '+dimx+', '+dimy+', '+maxCount+')" onmouseover="this.style.cursor=\'hand\'" class="nounderline">Next Page &raquo;</a>';
	}
}

/*
Modified by Peter Park for use specifics.
Floating Menu script-  Roy Whittle (http://www.javascript-fx.com/)
Script featured on/available at http://www.dynamicdrive.com/
This notice must stay intact for use
*/

//Enter "frombottom" or "fromtop"
var verticalpos="frombottom"

function JSFX_FloatTopDiv()
{
	var startX = 0,
	startY = 356;
	var ns = (navigator.appName.indexOf("Netscape") != -1);
	var d = document;
	if (document.body.clientWidth > 801) startX = ((document.body.clientWidth - 780) / 2 ) + 570;
	else startX = 570; 
	function ml(id)
	{
		var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
		if(d.layers)el.style=el;
		el.sP=function(x,y){this.style.left=x;this.style.top=y;};
		el.x = startX;
		if (verticalpos=="fromtop")
		el.y = startY;
		else{
		el.y = ns ? pageYOffset + innerHeight : document.body.scrollTop + document.body.clientHeight;
		el.y -= startY;
		}
		return el;
	}
	window.stayTopLeft=function()
	{
		if (verticalpos=="fromtop"){
		var pY = ns ? pageYOffset : document.body.scrollTop;
		ftlObj.y += (pY + startY - ftlObj.y)/8;
		}
		else{
		var pY = ns ? pageYOffset + innerHeight : document.body.scrollTop + document.body.clientHeight;
		ftlObj.y += (pY - startY - ftlObj.y)/8;
		}
		ftlObj.sP(ftlObj.x, ftlObj.y);
		setTimeout("stayTopLeft()", 10);
	}
	ftlObj = ml("divStayTopLeft");
	stayTopLeft();
}

// Ajax page reload for calendar
var ajaxdestination="";

function getdata(url,location) { // get data from source (url)
  try {
    xmlhttp = window.XMLHttpRequest?new XMLHttpRequest():
  		new ActiveXObject("Microsoft.XMLHTTP");
  }
  catch (e) { 
 	try {
		// Firefox, Opera 8.0+, Safari
		xmlhttp=new XMLHttpRequest();
	} catch (e) { /* do nothing */ }
  }

  //document.getElementById(location).innerHTML ="<center><img src='loading.gif'></center>";
  ajaxdestination=location;
  // when request finished, call the function to put result to destination DIV
  xmlhttp.onreadystatechange = triggered; 
  xmlhttp.open("GET", url);
  xmlhttp.send(null);
  return false;
}

// put data returned by requested URL to selected DIV
function triggered() { 
  if (xmlhttp.readyState == 4) if (xmlhttp.status == 200) 
    document.getElementById(ajaxdestination).innerHTML =xmlhttp.responseText;
}


