
function initStyles(){
	// フォント指定
	u = navigator.userAgent;
	if(u.indexOf('Mac') != -1){
	   $('body, .pickup_title, .works_title a').css('fontFamily','"ヒラギノ明朝 Pro W3", "Hiragino Mincho Pro", serif');
	}
	// 画像ホバーアニメーション
	if(u.indexOf('MSIE 6.0') != -1 || u.indexOf('MSIE 7.0') != -1){
	}else{
		$("a img").hover(
			function(){
				$(this).stop().fadeTo(250, .70);
			},
			function(){
				$(this).stop().fadeTo(500, 1);
			}
		);
	}
	var thumbBox = $("div#thumb-section");
	var styleLists = $("ul#change-style li a");
	var classTitle = $("div.title");
	var classThumb = $("div.thumb");
	var classFull = $("div.full");
	var biggerHeight = 0;
	// スライダー JP
	$("#jp #slide-line").slider({
		animate:true ,
		max:100,
		min:0,
		value:98,
		range:"min" ,
		change:function(event,ui){
			if(ui.value < 33){
				changeTitle();
				styleLists.removeClass("current");
				$("ul#change-style li#title a").addClass("current");
				$("a.ui-slider-handle").css("left",-2+"px");
			} else if ((ui.value > 33)&&(ui.value < 66)){
				changeThumb();
				styleLists.removeClass("current");
				$("ul#change-style li#thumb a").addClass("current");
				$("a.ui-slider-handle").css("left",58+"px");
			} else{
				changeFull();
				styleLists.removeClass("current");
				$("ul#change-style li#full a").addClass("current");
				$("a.ui-slider-handle").css("left",116+"px");
			}
		}
	});
	// TITLE
	$(".cs01 a").click(function(event){
		event.preventDefault();
		$(".thumb_box .photo").fadeOut();
		changeTitle();
		styleLists.removeClass("current");
		$(this).addClass("current");
		$(".thumb_box").click(function(){
			var titleLink = $(this).find("a").attr("href");
			location.href = titleLink;
		});
		return false;
	});
	// 
	function changeTitle(){
		if(!(thumbBox.className == "title")){
			thumbBox.fadeOut("fast", function(){
				thumbBox.addClass("title");
				$(this).removeClass("thumb");
				$(this).removeClass("full");
				$(this).fadeIn("fast"); 
				$(this).css("margin-bottom","25px");
				$("a.ui-slider-handle").animate({left:"-2px"});
				$(".top_info").hide();
				$(".thumb_box .photo").hide();
			});
		}
	}
	// THUMBNAIL
	$(".cs02 a").click(function(event){
		event.preventDefault();
		changeThumb();
		styleLists.removeClass("current");
		$(this).addClass("current");
		return false;
	});
	function changeThumb(){
		if(!(thumbBox.className == "thumb")){
			thumbBox.fadeOut("fast", function(){
				thumbBox.addClass("thumb");
				$(this).removeClass("title");
				$(this).removeClass("full");
				$(this).fadeIn("fast");
				$(this).css("margin-bottom","25px");
				$("a.ui-slider-handle").animate({left:"58px"});
				$(".photo img").width(210);
				$(".top_info").hide();
				$(".thumb_box .photo").show();
				//Hover caption
				$(function(){
					var u = navigator.userAgent;
					speed = 120;
					$(".thumb_box").hover(function(){
						if(!(u.indexOf("MSIE") != -1)){
							$(".caption", this).stop().animate({top:'0px' , opacity: '0.7'},{queue:false, duration:speed});
						}else{
							$(".caption", this).stop().animate({top:'0px' , opacity: '0.7'},{queue:false, duration:speed});
						}
					},function() {
						$(".caption", this).stop().animate({top:'0px' , opacity: '0'},{queue:false, duration:speed});
					});
				});
			});
		}
	}
	// FULL
	$(".cs03 a").click(function(event){
		event.preventDefault();
		changeFull();
		styleLists.removeClass("current");
		$(this).addClass("current");
		return false;
	});
	function changeFull(){
		if(!(thumbBox.className == "full")){
			thumbBox.fadeOut("fast", function(){
				thumbBox.addClass("full");
				$(this).removeClass("title");
				$(this).removeClass("thumb");
				$(this).fadeIn("fast");
				$(this).css("margin-bottom","0");
				$("a.ui-slider-handle").animate({left:"116px"});
				$(".photo img").width(288);
				$(".top_info").show();
				$(".thumb_box .photo").show();
			});
		}
	}
	// カスタムセレクトメニュー
	$("select").jQselectable({
		set:"fadeIn",
		callback: function(){if($(this).val().length>0) window.location = $(this).val();}
	});
	// 検索フォーム
	var searchbar = $("input#s")[0];
	if(searchbar){
		searchbar.onfocus = function(){
			if(this.value == this.defaultValue){ this.value = ""; this.style.color = "#000";}
		}
		searchbar.onblur = function(){
			if(this.value == ""){ this.value = this.defaultValue; this.style.color = "#999";}
		}
	}
}



//--------------------------------------------------------------------------------
// Accordion menu
//--------------------------------------------------------------------------------

function initMenus(){
	var accBox = $("#bottom-article div.hidebox");
	var topTrigger = $("#hTrigger li");
	accBox.hide();
	//topTrigger.click(function(){});
	var bottomTrigger = $("#bottom-article h3.trigger");
	bottomTrigger.click(function(){
		var idName = this.getAttribute("id");
		var thisBox = $(this).next();
		if(thisBox.css("display")=="block"){
			thisBox.slideUp("fast");
			$("#bottom-article h3#"+idName+" a").removeClass("open");
		}else{
			thisBox.slideDown("fast");
			$("#bottom-article h3#"+idName+" a").addClass("open");
			track("/"+idName.replace(/Trigger/, "")); // contact, campany, award
		}
		return false;
	});
}
function accordionScroll(idName,box){
	//アコーディオン開閉処理
	var thisBox = $("h3#"+box).next();
	if((thisBox.css("display")=="block")){
		//開いてるとき
		smartScroll.start(idName);
	}else if((thisBox.css("display")=="none")) {
		//閉まってるとき
		thisBox.slideDown('fast', function() {
			smartScroll.start(idName);
		});
		$("#bottom-article h3#"+box+" a").addClass("open");
		track("/"+idName); // contact, campany, award
	}
}


//--------------------------------------------------------------------------------
// smartScroll
//--------------------------------------------------------------------------------

var smartScroll = {};
smartScroll.scrolling = false;
smartScroll.start = function (targetId,easing,completeFunc) {
	smartScroll.scrolling = true;
	var element = $('#'+targetId)[0];
	var easing = easing || 0.18;
	var interval = 30;
	var st = $(document).scrollTop();
	var sl = $(document).scrollLeft();
	var ww = $(window).width();
	var wh = $(window).height();
	var dw = $(document).width();
	var dh = $(document).height();
	var tX = 0; var tY = 0;
	var myTimer; var moveX; var moveY;
	while(element){
	   tX += element.offsetLeft;
	   tY += element.offsetTop;
	   element = element.offsetParent;
	}
	if (dw > (tX + ww)) {
		var toX = tX - sl;
	} else {
		var toX = dw - sl - ww;
	}
	if (dh > (tY + wh)) {
		var toY = tY - st;
	} else {
		var toY = dh - st - wh;
	}
	function windowScroll () {	
		if (0 > toX) {
			moveX = Math.floor(toX*easing);
		} else {
			moveX = Math.ceil(toX*easing);
		}		
		if (0 > toY) {
			moveY = Math.floor(toY*easing);
		} else {
			moveY = Math.ceil(toY*easing);
		}		
		sl += moveX;
		st += moveY;
		window.scrollTo(sl, st);
		toX -= moveX;
		toY -= moveY;
		myTimer = setTimeout(windowScroll,interval);
		if (moveX == 0 && moveY == 0) {
			smartScroll.scrolling = false;
			clearTimeout(myTimer);
			if (completeFunc) { completeFunc(); }
		}
	}
	windowScroll();
};
smartScroll.setup = function () {
	var allLinks = document.links;
	for(var i = 0 ; i < allLinks.length; i++) {
		var lnk = allLinks[i];
		if ((lnk.href && lnk.href.indexOf('#') != -1) && ((lnk.pathname == location.pathname) || ('/'+lnk.pathname == location.pathname))) {
			lnk.onclick = function () {
				if (smartScroll.scrolling) { return false; }
				var targetId = this.hash.replace(/#/g,"");
				if (document.getElementById(targetId)) {
					smartScroll.start(targetId);
					return false;
				}
			};
		}
	}
};


//--------------------------------------------------------------------------------
// Access Log
//--------------------------------------------------------------------------------

function track(path){
	_gaq.push(["_trackPageview", path]);
}

function initLinkclick(){
	var links = $("#pickup a");
	var l = links.length;
	for(var i=0; i<l; i++){
		var e = links[i];
		if(e.target == "_blank" && e.href.match(/^https?:\/\//)){
			e.onclick = function(){
				_gaq.push(["_trackEvent", "Links", "Click", this.href]);
				var w = window.open(this.href);
				w.focus();
				return false;
			}
		}
	}
}



//--------------------------------------------------------------------------------
// initialize
//--------------------------------------------------------------------------------

$(function(){
	initStyles();
	initMenus();
	smartScroll.setup();
	initLinkclick();
});

