/*
** Purpose: General Javascript Functions and small jQuery plugins
*/

/* -------------------------------------------------- *
 * ToggleVal Plugin for jQuery                        *
 * Version 1.0                                        *
 * -------------------------------------------------- *
 * Author:   Aaron Kuzemchak                          *
 * URL:      http://kuzemchak.net/                    *
 * E-mail:   afkuzemchak@gmail.com                    *
 * Date:     8/18/2007                                *
 * -------------------------------------------------- */
jQuery.fn.toggleVal = function() {
	this.each(function() {
		jQuery(this).focus(function() {
			// clear value if current value is the default
			if(jQuery(this).val() == this.defaultValue) { jQuery(this).val(""); }
		}).blur(function() {
			// restore to the default value if current value is empty
			if(jQuery(this).val() == "") { jQuery(this).val(this.defaultValue); }
		});
	});
}

/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */
jQuery.cookie=function(name,value,options){if(typeof value!='undefined'){options=options||{};if(value===null){value='';options.expires=-1;}var expires='';if(options.expires&&(typeof options.expires=='number'||options.expires.toUTCString)){var date;if(typeof options.expires=='number'){date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*1000));}else{date=options.expires;}expires='; expires='+date.toUTCString();}var path=options.path?'; path='+(options.path):'';var domain=options.domain?'; domain='+(options.domain):'';var secure=options.secure?'; secure':'';document.cookie=[name,'=',encodeURIComponent(value),expires,path,domain,secure].join('');}else{var cookieValue=null;if(document.cookie&&document.cookie!=''){var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+'=')){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break;}}}return cookieValue;}};

// ************************************************
// ****** Javascript Functions ******
// ****** Reassign jQuery object to different value other than $ to stop any other libraries conflicting with it ******
var $jq = jQuery;

changeImage = function(image) {
	var src = image.src;
	if(/_lo/.test(src)) {
		src = src.replace("_lo","_hi")
	} else {
		src = src.replace("_hi","_lo")
	}
	image.src = src
};
function showLoginStatus() {
	if($jq.cookie("UMSInterlinkExpress")) {
		$jq("#login-sidebar").hide();
		$jq("#logout-sidebar").show();
	} else {
		$jq("#logout-sidebar").hide();
		$jq("#login-sidebar").show();
	}
}
// ****** Put this as the last function in the js file ******
// ****** Load functions when document is ready ******
$jq(document).ready(function(){
   rollover();
   // ****** Show the login status of user ******
   showLoginStatus();
   // ****** Add New Window Links to page ******
   $jq("a[@rel='external']").click(function(){this.target = "_blank";});
   // ****** Add New Application Window Links to page ******
   $jq("a[@rel='app_external']").click(function(){this.target = "application_window";});
   // ****** Add New Window Links to form submissions ******
   $jq("#track, #login_form").submit(function(){this.target = "application_window";});
   // ****** Toggle text in textfields, password fields and textareas ******
   $jq("#q, #qtrack, #username, #password").toggleVal();
   // ****** Toggle Print Image ******
   $jq("#print-icon").mouseover(function() {
						changeImage(this);
					}).mouseout(function() {
						changeImage(this);
					});
   // ****** Slide popup slide in box onready ******
   /*$jq("#slideup").slideToggle(1500);	
	$jq("#close").click(function() {
		$jq("#slideup").slideToggle(1500);			 
	});*/
});