// 'flood' is the global object for flood theme functions
var flood = {};
// Reduce potential conflicts with other scripts on the page
flood.jQuery = jQuery.noConflict(true);
var $flood = flood.jQuery;
// Create a unique object and namespace for theme functions
flood.themeFunctions = {};
// Define a closure
flood.themeFunctions = (function() {
    // When jQuery is used it will be available as $ and jQuery but only inside the closure
    var jQuery = flood.jQuery;
    var $ = jQuery;
	var $flood = jQuery.noConflict();

// ExtraContent functionality 
$flood(document).ready(function () {
	var extraContent =  (function() {
		var ecValue = 20;
		for (i=1;i<=ecValue;i++)
		{
			$flood('#myExtraContent'+i+' script').remove();
			$flood('#myExtraContent'+i).appendTo('#extraContainer'+i);
		}
	})();
});
	

// Function to fade-in parts of a page when the window has finished loading.
// Adjust the fadeIn speeds accordingly. Speeds are specified in milliseconds.		
$flood(window).load(function(){
	$flood('header').delay(0).fadeIn(2000);
	$flood('#bannerWrapper').delay(0).fadeIn(2000);
	$flood('#contentContainer').delay(0).fadeIn(2000);
	$flood('footer').delay(0).fadeIn(2000);
});
	
	
// Function to generate animated drop-down menus and to apply unique class ID's onto each list and list item
$flood(document).ready(function () {
	$flood("#nav>ul>li>ul").hide();
	$flood("#nav li").hover(function(){
	$flood(this).find('ul:first').css({visibility: "visible",display: "none"}).fadeIn(500);
	},function(){
	$flood(this).find('ul:first').fadeOut(500);
	});

	$flood("#nav li").each(function (i) {
		i = i+1;
		$flood(this).addClass("link"+i);
		});
		$flood("#nav ul").each(function (i) {
   		i = i+1;
   		$flood(this).addClass("list"+i);
	});
});

// Function to generate a mega menu with a given set of page links generated by RapidWeaver
$flood(document).ready(function () {
	$flood('#megamenu>ul>li').hover(  
	function () {  
	$flood('ul', this).fadeIn(500); 
	},   
	function () {
	$flood('ul', this).fadeOut(500);          
	}  
	);  
});

// Function to generate date
checkTime();
ct = setInterval(checkTime, 1000);
function checkTime(){
	var d=new Date();
	var weekday=new Array(7);
	weekday[0]="Sunday";
	weekday[1]="Monday";
	weekday[2]="Tuesday";
	weekday[3]="Wednesday";
	weekday[4]="Thursday";
	weekday[5]="Friday";
	weekday[6]="Saturday";
	
	var month=new Array(12);
	month[0]="January";
	month[1]="February";
	month[2]="March";
	month[3]="April";
	month[4]="May";
	month[5]="June";
	month[6]="July";
	month[7]="August";
	month[8]="September";
	month[9]="October";
	month[10]="November";
	month[11]="December";
	
	var y=d.getFullYear();
	
	$flood('#dateFunction').html(weekday[d.getDay()] +"&nbsp;" +d.getDate() +"&nbsp;" +month[d.getMonth()] +"&nbsp;" +y +"<br /><br />")
}

// Function to generate date and time
checkDateTime();
ct = setInterval(checkTime, 1000);
function checkDateTime(){
	var d=new Date();
	var weekday=new Array(7);
	weekday[0]="Sunday";
	weekday[1]="Monday";
	weekday[2]="Tuesday";
	weekday[3]="Wednesday";
	weekday[4]="Thursday";
	weekday[5]="Friday";
	weekday[6]="Saturday";
	
	var month=new Array(12);
	month[0]="January";
	month[1]="February";
	month[2]="March";
	month[3]="April";
	month[4]="May";
	month[5]="June";
	month[6]="July";
	month[7]="August";
	month[8]="September";
	month[9]="October";
	month[10]="November";
	month[11]="December";
	
	var y=d.getFullYear();
	var h=d.getHours();
	var m=d.getMinutes();
	var s=d.getSeconds();
		if (h<10){
		h="0"+h
	}else if (h>12){
		h-=12;
		if (h<10){
			h="0"+h
		}
	}
	if(m<10){
		m="0"+m
	}
	if(s<10){
		s="0"+ s
	}
	$flood('#dateTimeFunction').html(weekday[d.getDay()] +"&nbsp;" +d.getDate() +"&nbsp;" +month[d.getMonth()] +"&nbsp;" +y +"<br />" +h +":" +m +":" +s +"<br /><br />")
}
	
})(flood.themeFunctions);
