/*
 * general.js - for cyclops.co.jp
 * @requires jQuery v1.2.1
 *
 * Copyright (c) 2007 cyclops.co.,ltd.
 * $Date: 2007.11.16
 *
 */

/**
 *	Initialization
 */
$.cyc = {
	init: function() {
		for (module in $.cyc) {
			if ($.cyc[module].init){
				$.cyc[module].init();
			}
		}
	}
};

$(function(){
	$.cyc.init();
});


/**
 *	externalLinks (add target _blank)
 */
$.cyc.externalLinks = {
	init: function() {
		$('a[@rel=external]').attr("target","_blank");
	}
};


/**
 *	pagetop
 */
 $.cyc.pagetop = {
	init: function() {
		$('a[href*=#]').click(function() {
			if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
			&& location.hostname == this.hostname) {
			  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}, 1000);
			   return false;
			  }
			}
		});	
	 }
 };

//swap img
$.cyc.swap = {
	init: function() {
		$('img.swap')
			.bind('mouseover', this.enter)
			.bind('mouseout', this.exit)
			.each(this.preload);
		$('input[@type=image].swap')
			.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");
	}
};




/**
 *	#main-navigation li dropdown
 */
$.cyc.mainnavidropdown = {
	init: function(){
$("#main-navigation li").each(function(i){
	$("#m-"+i).hover(function(){
	$("#m-" +i+ " .dropdown").css("display","block");
	},function(){
	$("#m-"+i+" .dropdown").css("display","none");
	}
	)
})
}
};



