$(document).ready(function(){

	// handles rollover navigation
	$('#nav img').bind('mouseover', function(){
		if (this.src.indexOf('-over') == -1) {
			this.src = this.src.replace(/(.*)\.(jpg|gif|png)$/i, "$1-over.$2");
			$(this).bind('mouseout', function(){
				this.src = this.src.replace(/(.*)-over\.(jpg|gif|png)$/i, "$1.$2");
			});
		}
	});
	
	
	$("a#newsToggle").click(function(event){
		if (this.firstChild.src.indexOf('-over') == -1)
			this.firstChild.src = this.firstChild.src.replace(/(.*)\.(jpg|gif|png)$/i, "$1-over.$2");
		$('#boxNewsContent').removeClass("showCal").addClass("showNews").hide().slideDown('normal');
		this.parentNode.nextSibling.firstChild.firstChild.src = this.parentNode.nextSibling.firstChild.firstChild.src.replace(/(.*)-over\.(jpg|gif|png)$/i, "$1.$2")
		event.preventDefault();
	});
		
		
	$("a#calToggle").click(function(event){
		if (this.firstChild.src.indexOf('-over') == -1)
			this.firstChild.src = this.firstChild.src.replace(/(.*)\.(jpg|gif|png)$/i, "$1-over.$2");
		$('#boxNewsContent').removeClass("showNews").addClass("showCal").hide().slideDown('normal');
		this.parentNode.previousSibling.firstChild.firstChild.src = this.parentNode.previousSibling.firstChild.firstChild.src.replace(/(.*)-over\.(jpg|gif|png)$/i, "$1.$2")
		event.preventDefault();
	});
	
	$("#features a, a#submitArticle, .promoBox a").click(function(){
	
		var d = document;
	
		var overlay = document.createElement('div');
		overlay.id = 'igx_overlay';
				
		var iframe = document.createElement('iframe');
		iframe.src = this.href;
		
		var closeOverlay = document.createElement('a');
		closeOverlay.appendChild(document.createTextNode('Close'));
		closeOverlay.id = 'close_overlay';
		closeOverlay.onclick = function(){
			document.body.removeChild(overlay);
			$('html').removeClass('overlayed');
		}
		
		
		overlay.appendChild(iframe);
		overlay.appendChild(closeOverlay);
		document.body.appendChild(overlay);
		
		overlay.style.height = d.documentElement.scrollHeight+"px";
		iframe.style.top = (d.documentElement.scrollTop||d.body.scrollTop)+"px";
		iframe.style.height = (window.innerHeight||d.documentElement.clientHeight)+"px";
		closeOverlay.style.top = (d.documentElement.scrollTop||d.body.scrollTop)+"px";
		
		
		// iframe.style.bottom = 0;
		// closeOverlay.style.top=(d.documentElement.scrollTop||d.body.scrollTop)+"px";
				
		$('html').addClass('overlayed');
		// location.href = '#';
		
		return false;
	
	});
	
	// submits RSS feed dropdown on change.
	document.getElementById('rssFeeds').onchange = function(){ this.parentNode.submit(); };
	

	/* CSS is better, no? 
	
	$('#header .quickLinks').bind('mouseover', function(){
		clearTimeout(quickLinksTimer);
		$('#header .quickLinks ul').show();
	});
	
	$('#header .quickLinks').bind('mouseout', function(){
		quickLinksTimer = setTimeout(function(){
			$('#header .quickLinks ul').hide();
		}, 250);	
	}); */
				
});