
var dom = $("link").eq(0).attr("href");;
var DOMAIN = dom.slice(0,dom.indexOf("common/"));

/* ロールオーバー処理 */

function Btn(elm) {
	var me = this;
	this.elm = elm;
	this.over = function() { me.changeImage(true); };
	this.out = function() {	me.changeImage(false); };
	this.init();
}

var _Btn = Btn.prototype;

_Btn.init = function() {
	var me = this;
	var img_on = new Image();
	var img_str = this.elm.getAttribute("src");
	img_on.src = img_str.replace("_off", "_on");
	this.setEvent();
};


_Btn.doSelect = function() {
	this.deleteEvent();
	this.changeImage(true);
};


_Btn.setEvent = function() {
	try {
		this.elm.addEventListener("mouseover", this.over, false);
		this.elm.addEventListener("mouseout", this.out, false);
	} catch(e) {
		this.elm.attachEvent("onmouseover", this.over);
		this.elm.attachEvent("onmouseout", this.out);
	}
};


_Btn.deleteEvent = function() {
	try {
		this.elm.removeEventListener("mouseover", this.over, false);
		this.elm.removeEventListener("mouseout", this.out, false);
	} catch(e) {
		this.elm.detachEvent("onmouseover", this.over);
		this.elm.detachEvent("onmouseout", this.out);
	}
};


_Btn.changeImage = function(flag) {
	var img = this.elm.getAttribute("src");
	this.elm.setAttribute("src", (flag) ? img.replace("_off", "_on") : img.replace("_on", "_off"));
};


(function(func) {
	try {
		window.addEventListener("load", func, false);
	} catch(e) {
		window.attachEvent("onload", func);
	}
})(function() {
	var btnArray01 = document.getElementsByTagName("img");
	var btnArray02 = document.getElementsByTagName("input");
	for (var i = 0, ln = btnArray01.length; i < ln; i++) {
		if (btnArray01[i].getAttribute("src").indexOf("_off.") >= 0) new Btn(btnArray01[i]);
	}
	for (var i = 0, ln = btnArray02.length; i < ln; i++) {
		try{
			if (btnArray02[i].getAttribute("src").indexOf("_off.") >= 0) new Btn(btnArray02[i]);
		} catch(e){
		}
	}
	
	appleStyle();
	scrollTop();
	switchEvent();
	navigation();
	popWin();
	popFuncWin();
	
});

function scrollTop()
{
	$('#pageTop p img').click(function () {
		$('html,body').animate({ scrollTop: 0 }, 400, 'quart');
		return false;
	});
}

jQuery.easing.quart = function (x, t, b, c, d) {
    return -c * ((t=t/d-1)*t*t*t - 1) + b;
};



function navigation(){
	
	var src;
	
	$('#globalNavi li').hover(
		function() { 
			if($(this).index() != 3)
			{
				src = $(this).children("a").children("img");
				src.attr("src",src.attr("src").replace("_on","_over"));
				$(this).children("ul").css("display","block");
			}
		},
		function() { 
			if($(this).index() != 3)
			{
				src = $(this).children("a").children("img");
				src.attr("src",src.attr("src").replace("_over","_off"));
				$(this).children("ul").css("display","none");
			}
		}
	);
}

function switchEvent()
{
	var flag = false;
	var click = true;
	var height = $("#footerMiddle").height();
	$(".footerIn dl").hide();
		
	$(".switchEvent").click(function()
	{
		if(!click) return false;
		click = false;
		
		if(flag)
		{
			$(this).children("img").attr("src",$(this).children("img").attr("src").replace("_01","_01act"));
		}
		else
		{
			$(this).children("img").attr("src",$(this).children("img").attr("src").replace("_01act","_01"));
		}
		
		
		if (flag)
		{
			// 閉じる処理
			$("#footerMiddle").height(height);
			$(".footerIn dl").hide();
			
			$("#footerMiddle").animate({height:"0px"},400,function()
			{
				click = true;
			});
		}
		else
		{
			// 開く処理
			$("#footerMiddle").animate({height:height},400,function()
			{
				click = true;
				$(".footerIn dl").show();
			});				
		}
		
		flag = !flag;
	});
}


function popWin()
{
	$('.popwin').click(function () {
		$('.popupContainer').fadeIn(200);
	});
	$('.popwinClose').click(function () {
		$('.popupContainer').fadeOut(200);
	});
	
}

function popFuncWin()
{
	$('.popwin').click(function () {
		$('.popupContainerFunc').fadeIn(200);
	});
	$('.popwinClose').click(function () {
		$('.popupContainerFunc').fadeOut(200);
	});
	
}

/* 要素のheight揃え */
function fixedHeight(cl, num){
	var func = function(){
		$(cl).css({height : "auto"});
		var ln = $(cl).length;
		var offset = ln / num;
		var j = 0;
		var total = num;
		for(var i = 0; i < offset; i++){
			var maxH = 0;
			var total = num + j;
			for(j; j < total; j++){
				var h = $(cl).eq(j).height();
				if(maxH < h){
					maxH = h;
				}
			}
			var k = i * num;
			for(k; k < total; k++){
				$(cl).eq(k).css({height : maxH + "px"});
			}
		}
	}
	
	func();
	
	var d = document.createElement("div");
	var t = document.createTextNode("S");
	d.appendChild(t);
	d.style.visibility="hidden";
	d.style.position="absolute";
	d.style.top="0";
	document.body.appendChild(d);
	var defWidth = d.offsetWidth;
	var defHeight = d.offsetHeight;
	checkBoxSize = function(){
		if(defWidth != d.offsetWidth || defHeight != d.offsetHeight){
			func();
			defWidth= d.offsetWidth;
			defHeight= d.offsetHeight;
		}
	}
	setInterval(checkBoxSize,100)
}


/* Jquery Flat Heights
==========================================
Version: 2007-08-01

Copyright (c) 2007, KITAMURA Akatsuki

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
====================================================================== */
/*
	jQuery.changeLetterSize.addHandler(func)
	文字の大きさが変化した時に実行する処理を追加
*/

jQuery.changeLetterSize = {
	handlers : [],
	interval : 500,//定期処理を行う時間間隔。一応0.5秒で設定して有ります。1秒 = 1000
	currentSize: 0
};

(function(jQuery) {

	var self = jQuery.changeLetterSize;

	/* 文字の大きさを確認するためのins要素 */
	var ins = jQuery('<ins>M</ins>').css({
		display: 'block',
		visibility: 'hidden',
		position: 'absolute',
		padding: '0',
		top: '0'
	});

	/* 文字の大きさが変わったか */
	var isChanged = function() {
		
		//ins.appendTo('body');
		
		/*文字サイズ変更ボタン押下時、
		#wrapper以下のフォントサイズが変更となるため、
		判定用要素のappend先を変更*/
		
		ins.appendTo('#wrapper');
		var size = ins[0].offsetHeight;
		ins.remove();
		
		if (self.currentSize == size) return false;
		self.currentSize = size;
		
		return true;
	};

	/* 文書を読み込んだ時点で
	   文字の大きさを確認しておく */
	jQuery(isChanged);

	/* 文字の大きさが変わっていたら、
	   handlers中の関数を順に実行 */
	var observer = function() {
		if (!isChanged()) return;
		
		jQuery.each(self.handlers, function(i, handler) {
			handler();
		});
	};

	/* ハンドラを登録し、
	   最初の登録であれば、定期処理を開始 */
	self.addHandler = function(func) {
		self.handlers.push(func);
		if (self.handlers.length == 1) {
			setInterval(observer, self.interval);
		}
	};

})(jQuery);

/*
	jQuery(expr).flatHeights()
	jQuery(expr)で選択した複数の要素について、それぞれ高さを
	一番高いものに揃える
*/

(function(jQuery) {

	/* 対象となる要素群の集合 */
	var sets = [];

	/* 高さ揃えの処理本体 */
	var flatHeights = function(set) {
		var maxHeight = 0;
		set.each(function(){
			var height = this.offsetHeight;
			if (height > maxHeight) maxHeight = height;
		});
		set.css('height', maxHeight + 'px');
	};

	/* 要素群の高さを揃え、setsに追加 */
	jQuery.fn.flatHeights = function() {
		if (this.length > 1) {
			flatHeights(this);
			sets.push(this);
		}
		return this;
	};

	/* 文字の大きさが変わった時に、
	   setsに含まれる各要素群に対して高さ揃えを実行 */
	jQuery.changeLetterSize.addHandler(function() {
		jQuery.each(sets, function() {
			this.height('auto');
			flatHeights(this);
		});
	});

})(jQuery);

	/* 2-1.Setting
	---------------------------------------- */

jQuery(function(){
		jQuery('ul.brandLineList li').flatHeights();
	});



/*	iPad対応用CSS切り替え　*/

function appleStyle()
{
	
	var style = '<link rel="stylesheet" type="text/css" href="/sites/all/themes/cwy/common/css/apple.css" />'
	//var style = '<link rel="stylesheet" type="text/css" href="'+DOMAIN+'common/css/apple.css" />'
	
	if(navigator.userAgent.indexOf("iPhone") != -1)
	{
		//alert("iPhone");
		$("head").append(style);
	}
	else if(navigator.userAgent.indexOf("iPad") != -1)
	{
		//alert("iPad");
		$("head").append(style);
	}
	else
	{
		//alert("else");
	}
}








