/**
 * general.js - for brain-training.net
 * @requires jQuery v1.4.2
 *
 * Copyright (c) 2010 cyclops co.,ltd.
 * $Date: 2010.4.27
 *
 */


/**
 *	Initialization
 */
$(document).ready(function(){
	for (module in cyclops) {
		if (cyclops[module].init){
			cyclops[module].init();
		}
	}
});


var cyclops = {};


/**
 * navigation add class
 */
cyclops.navCurrent = {
	init:function(){
		var loc = location.href;
		loc = (loc.match(/^http:\/\//)) ? (loc.match(/^http:\/\/.+?\/(.+?)$/)||[])[1] :  (h.match(/^\/(.+?)$/)||[])[1];
		if(loc){
			loc = (loc.match(/^(.+?)\/.*$/)) ? (loc.match(/^(.+?)\/.*$/)||[])[1] : loc;
		}else{
			loc = "";
		}
		loc = "/" + loc;
		this.setCurrent('#nav', loc);
	},
	setCurrent:function(elmID, loc){
		$('a', elmID).each(function(){
			if((loc) === $(this).attr('href')){
				$(this).addClass('current');
			}
		});
	}
};

/**
 * externalLink
 *
 * href要素が、httpから始まっているリンクで、
 * 表示ページのドメインと違う場合は外部ウインドウで開く
 */
cyclops.externalLink = {
	init:function(){
		$('a[href^="http"]').filter(':not([href*='+location.hostname+'])').attr("target", "_blank");
	}
};

/**
 * mailSubscribe
 *
 *	メールアドレス入力フォームにメッセージを表示する
 *	submitアクション時にフォームの値がデフォルトと同様の場合は中止する
 */
cyclops.mailSubscribe = {
	mailFormClass:".mail-form",
	mailInputClass:".mail-form-input",
	defaultVal:"メールアドレスを入力してくだい",
	init:function(){
		if(!$(this.mailFormClass).length) return false;
			this.setTextFill();
			this.setSubmitProxy();
	},
	setTextFill:function(){
		var self = this;
		$(this.mailInputClass).each(function(){
			if( $.trim($(this).val()) == '' ) $(this).val(self.defaultVal);
			$(this).focus( function(){
				if( $.trim($(this).val()) == self.defaultVal ) $(this).val(''); 
			});
			$(this).blur( function(){
				if( $.trim($(this).val()) == '' ) $(this).val(self.defaultVal);
			});
		});
	},
	setSubmitProxy:function(){
		var self = this;
		$(this.mailFormClass).submit(function(){
			if( $.trim($(self.mailInputClass, this).val()) == self.defaultVal) return false;
		});
	}
}


function jf_MMWindowOpen51848(ptype){
 window.open("about:blank","MMSUB","width=500,height=200,scrollbars=yes,status=yes,resizable=yes");
 document.frmLMM51848.target = "MMSUB";
 document.frmLMM51848.action = "http://api.lolipop.jp/api/api.php?cmd=mm&type="+ptype;
 document.frmLMM51848.submit();
}


