/*
* lm 1.3
* 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();
	$("div.fBlockA01 p:eq(0)").css("margin-top", "0");
	$("div.newsBlockA01 div.pBlockA03:odd").addClass("even");
	$("div.newsBlockA01 div.pBlockA04:odd").addClass("even");
	$("div.newsBlockA01 div.pBlockA04:eq(1)").css("margin-top", "0");
	
	var body = document.getElementsByTagName('body')[0];
	//alert(body.className);	
	if( body.className == "") {
		$("table.mapTableA01").after('<div class="buttonBlockA02"><a href="/restaurant/access.html?act=print"><img id="print" src="img/access/btn_print_01.gif" alt="印刷する" width="141" height="42" /></a></div>');
	}
//	$("body.hwa table.mapTableA01").after('<div class="buttonBlockA02"><a href="/hwa/access.html?act=print"><img id="print" src="img/access/btn_print_01.gif" alt="印刷する" width="141" height="42" /></a></div>');
	$("body#nagoya table.mapTableA01").after('<div class="buttonBlockA02"><a href="/hwa/access.html?act=print"><img id="print" src="img/access/btn_print_01.gif" alt="印刷する" width="141" height="42" /></a></div>');
	$("body#kinshicho table.mapTableA01").after('<div class="buttonBlockA02"><a href="/hwa/kinshicho_access.html?act=print"><img id="print" src="img/access/btn_print_01.gif" alt="印刷する" width="141" height="42" /></a></div>');
	$("body.gon table.mapTableA01").after('<div class="buttonBlockA02"><a href="/gon/access.html?act=print"><img id="print" src="img/access/btn_print_01.gif" alt="印刷する" width="141" height="42" /></a></div>');
	$("#print").click(function(){
		print();
	});
});


// 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");
		}
	}
};


// 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");
	}
};


// 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);

