/*
 * general.js - for hello.ecc.ac.jp
 * @requires jQuery v1.2.3
 *
 * Copyright (c) 2008 cyclops.co.,ltd.
 * $Date: 2008.5.9
 *
 */


 
/**
 *	Initialization
 */
$(function(){
	$.cyc.init();
});

$(window).load(function () {
	$.cyc.load();
 });

/**
 *	Initialization
 */

$.cyc = {
	init: function() {
		for (module in $.cyc) {
			if ($.cyc[module].init){
				$.cyc[module].init();
			}
		}
	},
	load:function(){
		for (module in $.cyc) {
			if ($.cyc[module].load){
				$.cyc[module].load();
			}
		}
	}
};





/**
 *	externalLinks (add target _blank)
 */
$.cyc.externalLinks = {
	init: function() {
		$('a[@rel=external]').attr("target","_blank").filter(':not(:has("img"))').addClass("external");
	}
};


/**
 *	swap img
 */
$.cyc.swap = {
	init: function() {
		$('img.swap')
			.bind('mouseover', this.enter)
			.bind('mouseout', this.exit)
			.each(this.preload);
		$('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");
	}
};



/**
 *	pagetop
 */
 $.cyc.pagetop = {
	init: function() {
		$('a[href*=#]').click(function() {
			if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')&& location.hostname == this.hostname.replace(/:.*$/,'')) {
			  var $target = $(this.hash);
			  $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
			  if ($target.length) {
				var targetOffset = $target.offset().top;
				$('html,body').animate({scrollTop: targetOffset}, 500);
			   return false;
			  }
			}
		});	
	 }
 };


/**
 *	table-zebra
 */
$.cyc.zebra = {
	init:function(){
		$("tr","table.zebra tbody").removeClass("odd").filter(':odd').addClass("odd");
	}
};


/**
 *	table-trHover
 */
$.cyc.trHover = {
	init:function(){
		//hover
		$("tr","table.trhover tbody").hover(function() {
			$(this).addClass("hover");
		},
		function() {
		$(this).removeClass("hover");
		} ); 
	}
};


/**
 *	lightbox
 */

$.cyc.lightbox = {
	init:function(){
		$('a[@rel=lightbox-work]').lightBox();
		$('a[@rel=lightbox-practice1]').lightBox();
		$('a[@rel=lightbox-practice2]').lightBox();
		$('a[@rel=lightbox-skill1]').lightBox();
		$('a[@rel=lightbox-skill2]').lightBox();
		$('a[@rel=lightbox-present]').lightBox();
	}
};
