//***********************************
//オンマウスのエフェクト
//***********************************
$(function() {
	$("#works #wrapper #newest li a").fadeTo(0,0);
	$("#works #wrapper #ever li a").fadeTo(0,0);
	$("#related #post dd a").fadeTo(0,0);
	$(".thumbnail a.mask").fadeTo(0,0);
	});
	
$(function() {
	// WORKS
		// newest
	$('#works #wrapper #newest').hover(
		function() {
			$('#works #wrapper #newest li a').fadeTo(0,0.5);
			},
			
		function() {
			$('#works #wrapper #newest li a').fadeTo(300,0);
			}
		);
		
		// ever
	$('#works #wrapper #ever li').hover(
		function() {
			$(this).children('#works #wrapper #ever li a').fadeTo(0,0.5);
			},
			
		function() {
			$(this).children('#works #wrapper #ever li a').fadeTo(300,0);
			}
		);
	
		// single / related posts
	$('#related #post dd a').hover(
		function() {
			$(this).fadeTo(0,0.5);
			},
			
		function() {
			$(this).fadeTo(300,0);
			}
		);		
	
	// NOTE
	$('.thumbnail .image a').hover(
		function() {
			$(this).fadeTo(0,0.5);
			},
		function() {
			$(this).fadeTo(300,1);
			}
		);
		
	$('.thumbnail a.mask').hover(
		function() {
			$(this).fadeTo(0,0.5);
			},
		function() {
			$(this).fadeTo(300,0);
			}
		);
	
	// pagenation
	$('#pagenation a, .pagenation a').hover(
		function() {
			$(this).fadeTo(0,0.5);
			},
		function() {
			$(this).fadeTo(300,1);
			}
		);
	});





//***********************************
//一定量スクロールしたらページナビを表示
//***********************************
$(document).ready(function(){
	$("#pagenation, .pagenation").hide();
	
	$(function(){
		$(window).scroll(function(){
			if ($(this).scrollTop() > 50){
				$('#pagenation, .pagenation').fadeIn();
				}
			else{
				$('#pagenation, .pagenation').fadeOut();
				}
			});
		});
	});





//***********************************
//ギャラリー
//***********************************
//$(function(){
//	$('#photo .container li a').click(function(e){
//		e.preventDefault();
//		
//		var imagePath = $(this).attr('href');
//		var mainImage = $(this).parents('#photo .container').find('p img');
//		var selectedNo = $(this).parents('#photo .container').find('li a');
//		
//		$(selectedNo).removeClass('selected');
//		$(this).addClass('selected');
//		
//		if (imagePath == mainImage.attr('src')) {
//			return;
//			}
//		else {
//			$(mainImage).fadeOut('slow', function(){
//				$(this).fadeIn().attr('src', imagePath);
//				});
//			}
//		});
//	});

$(document).ready(function(){
	$('#photo .container li a').click(function(){
		var link = $(this);
		var img = $('#photo .container p img');
		var selectedNo = $(this).parents('#photo .container').find('li a');
		
		if (link.attr('href') != img.attr('src')) {			
			img.stop(true, false)
			.animate({'opacity': 0}, { duration: 'slow', complete: function(){				
				img
					.attr('src', link.attr('href'))
					.attr('alt', link.find('img').attr('alt'))
					.css({'opacity': 0})
					
					.load(function(){
						$(this).animate({'opacity': 1}, 'slow');
						});
					}});
				};
				
			$(selectedNo).removeClass('selected');
			$(this).addClass('selected');
            return false;
			});
		});





//***********************************
//ページスクロール
//***********************************
$(function () {
	$('a[href^=#], area[href^=#]').not('a[href=#], area[href=#]').each(function () {
		if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname && this.hash.replace(/#/, '')) {
			var $targetId = $(this.hash),
				$targetAnchor = $('[name=' + this.hash.slice(1) + ']');
			
			var $target = $targetId.length ? $targetId : $targetAnchor.length ? $targetAnchor : false;
				if ($target) {
					var targetOffset = $target.offset().top;
					
					$(this).click(function () {
						jQuery.easing.quart = function (x, t, b, c, d) {
							return -c * ((t = t / d - 1) * t * t * t - 1) + b;
							};
					
					$('html, body').animate({scrollTop: targetOffset}, 500, 'quart');
					return false;
					});
				}
			}
		});
	});





//***********************************
//詳細画面への表示切替
//***********************************
$(document).ready(function(){
	var name = "switch";
	
	//cookieがないときは
	if($.cookie(name) == null){
		$("#container .switch_thumbnail").addClass("switch_thumbnail");
		$("#container .switch_thumbnail").css("display", "block");
		$("#container .thumbnail").addClass("thumbnail");
		$("#container .thumbnail").css("display", "block");
		$("#container").css("margin", "0px auto -12px auto");
		$("#contents").addClass("contents_thumbnail");
		$("#contents .contents_thumbnail").css("display", "block");
		
		// トグルイベント
		$("a.switch").toggle(function(){
			$("#container .thumbnail").fadeOut("fast", function(){
				// IEのときは
				if($.browser.msie){
					$("#container .switch_thumbnail").fadeIn("fast",function(){ this.style.removeAttribute("filter"); }).addClass("switch_outline");
					$("#container .thumbnail").fadeIn("fast",function(){ this.style.removeAttribute("filter"); }).addClass("outline");
					$("#container").css("margin", "0px auto -30px auto");
					$("#contents").addClass("contents_outline");
					$.cookie(name,"OUTLINE", {path:'/' , expires:7});
					}
				
				// それ以外は
				else {
					$("#container .switch_thumbnail").fadeIn("fast").addClass("switch_outline");
					$("#container .thumbnail").fadeIn("fast").addClass("outline");
					$("#container").css("margin", "0px auto -30px auto");
					$("#contents").addClass("contents_outline");
					$.cookie(name,"OUTLINE", {path:'/' , expires:7});
					}
				});
			},
			
			
		function(){
			$("#container .thumbnail").fadeOut("fast", function() {
				// IEのときは
				if($.browser.msie){
					$("#container .switch_thumbnail").fadeIn("fast",function(){ this.style.removeAttribute("filter"); }).removeClass("switch_outline");
					$("#container .thumbnail").fadeIn("fast",function(){ this.style.removeAttribute("filter"); }).removeClass("outline");
					$("#container").css("margin", "0px auto -12px auto");
					$("#contents").removeClass("contents_outline");
					$.cookie(name,"", {path:'/' , expires:-1});	
					}
				
				// それ以外は
				else {
					$("#container .switch_thumbnail").fadeIn("fast").removeClass("switch_outline");
					$("#container .thumbnail").fadeIn("fast").removeClass("outline");
					$("#container").css("margin", "0px auto -12px auto");
					$("#contents").removeClass("contents_outline");
					$.cookie(name,"", {path:'/' , expires:-1});	
					}				
				});
			});
		}
	
	
	// cookieがあるときは
	else{
		$("#container .switch_thumbnail").addClass("switch_outline");
		$("#container .switch_thumbnail").css("display", "block");
		$("#container .thumbnail").addClass("outline");
		$("#container .thumbnail").css("display", "block");
		$("#container").css("margin", "0px auto -30px auto");
		$("#contents").addClass("contents_outline");
		$("#contents .contents_outline").css("display", "block");
		
		// トグルイベント
		$("a.switch").toggle(function(){
			$("#container .thumbnail").fadeOut("fast", function() {
				// IEのときは
				if($.browser.msie){
					$("#container .switch_thumbnail").fadeIn("fast",function(){ this.style.removeAttribute("filter"); }).removeClass("switch_outline");
					$("#container .thumbnail").fadeIn("fast",function(){ this.style.removeAttribute("filter"); }).removeClass("outline");
					$("#container").css("margin", "0px auto -12px auto");
					$("#contents").removeClass("contents_outline");
					$.cookie(name,"", {path:'/' , expires:-1});
					}
				
				// それ以外は
				else {
					$("#container .switch_thumbnail").fadeIn("fast").removeClass("switch_outline");
					$("#container .thumbnail").fadeIn("fast").removeClass("outline");
					$("#container").css("margin", "0px auto -12px auto");
					$("#contents").removeClass("contents_outline");
					$.cookie(name,"", {path:'/' , expires:-1});
					}
				});
			},
			
			
		function(){
			$("#container .thumbnail").fadeOut("fast", function(){
				// IEのときは
				if($.browser.msie){
					$("#container .switch_thumbnail").fadeIn("fast",function(){ this.style.removeAttribute("filter"); }).addClass("switch_outline");
					$("#container .thumbnail").fadeIn("fast",function(){ this.style.removeAttribute("filter"); }).addClass("outline");
					$("#container").css("margin", "0px auto -30px auto");
					$("#contents").addClass("contents_outline");
					$.cookie(name,"OUTLINE", {path:'/' , expires:7});
					}
				
				// それ以外は
				else {
					$("#container .switch_thumbnail").fadeIn("fast").addClass("switch_outline");
					$("#container .thumbnail").fadeIn("fast").addClass("outline");
					$("#container").css("margin", "0px auto -30px auto");
					$("#contents").addClass("contents_outline");
					$.cookie(name,"OUTLINE", {path:'/' , expires:7});
					}
				});
			});
		}
	});
	
	
	
	
		
//***********************************
//Google Analyticsの処理　
//***********************************
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
var header = document.getElementsByTagName("head")[0];
var scriptTag = document.createElement("script");

scriptTag.setAttribute("src", gaJsHost + "google-analytics.com/ga.js");
scriptTag.setAttribute("type", "text/javascript");
header.appendChild(scriptTag);

function analytics(){
	try{
		var pageTracker = _gat._getTracker("UA-25735122-1");
		pageTracker._trackPageview();
		}
	catch(err){
		// alert("Google Analytics:" + err);
		}
	}
	
if (window.attachEvent){
	window.attachEvent("onload", analytics);
	}
	
else{
	window.addEventListener("load", analytics, false);
	}
