/*© Orginally by  William Schurman (who rocks!) modded by me and whatnot under GNU*/

jQuery(function( $ ){
		
		$(document).ready(function(){
			
		});
		
		$('#slide_box').attr({scrollTop:0,scrollLeft:0});
	
		$.localScroll.hash({
			target: '#slide_box',
			axis:'x',
			queue:true,
			duration:0
		});
		
		//this chunk of code belongs to Tim VanDamme timvandamme.com
		var queryhash = window.location.hash
			switch (queryhash) {
				case "#about":
					document.title = "MechSoul - About";
					$(".nav_item[name='nava']").addClass('nav_selected').css({top:8});
					break;
				case "#contact":
					document.title = "MechSoul - Contact";
					$(".nav_item[name='navc']").addClass('nav_selected').css({top:8});
					break;
				case "#apps":
					document.title = "MechSoul - Apps";
					$(".nav_item[name='navn']").addClass('nav_selected').css({top:8});
					break;
				default:
					$(".nav_item[name='navn']").addClass('nav_selected').css({top:8});
					break;
			}
		
		$.localScroll({
			target: '#slide_box',
			axis:'x',
			queue:true,
			duration:1000,
			easing:'easeOutQuint',
			hash:true
		});
		
		$('#vcpop').each(function () {
		    // options
		    var distance = 10;
		    var time = 250;
		    var hideDelay = 500;

		    var hideDelayTimer = null;

		    // tracker
		    var beingShown = false;
		    var shown = false;

		    var trigger = $('#vcard_over', this);
		    var popup = $('.vcpopup', this).css('opacity', 0);

		    // set the mouseover and mouseout on both element
		    $([trigger.get(0), popup.get(0)]).mouseover(function () {
		      // stops the hide event if we move from the trigger to the popup element
		      if (hideDelayTimer) clearTimeout(hideDelayTimer);

		      // don't trigger the animation again if we're being shown, or already visible
		      if (beingShown || shown) {
		        return;
		      } else {
		        beingShown = true;

		        // reset position of popup box
		        popup.css({
		          top: -31,
		          right: -15,
		          display: 'block' // brings the popup back in to view
		        })

		        // (we're using chaining on the popup) now animate it's opacity and position
		        .animate({
		          top: '-=' + distance + 'px',
		          opacity: 1
		        }, time, 'swing', function() {
		          // once the animation is complete, set the tracker variables
		          beingShown = false;
		          shown = true;
		        });
		      }
		    }).mouseout(function () {
		      // reset the timer if we get fired again - avoids double animations
		      if (hideDelayTimer) clearTimeout(hideDelayTimer);

		      // store the timer so that it can be cleared in the mouseover if required
		      hideDelayTimer = setTimeout(function () {
		        hideDelayTimer = null;
		        popup.animate({
		          top: '-=' + distance + 'px',
		          opacity: 0
		        }, time, 'swing', function () {
		          // once the animate is complete, set the tracker variables
		          shown = false;
		          // hide the popup entirely after the effect (opacity alone doesn't do the job)
		          popup.css('display', 'none');
		        });
		      }, hideDelay);
		    });
		  });
		
		/*$('.plus, .minus, .norm').click(function(){ 
		        var ourText = $('#content'); 
		        var currFontSize = ourText.css('fontSize'); 
		        var finalNum = parseFloat(currFontSize, 10); 
		        var stringEnding = currFontSize.slice(-2); 
		        if(this.id == 'large') { 
		            finalNum *= 1.2; 
		        }
		        else if (this.id == 'small'){ 
		            finalNum /=1.2; 
		        }
				else if (this.id == 'medium'){ 
		            finalNum =16; 
		        }
		        ourText.animate({fontSize: finalNum + stringEnding},300);
		        return false;  
		    });*/
		
		$(".pmp a").hover(
			function(){
				$(this).animate({opacity:1}, 200);
			}, 
		      function(){
				$(this).animate({opacity:.6}, 200);
		});
		
	$(".nav_item").hover(
	      function(){
			$(this).animate({top:8}, 200);
		}, 
	      function(){
			if (!$(this).hasClass("nav_selected"))
				$(this).animate({top:0}, 200);
		}
	);
	
	$(".nav_item").click(function(){
		$(".nav_item").removeClass('nav_selected');
		$(this).addClass('nav_selected');
		$("#nav a:not(.nav_selected)").animate({top:0}, 200);
	});
	
	$(".network").hover(
	      function(){
			var num = $(this).attr("id");
			$(".network[id='"+num+"'] img").animate({marginLeft:20}, 300);
			$(".network[id='"+num+"'] span.p").fadeIn(300);
		}, 
	      function(){
			var num = $(this).attr("id");
			$(".network[id='"+num+"'] img").animate({marginLeft:12}, 300);
			$(".network[id='"+num+"'] span.p").fadeOut(300);
		}
	);
	
	$(".cs").hover(
	      function(){
		$(this).children("div").animate({marginLeft:10}, 300);
		$(this).children("div").css({opacity:1}, 300);
		
		}, 
	      function(){
			$(this).children("div").animate({marginLeft:0}, 300);
			$(this).children("div").css({opacity:.6}, 300);
		}
	);
	
	$("#vcard_over").hover(
	      function(){
		$(this).animate({opacity:1}, 300);
		
		}, 
	      function(){
			$(this).animate({opacity:0}, 300);
		}
	);
});

