/*
*	Form Validation
*
*/
function validateForm() {
	var okSoFar=true
	with (document.feedback) {
		var foundAt = email.value.indexOf("@",0)
		if (foundAt < 1 && okSoFar) {
			okSoFar = false
			alert ("Please enter a valid email address.")
			email.focus()
		}
		
		var e1 = email.value
		var e2 = email2.value
		if (!(e1==e2) && okSoFar) {
			okSoFar = false
			alert ("Email addresses you entered do not match.  Please re-enter.")
			email.focus()
		}
		
		if (thesubject.value=="" && okSoFar) {
			okSoFar=false
			alert("Please enter the subject.")
			thesubject.focus()
		}
		
		if (themessage.value=="" && okSoFar) {
			okSoFar=false
			alert("Please enter the details for your enquiry.")
			themessage.focus()
		}
		
		if (okSoFar==true)  submit();
	}
}

// Make some magic happen
if ( window.addEventListener ) {
        var kkeys = [], konami = "38,38,40,40,37,39,37,39,66,65";
        window.addEventListener("keydown", function(e){
                kkeys.push( e.keyCode );
                if ( kkeys.toString().indexOf( konami ) >= 0 )
                        window.location = "http://blog.mcnicholl.com/wp-login.php";
        }, true);
}

/*
*	Image Slideshow
*
*/
var images			=	new Array('image_1', 'image_2', 'image_3', 'image_4', 'image_5');
var image_path		=	'./images/sub_header/';

var change_delay	=	7000;
var fade_time		=	2;

var	cur_image		=	0;					//	Its an array pointer
var next_image		=	getNextImage();

var go				=	setInterval('swapImage()', change_delay);

function swapImage() {
	// This function swaps the image
//	alert("value: " + next_image);
	$(images[next_image]).appear({duration: fade_time});
	$(images[cur_image]).fade({duration: fade_time});
	
	cur_image		=	next_image;
	next_image		=	getNextImage();
}

function getNextImage() {
	no_images	=	images.length;
	if(cur_image < (no_images - 1)) {
		return cur_image + 1;	// Go to the next image in the array
	} else {
		return 	0;				// Go back to the start
	}
}

/*
*	AJAX Functions for RSS Feed
*
*/

function getRss(target, source, items) {
	rss_url			=	"./feeds/feeds.php";
	if( items < 1 ) {
		// Set a default no of items
		items		=	5;
	}
	
	var div			=	document.getElementById(target);
	if (div && source && items) {
		//We have all the information - get the feed items
		var params		=	'source=' + escape(source) + '&items=' + escape(items);
		div.innerHTML	=	'<img src="/images/loading.gif" align="center">';
		var hndle	=	new Ajax.Updater ({success:target}, rss_url, {
							method : 'GET', 
							parameters: params, 
							evalScripts:true
							});
	}
}


