/*
* lm 1.2.1
* Automatic functions for webpages
* Require:
*  jquery.js
*  frame.css
*  content_font.css
*
* Copyright: (c) 2008 ludicmind.net
**************************************/

// Initialization
$.lm = {
	init: function() {
		for (func in $.lm) {
			if ($.lm[func].init)
				$.lm[func].init();
		}
	}
};

$(document).ready(function(){
	$.lm.init();
});


// Image hover
$.lm.hover = {
	init: function() {
		$('.hover')
			.bind('mouseover', this.enter)
			.bind('mouseout', this.exit)
			.bind('focus', this.enter)
			.bind('blur', this.exit)
			.each(this.preload);
	},

	preload: function() {
		this.preloaded = new Image;
		this.preloaded.src = this.src.replace(/^(.+)(\.[a-z]+)$/, "$1_o$2");
	},

	enter: function() {
		if (!this.src.match(/^(.+)_o(\.[a-z]+)$/) && !this.src.match(/^(.+)_a(\.[a-z]+)$/)){
			this.src = this.src.replace(/^(.+)(\.[a-z]+)$/, "$1_o$2");
		}
	},

	exit: function() {
		if (this.src.match(/^(.+)_o(\.[a-z]+)$/)){
			this.src = this.src.replace(/^(.+)_o(\.[a-z]+)$/, "$1$2");
		} else {
			this.src = this.src.replace(/^(.+)_a(\.[a-z]+)$/, "$1$2");
		}
	}
};

// Add "first-child" class to all elements in #content
$.lm.firstChild = {
	init: function() {
		var ua = window.navigator;
		if (ua.appName == "Microsoft Internet Explorer" && ua.appVersion.indexOf("MSIE 7.0") == -1) {
			$("#content *:first-child").addClass("first-child");
		}
	}
};


// Menu List Add Class "first" and "last" - use to ul
(function($) {
	jQuery.fn.addClassFL = function(colNum) {
		return this.children("li").each(function(i){
			if (i % colNum == 0){
				$(this).addClass("first");
			}
			if (i % colNum == colNum - 1){
				$(this).addClass("last");
			}
		});
	};
})(jQuery);


// Menu List Add Class "first" and "last" - use to div
(function($) {
	jQuery.fn.addDivClassFL = function(colNum) {
		return this.children("div").each(function(i){
			if (i % colNum == 0){
				$(this).addClass("first");
			}
			if (i % colNum == colNum - 1){
				$(this).addClass("last");
			}
		});
	};
})(jQuery);


// Menu List Add Class "Odd" and "Even" - use to ul
(function($) {
	jQuery.fn.addClassOE = function() {
		return this.children("li").each(function(i){
			if (i % 2 == 0){
				$(this).addClass("odd");
			}
			if (i % 2 == 1){
				$(this).addClass("even");
			}
		});
	};
})(jQuery);

// Accordion Icon
$.lm.accordionIcon = {
	init: function() {
		$("div#accordion h3").bind('click', this.change);
	},
	
	change: function() {
		$("div#accordion h3 img").attr("src", "shared/img/icon_accordion_close.gif");
		if($(this).next("div").css("display") == "none") {
			$(this).children("img").attr("src", "shared/img/icon_accordion_open.gif");
		}
	}
};

// Utility Link
$.lm.subPage = {
	init: function() {
		$("div#topFooter a")
			.bind("click", this.openWindow)
			.bind("keypress", this.openWindow);
	},
	
	openWindow: function() {
		window.open($(this).attr("href"), "subPage", "width=1024, menubar=no, toolbar=no, scrollbars=yes");
		return false;
	}
};