//LAYOUT SCROLLING
$(document).ready(function() {
	$('a.panel').click(function () {

		$('a.panel').removeClass('selected');
		$(this).addClass('selected');

		current = $(this);

		$('#wrapper').scrollTo($(this).attr('href'), 800);
		return false;
	});

	$('#wrapper').scrollTo($('#home'), 0); //initial landing

	$(window).resize(function () {
		resizePanel();
	});

});

function resizePanel() {

	width = $(window).width();
	height = $(window).height();

	mask_width = width * $('.item').length;

	$('#debug').html(width  + ' ' + height + ' ' + mask_width);

	$('#wrapper, .item').css({width: width, height: height});
	$('#mask').css({width: mask_width, height: height});
	$('#wrapper').scrollTo($('a.selected').attr('href'), 0);

}


//KEY NAV

document.onkeyup = KeyCheck;       

function KeyCheck(e)

{

   var KeyID = (window.event) ? event.keyCode : e.keyCode;

   switch(KeyID)

   {
      case 36:
      case 72:

	// go home or h = home
		//Navigation animation effect
		$("#keyHome").css("background-position","0 -50px");
		setInterval( '$("#keyHome").css("background-position","0 0");', 500 );
	$('#wrapper').scrollTo($('#home'), 800);
	break; 

      case 37:
      case 71:

	// go left arrow or g = cogwurx
		$("#keyCog").css("background-position","0 -50px");
		setInterval( '$("#keyCog").css("background-position","0 0");', 500 );
	$('#wrapper').scrollTo($('#cog'), 800);
	break;

      case 38:
      case 66:

	// go up arrow or b = bio
		$("#keyBio").css("background-position","0 -50px");
		setInterval( '$("#keyBio").css("background-position","0 0");', 500 );
	$('#wrapper').scrollTo($('#bio'), 800);
	break;

      case 39:
      case 84:

	// go right arrow or t = tom and Jerry
		$("#keyTnj").css("background-position","0 -50px");
		setInterval( '$("#keyTnj").css("background-position","0 0");', 500 );
	$('#wrapper').scrollTo($('#tnj'), 800);
	break;

      case 40:
      case 67:

	// go down arrow or c = contact
		$("#keyContact").css("background-position","0 -50px");
		setInterval( '$("#keyContact").css("background-position","0 0");', 500 );
	$('#wrapper').scrollTo($('#contact'), 800);
	break;

      case 27:

	// go esc
	alert("Bye! Thanks for visiting!");
	window.location = "http://www.google.com/#hl=en&source=hp&q=romeo+and+juliet&aq=0&aqi=g10&aql=&oq=Romeo&gs_rfai=CLMa98rk0TNjsBJ-yMcr6vYgKAAAAqgQFT9Ctkew&fp=36ec6be010d257f";
	break;

      case 88:

	// x = closes legend
	$(function() {
		callback();
		return false;
	});
	break;

      case 76:
      
	// l = Legend
	$(function() {

		//run the currently selected effect
		function legendEffect(){
			//get effect type from 
			var selectedEffect = 'bounce';
			
			//run the effect
			$("#effect").show(selectedEffect,500);
		};
		
		
			legendEffect();
			return false;
		
		$("#effect").hide();
	});
	break;
	
      case 74:
	// go j
	if (confirm("Awesome! Do you want to see some great artwork?")) {
			window.location = "http://www.jzartworks.com";
			return true;
	   } else {
		   return false;
	   }
	break;
	
      case 18:
	// go alt
	if (confirm("Great Find! You will be rewarded with more visuals of my artwork!")) {
			window.location = "http://cogwurx.deviantart.com";
			return true;
	   } else {
		   return false;
	   }
	break;
	
      case 190:
      case 191:
	// go alt
	$(function() {	

			//Get the A tag
			var id = '#dialog';

			//Get the screen height and width
			var maskHeight = $(document).height();
			var maskWidth = $(window).width();

			//Set heigth and width to mask to fill up the whole screen
			$('#cover').css({'width':maskWidth,'height':maskHeight});

			//transition effect		
			$('#cover').fadeIn(1000);	
			$('#cover').fadeTo("slow",0.8);	

			//Get the window height and width
			var winH = $(window).height();
			var winW = $(window).width();

			//Set the popup window to center
			$(id).css('top',  winH/2-$(id).height()/2);
			$(id).css('left', winW/2-$(id).width()/2);

			//transition effect
			$(id).fadeIn(2000); 

		});	
			return false;
	    	break;
   }

}


//THE LEGEND

	$(function() {

		//run the currently selected effect
		function runEffect(){
			//get effect type from
			var selectedEffect = 'bounce';

			//most effect types need no options passed by default
			var options = {};
			//check if it's scale or size - they need options explicitly set
			if(selectedEffect == 'scale'){  options = {percent: 100}; }
			else if(selectedEffect == 'size'){ options = { to: {width: 280,height: 185} }; }

			//run the effect
			$("#effect").show(selectedEffect,options,1000);
		};
			runEffect();
			return false;

	});

		//callback function to close the legend
		function callback(){
			var selectedEffect = 'blind';
			$("#effect:visible").removeAttr('style').hide(selectedEffect,1000).fadeOut();
		};

//IE6 REDIRECT

	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
	 var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
	 if (ieversion==6)
	  window.location = "ie6.html"
	}

//HELP!! TRINITY!
$(document).ready(function theModal() {	

	//select all the a tag with name equal to modal
	$('a[name=modal]').click(function(e) {
		//Cancel the link behavior
		e.preventDefault();
		
		//Get the A tag
		var id = $(this).attr('href');
	
		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
	
		//Set heigth and width to mask to fill up the whole screen
		$('#cover').css({'width':maskWidth,'height':maskHeight});
		
		//transition effect		
		$('#cover').fadeIn(1000);	
		$('#cover').fadeTo("slow",0.8);	
	
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
              
		//Set the popup window to center
		$(id).css('top',  winH/2-$(id).height()/2);
		$(id).css('left', winW/2-$(id).width()/2);
	
		//transition effect
		$(id).fadeIn(2000); 
	
	});
	
	//if close button is clicked
	$('.window .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		
		$('#cover').hide();
		$('.window').hide();
	});		
	
	//if mask is clicked
	//$('#cover').click(function () {
	//	$(this).hide();
	//	$('.window').hide();
	//});			
	
});

