/* Sets default values for username/password boxes.
This jQuery statement is better than using javascript 'onload' command because
it executes as soon as the DOM has loaded - no waiting for images to load.
Note: 'if' statement necessary otherwise conflicts with logged-in state */

$("document").ready( function () {
	if(document.getElementById('navbar_password')) {
		setPrompts();
	}
});


/* ------- Setting focus and blur of login form inputs ------- */

//Variable to save prompt messages
var fieldPrompts = new Array();

function inputFocus(fieldObj) {
	if (fieldObj.className=='inputPrompt') {
		if (fieldObj.id=='navbar_password') {
			//change field type and reset obj reference
			changeInputType('navbar_password', 'password');
			fieldObj = document.getElementById('navbar_password');
		}
		fieldPrompts[fieldObj.id] = fieldObj.value;
		fieldObj.value = '';
		fieldObj.className = 'inputStd';
		fieldObj.select();
		fieldObj.focus();
	}
}

function inputBlur(fieldObj) {
	if (fieldObj.value=='') {
		if (fieldObj.id=='navbar_password') {
			//change field type and reset obj reference
			changeInputType('navbar_password', 'text');
			fieldObj = document.getElementById('navbar_password');
		}
		fieldObj.value = fieldPrompts[fieldObj.id];
		fieldObj.className = 'inputPrompt';
	}
}

function changeInputType(objID, oType) {
	var oldObject = document.getElementById(objID);
	var newObject = document.createElement('input');
	newObject.type = oType;
	if(oldObject.value) newObject.value = oldObject.value;
	if(oldObject.size) newObject.size = oldObject.size;
	if(oldObject.name) newObject.name = oldObject.name;
	if(oldObject.id) newObject.id = oldObject.id;
	if(oldObject.onfocus) newObject.onfocus = oldObject.onfocus;
	if(oldObject.onblur) newObject.onblur = oldObject.onblur;
	if(oldObject.className) newObject.className = oldObject.className;
	oldObject.parentNode.replaceChild(newObject,oldObject);
	return;
}

function setPrompts() { //Run onload of the page
	document.getElementById('navbar_username').className = 'inputPrompt';
	// changeInputType('navbar_password', 'text');
	// document.getElementById('navbar_password').value = 'Enter password';
	document.getElementById('navbar_password').className = 'inputPrompt';
	}





$(document).ready(function(){
	
	/* navigation for IE6 */
	if($.browser.msie && $.browser.version.substr(0,1) == '6'){
		$('#navov li').hover(function(){
			$(this).addClass('over');
		},function(){
			$(this).removeClass('over');
		});
	}
	
	/* navigation keyboard accessibility */
	$('#navov a').focus(function(){
		$(this).css('text-decoration','none');
		$(this).parents('ul').eq(0).addClass('over');
		$(this).parent('li').find('ul').eq(0).addClass('over');
	}).blur(function(){
		$(this).css('text-decoration','none');
		$(this).parents('ul').eq(0).removeClass('over');
		$(this).parent('li').find('ul').eq(0).removeClass('over');
	});
	
	/* nav on */
	$('#navov > ul > li:not(.spacer) > a').hover(function(){
		$(this).parent().parent().find('> li').removeClass('currentov');
		$(this).parent().addClass('currentov');
	},function(){
	
	});
	
	/* tabs */
	$('div.tabbedContainer').each(function(){
		var cont = $(this);
		cont.find('ul.anchors li:first-child').addClass('tabs-selected');
		cont.find('ul.anchors li a').click(function(){
			cont.find('ul.anchors li').removeClass('tabs-selected');
			$(this).parent('li').addClass('tabs-selected');
			
			cont.find('>div:visible').hide();
            var re = /([_\-\w]+$)/i;
            $('#' + re.exec($(this).attr('href'))[1]).show();
			
			return false;
		});
	});
	
	
});



/* ------- Slide up and down panels ------- */

function ToggleAttrib(name, subtype) {
 if (subtype == "a") {
         $('#' + name + "_b").slideToggle("medium");  // can be '.show' or '.slideToggle' or '.toggle' etc
		 $("#divReadMore_a span").removeClass("linkreadmore");
		 $("#divReadMore_a span").addClass("linkreadmorenoy");
 } else if (subtype == "b") {
         $('#' + name + "_b").slideUp('slow');
		 $("#divReadMore_a span").removeClass("linkreadmorenoy");
		 $("#divReadMore_a span").addClass("linkreadmore");
 }
}





/* ------- URL form inputs that highlight text on click ------- */

function highlight(field)
{
    field.focus();
    field.select();
    
    return true;    
}



