/****************************************************************************
	Administration Site Base Client Script
	Zac Hester
****************************************************************************/


/**
 * Detect IE for work-around code.
 */
var detect = navigator.userAgent.toLowerCase();
var isIE = detect.indexOf('msie') != -1;




/**
 * Page initialization.  Called when the body is loaded. 
 */

function init() {
	//Parse any URL query components.
	//parse_get();

		if(window.init_menu) {
			init_menu();
		}
    
  //Set up jump select menu.
	init_jump_select();

}


/**
 * Delete confirmation and requesting.
 */
function confirm_delete(objid,referer,type) {

	//Confirm the deletion of this object.
	if(confirm('Are you sure you want to delete this?')) {

		//Run the processor to delete this object from the current module.
		window.location = 'process.php?action=delete'+'&id='+objid+'&referer='+referer+'&type='+type;
	}

	//They didn't confirm the deletion.
	return(false);
}

/**
 * Move record up in database
 */
function move_item_up(objid,type,key, referer) {

	//Confirm the deletion of this object.
	if(confirm('Are you sure you want to move this record?')) {

		//Run the processor to delete this object from the current module.
		window.location = 'process.php?action=move_item'+'&id='+objid+'&type='+type+'&key='+key+'&referer='+referer;
	}

	//They didn't confirm the deletion.
	return(false);
}   
/**
 * General-form delete confirmation.
 */
function request_delete(module, object, id) {
	if(confirm('Are you sure you want to delete this '+object+'?')) {
		var next = encodeURIComponent(window.location.toString());
		window.location = 'process.php?action=delete&id='+id+'&referer='+next;
	}
	return(false);
}

/**
 * Simple whitespace trimmer.
 */
function trim(string) {
	var new_string = string.replace(/^\s+/g, '');
	new_string = new_string.replace(/\s+$/g, '');
	return(new_string);
}


/**
 * Add my own trim method to the String object.
 */
String.prototype.trim = function() {
    var str = this.replace(/^\s+/g, '');
    str = str.replace(/\s+$/g, '');
    return(str);
}


/**
 * Establish a global array to store the query data.
 */
var _GET = new Array();

/**
 * Parses the current page's GET query into a global array.
 *
 * @author Zac Hester <zac@zacharyhester.com>
 * @date 2005-10-28
 */
function parse_get() {

	//A temporary place to keep array items.
	var temp = new Array();

	//Pull the GET query of the current page.
	var get = window.location.search.substring(1);

	//Check for any query.
	if(get.length == 0) {
		return(false);
	}

	//Check for multiple query pairs.
	else if(get.indexOf('&') != -1) {

		//Break the query on the standard pair separator.
		var pairs = get.split('&');

		//Run through each key=value pair.
		for(var i = 0; i < pairs.length; ++i) {

			//Break the pair on the standard assignment separator.
			temp = pairs[i].split('=');

			//Load the data in the global array.
			parse_get_assign_pair(temp[0], temp[1]);
		}
	}

	//This query only has one pair.
	else {

		//Break the pair on the standard assignment separator.
		temp = get.split('=');

		//Load the data in the global array.
		parse_get_assign_pair(temp[0], temp[1]);
	}
}


function parse_get_assign_pair(key, val) {

	//Every string from the query needs to be checked for plus-sign as
	//  spaces (PHP-style), and then unescape()d like usual.
	key = key.replace('+', ' ');
	key = unescape(key);
	val = val.replace('+', ' ');
	val = unescape(val);

	//Put the data in the global array.
	_GET[key] = val;
}
/**
 * Jump Select Menu Control
 */
function jump_to() {
	for(var i = 0; i < this.options.length; ++i) {
		if(this.options[i].selected && this.options[i].value != 0) {
			window.location = 'index.php?category='+this.options[i].value;
		}
		if(this.options[i].selected && this.options[i].value == 0) {
      window.location = 'index.php';
    }
	}
	this.options[0].selected = true;
	return(false);
}
function init_jump_select() {
	var js = document.getElementById('jump_select');
	if(js) { js.onchange = jump_to; }
}
$(document).ready(function() {
	
$("ul#topnav li").hover(function() { //Hover over event on list item
	$(this).css({ 'background' : '#ffa200'}); //Add background color + image on hovered list item
  $(this).find("span").show(); //Show the subnav
} , function() { //on hover out...
	$(this).css({ 'background' : 'none'}); //Ditch the background
	$(this).find("span").hide(); //Hide the subnav
	
});
	
});



