/* actionSet
---------------------------------*/
$(function () {
	$.actionSet.areaMainFooter();//キャンペーン情報を表示する
	$.actionSet.imgHover();//ホバー画像を表示
	$.actionSet.smtBannerLoader();//iPhone誘導バナー表示
	$.actionSet.fontChange();	
	$.actionSet.pageScroll();
	$.actionSet.ie6PicCatch();
	$.actionSet.autoHeight();
	$.actionSet.includeFaq();
});

$.actionSet = {
areaMainFooter : function(options) {
	areaMainFooter = function(){
		var href = "/fx/service/campaign/commission.html"
		var src  = "/img/common/banner/cash_back_569x110.gif"
		var alt = "キャンペーン"
		var divBox = "<div class='sectionBlock'><div class='center'>"
		var end    = "</div></div>"
		$("#areaMain").append( divBox + "<a href='"+ href +"'><img src='"+src+"' alt='" + alt + "'/></a>" + end);
	}
},

imgHover: function(options) {
	$("img.imgHover,input.imgHover").each(function() {
		var off = this.src;
		var dot = this.src.lastIndexOf('.');
		var on = this.src.substr(0, dot) +
		'_hover' + this.src.substr(dot, 4);
		$(this).hover(
			function() { this.src = on; },
			function() { this.src = off; });
		$(this).click(function() { this.src = off; });
	});
},

smtBannerLoader : function(options) {
	
	var page1 = $("body").attr("id") ;
	var page2 = $("body").attr("class") ;
	
	var pageId = page1 + page2;
	
	if ( pageId == "homehome" || pageId == "category_fxcategory-home" ){
		var nUa=navigator.userAgent;
		var uaAR=nUa.indexOf('Linux; U; Android ')!=-1;
		var uaIPO=nUa.indexOf('iPod; U')!=-1;
		var uaIPH=nUa.indexOf('iPhone; U')!=-1;
		var href = "http://www.invast.jp/ipn/"//誘導先URL
		var bnrSrc ="http://www.invast.jp/ipn/img/banner/smtload.jpg";//誘導バナー
		var bnrBg ="http://www.invast.jp/ipn/img/banner/bg_smtload.jpg";//誘導バナー背景
		
		if(uaAR||uaIPO||uaIPH){
		　$("#wrapper").before("<div id='smtLoad' style ='background:url(" + bnrBg + ") repeat-x 0 0; text-align:center; ' ><a href='"+ href +"'><img src="+bnrSrc+" /></a></div>");
		}
	}
},

fontChange: function() {			
	$("body").css("font-size",$.cookie('fsize'));
	var cookieSize =$.cookie('fsize');
	var liNameCookie; 
	switch (cookieSize){
	case "12px": liNameCookie = "#fontSmall"; break;
	case "14px": liNameCookie = "#fontNormal"; break;
	case "16px": liNameCookie = "#fontLarge"; break;
	default: liNameCookie = "#fontNormal"; break;
}

$(".navFontChange li").removeClass();	
	$(liNameCookie).addClass("current");
	$(".navFontChange").each(function(){
		$("li",this).click(function(){	  
			var liName = $(this).attr("id");
			font(liName);
			$(".navFontChange li").removeClass();
			$(this).addClass("current");			
		});
	});	

	function font(liName){
		switch (liName){
			case "fontSmall" : size = '12px'; break;
			case "fontNormal": size = '14px'; break;
			case "fontLarge" : size = '16px'; break;
			default: size = '14px'; break;
		}
		$("body").css("font-size",size);
		$.cookie("fsize",size,{expires:30,path:'/'});//※1
		$.actionSet.autoHeight();	
	}

},

pageScroll: function(options) {
	jQuery.easing.quart = function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	};
	
	$(".marketList a").each(function(){
		return false;
	})

	$('a[href*=#]').click(function() {
			if($(this).parent().parent().hasClass("navTab")){
				return false;
			}
	
		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 pos = $target;
				scrollAction("Anchor",pos);
			}
			return false;
		}
	});

	$('#navPage .navDown').click(function() {scrollAction("down");});
	$('#navPage .navUp').click(function() {scrollAction("up");});

	function scrollAction(updown,target){
		var moveTime =500;
		var movePos = $("html").attr("clientHeight");
		var thisOffset = $("html").scrollTop();
		var get_posWin = $(window).scrollTop();
		if(updown=="Anchor")var targetOffset = target.offset().top;
		if(updown=="up")var targetOffset = get_posWin - (movePos+50);
		if(updown=="down")var targetOffset = get_posWin + (movePos-50);
		var movePage = Math.abs(thisOffset-targetOffset)/3000;
		movePage = movePage.toFixed(1);
		if(1>=movePage)movePage=1;
		moveTime = moveTime * movePage;
		if(!jQuery.browser["opera"])$('html,body').animate({scrollTop: targetOffset}, moveTime, "quart");
		if(jQuery.browser["opera"])$('html,body').scrollTop(targetOffset);
		return false;
	}

},

ie6PicCatch: function(options){//IE画像表示処理
	try {
		document.execCommand('BackgroundImageCache', false, true);
	} catch(e) {}
},

autoHeight: function(options){
	var n = 0
	var target  = "#commodity .unitColumn .unitFloat";
	var target2 = "#seminar .sectionBox .boxInnerA";
	hMax = 0
	hMax2 = 0
	
	$(target).removeAttr("style");
	
	$(target).each(
		function (i){
			var h = $(this).height();
			if (h > hMax) {
				hMax = h
			}
		});
	
	$(target).each(
		function (){
			if ($.browser.msie && $.browser.version > 6) {
				//$("body").addClass("overIE6");
				$(this).css("min-height",hMax );
			} else if ($.browser.msie && $.browser.version < 7){
				//$("body").addClass("underIE6");
				$(this).css("height",hMax );
			} else{
				$(this).css("min-height",hMax );
			}
		});
	
	$(target2).removeAttr("style");
	
	$(target2).each(
		function (i){
			var h = $(this).height();
			if (h > hMax2) {
				hMax2 = h
			}
		});
	
	$(target2).each(
		function (){
			if ($.browser.msie && $.browser.version > 6) {
				//$("body").addClass("overIE6");
				$(this).css("min-height",hMax2 );
			} else if ($.browser.msie && $.browser.version < 7){
				//$("body").addClass("underIE6");
				$(this).css("height",hMax2 );
			} else{
				$(this).css("min-height",hMax2 );
			}
		});

},

includeFaq : function(options){
	/**
	var test=$("#areaFaq iframe body",top.document).height();
	console.log(test);
	
	$('#areaFaq iframe').load(function(){
									   
		if (typeof $(this).attr('height') == 'undefined') {
		  $(this).height(this.contentWindow.document.documentElement.scrollHeight+10);
		}
	
	});
	
	$('#areaFaq iframe').triggerHandler('load');
	*/
	
function doIframe(){
	o = document.getElementsByTagName('iframe');
	for(i=0;i<o.length;i++){
		if (/\bautoHeight\b/.test(o[i].className)){
			setHeight(o[i]);
			addEvent(o[i],'load', doIframe);
		}
	}
}

function setHeight(e){
	if(e.contentDocument){
		e.height = e.contentDocument.body.offsetHeight + 15;
	} else {
		e.height = e.contentWindow.document.body.scrollHeight+10;
	}
}

function addEvent(obj, evType, fn){
	if(obj.addEventListener)
	{
	obj.addEventListener(evType, fn,false);
	return true;
	} else if (obj.attachEvent){
	var r = obj.attachEvent("on"+evType, fn);
	return r;
	} else {
	return false;
	}
}

if (document.getElementById && document.createTextNode){
 addEvent(window,'load', doIframe);	
}

	

}

	
}



