// SPLASH PAGE
// @author Joel Grannas - Creative Director, Schoolwires, Inc. 
// Last updated on 7/26/2011

(function($) {
		  
	$.fn.joelSplash = function(settings){
		//SETTINGS
		var config = {
			'width'					: "960",
			'useCookies'			: "no"
		};
		if (settings){$.extend(config, settings);}
		
		// loop thru each matched element
		return this.each(function(index, list) {
			var element = this;
			$("div.ui-article-description:contains('[SPLASH]')", this).addClass("joel-splash");
			
			if($(".joel-splash").size()){
				//CLEAR ALERT TEXT FROM ANNOUNCEMENT
				strippedAlert = $(".joel-splash").html().replace(/\[SPLASH\]/i, "");
				$(".joel-splash").html(strippedAlert);
				//BUILD STRUCTURE
				var structure = 	"<div id='jg-splash-outer'>" +
									"	<div id='jg-splash-fader'></div>" + 
									"	<div id='jg-splash-container'>" + 
									"		<div id='jg-splash-bg'>" +
									"			<div id='jg-splash-t'></div>" +
									"			<div id='jg-splash-tr'></div>" +
									"			<div id='jg-splash-r'></div>" +
									"			<div id='jg-splash-br'></div>" +
									"			<div id='jg-splash-b'></div>" +
									"			<div id='jg-splash-bl'></div>" +
									"			<div id='jg-splash-l'></div>" +
									"			<div id='jg-splash-tl'></div>" +
									"		</div>" +
									"		<div id='jg-splash-content'></div>" +
									"		<div id='jg-splash-x'></div>" +
									"	</div>" +
									"</div>";
				$("body").append(structure);
				
				//ADD CONTENT
				$("#jg-splash-content").html(strippedAlert);
				
				//POSITIONS THE SPLASH BOX
				var myTop = 40;
				browserWidth = $(window).width(); 
				browserHeight = $(window).height();
				boxHeight = $("#jg-splash-container").height();
				if(boxHeight < browserHeight){
						myTop = (browserHeight-boxHeight)/2;
				}
				var boxWidth = config.width + "px";
				$("#jg-splash-container").css({"width":boxWidth,"margin-top":myTop});
				
				//SHOWS BOX AFTER POSITIONING
				$("#jg-splash-container, #jg-splash-fader").show();
				
				//ACTIVATES CLOSE BUTTON
				$("#jg-splash-x").click(function(){
					 $("#jg-splash-fader").fadeOut("fast");
					 $("#jg-splash-container").fadeOut("fast");
					 $("#jg-splash-x").fadeOut("fast");
				});
			}
			
		});
	};

})(jQuery); 
