/*
* lm 1.1
* Automatic functions for webpages
* Require:
*  jquery.js
*  frame.css
*  content_font.css
*
* Copyright: (c) 2007 ludicmind.net
**************************************/

// Initialization
$.lm = {
	init: function() {
		for (func in $.lm) {
			if ($.lm[func].init)
				$.lm[func].init();
		}
	}
};

$(document).ready(function(){
	$.lm.init();
	$('ul.socksList').each(function(){
		$(this).addClassFc(6);
	});
	$('ul.socksList2').each(function(){
		$(this).addClassFc(4);
	});
	$('div.projectListBlock div.parallelBlockA08:nth-child(odd)').addClass("odd");
	$('#imageboxClose').click(function(){
		window.close();
	});
});


// Open Window
$.lm.openWin = {
	openWindow: function(url){
		h = Math.floor(Math.random()*3);
		var sh=parseInt(screen.availHeight); // スクリーン表示縦幅の取得
		var topFull=sh-380-10; // 表示可能最大縦幅=スクリーン表示縦幅-ウィンドウ縦幅-位置調整
		var topPos=topFull/h; // ウィンドウ縦位置=表示可能最大縦幅/乱数
		w = Math.floor(Math.random()*3);
		var sw=parseInt(screen.availWidth); // スクリーン表示幅の取得
		var leftFull=sw-420-10; // 表示可能最大横幅=スクリーン表示幅-ウィンドウ幅-位置調整
		var leftPos=leftFull/w; // ウィンドウ横位置=表示可能最大横幅/乱数
		var wid=window.open(url, "", "menubar=no, toolbar=no, directories=no, location=no, status=no, scrollbars=no, resizable=yes, width=420, height=380, top="+topPos+" ,left="+leftPos+"");
		
	}
};


// 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");
		}
	}
};


// Add "nolink" class to Heading without a[href]
$.lm.noLink = {
	init: function() {
		$("a:not([href])").parent("h2").addClass("nolink");
		$("a:not([href])").parent("h3").addClass("nolink");
		$("a:not([href])").parent("h4").addClass("nolink");
	}
};


// Mouse hover on input[type='image']
$.lm.inputHover = {

	init: function() {
		$('input[type="image"]')
			.bind('mouseover', this.enter)
			.bind('mouseout', this.exit)
			.each(this.preload);
	},

	preload: function() {
		this.preloaded = new Image;
		this.preloaded.src = this.src.replace(/^(.+)(\.[a-z]+)$/, "$1_o$2");
	},

	enter: function() {
		this.src = this.src.replace(/^(.+)(\.[a-z]+)$/, "$1_o$2");
	},

	exit: function() {
		this.src = this.src.replace(/^(.+)_o(\.[a-z]+)$/, "$1$2");
	}
};


// Navigation Submenu
$.lm.submenu = {
	init: function() {
		var toggle = function(direction, display) {
			return function() {
				var self = this;
				var ul = $("ul", this);
				if( ul.css("display") == display && !self["block" + direction] ) {
					self["block" + direction] = true;
					ul["slide" + direction]("fast", function() {
						self["block" + direction] = false;
					});
				}
			};
		}
		$("li.hasSubmenu").hover(toggle("Down", "none"), toggle("Up", "block"));
		$("li.hasSubmenu ul").hide();
	}
};


// Replace "abbr" with "acronym" (only IE6)
$.lm.changeAbbr = {
	init: function() {
		var ua = window.navigator;
		if (ua.appName == "Microsoft Internet Explorer" && ua.appVersion.indexOf("MSIE 7.0") == -1) {
			var abbrs = document.getElementsByTagName('abbr');
			for (var i = 0; i < abbrs.length; i++) {
				var oldAbbr = abbrs.item(i);
				var newAbbr = document.createElement('abbr');
				newAbbr.title = oldAbbr.title;
				oldAbbr.parentNode.insertBefore(newAbbr, oldAbbr);
				while (oldAbbr.nextSibling.nodeName != '/ABBR') {
					newAbbr.appendChild(oldAbbr.nextSibling);
				}
				oldAbbr.parentNode.removeChild(oldAbbr.nextSibling);
				oldAbbr.parentNode.removeChild(oldAbbr);
			}
		}
	}
};


// Menu List Add Class "first" and "last"
(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 "Odd" and "Even"
(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);

// Menu List Add Class "firstCol"
(function($) {
	jQuery.fn.addClassFc = function(colNum) {
		return this.children("li").each(function(i){
			if (i % colNum == 0){
				$(this).addClass("firstCol");
			}
		});
	};
})(jQuery);


