/* ########################################################################### *
/* ***** ECLIPSE GROUP  ****************************************************** *
/* ########################################################################### *
 * ##### DOCUMENT NAME:  global.js
 * ##### DOCUMENT INFO:
 * ##### Original v1.0: 15/11/07 (Eclipse Group)
/* ########################################################################### *

/* ########################################################################### *
/* ***** INDEX *************************************************************** *
/* ########################################################################### *
/* ##### INITIALISATION
/* ##### TOOL TIPS
/* ##### TABLES
/* ##### BUTTONS
/* ##### NAVIGATION
/* ##### POPUP OVERLAYS / MODAL WINDOWS
/* ##### ACCESSIBILITY
/* ##### PATTERN BEHAVIOUR
/* ##### GLOBAL FUNCTIONS
/* ########################################################################### */

/* ########################################################################### *
/* ##### INITIALISATION
/* ########################################################################### */

$(document).ready(ecl_init_global);

function ecl_init_global()
{
	
	// Tables
	ecl_init_tables();
	
	// Buttons
	ecl_init_buttons();
	
	// Misc Pattern Behaviour
	ecl_init_patternBehaviour();

	// Accessibility: Font Size Buttons
	ecl_accessibility_fontSize();
	
	// Navigation
	ecl_init_nav();		

}





////////////
// TABLES //
////////////
function ecl_init_tables()
{
	ecl_init_tableAltRows();
	ecl_init_tableHighlightRows();
}

// Table methods
function ecl_init_tableAltRows()
{
	var nodes = $("table.altRows tbody tr");
	for (var i = 0; i < nodes.length; i += 2)
	{
		$(nodes[i]).addClass("odd");
	}
}

function ecl_init_tableHighlightRows()
{
	$("table.highlightRowHover tr").hover(hoverOver, hoverOut); 
}





////////////////////////
// BUTTONS //
////////////////////////
function ecl_init_buttons(scope)
{
	var nodes = $("button").add("a.button");
	
	// Handle with passed scopeNode parameter
	if (typeof scope != "undefined" || scope != null) 
	{
		nodes = $(scope + " button");
	}
	
	// For Positive, Negative & Neutral button types
	for (var i = 0; i < nodes.length; i++)
	{
		if ($(nodes[i]).is("button"))
		{
			$(nodes[i]).hover(hoverOver, hoverOut);
		} else if ($(nodes[i]).is("a")) {
			$(nodes[i]).hover(ecl_hoverOver_button, ecl_hoverOut_button);
		}

		if ($(nodes[i]).hasClass("positive"))
		{
			// Check if a positive / green button and add hover functionality
			$(nodes[i]).hover(function(){
				$(this).addClass("positiveHover");
			},function(){
				$(this).removeClass("positiveHover");
			});			
		} else if ($(nodes[i]).hasClass("negative")) {
			// For negative / blue buttons
			$(nodes[i]).hover(function(){
				$(this).addClass("negativeHover");
			},function(){
				$(this).removeClass("negativeHover");
			});
		} else if ($(nodes[i]).hasClass("neutral")) {
			// For negative / blue buttons
			$(nodes[i]).hover(function(){
				$(this).addClass("neutralHover");
			},function(){
				$(this).removeClass("neutralHover");
			});
		}
	}
}

function ecl_hoverOver_button()
{
	$(this).addClass("buttonHover");
}

function ecl_hoverOut_button()
{
	$(this).removeClass("buttonHover");	
}

	

////////////////////////////////////
// NAVIGATION                     //
////////////////////////////////////

function ecl_init_nav()
{
	// SuperFish Navigation
	$(".nav-primary ul.nav-superfish")
		.superfish({
			animation : { height:"show" }
		})
		.find(">li:has(ul)")
			.mouseover(function(){
				$("ul", this).bgIframe({opacity:true});
			})
			.find("a")
				.focus(function(){
					$("ul", $(".nav>li:has(ul)")).bgIframe({opacity:true});
				});
	
	$(".nav-primary ul.nav-superfish li").hover(ecl_superfishHoverOver, ecl_superfishHoverOut);
	$(".nav-primary ul.nav-superfish li.current").next("li").children("a:first").addClass("bgOffActive");
}

function ecl_superfishHoverOver()
{

	$(this).next("li").children("a:first").addClass("bgOff");
	
	if ($(this).hasClass("sfHover"))
	{
		if ($(this).hasClass("last"))
		{
			$(this).addClass("lastHover")
		} else if ($(this).hasClass("first")) {
			$(this).addClass("firstHover")
		}
	}
}
 
function ecl_superfishHoverOut()
{
	$(this).next("li").children("a:first").removeClass("bgOff");	
	
	if ($(this).hasClass("sfHover"))
	{
		if ($(this).hasClass("last"))
		{
			$(this).removeClass("lastHover")
		} else if ($(this).hasClass("first")) {
			$(this).removeClass("firstHover")
		}
	}
}
 




////////////////////////
// ACCESSIBILITY      //
////////////////////////

// Font Size Buttons
function ecl_accessibility_fontSize()
{
	if ($(".fontSize").length > 0)
	{
		$(".fontSize").html('<a href="#" class="increase" alt="Increase font size" title="Increase font size"><span class="increaseIcon"></span></a><a href="#" class="decrease" alt="Decrease font size" title="Decrease font size"><span class="decreaseIcon"></span></a>');
		$(".fontSize .increase").click($.FontSizer.IncreaseSize);
		$(".fontSize .decrease").click($.FontSizer.DecreaseSize);
	
		var options = { min: 80, max: 130};
		$.FontSizer.Init(options);
	}
}


////////////////////////
// PATTERN BEHAVIOUR  //
////////////////////////
function ecl_init_patternBehaviour()
{
	/* Generic */
	ecl_init_expandoCollapso();
	ecl_init_globalSearch();
}

// Expando Collapso
function ecl_init_expandoCollapso()
{
	$(".js_expandoCollapso dd").hide();
	$(".js_expandoCollapso dt").hover(hoverOver, hoverOut);
	$(".js_expandoCollapso dt").click(function() 
			{
				$(this).next().toggle();
				if ($(this).hasClass("active"))
				{
					$(this).removeClass("active");
				} else {
					$(this).addClass("active");
				}
			});
}

function ecl_init_globalSearch()
{
	$(".header .globalSearch input").focus(function() {  $(this).select(); } );
}




////////////////////////
// GLOBAL FUNCTIONS   //
////////////////////////

function toggleHover()
{
	$(this).toggleClass("hover");
}

function hoverOver()
{
	$(this).addClass("hover");
}

function hoverOut()
{
	$(this).removeClass("hover");
}


