/**
 * @version  1.00
 * @updated  2010/04/01
 */



(function ($) {
	var common = window.common = {
		init: function() {
			common.scroll();
			common.hover();
			common.stripe_table();
			common.height();
			common.showcase();
		},


		scroll: function() {
			var evnt = 0;
			
			jQuery.fn.extend({
				scrollTo : function(speed) {
					/* hashの取得が出来なければ、処理を中断 */
					if(!$(this)[0].hash || $(this)[0].hash == "#") {
						return false;
					}
					return this.each(function() {
						var targetOffset = $($(this)[0].hash).offset().top - 20;
						$('html,body').animate(
							{scrollTop: targetOffset},
							speed,
							'swing',
							function () {
								evnt = 1;
							}
						);
					});
				}
			});
			
			$('a[href*=#page-top],a.pn').bind('click', function() {
				$(this).scrollTo('normal');
				return false;
			});
			
			var d = document;			
			var clear = function () {
				$('html,body').stop();
				evnt = 0;
			}
			
			if (/Firefox/.test(navigator.userAgent)) {
				d.body.addEventListener('DOMMouseScroll', function () {
					if (evnt == 1) clear();
				}, false);
			}
		},
		
		
		
		hover: function() {
			var preLoad = new Object();
			$('img.hover,input.hover').not("[src*='_hover.']").each(function(){
				var imgSrc = this.src;
				var fType = imgSrc.substring(imgSrc.lastIndexOf('.'));
				var imgName = imgSrc.substr(0, imgSrc.lastIndexOf('.'));
				var imgOver = imgName + '_hover' + fType;
				preLoad[this.src] = new Image();
				preLoad[this.src].src = imgOver;
				$(this).hover(
					function (){
						this.src = imgOver;
					},
					function (){
						this.src = imgSrc;
					}
				);
			});
		},
		
		
		
		stripe_table: function() {
			if ($('table.stripe')) {
				$('table.stripe').each(function(){
					$(this).children('tbody').each(function(){
						$(this).children('tr:even').not('tr.tbl-h2,tr.tbl-h3').each(function(){
							this.className = 'even';
						});
					});
				});
			}
		},
		
		
		
		height: function() {
			if ($('ul.horizon')){
				$('ul.horizon').each(function(){
					var highest = 0;
					
					$(this).children().each(function(){
						var height = $(this).height();
						
						if(height > highest) {
							highest = height;
						}
						
						$(this).children().height(highest);
					});
				});
			}
		},
		
		
		
		showcase: function() {
			if ($('div.showcasebox')) {
				$('div.showcasebox div.elm a').hover(
					function () {
						$(this).parent().css({'background':'#a2cfef'});
					},
					function () {
						$(this).parent().css({'background':'#ffffff'});					
					}
				);
			}
		}
		

	}



	$(function () {
		common.init();
	});
	
})($);