//////////////////////////////////////////////////////////////////////////

/* フォームクリックで文字消える */
function cText(obj){
	if(obj.value==obj.defaultValue){
		obj.value="";
		obj.style.color="#333";
	}
}
	
function sText(obj){
	if(obj.value==""){
		obj.value=obj.defaultValue;
		obj.style.color="#333";
	}
}

//////////////////////////////////////////////////////////////////////////

/* Smooth Scroll */
var span = 600; //スクロールスピード
var effect = 'easeOutExpo'; //アニメーションタイプ
 
$(function() {
	var ua = $.browser;
	$('a[href*=#]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			$(this).blur();
			var t = navigator.appName.match(/Opera/) ? "html" : "html,body";
			$(t).queue([]).stop();
			var $targetElement = $(this.hash);
			var scrollTo = $targetElement.offset().top;
			if (window.scrollMaxY) {
				var maxScroll = window.scrollMaxY;
			} else {
				var maxScroll = document.documentElement.scrollHeight - document.documentElement.clientHeight;
			}
			if (scrollTo > maxScroll){
				scrollTo = maxScroll;
			}
			$(t).animate({ scrollTop: scrollTo }, span, effect);
			return false;
		}
	});
});


//////////////////////////////////////////////////////////////////////////

/* SOLD */
function money($numCalc,$numCalcDis){
	$numCalc = ""+$numCalc;
	//alert($numCalcDis);
	if($numCalcDis != ""){
		$numCalcDis = ""+$numCalcDis;
		
		$disPercent = Math.floor((($numCalc - $numCalcDis)/$numCalc)*100) + "%OFF";
		
		var $numCalcDis = $numCalcDis.replace(/,/g, '');
		var $numCalcDis = $numCalcDis.replace(/(\d{1,3})(?=(\d{3})+(?!\d))/g, "$1,");
		document.getElementById("discount").innerHTML = "&yen;" + $numCalcDis + " " + $disPercent;
		document.getElementById("discount").style.color = "#ff8400";
		document.getElementById("discount").style.fontWeight = "bold";
		document.getElementById("discount").style.display = "block";
		
		if($numCalc == "SOLD"){
			document.getElementById("money").innerHTML = $numCalc;
			document.getElementById("money").style.fontWeight = "bold";
			document.getElementById("money").style.fontSize = "0.9em";
			document.getElementById("money").style.color = "#ff0000";
			document.getElementById("money").style.textDecoration = "line-through";
			document.getElementById("money").style.display = "block";
		}else{
			var $numCalc = $numCalc.replace(/,/g, '');
			var $numCalc = $numCalc.replace(/(\d{1,3})(?=(\d{3})+(?!\d))/g, "$1,");
			document.getElementById("money").innerHTML = "&yen;" + $numCalc;
			document.getElementById("money").style.fontWeight = "bold";
			document.getElementById("money").style.fontSize = "0.9em";
			document.getElementById("money").style.textDecoration = "line-through";
			document.getElementById("money").style.display = "block";
		}
	}else{
		if($numCalc == "SOLD"){
			document.getElementById("money").innerHTML = $numCalc;
			document.getElementById("money").style.color = "#ff0000";
			document.getElementById("money").style.fontWeight = "bold";
		}else if($numCalc == "HOLD"){
			document.getElementById("money").innerHTML = $numCalc;
			document.getElementById("money").style.color = "#ff7800";
			document.getElementById("money").style.fontWeight = "bold";
		}else{
			var $numCalc = $numCalc.replace(/,/g, '');
			var $numCalc = $numCalc.replace(/(\d{1,3})(?=(\d{3})+(?!\d))/g, "$1,");
			document.getElementById("money").innerHTML = "&yen;" + $numCalc;
		}
	}
	
}


//////////////////////////////////////////////////////////////////////////

/* Clipping IMG */
$(function(){
	$(window).bind('load', function() {
		var selector=$(".clipImg");
		selector.each(function(){
			var w = $(this).width();
			var h = $(this).height();
			
			if(w >= h){
				$(this).addClass('wide');
			}else{
				$(this).addClass('tall');
			}
 		});
	});
});


//////////////////////////////////////////////////////////////////////////

/* Large IMG */
$(function(){
	$(window).bind('load', function() {
		var selector=$("#largeImg");
		var w = selector.width();
		var h = selector.height();
		//alert(w + " " + h);
		if(w >= h){
			selector.addClass('wide');
		}else{
			selector.addClass('tall');
		}
	});
});


//////////////////////////////////////////////////////////////////////////

/* フワッとホバー */
$(function(){
	// alphaOver
	if(typeof document.documentElement.style.maxHeight != "undefined")
	{
		$("a img").hover(
			function(){			
				$(this).stop().fadeTo(250, .70);
			},
			function(){
				$(this).stop().fadeTo(500, 1);
			}
		);
	}	
});

//////////////////////////////////////////////////////////////////////////

// class="blank"でtarget="_blank"と同じ効果

window.onload=autoPOP;

function autoPOP()
{
	var x = document.getElementsByTagName('a');
	for (var i=0;i<x.length;i++)
	{
		if (x[i].getAttribute('className') == 'blank' || x[i].getAttribute('class') == 'blank')
		{
			x[i].target = '_blank';
		}
	}
}
