/**
 * Common Javascript Functions
 *
 * @author gUncle Development [http://www.guncle.com]
 * @version 2/3/2008
 */


/**
 * Recolors alt rows in table
 * @param element = id of table
 */
function colorAltRows(element) {
	if( document.getElementById(element) ) {
		var trs = document.getElementById(element).getElementsByTagName('tr');
		var num=0;
		for( var n=0; n<trs.length; n++ ) {
			var curclass = '';
			if( getClassName(trs[n]) ) {
				curclass += getClassName(trs[n]);
			}
			if( curclass.indexOf('table_header') < 0 ) {
				curclass = curclass.replace('alternate','');
				if( num%2 ) {
					curclass += ' alternate';
				}
				setClassName(trs[n],curclass);
				if( curclass.indexOf('hidden') < 0 ) {
					num++;
				}
			}
		}
	}
}


/**
 * Gets class name of specific element
 * @param element | the element to retrieve class name of
 */
function getClassName(element) {
	var className = (document.all && document.getElementById ? element.className : element.getAttribute("class"));
	return className;
}


/**
 * Sets class name of specific element
 * @param element = element to set class name for
 * @param style = class name to assign to element
 */
function setClassName(element,style) {
	if( document.all && document.getElementById ) element.className=style;
	else element.setAttribute("class", style);
}


/**
 * Displays pages dropdown
 * @param page = url of current page
 */
function pagesTop(page) {
	var url = document.getElementById("pagesDropdownTop").value;
	window.location = page + "?pstart=" + url;
}
function pagesBottom(page) {
	var url = document.getElementById("pagesDropdownBottom").value;
	window.location = page + "?pstart=" + url;
}


/**
 * Pop open photo window
 * @param url = folder name for photos
 * @param pyear = year of the photos for folder
 */
function photo(url,pyear) {
	var photos = "/photos/" + pyear + "/" + url + "/index.html";
	window.open(photos,"photos","toolbar=no,location=no,status=no,menubar=no,resizable=yes,width=850,height=750");
}


/**
 * Sets selected theme
 * @param {int} id = id of theme
 */
function selectTheme(id) {
	document.getElementById('selected_theme').value = id;
	$(".pbox_link").removeClass('selected');
	$("#theme_"+id).addClass('selected');
}


/**
 * Jumps to recent items in site
 */
function siteJump() {
	var url = $("#siteJump")[0].value;
	if( url ) {
		window.location = url;
	}
	else {
		alert('Please select a page to jump to.');
	}
}


/**
 * Swaps default value of input field
 */
swapValue = [];
$("document").ready(function(){
	$(".swap-value").each(function(i){
		swapValue[i] = $(this).val();
		$(this).focus(function(){
			if ($(this).val() == swapValue[i]) {
				$(this).val("");
				$(this).addClass("value-swap");
			}
		}).blur(function(){
			if ($.trim($(this).val()) == "") {
				$(this).val(swapValue[i]);
				$(this).removeClass("value-swap");
			}
		});
	});
});


/**
 * Toggle e-mail messages
 * @param key = id of message
 */
function toggleMessage(key) {
	if( document.getElementById('message' + key).style.display == 'none' ) {
		document.getElementById('message' + key).style.display = '';
	}
	else {
		document.getElementById('message' + key).style.display = 'none';
	}
}


/**
 * Toggles value in search field
 * @param bool $toggle = on off for if field is blank
 */
function toggleSearch(toggle) {
	var words = document.getElementById('words');
	if( words ) {
		if( toggle==1 && words.value=='Search' ) {
			words.value='';
		}
		else if( toggle==0 && words.value=='' ) {
			words.value='Search';
		}
	}
}


/**
 * Starts photo slideshow
 */
function viewSlideshow() {
	$('lightboxSSFirst').onclick();
	Lightbox.prototype.startSlideshow();
}

