/**
 * @author w951ags
 */
//Load style sheet for avoiding flicker with jQuery show/hide
//Initialise hidden elements in this stylesheet
(function () {
	var head = document.getElementsByTagName("head")[0];
	if (head) {
		var scriptStyles = document.createElement("link");
		scriptStyles.rel = "stylesheet";
		scriptStyles.type = "text/css";
		scriptStyles.href = "css/jsHide.css";
		head.appendChild(scriptStyles);
	}
}());

//Event handlers for SLAPI login box
$(function(){
	$('#useridCEB').focus();
	$("#businessTab").click(function(){ 
		$("#login_business").show();
		$("#login_personal").hide();
	}); 
	$("#personalTab").click(function(){ 
		$("#login_personal").show();
		$("#login_business").hide();
	});
	//Initialize tooltip for email disclaimers
	$('a[href^=mailto:]').click(function(){
		alert('NOTICE:  Please do not send any confidential information via email');
	});
	$('.notice').click(function(){
		alert('NOTICE:  Please do not send any confidential information via email');
	});
});

function initJumpMenus() {
    // Turns all <select> elements with the 'jumpmenu' class into jump menus
    var selectElements = document.getElementsByTagName("select");
    for( i = 0; i < selectElements.length; i++ ) {
        // Check for the class and make sure the element has an ID
        if( selectElements[i].className == "calc_jump" && document.getElementById(selectElements[i].id) != "" ) {
            jumpmenu = document.getElementById(selectElements[i].id);
            jumpmenu.onchange = function() {
                if( this.options[this.selectedIndex].value != '' ) {
                    // Redirect
                    location.href=this.options[this.selectedIndex].value;
                }
            }
        }
    }
}

window.onload = function() {
    initJumpMenus();
}

/*
 * Tooltip script 
 * powered by jQuery (http://www.jquery.com)
 * 
 * written by Alen Grakalic (http://cssglobe.com)
 * 
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 *
 */

this.tooltip = function(){	

	/* CONFIG */		
		xOffset = -10;
		yOffset = 0;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		

	$(".tooltip").hover(function(e){											  
		this.t = $(this).attr('alt') || this.title;
		this.title = "";
		$(this).after("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.css({
				"position":"absolute",
				"border":"1px solid black",
				"background-color":"white",
				"padding":"3px 5px"
			})
			.fadeIn("fast");		
	  },
	
		function(){
			this.title = this.t;
			$("#tooltip").remove();
  });	

	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			

};
