function smartRollover() {
	if(document.getElementsByTagName) {
		var images = document.getElementsByTagName("img");

		for(var i=0; i < images.length; i++) {
			if(images[i].getAttribute("src").match("_off."))
			{
				images[i].onmouseover = function() {
					this.setAttribute("src", this.getAttribute("src").replace("_off.", "_on."));
				}
				images[i].onmouseout = function() {
					this.setAttribute("src", this.getAttribute("src").replace("_on.", "_off."));
				}
			}
		}
	}
}

if(window.addEventListener) {
	window.addEventListener("load", smartRollover, false);
}
else if(window.attachEvent) {
	window.attachEvent("onload", smartRollover);
}

jQuery.easing.quart = function (x, t, b, c, d) {  
    return -c * ((t=t/d-1)*t*t*t - 1) + b;  
}; 

jQuery(document).ready(function(){  
    jQuery('a[href*=#wrapper]').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 }, 1500, 'easeOutQuart');  
                return false;  
            }  
        }  
    });  
  
});


$(function(){
	li = $('#gNavi li:not(:last)');
	$('a',li).click(function(){
		href = $(this).attr('href');
		if($('.jScrollArrowUp').size() != 0){
			$('.jScrollArrowUp').fadeTo(300,0);
		}
		if($('.jScrollArrowDown').size() != 0){
			$('.jScrollArrowDown').fadeTo(300,0);
		}
		$('#mainArea, #logo, #gNavi li').fadeTo(300,0,function(){
			location.href = href;
		});
		return false;
	});
});

function top(){
	p = window.location.search;
	if(p != '') {
		$('#splash').css({display:'none'});
		$('#mainArea').fadeTo(0,0)
		setTimeout(function(){
			$('#mainArea').fadeTo(0,0).fadeTo(300,1);
			$('#logo, #gNavi li').fadeIn(300);
		},600);
	} else {
		setTimeout(function(){
			$('#splash #img1').fadeIn(500,function(){
				$('#splash #img2').fadeIn(1000,function(){
					setTimeout(function(){
						$('#splash img').fadeOut(600,function(){
							$('#splash').fadeOut(300);
							$('#logo, #gNavi li').fadeIn(300);
						});
					},1000);
				});
			});
		},600);
	}
}

function page(){
	setTimeout(function(){
		$('#mainArea').fadeTo(300,1);
		$('#logo, #gNavi li').fadeIn(300);
		if($('.jScrollArrowUp').size() != 0){
			$('.jScrollArrowUp').fadeIn(300);
		}
		if($('.jScrollArrowDown').size() != 0){
			$('.jScrollArrowDown').fadeIn(300);
		}
	},600);
}

function brand(){
	setTimeout(function(){
		$('#mainArea').fadeTo(300,1,function(){
			setTimeout(function(){
				$('#mainArea #img2').fadeTo(600,1,function(){
					$('#mainArea #img3').fadeTo(600,1,function(){
						$('#mainArea #img4').fadeTo(600,1);
					});
				});
			},600);
		});
		$('#logo, #gNavi li').fadeIn(300);
	},600);
}

function shop(){
	$(function(){
		$('#flagship,#japan,#international').append('<table><tbody></tbody></table>');
		$.ajax({
			url: 'common/js/shop.xml',
			type: 'GET',
			dataType: 'xml',
			timeout: 1000,
			error: function(){
			//XMLデータの読み込みに失敗した場合にアラート
				alert("xmlファイルの読み込みに失敗しました");
			},
			success: function(xml){
				$(xml).find("flagship").each(function(i){
					var name = $(this).find('name').text();
					var map = $(this).find('map').text();
					var area = $(this).find('area').text();
					var place = $(this).find('place').text();
					var tel = $(this).find('tel').text();
					
					tr = '<tr><th scope="row">'+name+'<span><a href="'+map+'" rel="lightbox">MAP</a></span></th><td>'+area+'</td><td>'+place+'</td><td class="tel">'+tel+'</td></tr>';
					$('#flagship tbody').append(tr);
				});
				
				$(xml).find("japan").each(function(i){
					var name = $(this).find('name').text();
					var area = $(this).find('area').text();
					var place = $(this).find('place').text();
					var tel = $(this).find('tel').text();
					
					tr = '<tr><th scope="row">'+name+'</th><td>'+area+'</td><td>'+place+'</td><td class="tel">'+tel+'</td></tr>';
					$('#japan tbody').append(tr);
				});
				
				$(xml).find("international").each(function(i){
					var name = $(this).find('name').text();
					var area = $(this).find('area').text();
					var place = $(this).find('place').text();
					var tel = $(this).find('tel').text();
					
					tr = '<tr><th scope="row">'+name+'</th><td>'+area+'</td><td>'+place+'</td><td class="tel">'+tel+'</td></tr>';
					$('#international tbody').append(tr);
				});
				
				if (!/android|iphone|ipod|series60|symbian|windows ce|blackberry/i.test(navigator.userAgent)) {
					jQuery(function($) {
						$("a[rel^='lightbox']").slimbox({/* Put custom options here */}, null, function(el) {
							return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
						});
					});
				}
			}
		});
	});
}

function archive(){
	$(function(){
		flag = true;
		$('#mainArea').append('<p id="btn_left"><img src="images/archive/btn_left_off.gif" /></p><p id="btn_right"><img src="images/archive/btn_right_off.gif" /></p>');
		$('#btn_left img').click(function(){
			if(flag) {
				flag = false;
				act = $('#archiveList .act');
				$(act).fadeOut(300,function(){
					$(this).removeClass('act');
					$(act).prev().fadeIn(300,function(){
						$(this).addClass('act');
						$('#btn_right img').css('display','block');
						
						if($('#archiveList li:first').css('display') != 'none') {
							$('#btn_left img').css('display','none');
						} else {
							$('#btn_left img').css('display','block');
						}
						flag = true;
					});
				});
			}
		});
		
		$('#btn_right img').click(function(){
			if(flag) {
				flag = false;
				act = $('#archiveList .act');
				$(act).fadeOut(300,function(){
					$(this).removeClass('act');
					$(act).next().fadeIn(300,function(){
						$(this).addClass('act');
						$('#btn_left img').css('display','block');
						
						if($('#archiveList li:last').css('display') != 'none') {
							$('#btn_right img').css('display','none');
						} else {
							$('#btn_right img').css('display','block');
						}
						flag = true;
					});
				});
			}
		});
	});
}

function news(){
	$(function(){
		setTimeout (function(){
		imgH = $('#newsList .act img').height();
			if (imgH < 540){
				maT = (540 - imgH)/2;
				$('#newsList .act img').css({marginTop:maT});
			}
			if (imgH > 540){
				$('#newsList .act img').css({height:540+'px'});
			}
		},100);
		
		if ($('#newsList li').size() >= 2) {
			flag = true;
			$('#mainArea').append('<p id="btn_left"><img src="images/archive/btn_left_off.gif" /></p><p id="btn_right"><img src="images/archive/btn_right_off.gif" /></p>');
			$('#btn_left img').click(function(){
				if(flag) {
					flag = false;
					act = $('#newsList .act');
					$(act).fadeOut(300,function(){
						$(this).removeClass('act');
						$(act).prev().fadeIn(300,function(){
							$(this).addClass('act');
							$('#btn_right img').css('display','block');
							
							if($('#newsList li:first').css('display') != 'none') {
								$('#btn_left img').css('display','none');
							} else {
								$('#btn_left img').css('display','block');
							}
							flag = true;
						});
					});
				}
			});
			
			$('#btn_right img').click(function(){
				if(flag) {
					flag = false;
					act = $('#newsList .act');
					next = $(act).next();
					nextImg = $('img',next);
					$(next).css('display','block');
					$(nextImg).css('display','block');
					niH = $(nextImg).height();
					$(next).css('display','none');
					$(nextImg).css('display','');
					$(act).fadeOut(300,function(){
						$(this).removeClass('act');
						if (niH < 540){
							maT = (540 - niH)/2;
							$(nextImg).css({marginTop:maT});
						}
						if (niH > 540){
							$(nextImg).css({height:540+'px'});
						}
						$(act).next().fadeIn(300,function(){
							$(this).addClass('act');
							$('#btn_left img').css('display','block');
							
							if($('#newsList li:last').css('display') != 'none') {
								$('#btn_right img').css('display','none');
							} else {
								$('#btn_right img').css('display','block');
							}
							flag = true;
						});
					});
				}
			});
		}
	});
}
