//ロールオーバー
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);
}


pathname = window.location.pathname;
file_url = pathname.substring(pathname.lastIndexOf('/')+1,pathname.length)
file = file_url.replace('.html', '')

hash = window.location.hash;
hashID = hash.substring(hash.lastIndexOf('/')+1,hash.length);

cH = '';

function topJS(){
	//$('#line1 .thumbnailBox:even,#line2 .thumbnailBox:even,#line3 .thumbnailBox:even,#line4 .thumbnailBox:even,#line5 .thumbnailBox:even').addClass('even');
	//$('#line1 .thumbnailBox:odd,#line2 .thumbnailBox:odd,#line3 .thumbnailBox:odd,#line4 .thumbnailBox:odd,#line5 .thumbnailBox:odd').addClass('odd');
	$('#contentsArea').append('<p id="detailClose"><a href="javascript:void(0);" rel="home"><img src="/images/top/btn_detailClose.gif" alt="閉じる" /></a></p>')
	$('#contentsArea').css({height:0});
	
	$.fn.contentOut = function() {
		if(hashID == "/") {
			return false;
		} else {
			$('#contentsArea').animate({height:0},600);
		}	
		return this;
	}
	
	$.fn.contentIn = function() {
		if(hashID == "/") {
			return false;
		} else {
			$('#contentsArea').animate({height:cH},600);
		}
		return this;
	}



	if(hash == ''){
		if(file == 'index') {
			location.href = '#/';
			$('body').attr('id','home');
		} else if(file == ''){
			location.href = '#/';
			$('body').attr('id','home');
		} else {
			location.href = '#/' + file;
			$('body').attr('id',file);
		}
	}
	
	$('.viewLink a').click(function(){
		if($('#contentsArea').is(':animated')) {
			return false;
		} else {
			linkDef = $(this).attr('rel');
			if(linkDef == 'home') {
				jsLink = '#/';	
			} else {
				jsLink = '#/' + linkDef;	
			}
			
			if(hash != jsLink){
				if(hash == '#/') {
					if($('html,body').scrollTop() != 100) {
						$('html,body').animate({ scrollTop: 100 }, 700, 'easeOutQuart',function(){
							location.href = jsLink;
						});
					} else {
							location.href = jsLink;
					}
				} else {
					if($('html,body').scrollTop() != 100) {
						$('html,body').animate({ scrollTop: 100 }, 700, 'easeOutQuart',function(){
							$('#contentsArea').contentOut();
							location.href = jsLink;
						});
					} else {
							$('#contentsArea').contentOut();
							location.href = jsLink;
					}
				}
				return false;
			} else {
				return false;
			}
		}
	});
	
	$('.thumbnailImg').click(function(){
		if($('#contentsArea').is(':animated')) {
			return false;
		} else {
			linkDef = $('a',this).attr('rel');
			if(linkDef == 'home') {
				jsLink = '#/';
			} else {
				jsLink = '#/' + linkDef;	
			}
			
			if(hash != jsLink){
				if(hash == '#/') {
					if($('html,body').scrollTop() != 100) {
						$('html,body').animate({ scrollTop: 100 }, 700, 'easeOutQuart',function(){
							location.href = jsLink;
						});
					} else {
							location.href = jsLink;
					}
				} else {
					if($('html,body').scrollTop() != 100) {
						$('html,body').animate({ scrollTop: 100 }, 700, 'easeOutQuart',function(){
							$('#contentsArea').contentOut();
							location.href = jsLink;
						});
					} else {
							$('#contentsArea').contentOut();
							location.href = jsLink;
					}
				}
				return false;
			} else {
				return false;
			}
		}
	});
	
	$('#logo .viewLink').click(function(){
		if($('#contentsArea').is(':animated')) {
			return false;
		} else {
			linkDef = $(this).attr('rel');
			if(linkDef == 'home') {
				jsLink = '#/';	
			}
			if(hash != jsLink){
				$('#contentsArea').contentOut();
				location.href = jsLink;
				return false;
			} else {
				return false;
			}
		}
	});
	
	$('#detailClose').click(function(){
		if($('#contentsArea').is(':animated')) {
			return false;
		} else {
			$('#contentsArea').contentOut();
			location.href = '#/';
			$('body').attr('id','home');
			return false;
		}
	});


	$(window).hashchange( function(){							   
		hash = window.location.hash;
		hashID = hash.substring(hash.lastIndexOf('/')+1,hash.length);
			setTimeout(function(){
				if(hash == '#/') {
					return false;
				} else  {
					$('#changeArea').load('works/' + hashID + '.html #contentsArea > *',function(){
						cH = $('#detailArea').height();
						$('#contentsArea').contentIn();
					});
					$('body').attr('id',hashID);
				}
			},600);
	});
	$(window).hashchange();
	
	
	$('.thumbnailImg').hover(function() {
		var thumbOver = $(this).find('img').attr('src');
		$(this).find('a').css({'background' : 'url(' + thumbOver + ') no-repeat center bottom'});
		$(this).find('span').stop().fadeTo(200, 0 , function() {
			$(this).hide()
		});
	} , function() {
		$(this).find('span').stop().fadeTo(200, 1).show();
	});
};
//document.title = jsTitle;
