// JavaScript Document
$(document).ready(function(){
	if($(".pmFields textarea").length > 0){
		$(".pmFields textarea").focus(function () {
			var myTarget = this.parentNode;
			if(this.readOnly==false){
				$(myTarget).removeClass("pmGrey");
				$(myTarget).addClass("pmGold");
			}
		});
		$(".pmFields textarea").blur(function () {
			var myTarget = this.parentNode;
			if(this.readOnly==false){
				$(myTarget).removeClass("pmGold");
				$(myTarget).addClass("pmGrey");
			}
		});
		var numTargets = $(".pmFields textarea").length -1;
		var theTarget = $(".pmFields textarea");
		var theParent = $(".pmGrey");
		for(i=0;i<=numTargets;i++){
			if(theTarget[i].readOnly==false){
				myArray = new Array();
				myArray.push(i);
				$(theTarget[myArray]).focus();
				return;
			}
		}
	}
	

	if($(".adminMsgSummary").length > 0){
		$(".adminMsgSummary h3").hover(
			function () {
			$(this).addClass("hoverh3");
			$(this).next("dl").addClass("hoverdl");
		},
			function () {
			$(this).removeClass("hoverh3");	
			$(this).next("dl").removeClass("hoverdl");
		}
		); //end hover
		
		if($(".sIFR-replaced").length <= 0){
			$(".adminMsgSummary h3").click(
				function(){
					$(this).next("dl").slideToggle("fast");	
				}
			);
		}
	
	}// end if
	
	if($("#msgListing").length > 0){
		$("#msgListing h2").hover(
			function () {
			$(this).addClass("hoverh2");
			$(this).children("span.new").addClass("hoverSpan");
			$(this).next("dl").addClass("hoverdl");
		},
			function () {
			$(this).removeClass("hoverh2");	
			$(this).children("span.new").removeClass("hoverSpan");
			$(this).next("dl").removeClass("hoverdl");
		}
		); //end hover
			
	}// end if
	
	if($("#msgFullWidth").length > 0){
		$("#msgFullWidth h2").hover(
			function () {
			$(this).addClass("hoverh2");
			$(this).children("span.new").addClass("hoverSpan");
			$(this).next("dl").addClass("hoverdl");
		},
			function () {
			$(this).removeClass("hoverh2");	
			$(this).children("span.new").removeClass("hoverSpan");
			$(this).next("dl").removeClass("hoverdl");
		}
		); //end hover
			
	}// end if
	
	if($(".newsItems").length > 0){
		$(".newsItems dt").hover(
			function () {
			$(this).addClass("hoverdt");
			$(this).children("span.new").addClass("hovernew");
			$(this).next("dd").addClass("hoverdd");
		},
			function () {
			$(this).removeClass("hoverdt");	
			$(this).children("span.new").removeClass("hovernew");
			$(this).next("dd").removeClass("hoverdd");
		}
		); //end hover
			
	}// end if
	
			// this is to apply styling to the pop-up contacts on the extranet side
	if($("#previousContacts").length > 0){
			$("#pub dl:first").addClass("topDL");
			$("#priv dl:first").addClass("topDL");
			$("#o2o dl:first").addClass("topDL");
	}
	
	if($(".haveYourSay").length > 0){
		$(".expando").hide();
		$("#poll-toggle").click(function () {
		  $(".expando").slideToggle();
		});
	}
	
});

function initDashboard(){
	$('.adminMsgSummary dl:not(:first)').hide("fast"); 
}

function expando(ref){ //to make it work with sIFR in IE - this is called in the sIFR-config file
	$(document).ready(function(){
		var target = document.getElementById(ref);
		var targetDl = target.parentNode.parentNode;
		$(targetDl).next("dl").slideToggle("fast");
	});
}
