// JavaScript Document
//replace pngs with gifs in IE6
$(function(){
	var br = navigator.appName;
	if (typeof document.body.style.maxHeight == "undefined" && br == "Microsoft Internet Explorer") {
		var imSrc, newImg;
		$.each($("img"), function(){
			imSrc = $(this).attr("src");
			if(imSrc.substr(imSrc.length-4,4) == ".png"){
				newImg = imSrc.replace(".png",".gif");
				$(this).attr("src", newImg);
			}
		});
		var bImUrl, newBIm;
		$.each($("a, div, body, li, h1, h2, h3, html"), function(){
			bImUrl = $(this).css("background-image");
			if(bImUrl.substr(bImUrl.length-6,4) == ".png"){
				newBIm = bImUrl.replace(".png",".gif");
				$(this).css("background-image", newBIm);
			}
		});
	}
});

//preload images
$(function(){
	simplePreload("/Images/newsFlash-off.png", "/Images/newsFlash-over.png")
});
function simplePreload(){ 
	var args = simplePreload.arguments;
	document.imageArray = new Array(args.length);
	for(var i=0; i<args.length; i++){
		document.imageArray[i] = new Image;
		document.imageArray[i].src = args[i];
	}
}

//create flashing 'NewsFlash' button
$(function(){
	var flashInt = setInterval("flash()", 1000);
	$("td.newsFlash a").hover(
		function(){
			clearInterval(flashInt);
			$("td.newsFlash a img").attr("src", "/Images/newsFlash-over.png");	
		},
		function(){
			$("td.newsFlash a img").attr("src", "/Images/newsFlash.png");	
			flashInt = setInterval("flash()", 1000);
		}
	);
});	
function flash(){
	if($("td.newsFlash a img").attr("src") == "/Images/newsFlash.png"){
		$("td.newsFlash a img").attr("src", "/Images/newsFlash-off.png");	
	}else{
		$("td.newsFlash a img").attr("src", "/Images/newsFlash.png");	
	}
}

//header image rotate
$(function(){
	$("#headerRotate").fadeIn(2000);
	$("#headerRotate").cycle({
    	fx: 'fade', 
		pause:2,
		speed:2000,
		timeout:8000
	});	
});

