/*
common.js
REQUIRES: jquery,js
Site URI: 
Description: ミューフル
Since: 2009-12-07
Author: Tooru Ehara
*/

/*jQuery.noConflict();*/


// *************************************************
// ページの読み込み時に起動
// *************************************************

$(document).ready(function(){
	setPullDownMenu();
	setRollOver();
	setStripedTable();
});



// *************************************************
// 汎用関・E
// *************************************************


// eventSetter
var isIE = isIE = (document.documentElement.getAttribute('style') == document.documentElement.style);

function eventSetter(obj,eventType,func){
	if(isIE) {
		obj.setAttribute(eventType,new Function(func));
	} else {
		obj.setAttribute(eventType,func);
	}
}


// open new window
function newWindow(uri,width,height){
	var myWindow = window.open(uri, 'newWindow', 'resizable=yes,scrollbars=yes,status=0,width='+width+',height='+height);
	if (myWindow.focus!=null) {
		myWindow.focus();
	}
}


// print window
function printWindow(){
	if(document.getElementById || document.layers){
		window.print();
	}
}


// Ajax recover UTF-8 (for Safari)
function recover_utf8(text){
	if(navigator.appVersion.indexOf('KHTML') > -1){
		var esc = escape(text);
		if(esc.indexOf('%u') < 0 && esc.indexOf('%') > -1){
			text = decodeURIComponent(esc);
		}
	}
	return text;
}


// input clear
function inputClear(id,txt){
	if ($(id).value == txt) $(id).value = '';
}

// scroll to top
/*function scrollTop(){
	if('#pagetop'){
		$('#pagetop img').scrollTo( 0, 800, {queue:true} );
	}
}*/

// *************************************************
// 画・E晙璽・・璽弌視
// *************************************************

function setRollOver(){
	var postfix = '_o';
	$('.swap').not('[src*="'+ postfix +'."]').each(function() {
		var img = $(this);
		var src = img.attr('src');
		var src_on = src.substr(0, src.lastIndexOf('.'))
		           + postfix
		           + src.substring(src.lastIndexOf('.'));
		$('<img>').attr('src', src_on);
		img.hover(
			function() {
				img.attr('src', src_on);
			},
			function() {
				img.attr('src', src);
			}
		);
	});
}



// *************************************************
// プ・E瀬Ε鵐瓮縫紂視
// *************************************************

function setPullDownMenu(){
	$('#globalnav li.menu').bind('mouseover', jsddm_open);
	$('#globalnav li.menu ').bind('mouseout',  jsddm_timer);
	
	var timeout			= 500;
	var closetimer	= 0;
	var ddmenuitem	= 0;
	
	function jsddm_open(){
		jsddm_canceltimer();
		jsddm_close();
		ddmenuitem = $(this).find('ul').eq(0).css('display', 'block');
	}

	function jsddm_close(){
		if(ddmenuitem) ddmenuitem.css('display', 'none');
	}
		
	function jsddm_timer(){
		closetimer = window.setTimeout(jsddm_close, timeout);
	}
		
	function jsddm_canceltimer(){
		if(closetimer){
			window.clearTimeout(closetimer);
			closetimer = null;
		}
	}
	document.onclick = jsddm_close;
}



// *************************************************
// テーブ・E鬟好肇薀ぅ弉・
// *************************************************

function setStripedTable(){
	$('.stripe tr:even').addClass('even');
	$('.stripe tr:odd').addClass('odd');
}


