$(document).ready(function(){
  $(".topnav li").each(function(){
    $(this).append("<span></span>")}).hover(function(){
				$(this).find("span").stop(true).animate({width:'100%'},150).animate({height:'43px'},100).css("cursor","pointer")},function(){
					$(this).find("span").stop(true).animate({height:'36px'},100).animate({width:'0'},150)}).click(function(){window.location=$(this).find("a").attr("href");return false});
						getBodyID=$('#pageID').attr('class');
						$('ul.catnav li').each(function(){
							getNavClass=$(this).attr('class');
							if(getNavClass==getBodyID){$(this).addClass('active')}
						});
						$('ul.catnav > li').hover(function(){
							$('ul.catnav li').removeClass('active');
							$(this).addClass('active')},function(){$('ul.catnav li').removeClass('active');
							  $('ul.catnav li').each(function(){
								  getNavClass=$(this).attr('class');
								  if(getNavClass==getBodyID){$(this).addClass('active')}
								})
							});
												$('pre').hover(function(){$(this).stop().animate({width:680},300).css({'overflow-x':'scroll'})},function(){$(this).stop().animate({width:478},300).css({'overflow-x':'scroll'})});
												$('ul.aux li a span').click(function(){
													if($(this).parent().next().is(":visible")){
														$(this).parent().next().slideUp('fast')
													}else{
														$(".drop").slideUp();
													$(this).parent().next().slideDown('fast')
												  }
												});
												$('.drop p a').click(function(){
														window.location=$(this).attr("href");
														return false;
													});
														$('#speak input, #speak textarea, input#search').each(function(){var a=$(this).val();
															$(this).attr({title:a})}).focus(function(){if(this.value==$(this).attr('title')){this.select()}}).blur(function(){if(this.value==''){this.value=$(this).attr('title')}});
																$("input#submit").click(function(){if($('input.url').attr('value')=='Your URL...'){$('input.url').attr({value:''})}});
																$(".experience .desc").hide();
																$(".experience h3").click(function(){if($(this).hasClass("open")){$(".experience div").slideUp('fast')}else{$(".experience h3").removeClass("open");
																	$(".experience div").slideUp('fast');
																	$(this).next().slideToggle('fast')}$(this).toggleClass("open");
																	return false});
																	$('.col4 section:first-child').css({'margin-left':'0'});
																	$('#home .blog li:last-child, #blog .bloglist li:last-child, #blog .scrollbox li:last-child').addClass('last');
																	$('ul.popularposts li:last').removeClass('last');
																	$('#catlevel article').hover(function(){$(this).addClass('hover')},function(){$(this).removeClass('hover')});
																	$('a.switchview').click(function(){$(this).toggleClass('on');
																		$('.post').toggleClass('white');
																		return false});
																		if($('.wpcf7-not-valid-tip-no-ajax').length==1){$("input.email").addClass("alert")}$('.drop a, #comments small a, .ads a').attr({target:"_blank"});
																		$('img.wp-post-image').before('<span></span>');
																		$('.footwrap .twitter').click(function(){window.location='http://www.twitter.com/sohtanaka';return false});
																			$('.twitter').append("<span></span>").hover(function(){$(this).parent().parent().css({'background-position':'center bottom'})},function(){$(this).parent().parent().css({'background-position':'center top'})});
																			$('.testimonials blockquote:first-child').show();
																			$(function(){$('.testimonials blockquote:gt(0)').hide();
																				setInterval(function(){$('.testimonials blockquote:first-child').fadeOut().next().fadeIn().end().appendTo('.testimonials')},10000)});
																					$('.photo img:first-child').show();
																					$(function(){$('.photo img:gt(0)').hide();
																						setInterval(function(){$('.photo img:first-child').fadeOut().next().show().end().appendTo('.photo')},3000)});
																							$('.control img').animate({right:-55,opacity:0},1);
																							$('.desc').hover(function(){$(this).find('.control img').stop().animate({right:-45,opacity:1},200).show()},function(){$(this).find('.control img').stop().animate({right:-55,opacity:0},function(){$(this).hide()})});
$(window).load(function(){
  function scrollableElement(a){
    for(var i=0,argLength=arguments.length;i<argLength;i++){
      var b=arguments[i],$scrollElement=$(b);
      if($scrollElement.scrollTop()>0){
      	return b;
      }else{
      	$scrollElement.scrollTop(1);
        var c=$scrollElement.scrollTop()>0;
        $scrollElement.scrollTop(0);
        if(c){return b;}
      }
		}
    return[];
  }

	function filterPath(a){return a.replace(/^\//,'').replace(/(index|default).[a-zA-Z]{3,4}$/,'').replace(/\/$/,'')}
	var d=filterPath(location.pathname);
	var e=scrollableElement('html','body');
	$('a[href*=#]').each(function(){
		var b=filterPath(this.pathname)||d;
		if(d==b&&(location.hostname==this.hostname||!this.hostname)&&this.hash.replace(/#/,'')){
			var c=$(this.hash),target=this.hash;
			if(target){
				//targetOffset=c.offset().top;
				targetOffset=$(this).offset().top;
				$(this).click(function(a){
					a.preventDefault();
					$(e).animate({scrollTop:targetOffset},400,function(){location.hash=target})
				})
			}
		}
	})
});

	if($(".scrollbox").length>0){
		var g=$('.scrollbox').offset().top-parseFloat($('.scrollbox').css('marginTop').replace(/auto/,0));
		$('li.web').addClass('active');
		$(window).scroll(function(a){
			var y=$(this).scrollTop();
			if(y>=g){
				$('.scrollbox').addClass('fixed');
				$('.scrollbox .backtop').show()
			}else{
				$('.scrollbox').removeClass('fixed');
				$('.scrollbox .backtop').hide()
			}
			if($("#web-design-portfolio").length>0){
				var b=$(window).width();
				var c=(b/2)-480;
				var d=$('#webdesign').offset().top-parseFloat($('#webdesign').css('marginTop').replace(/auto/,0));
				var e=$('#illustrations').offset().top-parseFloat($('#illustrations').css('marginTop').replace(/auto/,0));
				var f=$('#articles').offset().top-parseFloat($('#articles').css('marginTop').replace(/auto/,0));
				if(y>=g){
					$('.scrollbox').addClass('fixed').css({'right':c});
					$('.scrollbox .backtop').show()
				}else{
					$('.scrollbox').removeClass('fixed');
					$('.scrollbox .backtop').hide()
				}

				if(y>=d){
					$('.folionav li').removeClass('active');
					$('li.web').addClass('active')
				}else{
					$('li.web').removeClass('active')
				}

				if(y>=e){
					$('.folionav li').removeClass('active');
					$('li.illus').addClass('active')
				}else{
					$('li.illus').removeClass('active');
				}

				if(y>=f){
					$('.folionav li').removeClass('active');
					$('li.articles').addClass('active')
				}else{
					$('li.articles').removeClass('active');
				}
			}}
		)
	}
});

