// '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 = 10;
		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(1000).fadeIn(2000);
	$flood('#bannerWrapper').delay(1000).fadeIn(2000);
	$flood('#contentContainer').delay(1000).fadeIn(2000);
	$flood('#footer').delay(1000).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 ul").css({display: "none"}); // Opera Fix	
	$flood("#nav li").hover(function(){
	$flood(this).find('ul:first').css({left: "0px",visibility: "visible",display: "none"}).fadeIn(400);
	},function(){
	$flood(this).find('ul:first').fadeOut(400);
	});
	
	$flood("#nav li:has(ul)").find("a:first").css("paddingRight","12px").append("<span class='arrow'></span>");

	$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 block navigation links
$flood(document).ready(function () {
	$flood('#blockNav').prepend($('#navSource > .toolbarList, #navSource > .currentAncestorListItem > .toolbarList').clone());
});


// Function to generate mobile navigation links
$flood(document).ready(function () {
	$flood('#shakeNav').prepend($('#navSource > .toolbarList, #navSource > .currentAncestorListItem > .toolbarList').clone());
	$flood('#shakeNav li a').append("<span class='chevron'>&gt;</span>");
});

// Function to generate split navigation links
$flood(document).ready(function () {
	$flood('#splitNav').prepend($('#navSource > .toolbarList > .currentListItem > .toolbarList, #navSource > .toolbarList > .currentAncestorListItem > .toolbarList').clone());
});

// Function to generate a mega menu with a given set of page links generated by RapidWeaver
$flood(document).ready(function () {
	$flood("#megamenu li:has(ul)").find("a:first").append("<span class='arrow'></span>");
	$flood('#megamenu>ul>li').hover(  
	function () {  
	$flood('ul', this).fadeIn(500); 
	},   
	function () {
	$flood('ul', this).fadeOut(500);          
	}  
	);  
});

// Function to measure the height of the header and set the height accordingly
// This code was added in version 2.0 to stop an ugly jumping effect if the header was set to fade in.
$flood(document).ready(function () {
	var headerHeight = $flood('#header').height(); 
	$flood('#headerWrapper').css({'height':headerHeight});
});

// Function to make the sidebar title toggle the sidebar container
$flood(document).ready(function(){
	$flood("#sidebarTitle").click(function(){
		$flood("#sidebarContent").slideToggle(500);
		return false;
	});
});

// Function to make the navigation title toggle the navigation container
$flood(document).ready(function(){
	$flood("#shakeNavTitle").click(function(){
		$flood("#shakeNav").slideToggle(500);
		return false;
	});
});

// SS3 slideshow settings
$flood(document).ready(function($){
	$flood.SeydoggySlideshow({
		wrapper : '#banner',
		target : '.ss3',
		ecValue : 4,
		bgPosition : 'center center',
		bgRepeat : 'no-repeat'
	});
});

	
})(flood.themeFunctions);

