$(document).ready(function() {
	
	//customer center jump links
	$('[href="#"]').click(function() {
		$('header').ScrollTo(500, 'easeout'); return false;
	});
	
	$('[href="#customer-center-tokyo"]').click(function() {
		$('#customer-center-tokyo').ScrollTo(500, 'easeout'); return false;
	});

	$('[href="#customer-center-osaka"]').click(function() {
		$('#customer-center-osaka').ScrollTo(500, 'easeout'); return false;
	});

	$('[href="#customer-center-sapporo"]').click(function() {
		$('#customer-center-sapporo').ScrollTo(500, 'easeout'); return false;
	});

	$('[href="#customer-center-nagoya"]').click(function() {
		$('#customer-center-nagoya').ScrollTo(500, 'easeout'); return false;
	});

	$('[href="#customer-center-fukuoka"]').click(function() {
		$('#customer-center-fukuoka').ScrollTo(500, 'easeout'); return false;
	});
	

	//faq jump links
	$('[href="#about-afterservice"]').click(function() {
		$('#about-afterservice').ScrollTo(500, 'easeout'); return false;
	});

	$('[href="#about-function"]').click(function() {
		$('#about-function').ScrollTo(500, 'easeout'); return false;
	});

	$('[href="#about-maintenance"]').click(function() {
		$('#about-maintenance').ScrollTo(500, 'easeout'); return false;
	});
	
	//company jump links
	$('[href="#company-outline"]').click(function() {
		$('#company-outline').ScrollTo(500, 'easeout'); return false;
	});

	$('[href="#company-history"]').click(function() {
		$('#company-history').ScrollTo(500, 'easeout'); return false;
	});
	
	if(getUrlValue()){
		$('.trigger-list li:not("#'+ getUrlValue() +'-trigger") .outcome').hide();
	}else{
		$('.outcome').hide();
	}
	
	//open trigger
	$('.trigger').click(function() {
		$(this).next().slideToggle();
	});
	
	//CS map display
	if($("#customer-center").length){
		mapInitialize('cs-map-tokyo', '35.668945' , '139.763059');
		mapInitialize('cs-map-osaka', '34.676165', '135.500771');
		mapInitialize('cs-map-sapporo', '43.059377', '141.35374');
		mapInitialize('cs-map-nagoya', '35.165849', '136.912456');
		mapInitialize('cs-map-fukuoka', '33.593026', '130.396957');
	}
	
	//brand description
	$('#brand-description-open').click(
		function() {
			$("#brand-description .short").fadeOut(500);
			$("#brand-description").delay(600).animate({ width: "900px"});
			$("#brand-description .long").delay(900).fadeIn(600);
	});

	$('#brand-description-close').click(
		function() {
			$("#brand-description .long").fadeOut(500);
			$("#brand-description").delay(600).animate({ width: "290px"});
			$("#brand-description .short").delay(900).fadeIn(600);
	});
	
	
	if($("#brand-description .long .description").find('.second').size() == 0){
		$('#brand-description .long #brand-description-pagenation').hide();
	}

	$('#brand-description .long #brand-description-pagenation .icon-down').click(
		function() {
			$("#brand-description .long .description .first").fadeOut(500);
			$("#brand-description .long .description").find('.second').delay(500).fadeIn();
			$("#brand-description .long #brand-description-pagenation .icon-down").hide();
			$("#brand-description .long #brand-description-pagenation .icon-up").delay(500).fadeIn();
	});
	
	$('#brand-description .long #brand-description-pagenation .icon-up').click(
		function() {
			$("#brand-description .long .description .second").fadeOut(500);
			$("#brand-description .long .description").find('.first').delay(500).fadeIn();
			$("#brand-description .long #brand-description-pagenation .icon-up").hide();
			$("#brand-description .long #brand-description-pagenation .icon-down").delay(500).fadeIn();
	});

	$('#brand-introduction .clickSlideshow ul.image-list li:eq(0)').show();
	$('#brand-introduction .clickSlideshow ul.cap-list li:eq(0)').show();
	$('#brand-introduction  .clickSlideshow ul.thumb-list li').click(function(){
		var index = $('#brand-introduction .clickSlideshow .thumb-list li').index(this);
		$('#brand-introduction .clickSlideshow ul.image-list li').hide();
		if($('#brand-introduction .clickSlideshow').find('ul.cap-list')){
			$('#brand-introduction .clickSlideshow ul.cap-list li').hide();
		}
		$('#brand-introduction .clickSlideshow ul.image-list li:eq('+ (index) +')').fadeIn();
		if($('#brand-introduction .clickSlideshow').find('ul.cap-list')){
			$('#brand-introduction .clickSlideshow ul.cap-list li:eq('+ (index) +')').fadeIn();
		}
	});
	
	$('#featured-product .clickSlideshow ul.image-list li:eq(0)').show();
	$('#featured-product .clickSlideshow ul.cap-list li:eq(0)').show();
	$('#featured-product  .clickSlideshow ul.thumb-list li').click(function(){
		var index = $('#featured-product .clickSlideshow .thumb-list li').index(this);
		$('#featured-product .clickSlideshow ul.image-list li').hide();
		if($('#featured-product .clickSlideshow').find('ul.cap-list')){
			$('#featured-product .clickSlideshow ul.cap-list li').hide();
		}
		$('#featured-product .clickSlideshow ul.image-list li:eq('+ (index) +')').fadeIn();
		if($('#featured-product .clickSlideshow').find('ul.cap-list')){
			$('#featured-product .clickSlideshow ul.cap-list li:eq('+ (index) +')').fadeIn();
		}
	});
	
	
	
	//Boutique NGHC
	$('#floor-trigger-list ul li .floor-intro').click(function(){
		var index = $('#floor-trigger-list .floor-intro').index(this);
		$('#floor-trigger-list > ul li div').removeClass("showing");
		$('#floor-trigger-list > ul div.floor-intro:eq('+ index +')').addClass("showing");
		$('#floor-content-list > div').fadeOut();
		$('#floor-content-list > ul > li').css('left', '-480px');
		var $lefty = $('#floor-content-list > ul > li:eq('+ index +')');
			$lefty.animate({
				left: parseInt($lefty.css('left'), 10) == 10 ?
				-$lefty.outerWidth() :
				20
		});
	});
	
	//topic gallery
	$('#topic-gallery ul.image-list li.showing').fadeIn();
	$('#topic-gallery ul.thumb-list li').click(function(){
		$('#topic-gallery ul.image-list li').removeClass('showing');
		$('#topic-gallery ul.image-list li').hide();
		var index = $('#topic-gallery ul.thumb-list li').index(this);
		$('#topic-gallery ul.image-list li:eq('+ index +')').fadeIn();
		$('#topic-gallery ul.image-list li:eq('+ index +')').addClass('showing');
	});
	
	//Brand product pagenation
	var pageIndex = 0;
	var productNum = $("#featured-product #thumb-list-box .thumb-list li").length;
	
	$('#featured-product #thumb-list-box .thumb-list-back').click(function(){
		
		$('#featured-product #thumb-list-box .thumb-list').animate({
				"left": "+=198px"
			}, 500
		);
		pageIndex -= 1;
		if(pageIndex == 0){
			$('#featured-product #thumb-list-box .thumb-list-back').delay(300).fadeOut();
		}
		$('#featured-product #thumb-list-box .thumb-list-next').delay(300).fadeIn();
	});
		

	
	$('#featured-product #thumb-list-box .thumb-list-next').click(function(){
		$('#featured-product #thumb-list-box .thumb-list').animate({
				"left": "-=198px"
			}, 500
		);
		pageIndex += 1;
		if(pageIndex == (Math.ceil(productNum/3)-1)){
			$('#featured-product #thumb-list-box .thumb-list-next').delay(300).fadeOut();
		}
		$('#featured-product #thumb-list-box .thumb-list-back').delay(300).fadeIn();
	});

	
	
	$('.rollover-text .sub').hide();
	$('.rollover-text').hover(function(){
		$(this).find('.main').hide();
		$(this).find('.sub').show();
	},function(){
		$(this).find('.sub').hide();
		$(this).find('.main').show();
	});
	
});


function mapInitialize(elementId, latitude, longitude) {
	var latlng = new google.maps.LatLng( latitude, longitude);
	var myOptions = {
		zoom: 16,
		center: latlng,
		disableDefaultUI: true,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	var map = new google.maps.Map(document.getElementById(elementId), myOptions);
	
	var marker = new google.maps.Marker({
		position: latlng, 
		map: map
	}); 
}

function getUrlValue()
{
	var vars = [], hash;
	var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('#');
	for(var i = 0; i < hashes.length; i++)
	{
		hash = hashes[i].split('=');
		vars.push(hash[0]);
		vars[hash[0]] = hash[1];
	}
	return vars[1];
}

