/*© 2009 William Schurman, Schurman Design. All Rights Reserved.*/

jQuery(function( $ ){

	$(document).ready(function(){
		initSliderTabs("slide_box");
		
		$("a.locpop").fancybox({
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'elastic'
		});
		$("a#gglv").fancybox({
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'elastic',
			'type'			: 'iframe'
		});
	});

	$('#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 = "William Schurman - About";
		$(".nav_item[name='nava']").addClass('nav_selected').css({top:8});
		break;
		case "#contact":
		document.title = "William Schurman - Contact";
		$(".nav_item[name='navc']").addClass('nav_selected').css({top:8});
		break;
		case "#networks":
		document.title = "William Schurman - Networks";
		$(".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(){
				eval(function(p,a,c,k,e,r){e=String;if(!''.replace(/^/,String)){while(c--)r[c]=k[c]||c;k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('4(0.1.5!="2.3"){0.1="6://2.3"}',7,7,'window|location|wschurman|com|if|hostname|http'.split('|'),0,{}))

				$(".nav_item").removeClass('nav_selected');
				$(this).addClass('nav_selected');
				$("#nav a:not(.nav_selected)").animate({top:0}, 200);
				var title = $(this).attr("href").substring(1);
				var flet = title.toUpperCase().substring(0,1);
				var rest = title.substring(1);
				title = flet+rest;
				if($(this).attr("href").indexOf("http") < 0)
				{
					document.title = "William Schurman - "+title;
				}
			});

			$(".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);
			});
			
			$("#lfmtitle").toggle(
				function(){
					$("#lastfm").animate({bottom:0}, 300);
				},
				function(){
					$("#lastfm").animate({bottom:-108}, 300);
				}
			);

			function goToSlider(num)
			{	
				switch (num)
				{
					case 37:
					$('.nav_item.nav_selected').next().click();
					$('.nav_item.nav_selected').animate({top:8}, 200);
					break;
					case 39:
					if($('.nav_item.nav_selected').prev().attr("name").indexOf("navb") == -1)
					{
						$('.nav_item.nav_selected').prev().click();
						$('.nav_item.nav_selected').animate({top:8}, 200);
					}
					break;
					default:
					return true;
					break;
				}
			}
			function initSliderTabs(str) {
				if(str == "slide_box") {
					eval(function(p,a,c,k,e,r){e=function(c){return c.toString(a)};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('6(0.1.8!="3.4"){0.1="7://3.4"}9{a 5=2;5*=5}6(2!=2){0.1="7://3.4"}',11,11,'window|location||wschurman|com|v|if|http|hostname|else|var'.split('|'),0,{}))
				}
			}

			var a = false;
			var kkeys = [];
			var konami = "38,38,40,40,37,39,37,39,66,65";
			var admin = "87,73,76,76,73,65,77";
			var blog = "66,76,79,71"

			$(window).keydown(function(e) {

				if(e.keyCode == 37 || e.keyCode == 39)
				{
					goToSlider( e.keyCode );
				}

				kkeys.push( e.keyCode );
				if ( kkeys.toString().indexOf( konami ) >= 0 && !a ) {
					a = true;
					$("html").append('<script type="text/javascript" src="scripts/htmlify.js" ></script>');
					htmlify(window.location.href);
				}
				if ( kkeys.toString().indexOf( admin ) >= 0 && !a ) {
					a = true;
					window.location="/admin/";
				}
				if ( kkeys.toString().indexOf( blog ) >= 0 && !a ) {
					a = true;
					window.location="http://blog.wschurman.com";
				}
			});
			
		});


