/* PAGE SCROLL */

// Easingの追加
jQuery.easing.quart = function (x, t, b, c, d) {
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
};

/*-------------------------------------
 ページ読み込み中
-------------------------------------*/
jQuery(document).ready(function(){

	//
	// <a href="#***">の場合、スクロール処理を追加
	//
	jQuery('a[href*=#]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			var $target = jQuery(this.hash);
			$target = $target.length && $target || jQuery('[name=' + this.hash.slice(1) +']');
			if ($target.length) {
				var targetOffset = $target.offset().top;
				jQuery('html,body').animate({ scrollTop: targetOffset }, 1200, 'quart');
				return false;
			}
		}
	});

});

// cross feed


$(function()
{
  $("#slideshow li:not(:first)").hide();
  $("#slideshow li:first").addClass("selected");
  var dim=1;
  var count = function(){
  var len =$("#slideshow").children().length;
     if(dim>=len){
         dim=1;
         crossfeadeF();
     }else{
        dim +=1;
     crossfeade();}
  }
  var crossfeade = function(){
$("#slideshow").children(".selected").fadeOut("3300").removeClass().next().fadeIn("slow").addClass("selected");
   };
   var crossfeadeF = function(){
$("#slideshow").children(".selected").fadeOut("3300").removeClass().siblings("li:first").fadeIn("slow").addClass("selected");
   };
   var intervalID = setInterval(count, 5000);
  }
);

/* tab menu */

$(function(){
	$("#priceList").each(function(){
		var TabAreaAmount = $(this).find("#priceTab").children("li").length;
		var ActiveTabNo;
		for(i=0;i<TabAreaAmount;i++){
			if($(this).find("#priceTab li").eq(i).attr("class") == "On"){
				ActiveTabNo = i;
			}
		}
		for(i=0;i<TabAreaAmount;i++){
			if(i!=ActiveTabNo){
				$(this).find(".priceTable").eq(i).hide();
			}
		}
		$(this).find("#priceTab li a").click(function(){
			$(this).parents("li").eq(0).addClass("Clicked");
			var ClickedTabNo;
			for(i=0;i<TabAreaAmount;i++){
				if(
					$(this).parents("#priceList").eq(0).find("#priceTab li").eq(i).attr("class")!=null
					&& $(this).parents("#priceList").eq(0).find("#priceTab li").eq(i).attr("class").indexOf("Clicked")!=-1
				){
					ClickedTabNo = i;
					$(this).parents("li").eq(0).removeClass("Clicked");
					$(this).parents("li").eq(0).addClass("On");
				}else if($(this).parents("#priceList").eq(0).find("#priceTab li").eq(i).attr("class")!=null){
					$(this).parents("#priceList").eq(0).find("#priceTab li").eq(i).removeClass("On");
				}
			}
			for(i=0;i<TabAreaAmount;i++){
				if(i!=ClickedTabNo){
					$(this).parents("#priceList").eq(0).find(".priceChange").eq(0).find(".priceTable").eq(i).hide();
				}
			}
			$(this).parents("#priceList").eq(0).find(".priceChange").eq(0).find(".priceTable").eq(ClickedTabNo).show();
			return false;
		});
	});
});


/* RollOver */

function initRollOverImages() {
	var image_cache = new Object();
	$("#lead1 ul li a img,#running1 ul li a img,#connect li a img,#side .banner li a img").not("[src*='_on.']").each(function(i) {
		var imgsrc = this.src;
		var dot = this.src.lastIndexOf('.');
		var imgsrc_on = this.src.substr(0, dot) + '_on' + this.src.substr(dot, 4);
		image_cache[this.src] = new Image();
		image_cache[this.src].src = imgsrc_on;
		$(this).hover(
			function() { this.src = imgsrc_on; },
			function() { this.src = imgsrc; }
		);
	});
}
$(document).ready(initRollOverImages);



/* TIP */

$(function () {
        $('#webFee .planDetails').each(function () {
            var distance = 10;
            var time = 250;
            var hideDelay = 500;
            var hideDelayTimer = null;
            var beingShown = false;
            var shown = false;
            var trigger = $('.pdtsImg', this);
            var info = $('.commentary', this).css('opacity', 0);
            $([trigger.get(0), info.get(0)]).mouseover(function () {
                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                if (beingShown || shown) {
                    // don't trigger the animation again
                    return;
                } else {
                    // reset position of info box
                    beingShown = true;
                    info.css({
                        top: -86,
                        left: -3,
                        display: 'block'
                    }).animate({
                        top: '-=' + distance + 'px',
                        opacity:1
                    }, time, 'swing', function() {
                        beingShown = false;
                        shown = true;
                    });
                }
                return false;
            }).mouseout(function () {
                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                hideDelayTimer = setTimeout(function () {
                    hideDelayTimer = null;
                    info.animate({
                        top: '-=' + distance + 'px',
                        opacity: 0
                    }, time, 'swing', function () {
                        shown = false;
                        info.css('display', 'none');
                    });
                }, hideDelay);
                return false;
            });
        });
    });


/*--------------------------------------------------------------------------*
 *  
 *  heightLine JavaScript Library beta4
 *  
 *  MIT-style license. 
 *  
 *  2007 Kazuma Nishihata 
 *  http://www.webcreativepark.net
 *  
 *--------------------------------------------------------------------------*/
new function(){
	
	function heightLine(){
	
		this.className="heightLine";
		this.parentClassName="heightLineParent"
		reg = new RegExp(this.className+"-([a-zA-Z0-9-_]+)", "i");
		objCN =new Array();
		var objAll = document.getElementsByTagName ? document.getElementsByTagName("*") : document.all;
		for(var i = 0; i < objAll.length; i++) {
			var eltClass = objAll[i].className.split(/\s+/);
			for(var j = 0; j < eltClass.length; j++) {
				if(eltClass[j] == this.className) {
					if(!objCN["main CN"]) objCN["main CN"] = new Array();
					objCN["main CN"].push(objAll[i]);
					break;
				}else if(eltClass[j] == this.parentClassName){
					if(!objCN["parent CN"]) objCN["parent CN"] = new Array();
					objCN["parent CN"].push(objAll[i]);
					break;
				}else if(eltClass[j].match(reg)){
					var OCN = eltClass[j].match(reg)
					if(!objCN[OCN]) objCN[OCN]=new Array();
					objCN[OCN].push(objAll[i]);
					break;
				}
			}
		}
		
		//check font size
		var e = document.createElement("div");
		var s = document.createTextNode("S");
		e.appendChild(s);
		e.style.visibility="hidden"
		e.style.position="absolute"
		e.style.top="0"
		document.body.appendChild(e);
		var defHeight = e.offsetHeight;
		
		changeBoxSize = function(){
			for(var key in objCN){
				if (objCN.hasOwnProperty(key)) {
					//parent type
					if(key == "parent CN"){
						for(var i=0 ; i<objCN[key].length ; i++){
							var max_height=0;
							var CCN = objCN[key][i].childNodes;
							for(var j=0 ; j<CCN.length ; j++){
								if(CCN[j] && CCN[j].nodeType == 1){
									CCN[j].style.height="auto";
									max_height = max_height>CCN[j].offsetHeight?max_height:CCN[j].offsetHeight;
								}
							}
							for(var j=0 ; j<CCN.length ; j++){
								if(CCN[j].style){
									var stylea = CCN[j].currentStyle || document.defaultView.getComputedStyle(CCN[j], '');
									var newheight = max_height;
									if(stylea.paddingTop)newheight -= stylea.paddingTop.replace("px","");
									if(stylea.paddingBottom)newheight -= stylea.paddingBottom.replace("px","");
									if(stylea.borderTopWidth && stylea.borderTopWidth != "medium")newheight-= stylea.borderTopWidth.replace("px","");
									if(stylea.borderBottomWidth && stylea.borderBottomWidth != "medium")newheight-= stylea.borderBottomWidth.replace("px","");
									CCN[j].style.height =newheight+"px";
								}
							}
						}
					}else{
						var max_height=0;
						for(var i=0 ; i<objCN[key].length ; i++){
							objCN[key][i].style.height="auto";
							max_height = max_height>objCN[key][i].offsetHeight?max_height:objCN[key][i].offsetHeight;
						}
						for(var i=0 ; i<objCN[key].length ; i++){
							if(objCN[key][i].style){
								var stylea = objCN[key][i].currentStyle || document.defaultView.getComputedStyle(objCN[key][i], '');
									var newheight = max_height;
									if(stylea.paddingTop)newheight-= stylea.paddingTop.replace("px","");
									if(stylea.paddingBottom)newheight-= stylea.paddingBottom.replace("px","");
									if(stylea.borderTopWidth && stylea.borderTopWidth != "medium")newheight-= stylea.borderTopWidth.replace("px","")
									if(stylea.borderBottomWidth && stylea.borderBottomWidth != "medium")newheight-= stylea.borderBottomWidth.replace("px","");
									objCN[key][i].style.height =newheight+"px";
							}
						}
					}
				}
			}
		}
		
		checkBoxSize = function(){
			if(defHeight != e.offsetHeight){
				changeBoxSize();
				defHeight= e.offsetHeight;
			}
		}
		changeBoxSize();
		setInterval(checkBoxSize,1000)
		window.onresize=changeBoxSize;
	}
	
	function addEvent(elm,listener,fn){
		try{
			elm.addEventListener(listener,fn,false);
		}catch(e){
			elm.attachEvent("on"+listener,fn);
		}
	}
	addEvent(window,"load",heightLine);
}
