/*
 * general.js - for www.lontechno.com
 * @requires jQuery v1.2.3
 *
 * Copyright (c) 2008 cyclops.co.,ltd.
 * $Date: 2008.5.23
 *
 */


 
/**
 *	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() {
		$('#footer 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(){
		$('tbody','table.zebra').each(function(){
				$("tr",this).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");
		} ); 
	}
};


/**
 *	fontSizechange
 */
$.cyc.fontSizechange = {
	init:function(){
		var cv = $.cookie('fontSize');
		if(!cv) cv = 1;
		this.setSize(cv);
		$('#font-size-button a').bind('click', function(event){
			var v = $(this).attr("rel");
			$.cyc.fontSizechange.setSize(v);
			return false;
		});
	},
	setSize: function(v) {
		var sizeArr = ['0.9em','1em','1.125em'];
		$("#container").css("font-size",sizeArr[v]);
		$("#header").css("font-size",sizeArr[v]);
		$("#footer").css("font-size",sizeArr[v]);

		$('#font-size-button a').removeClass('current');
		$('#font-size-button a[rel*='+v+']').addClass('current');
		$.cookie('fontSize', null);
		$.cookie('fontSize', v, { expires: 1, path: '/' }); 
	}
};




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





/**
 *	main-navigatoin current
 */
$.cyc.mainNavCurrent = {
	init:function(){
		var bodyID = $('body').attr('id');
		var mnID = '#mn-' + bodyID;
		$(mnID, "#main-navigation").addClass('current');
	}
};





/**
shadowboxの設定
*/

Shadowbox.init({  
	language:   "ja",  
	players:    ["img","flv","html","iframe"]
});  




/**
dropdown
http://bassistance.de/jquery-plugins/jquery-plugin-accordion/

additional option
find:(default:"a")
指定されたセレクタを検索し、navigationFilterで指定された条件に一致する場合はactiveにする
*navigationオプションがtrueの場合のみ有効
*/

$.cyc.accordion = {
	init:function(){
		$('.ac-navigation').accordion({
			active: 1,
			selectedClass: 'ac-active',
			autoheight: false,
			header: 'h3',
			alwaysOpen: false
		});
	}
};


/**
acsubnNavi
*/

$.cyc.acsubNavi1 = {
	init:function(){
		var bodyID = $('body').attr('id');
		
		if(bodyID =='products'){
			$('#ac-subnavi').accordion({
				active: ".current",
				autoheight: true,
				navigation: true,
				header: 'h3',
				alwaysOpen: true,
				navigationFilter:function(){
					return ($(this).parent().parent().parent().hasClass('current')) ? true : false;
				}
			});
		}else if(bodyID == 'topics'){
			$('#ac-subnavi').accordion({
				autoheight: false,
				navigation: true,
				header: 'h3',
				find: 'h3',
				alwaysOpen: true,
				navigationFilter:function(){
					return ($(this).hasClass('current')) ? true : false;
					//return ($('li',  $(this).parent()[0]).hasClass('current')) ? true : false;
				}
			});
		}
	}
};
