// Main body of Javascript functions used for www.esstec.co.uk
//


// Window onload stuff

window.onload = prepare;

function prepare() {
	$( "picbitcloser" ).onclick = hidePicBit;
	$( "mailbitcloser" ).onclick = hideMailBit;
}


// Show the picbit div

function showPicBitwPicture( pictureNo, theDate, numberOfPics, picHeight ) {
	var bottomText = "";
	var imageName = "images/blogimages/640/" + theDate + "-" + pictureNo + ".jpg";

	$( "picbitpicture" ).innerHTML = "<img src='" + imageName + "' alt='images' title='click to close' width='640'  onclick='hidePicBit();' /><div id='picbitlabel'></div>";
	if( numberOfPics > 1 ) {
		var nextPic = pictureNo + 1;
		var prevPic = pictureNo - 1;
		if( prevPic != 0 ) { bottomText = "<img onclick='showPicBitwPicture( " + prevPic + ",\"" + theDate + "\",\"" + numberOfPics + "\" );' src='images/bgpics/left.gif' alt='left' width='15' height='15'>"; }
		bottomText = bottomText + "<span class='labelText'>" + theDate + "-" + pictureNo + "</span>";
		bottomText = bottomText + "<img onclick='showPicBitwContactSheet( \"showContactInPane.php?date=" + theDate + "&amp;noOfImages=" + numberOfPics + "\" );' src='images/bgpics/thumbs.gif' alt='thumbs' width='15' height='15'>";
		if( nextPic <= numberOfPics ) { bottomText = bottomText + "<img onclick='showPicBitwPicture( " + nextPic + ",\"" + theDate + "\",\"" + numberOfPics + "\" );' src='images/bgpics/right.gif' alt='right' width='15' height='15'>"; }
	}
	else
	{
		bottomText = "<span class='labelText'>" + theDate + "-" + pictureNo + "</span>";
	}
	$( "picbitlabel" ).innerHTML = bottomText;
	$( "picbit" ).style.display = "block";
}


// Show the contact sheet

function showPicBitwContactSheet( url ) {
	var myAjax = new Ajax.Updater( "picbitpicture", url, "" );
	$( "picbit" ).style.display = "block";
}


// Hide the picbit div

function hidePicBit() {
	$( "picbit" ).style.display = "none";
}


// Replace imageInfoText

function imageInfoText( element ) {
	$( "picbitlabel" ).innerHTML = element.getAttribute( "alt" );
}


// Show the mailer

function showMailBit() {
	var myAjax = new Ajax.Updater( "mailbitmain", "mailerAjax.php", "" );
	$( "mailbit" ).style.display = "block";
}


// Hide the mailer

function hideMailBit() {
	$( "mailbit" ).style.display = "none";
}


// Process the mail form

function doMailForm() {
	var returnFalse = 0;
	
	if( $F( "name" ) == "" ) {
		$( "nameheader" ).style.color = "#ff0000";
		returnFalse = 1;
	}
	else {
		$( "nameheader" ).style.color = "#666666";
	}
	
	if( $F( "email" ) == "" ) {
		$( "emailheader" ).style.color = "#ff0000";
		returnFalse = 1;
	}
	else {
		$( "emailheader" ).style.color = "#666666";
	}
	
	if( $F( "message" ) == "" ) {
		$( "messageheader" ).style.color = "#ff0000";
		returnFalse = 1;
	}
	else {
		$( "messageheader" ).style.color = "#666666";
	}
	
	if( returnFalse == 1 ) {
		return false;
	}
	
	var toPass = Form.serialize( "mailform" );
	var myAjax = new Ajax.Updater( "mailbitmain", "mailerAjax.php", { method: 'post', parameters: toPass } );
}
