/*
St. Clair Hospital
General JavaScript file
15 November 2007
Created by: Michael Fulk <michael@walltowall.com>
*/

var flash_duration = 6000;

$(document).ready(function(){
	//Fade blue top navigation when hovered over
	$("#blue_nav").children("ul").children("li").hover(function(){
		$(this).children("a").fadeTo(1, 0.7);
	},function(){
		$(this).children("a").fadeTo(1, 1);
	});
	
	//Fade links with fadelink class on hover
	$("a.fadelink").hover(function(){
		$(this).children("img").fadeTo(1, 0.75);
	},function(){
		$(this).children("img").fadeTo(1, 1);
	});	
	
	// Add 'top' class to the first header tag in each of the left, content, and right columns.
	$("#left-content").children(":header").filter(":first").add(
		$("#content").children(":header").filter(":first").get()
	).add(
		$("#right-content").children(":header").filter(":first").get()
	).addClass("top");
	
	// Append a self-clearing div after each feature
	$("div.feature").append("<div class='clear'></div>");
	
	// Replace all horizontal rules with a custom HR div, maintaining the classes set on them.
	$("hr").wrap('<div class="hr"></div>').each(function(){
		var tmpCls = this.className.split(' ');
		var theDiv = $(this).parent();
		$(tmpCls).each(function(index){
			theDiv.addClass(tmpCls[index]);
		});
	}).remove();
	
	//Hide the hint in the input boxes
	$("input:text").hint();
	
	setTimeout('hideMessages()', flash_duration);
	
	//top bar scrolling quotes
	var sitequotes_parsed = Array();
	var current_quote = {};
	jQuery.each(sitequotes.split('\n'), function(i, val) {
		if(val.slice(0, 1) != '-'){
			if(val.length != 0){
				current_quote = {quote:val};
				sitequotes_parsed.push(current_quote);				
			}
		}else{
			current_quote.attr = val.slice(1);
		}
    });
	if($("#flash_quote img").length == 1){
		$("#flash_quote").empty();
		jQuery.each(sitequotes_parsed, function(i, val){
			$("#flash_quote").html($("#flash_quote").html()+"<div class='quote'>&ldquo;"+val.quote+"&rdquo;<span class='attribution'>"+val.attr+"</span></div>");
		});
		$("#flash_quote div:gt(0)").hide();
		var current_quote = 0;
		var quoteanimation = function(){
			$("#flash_quote div.quote:eq("+current_quote+")").fadeOut('normal');
			current_quote = (current_quote+1)%$("#flash_quote div.quote").length;
			$("#flash_quote div.quote:eq("+current_quote+")").fadeIn('normal');
		}
		var interval = window.setInterval(quoteanimation, 8000);		
	}
});

function hideMessages() {
	$("div.message").filter(function(){
		return $(this).css("display") != "none"; // don't do the fade action if it's already hidden!
	})
	.animate({
		top: '-=75px'
	}, 'normal', 'swing', function(){
		$(this).remove();
	});
}
