// JavaScript Document



/*
============================================================*/

var host = (("https:" == document.location.protocol) ? "/~z302062/" : "/");
var siteMatrix = host + "matrix";



try {
document.execCommand('BackgroundImageCache', false, true);
} catch(e) {}




/*	byon.js difference
============================================================*/
var dif;
dif = 0;



$(document).ready(function(){
//============================================================

focusBlur();
pageScroll();
topics();
yahooSearch();


//view cart / shop purchase
$('.submit_section').each(function(i){
	var itemAmount = $(this).find('.item_num');
	var errorMsg = $(this).find('.error_msg');
	$(this).find('.btn_submit').click(function(){
		var itemVariation = $(this).parent().parent().parent().find('input[@type="radio"]:checked');
		var itemAmountVal = itemAmount.val();
		var itemVariationVal = itemVariation.val();
		var tmp = itemAmountVal.match(/[0-9a-zA-Z\+\-\/\*\,\. ]+/g);
		if(itemVariationVal == undefined){
			errorMsg.text('商品をお選びください').fadeIn('slow');
			return false;
		} else if (tmp != itemAmountVal) {
			errorMsg.text('半角で入力してください').fadeIn('slow');
			return false;
		  
		} else {
			$(this).parent('form').submit();
		}
	});
});

//maintenance 
//$('.btn_submit').click(function(){
//	location.href = '/maintenance.php';
//	return false;
//})
//$('#header2 iframe').css({'display':'none'});
//$('#status_disp').css({'display':'none'});



//gnv
var gnvLi = $('#gnv li');
gnvLi.hover(
	function(){$(this).find('img').stop().fadeTo(150, 0.0);},
	function(){$(this).find('img').stop().fadeTo(400, 1.0);}
);
if(gnvID != ""){$('#gnv' + gnvID).find("img").css({'visibility':'hidden'});}



//lnv
var lnvLi = $('.lnv li');
lnvLi.hover(function(){$(this).find('a').addClass('hv')},function(){$(this).find('a').removeClass('hv')});
if(lnvID != ""){
	$('#lnv' + lnvID).find('a').addClass('sl').unbind('mouseover').unbind('mouseout');
}


//home_list
$('.inner2', '#home_list').flatHeights();



//best_sell
$('li:last', '#box_bestsell').addClass('last');



//shop item thumbnail
$('li:odd', '#item_top_left ul').addClass('odd');
$('li:even', '#item_top_left ul').addClass('even');



//shop comment
$('#btn_comments_open').click(function(){
    var hrefstr = $(this).find('a').attr('href');
	window.open(hrefstr,'','width=698,height=760,scrollbars=yes,resizable=yes');
	return false;
})
$('#btn_submit_back').click(function(){
	history.back();
})
$('#btn_submit_close').click(function(){
	window.close();
})






//form
$("#privacy_policy_box_inner").load('../guide/matrix/inc/privacy_txt.txt');
if($('.resizable').length) {$('.resizable:not(.processed)').TextAreaResizer();}




//guide opwin
$('.btn_opwin').click(function(){
    var hrefstr = $(this).attr('href');
	window.open(hrefstr,'','width=432,height=350,scrollbars=yes,resizable=yes');
	return false;
})




$('a[href^=http]','.entry_body')
	.not('[href*="jakamiina-inaka.net"]')
	.not('[href*="z302.secure.ne.jp"]')
	.not('[href*="enekoshop.jp"]')
	.attr("target","_blank");


//============================================================
});



function focusBlur() {
	$("a").focus(function(){this.blur();})
	$("area").focus(function(){this.blur();})
	$("input:image").focus(function(){this.blur();})
}



/* byon.js
 * Copyright (c) 2009 SACHIO MARUYAMA
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 */
function pageScroll(){

	var scrolledX = scrolledY = null;
	var targetX = targetY = null;
	var scrollX,scrollY;
	var html = document.documentElement;
	var body = document.body;
	var scrollBtns = document.links;
	var url = location.href.replace(location.hash,"");
	
	var easing = 0.25;
	var interval = 30;
	
	
	for(var i=0;i<scrollBtns.length;i++){
		if(scrollBtns[i].getAttribute("href").match("#")){
			var btn = scrollBtns[i];
			btn.onclick = function(){
				var TargetId = (this.getAttribute("href").replace(url,"")).substr(1);
				if (document.getElementById(TargetId)) {
					var Target = document.getElementById(TargetId);
					try {
						var position = Target.getBoundingClientRect();
						targetX = position.left + (body.scrollLeft || html.scrollLeft) - html.clientLeft;
						targetY = position.top + (body.scrollTop || html.scrollTop) - html.clientTop;
					} catch(e) {
						targetX = Target.offsetLeft, targetY = Target.offsetTop;
					}
					scrollX = window.pageXOffset || html.scrollLeft || body.scrollLeft || 0;
					scrollY = window.pageYOffset || html.scrollTop || body.scrollTop || 0;
					scroll();
					return false;
				}
			}
		}
	}

	function scroll(){
		var X = window.pageXOffset || html.scrollLeft || body.scrollLeft || 0;
		var Y = window.pageYOffset || html.scrollTop || body.scrollTop || 0;
//			scrollX += Math.floor((targetX - X) * easing);
		scrollX = X;
		scrollY += Math.floor((targetY - Y + dif) * easing);
		if((targetY === scrollX && targetY === scrollY) || (X === scrolledX && Y === scrolledY)) {
			scrolledX = scrolledY = null;
		} else {
			window.scrollTo(scrollX, scrollY);
			scrolledX = X, scrolledY = Y;
			setTimeout(function(){scroll()},interval);
		}
	}
}


//topics
function topics() {
	var tickers = $('#ticker li');
	var i;
	
	function htmlFadeIn() {
		$(this).html($(tickers[i]).html()).fadeIn();
		focusBlur();
	}
	
	function tickerInit() {
		var initIndex =  Math.floor(Math.random()*tickers.length);
		i = initIndex;
		$('#tickerDisp').find("p").fadeOut('slow',htmlFadeIn);
	}
	
	function showTicker() {
		i++;
		if(i <= tickers.length - 1) {
			$('#tickerDisp').find("p").fadeOut('slow',htmlFadeIn);
		} else {
			tickerInit();
		}
	}
	
	tickerInit();
	timer = setInterval(showTicker,5000);
}



//yahoo search
function yahooSearch() {
var srchInput = $('#srchInput');
var srchLogo = 'url("' + siteMatrix + '/images/logo_wm.gif")';
if($(srchInput).val() =='') {
	$(srchInput).css('background-image',srchLogo)
};
$(srchInput)
	.focus(function(){$(this).css('background-image','none')})
	.blur(function(){if($(this).val() =='')$(this).css('background-image',srchLogo)});
}



//tooltip
var mouseY,mouseX;
$(document).ready(function(){
	$('html').mousemove(function(e){
		mouseY = e.pageY;
		mouseX = e.pageX;
	});
});


var tooltip=function(){
	var id = 'tt';
	var top = -50;
	var left = 10;
	var maxw = 700;
	var speed = 30;
	var timer = 20;
	var endalpha = 70;
	var alpha = 0;
	var tt,t,c,b,h;
	var ie = document.all ? true : false;
	var note = '<p class="note">クリックすると拡大します（別ウィンドウ）</p>';
	
	return{
		show:function(v,w){
			if(tt == null){
				tt = document.createElement('div');
				tt.setAttribute('id',id);
				c = document.createElement('div');
				c.setAttribute('id',id + 'cont');
				tt.appendChild(c);
				document.body.appendChild(tt);
				tt.style.opacity = 0;
				tt.style.filter = 'alpha(opacity=0)';
				document.onmousemove = this.pos;
			}
			tt.style.display = 'block';
			if(!ie){
				c.innerHTML = v + note;
			}else{
				c.innerHTML = v + note;
				$('#tt').addClass('iepngfix').find('#ttcont').addClass('iepngfix');
			}
			tt.style.width = w ? w + 'px' : 'auto';
			if(!w && ie){
				tt.style.width = tt.offsetWidth;
			}
			if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
			h = parseInt(tt.offsetHeight) + top;
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(1)},timer);
		},
		pos:function(){
			u = mouseY;
			l = mouseX;
			tt.style.top = (mouseY - $('#tt').height()/2) + 'px';
			tt.style.left = (mouseX + left) + 'px';
		},
		fade:function(d){
			var a = alpha;
			if((a != endalpha && d == 1) || (a != 0 && d == -1)){
				var i = speed;
				if(endalpha - a < speed && d == 1){
					i = endalpha - a;
				}else if(alpha < speed && d == -1){
					i = a;
				}
				alpha = a + (i * d);
				tt.style.opacity = alpha * .01;
				tt.style.filter = 'alpha(opacity=' + alpha + ')';
			}else{
				clearInterval(tt.timer);
				if(d == -1){tt.style.display = 'none'}
			}
		},
		hide:function(){
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
		}
	};
}();






//$(document).ready(function(){
//	$('a', '#item_top_left #itemImgs').click(function(){
//		var url = $(this).attr('href');
//		var flag = $(this).find('img').height();
//		var commonProp = ',menubar=no,toolbar=no,scrollbars=no'
//		//alert(flag);
//		if(flag < 100) {
//			window.open(url,'','width=660,height=500' + commonProp);
//		} else {
//			window.open(url,'','width=500,height=500' + commonProp);
//		}
//		return false;
//	});
//});




//tab
$(document).ready(function(){

if($('#calendar_tabs li').length) {
	var tabLi = $('#calendar_tabs li');
	var sheetLi = $('#calendar_tables li');
	var opS;
	if($.cookie('tab_cookie')==null){
		opS = 0;
	} else {
		opS = $.cookie('tab_cookie');
	}

	//alert(opS);

	$.cookie('tab_cookie',opS ,{ expires: 30 });
	sheetLi.hide();
	$(sheetLi[opS]).css({'display':'block'});
	$(tabLi[opS]).addClass('selected');

	

	tabLi.each(function(i){
		$(this).click(function(){
			$(tabLi).removeClass('selected');
			$(this).addClass('selected');
			sheetLi.hide();
			$(sheetLi[i]).show();
			$.cookie('tab_cookie',i ,{ expires: 30 });
			return false;
		})					
	})
}

});



