/* 

	GLOBAL JAVASCRIPT INCLUDE FUNCTIONS
	AUTHOR:	Marcus Ellis
	DATE:	26 May 2010
	
*/


/*
// Login Widget Inclusion
function incLogin() {
	var str = '<iframe id="iflogin" src="/cafe.cfm?act=member.showlogin&spanid=loginform" frameborder="0" width="0" height="0"></iframe>';
		str += '<span id="loginform">&nbsp;</span>';	
	document.write(str);
}


// Add Class to Module Pages
function adjustModule() {
	if (!document.getElementById("maincontenttable")) return false;
	if (document.getElementById("maincontentsubcell")) return false;
	
	mainContent = document.getElementById("maincontenttable");
	mainContent.className = "module";
}


// Manipulate Load event (LEGACY)
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}
*/



/* Creative Services jQuery Plugins
-------------------------------------------------*/
(function ($) {


	// Adjust Module Function
	// Adds a class to the main table
	$.fn.adjustModule = function(){
		if ($('#maincontenttable').length != 0 && $('#maincontentsubcell').length == 0) {
			if ($('#content').length != 0) {
				$('#maincontenttable').addClass('m360');
			} else {
				$('#maincontenttable').addClass('module');
			}
		}
	};
	
	// Clickable Logo
	// Adds invisible button over logo in banner
	$.fn.clickableLogo = function(text){	
		// Add invisible button on top of logo
		var str = '<div id="logo-click"><h1>' + text + '</h1></div>';
		$('#structuraltable').after(str);
		
		// Add hyperlink to invisible button
		$("#logo-click h1").click(function() {
			window.location = "/index.cfm";
		});
	};


	// Login Widget Include Function
	// Adds iframe to cafe.cfm, which in turn replaces the contents of the loginform element
	$.fn.incLogin = function(){
		var str = '<iframe id="iflogin" src="/cafe.cfm?act=member.showlogin&spanid=loginform" frameborder="0" width="0" height="0"></iframe>';
		return $('#loginform').after(str);
	};


	// Login Widget Include Function
	// Adds iframe to cafe.cfm, which in turn replaces the contents of the loginform element
	$.fn.inc360calendar = function(assnnbr){
		var str = '<iframe id="if360cal" src="/associations/'+ assnnbr +'/cafe/widget-360calendar.cfm?container=calendar360" frameborder="0" width="800" height="600"></iframe>';
		return $('#calendar360').after(str);
	};


	// Nav-left Fix Function
	// Adds classes to left nav <li> elements, This JS fixes the misalignment of the hover state if an image is taller than 32px
	$.fn.fixNavleft = function(){
		var i = 0;
		return $('#navleft > li').each(function () {
			$(this).addClass("nav-left-sub_"+i);
			i++;
		});
	};


	// Sponsor Rotation Function
	// Takes a <ul> with the id of "sponsors" and turns it into a simple, random slideshow
	$.fn.sponsorBox = function(){
		// Get height of tallest image
		var height = 0;
		$('#sponsors').children().each(function(){
			var h = $(this).children('a').children('img').height() || $(this).children('img').height() || 100;
			if (height < h) {
				height = h;
			}
		});
		
		// Call "Cycle" plugin
		return $('#sponsors').cycle({
			fx: 'fade',
			random: true,
			timeout: 6000
		}).addClass('imageRotation').attr('style', function(){
			return 'height:'+ height +'px';
		});
	};


})(jQuery);


var j = jQuery.noConflict();
j(document).ready(function($){

	
	$().adjustModule();

});

