// Various javascript stuff
// Mike Martinet - www.southrustern.com
//
//

// Cobbed from mediacollege.com
String.prototype.capitalize = function(){
	return this.replace( /(^|\s)([a-z])/g , function(m,p1,p2){ return p1+p2.toUpperCase(); } );
};

function URLDecode(psEncodeString)
{
  // Create a regular expression to search all +s in the string
  var lsRegExp = /\+/g;
  // Return the decoded string
  return unescape(String(psEncodeString).replace(lsRegExp, " "));
}

function nextFive( start, imgDir, max, limit, type ) {

	var ref = document.referrer;
	var re = /(.*com).*/;
	ref = ref.replace( re, "$1" );
	$.get( ref + "/node/94", { dir: imgDir, start: start, max: max, limit: limit, type: type }, 
		function(data){
		re = /<.*>/;
		data = data.replace( re, "" );
		data = data.replace( re, "" );
		re = new RegExp( "<\/div>$", "m" );
		document.getElementById( 'ImgThm').innerHTML = data; 
    });
}

function swapIt( img, type ) {

	// Change the thumbnail string to image string
	var imgSrc = img.src.replace("info_thm", "info_img")
	// Update the main image
	document.getElementById('MainImg').src = imgSrc;

	// Get the current image div
	var imgDiv = document.getElementById('ImgDiv').innerHTML;

	// Get the new image string
	var re = /http:.*info_img(.*)/;
	var imgRep = imgSrc.replace( re, "$1" );

	// Starting, imgRep = /info/CA/barstow/img/whitey_ford-1.2.png
	re = /.*\//;
	var imgTxt = imgRep.replace( re, "" );
	re = /.{4}$/;
	var imgTxt = imgTxt.replace( re, "" );
	// Ending, imgTxt = whitey_ford-1.2

	// Get the node and image description from the hidden form field
	thumbForm = document.forms[0]; 
	var imgText = URLDecode( thumbForm.elements[imgTxt].value ); 
	var node = imgText.substring( 0, imgText.indexOf( ":" ) );
	//alert( "imgText = " + imgText + " node = " + node );
	re = /(.*?:)/;
	imgText = imgText.replace( re, "" );
	document.getElementById('ImgText').innerHTML = imgText;

	// Turn the file name into the alt and title strings
	var re = /.*\/(.*)-.*/;
	var imgNam = imgRep.replace( re, "$1" );
	imgNam = imgNam.replace( /_/g, " " );
	// Uppercase first letter of each word
	imgNam = imgNam.replace( /(^|\s)([a-z])/g , function(m,p1,p2){ return p1+p2.toUpperCase(); } );

	// Rebuild the image link and rewrite the div contents
	var re = /(.*<a href=).*?>(.*)/;
	imgDiv = imgDiv.replace( re, "$1\"" + imgRep + "\"> $2" );
	// Replace the alt and title tags
	var re = /(.*alt=).*title=.*( id.*)/;
	imgDiv = imgDiv.replace( re, "$1\"" + imgNam + "\" title=\"" + imgNam + "\" $2" );
	document.getElementById('ImgDiv').innerHTML = imgDiv;

	var imgTitle = document.getElementById('ImgTitle').innerHTML;
	imgTitle = "<a href=\"/?q=/node/" + node +"\">" + imgNam + "</a>";
	document.getElementById('ImgTitle').innerHTML = imgTitle;

	//window.imgTitle.focus();
	//document.getElementById('ImgTitle').focus();
	window.scrollTo(0,250)

}

function pause( secs, target ) {
	timer = setTimeout( "endPause()", secs ); // 3 secs
	return false;
}

function endPause() {
	return false;
}


