/**
 * top.js
 *
 * @version     1.10
 * @modified   2010-09-03
 * @requires    jQuery 1.4.2, jQuery Easing Scroll
 */ 

/* -----------------------------------------------------------------------*/
// jQuery noConflict
/* -----------------------------------------------------------------------*/
jQuery.noConflict();
var $j = jQuery;

/* -----------------------------------------------------------------------*/
// main visual
/* -----------------------------------------------------------------------*/
$j(document).ready(function() {
	//実行間隔、速度、イージングの設定
//	var autoTime = 14200;
	var autoTime = 6500;
	var speed = 1400;
	var easing = 'easeInOutExpo';
	
	var lists = $j('#mainvisual li');
	var count;
	if(count == undefined) { count = lists.length; }
	
	// branding /////////////////////////////////////
	
	var item_width = 950;
	var left_value = item_width * (-1); 
	
	if(navigator.userAgent.indexOf("MSIE") != -1) { $j('#mainvisual li img').attr('galleryimg', 'no'); }
	
	//リスト全体をコピーして最後に追加
	var init_pos = (lists.length) * (left_value);
	$j('#mainvisual').css({'left': init_pos});
	$j('#mainvisual li').clone().appendTo('#mainvisual');

	if(lists.length > 2) {
		$j('#slidelist, #slidenext, #slideprev').mouseover(function() {
			$j('#slideprev').show();
			$j('#slidenext').show();
		}).mouseout(function() {
			$j('#slideprev').hide();
			$j('#slidenext').hide();
		});
	}

	//前へボタンをクリック
	$j('#slideprev').click(function() {
			var left_indent = parseInt($j('#mainvisual').css('left')) + item_width;
			
			$j('#mainvisual:not(:animated)').animate({
					'left': left_indent
				}, {
					easing: easing,
					duration: speed,
				 	complete: function() {
						left_indent = left_indent - item_width;
						$j('#mainvisual li:first').before($j('#mainvisual li:last')); 
						$j('#mainvisual').css({'left' : left_indent});
					}
				});
			  
		return false;    
	});

	//次へボタンをクリック
	$j('#slidenext').click(function() {
			var left_indent = parseInt($j('#mainvisual').css('left')) - item_width;
			
			$j('#mainvisual:not(:animated)').animate({
					'left': left_indent
				}, {
					easing: easing,
					duration: speed,
					complete: function() {
						left_indent = left_indent + item_width;
						$j('#mainvisual li:last').after($j('#mainvisual li:first'));
						$j('#mainvisual').css({'left': left_indent});
					}
				});
		         
		return false;
	});        
	
	//オートプレイ
	count++;
	if(run == undefined) {
		var run = setInterval("exec('"+count+"')", autoTime);
	}
	
	//画像エリアにマウスがあるときには、オートプレイ解除
	$j('#slidelist').hover(
		function() {
			clearInterval(run);
		},
		function() {
			run = setInterval("exec('"+count+"')", autoTime);
	});
});

function exec(count) {
	$j('#slidenext').click();
}
	
/* -----------------------------------------------------------------------*/
// product list
/* -----------------------------------------------------------------------*/
$j(document).ready(function() {
	//速度、イージングの設定
	var speed = 600;
	var easing = 'easeInOutExpo';
	
	var item_height = $j('#productlistinner dl').outerHeight();
	var top_value = item_height * (-1); 

	$j('#productlistinner dl:first').before($j('#productlistinner dl:last'));
	$j('#productlistinner').css({'top' : top_value});

	var items = $j('#productlistinner dl');
	if(items.length > 10) {
		
		//上矢印をクリック
		$j('#slideup').click(function() {  
			var top_indent = parseInt($j('#productlistinner').css('top')) + item_height;         
			$j('#productlistinner:not(:animated)').animate({
					'top' : top_indent
				}, {
					easing: easing,
					duration: speed,
					complete: function() {    
							$j('#productlistinner dl:first').before($j('#productlistinner dl:last'));           
							$j('#productlistinner').css({'top' : top_value});
						}
					});
			return false;    
		});
		
		//下矢印をクリック
		$j('#slidedown').click(function() {
			var top_indent = parseInt($j('#productlistinner').css('top')) - item_height;
			$j('#productlistinner:not(:animated)').animate({
					'top' : top_indent
				}, {
					easing: easing,
					duration: speed,
					complete: function () {
							$j('#productlistinner dl:last').after($j('#productlistinner dl:first'));
							$j('#productlistinner').css({'top' : top_value});
						}
					});
			return false;
		});
	}
});

/* -----------------------------------------------------------------------*/
// linkWrapper
/* -----------------------------------------------------------------------*/
function linkWrapper() {
	// リンク領域を拡張
	var dl = $j('#productlist dl');
	var tempClass;
	
	for(var i=0; i<dl.length; i++) {
		var linkNode = dl[i].getElementsByTagName('a').item(0);
		dl[i].onmouseover = function() {
			var links = this.getElementsByTagName('a').item(0);
			tempClass = this.className;
			if(links) {
				addClass(this, 'over');
			}
		}
		dl[i].onmouseout = function() {
			this.className = tempClass;
		}
		linkNode.onclick = function() {
			return false;
		}
		dl[i].onclick = function() {
			var links = this.getElementsByTagName('a').item(0);
			if(links) {
				var ref = links.getAttribute('href');
				window.location.href = ref;
			}
		}
	}

	var divs = $j('#extrainfo div.boxinner');
	var heading = $j('#extrainfo h3 img');
	
	var tempBoxClass;
	var src;
	var src_on;
	var suffix = '_on';
	
	for(var j=0; j<divs.length; j++) {
		var boxLinkNode = divs[j].getElementsByTagName('a').item(0);
		
		divs[j].onmouseover = function() {
			var boxLinks = this.getElementsByTagName('a').item(0);
			tempBoxClass = this.className;
			if(boxLinks) {
				addClass(this, 'over');
			} 
			img = this.getElementsByTagName('img').item(0);
			src = img.getAttribute('src');
			src_on = src.substr(0, src.lastIndexOf('.'))
								+ suffix
								+ src.substring(src.lastIndexOf('.'));
			img.setAttribute('src', src_on);
		}
		divs[j].onmouseout = function() {
			this.className = tempBoxClass;
			img.setAttribute('src', src);
		}
		boxLinkNode.onclick = function() {
			return false;
		}

/*
		divs[j].onclick = function() {
			var boxLinks = this.getElementsByTagName('a').item(0);
			if(boxLinks) {
				var boxRef = boxLinks.getAttribute('href');
				window.location.href = boxRef;
			}
		}
*/
	}
}

/* -----------------------------------------------------------------------*/
// addClass
/* -----------------------------------------------------------------------*/
function addClass(element,value) {
	if(!element.className) {
		element.className = value;
	} else {
		newClassName = element.className;
		newClassName += ' ';
		newClassName += value;
		element.className = newClassName;
	}
}

/* -----------------------------------------------------------------------*/
// addLoadEvent
/* -----------------------------------------------------------------------*/
function addLoadEvent(func) {
	var oldonload = window.onload;
	if(typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

addLoadEvent(linkWrapper);
