function overlayRedirect() {
	$("#closelink").click( function() {
		document.hashVars = [];
		document.getVars = [];
		var urlHalves = String(document.location).split('#');
	    if(urlHalves[0]){
			var getURLHalves = urlHalves[0].split('?');
			if (getURLHalves[1]) {
				var urlVars = getURLHalves[1].split('&');
				for(var i=0; i<=(urlVars.length); i++){
					if(urlVars[i]){
						var urlVarPair = urlVars[i].split('=');
						document.getVars[urlVarPair[0]] = urlVarPair[1];
	                 }
				}
	        }
	    }
		if(urlHalves[1]){
			var urlVars = urlHalves[1].split('&');
			for(var i=0; i<=(urlVars.length); i++){
				if(urlVars[i]){
					var urlVarPair = urlVars[i].split('=');
					document.hashVars[urlVarPair[0]] = urlVarPair[1];
				}
			}
		}
		referrerURL = document.referrer;
		if(typeof document.getVars['ref'] != 'undefined') {
			switch(document.getVars['ref'])
			{
				case 'section-audiofun':
				  window.location = 'index.php#section-audiofun';
				  break;
				case 'section-customizeit':
				  window.location = 'index.php#section-customizeit';
				  break;
				case 'section-directorschair':
				  window.location = 'index.php#section-directorschair';
				  break;
				case 'section-howtos':
				  window.location = 'index.php#section-howtos';
				  break;
				case 'section-coloringpages':
				  window.location = 'printables.php#section-coloringpages';
				  break;
				case 'section-pencilpuzzles':
				  window.location = 'printables.php#section-pencilpuzzles';
				  break;
				case 'section-designstudio':
				  window.location = 'printables.php#section-designstudio';
				  break;shrinkydinks
				case 'section-shrinkydinks':
				  window.location = 'printables.php#section-shrinkydinks';
				  break;  
				case 'section-wallpapers':
				  window.location = 'downloads.php#section-wallpapers';
				  break; 
				case 'section-screensavers':
				  window.location = 'downloads.php#section-screensavers';
				  break; 
				case 'section-buddyicons':
				  window.location = 'downloads.php#section-buddyicons';
				  break; 
				default:
				  window.location = 'index.php';
			}			
		} else if((referrerURL == location.href) || (referrerURL == '') || (referrerURL == 'null') || (typeof referrerURL == 'undefined')) {
			window.location = 'index.php';
		} else {
			window.location = document.referrer;
		}
		return false;
	});
}

function flashembed() {
	var flashversion = '9.0.115';
	if(typeof(swfobject)=='object' && swfobject.hasFlashPlayerVersion(flashversion)){
		$('head').append("<style type='text/css'>.flash-error {display: none;}</style>");
		var embedflash = true;
	} else {
		var embedflash = false;
	}
	if (embedflash) {
		activityswf();	
	}	
}

$(document).ready(function() {	
	overlayRedirect();
});
