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


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


/**
 *	generalNavigation SiteSearch
 */
$.cyc.siteSearch = {
	init:function(){
		var defVal = 'サイト内検索';
		$('#general-search input.field').focus(function(){
			var v = $(this).val();
			if(v==defVal) $(this).val('');
		}).blur(function(){
			var v = $(this).val();
			if(v=='') $(this).val(defVal);
		});
	}
};



/**
 *	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]').lightBox();
	}
};



/**
 *	round corner 
 */
/*
$.cyc.roundCorner = {
	init:function(){
	    if(!$.browser.msie ) {
			$('a.btn').cornerz({radius:3});
			$( '.prev a,.next a','a.btn,.page-navigation').cornerz({radius:3});
		}
	}
};
*/



/**
 *	thumbnails list height fix
 */
 
 $.cyc.thumbnails = {
 	init:function(){
	 	$("li",".thumbnails").css('height','auto');
	 },
	load:function(){
		//list height even
		$(".thumbnails").each(function(){
			var liSize = 0;
			$('li',this).each(function(){
				var h = $(this).height();
				if(liSize < h) liSize = h;
			}).css('height', (liSize) + 'px');
		});
	}
};



/**
 *	guidance/students/
 *	accordion
 *
 *
 *	div class="accordion"
 *	で囲んだ中の
 *	div class="more-entry"
 *	がアコーディオンの対象となる
 
<div class="accordion">
<p>表示部分</p>
<div class="more-entry">
<p>非表示部分</p>
</div>
<p class="more-entry-btn">
<a>もっと見る</a>
</p>
</div>

 *
 *
 */
 
  $.cyc.entryMore = {
 	init:function(){
	 	var bodyid = $('body').attr('id');
		 if(bodyid == 'admission'){
		 	$('.accordion:has(".more-entry")', '#content').each(function(){
			 	var self = $(this);
				$('.more-entry' ,this).hide();
				$('.show-entry-btn a' ,this).toggle(function(){
					$('.show-entry-btn a span' , self).slideDown('3000');
					$('.more-entry' , self).slideDown('3000');
				}, function(){
					$('.show-entry-btn a span' , self).slideUp('1500');
					$('.more-entry' , self).slideUp('1500');
				});/*toggle*/
			});/*each*/
		}else{
			$('.accordion:has(".more-entry")', '#content').each(function(){
				var self = $(this);
				$('.more-entry' ,this).hide();
				$('.more-entry-btn', this).show();
				$('.more-entry-btn a' ,this).toggle(function(){
					$(this).text('閉じる');
					$('.more-entry' , self).slideDown('3000');
				}, function(){
					$(this).text('もっと見る');
					$('.more-entry' , self).slideUp('1500');
				});
			});
		 }
	 }
 };
 
 
 /*
 $.cyc.entryMore = {
 	init:function(){
	 	var bodyid = $('body').attr('id');
		$('.accordion:has(".more-entry")', '#content').each(function(){
			var self = $(this);
			$('p.intro' , this).show();
			$('.more-entry' ,this).hide();
			$('.more-entry-btn', this).show();
			$('.more-entry-btn a' ,this).toggle(function(){
				$(this).text('閉じる');
				$('.more-entry' , self).fadeIn('3000');
				$('p.intro' , self).hide();
			}, function(){
				$(this).text('もっと見る');
				$('.more-entry' , self).fadeOut('1500');
				$('p.intro' , self).show();
			});
		});
	}
 };
 
 */
 
 /**
 *	thumbnails list height fix
 */
 
/*
$.cyc.thumbnails = {
 	init:function(){
		$('#work #comp.thumbnails .unit li').flatHeights();
		$('#work #art.thumbnails li').flatHeights();
	}
};
*/

 /**
 *	行動ナビゲーション
 */
/*
$.cyc.my_kwicks = {
	init:function(){
		$('.kwicks').kwicks({
		duration: 300,   
		max: 171,  
		spacing:  0  
		});
	}
};
*/



