
	$(document).ready(function() {
	
		//	login form
			var checkLogin = $('#login-form a').text();
		//	alert(checkLogin);
			if (checkLogin == 'Logout') {
				$('#top-nav .login a').attr('href',"javascript:__doPostBack('headerphd_0$imisLoginForm$loginView$LoginStatusControl$ctl00','')").find('span').text('Logout');
			} else {
				$('#login-form label').each( function(){
					id = $(this).next('input').attr('id');
					$(this).attr('for', id);
				});
				
				$("#top-nav li.login").click(function(e) {
	                e.preventDefault();
	                $("#login-form").toggle();
	                $("#top-nav li.login").toggleClass("menu-open");
	            });
	
	            $("#login-form").mouseup(function() {
	                return false
	            });
	            $(document).mouseup(function(e) {
	                if($(e.target).parent("#top-nav li.login, #top-nav li.login a").length==0) {
	                    $("#top-nav li.login").removeClass("menu-open");
	                    $("#login-form").hide();
	                }
	            });   
			}
		
		// Header > MORE drop down
		$('#trigger-more').click(function(e) {
			e.preventDefault();
			var moreContainer = $('#more-container');		
			var image = $(this).find('#dd-arrow');
			var src = image.attr('src');
			var offset = image.offset();
			var top = image.height() ;
			var left = parseInt(moreContainer.width()) - 130;
			
			moreContainer.css({top: top, left: left});		
			
			if (moreContainer.is(':visible')) {
				image.attr('src', src.replace('-on', '-off'));
				moreContainer.slideUp('normal');			
			} else {
				image.attr('src', src.replace('-off', '-on'));
				moreContainer.slideDown('normal', function() {
					$('body').css({cursor: 'pointer'});
					$(moreContainer).css({cursor: 'auto'});					
					$('body').one('click', function() {
						moreContainer.slideUp('normal', function() {
							$('body').css({cursor: 'auto'});
						});
					});
				});
			}
			
	
		});
		
		// state changer
		$('div#more-content ul li a').click(function(e) {
			var location = $(this).text();
			$("div#top-nav ul li.location span").empty().fadeOut().append(location).fadeIn();
			$("img#dd-arrow").attr('src', 'img/arrow-drop-down-off.png');
		});
		
		$(function(){
		// find all the input elements with title attributes
			$('input[title!=""]').hint();
		});
	
		$('#txtSearch').focus(function() { // Remove hint class on focus    	
			$(this).removeClass("hint");
     	}); 		 
     	$('#txtSearch').blur(function() {  // Add back hint class on focus out
        	$(this).addClass("hint");          
		});
		
		
	
		// toolbar print button handler
		$('.launch-print').click(function(e) {
			e.preventDefault();						
			window.print();							
		});
		
		// toolbar decrease text size
		$('.text-decrease').click(function(e) {
			e.preventDefault();
			decrease();
		});
		
		// toolbar increase text size
		$('.text-increase').click(function(e) {
			e.preventDefault();
			increase();
		});	
/*
		$('.emailFriendButton').click(
		function()
		{   
		    $('.emailFriendForm').toggle('slow');
		    return false;
		});
		
		$('.emailButtonCancel').click(
		function()
		{   
		    $('.emailFriendForm').hide('slow');
		    return false;
		});
*/		
	});
	
	
function decrease() {
	oHTML = document.getElementsByTagName('BODY')[0];
	oHTML.style.fontSize = parseInt(oHTML.style.fontSize)-10+"%";
//	window.status += oHTML.style.fontSize;

	// Update the cookie that holds the font size setting. Do this by calling the cookieMonster function, which
	// looks at the oHTML.style.fontSize; and updates the cookie value accordingly.  If a cookie doesn't exist it creates one.
	updateCookie();
}

function increase() {
	oHTML = document.getElementsByTagName('BODY')[0];
	oHTML.style.fontSize = parseInt(oHTML.style.fontSize)+10+"%";
//	window.status += oHTML.style.fontSize;

	// Update the cookie that holds the font size setting. Do this by calling the cookieMonster function, which
	// looks at the oHTML.style.fontSize; and updates the cookie value accordingly.  If a cookie doesn't exist it creates one.
	updateCookie();
}

function cookieMonster() {
	// This function looks at the oHTML.style.fontSize; and updates the cookie value accordingly.  If a cookie doesn't exist it creates one.
	var oHTML = document.getElementsByTagName('BODY')[0];

	// Look for the cookie that holds font size.  If found, set document to that font size, else set cookie to current font size.
	if(readCookie('fontSize')==null) {
		// No cookie found. Create a new cookie that is set to the font size as defined in the HTML tag on the page (70%).
		createCookie('fontSize',parseInt(oHTML.style.fontSize),365);	
	} else {
		// Cookie found.  Set the HTML font size to the value of the cookie.
		oHTML.style.fontSize = readCookie('fontSize')+"%";
//		window.status += readCookie('fontSize');
	}

	//alert('cookieMonster: ' + readCookie('fontSize'));
}

function updateCookie() {
	var oHTML = document.getElementsByTagName('BODY')[0];

	// Check if the cookie exists.  If not, create one.
	if(readCookie('fontSize')==null) {
		// Create a new cookie that is set to the font size as defined in the HTML tag on the page (70%).
		cookieMonster();	
	} else {
		// Cookie exists, so update it's value.  Look at the recently set font size as defined in the HTML tag on the page, which will have been increased/decreased.
		createCookie('fontSize',parseInt(oHTML.style.fontSize),365);
	}
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0){
			return c.substring(nameEQ.length,c.length);
		}
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

