$(document).ready(function(){
	//draw();
	//$('.CardHolder').scale(0.1);
	//$('.CardHolder').animate({scale: '1'}, 1000, function(){
		$('.Card').not('.Home').each(function(){
			$(this).animate({rotate: -10 + Math.random()*20}, 1000);
		});
		$('.Ring, .HomeLink a').click(function(){SwitchCard('Home');});
		$('.PortfolioLink a').click(function(){SwitchCard('Portfolio');});
		$('.ArtLink a').click(function(){SwitchCard('Art');});
		$('.AboutLink a').click(function(){SwitchCard('About');});
		$('.MusicLink a').click(function(){SwitchCard('Music');});
		$('.BlogLink a').click(function(){return GoToBlog($(this).attr('href'))});
	//});
});

function SwitchCard(pClass){
	AnalyticsCode(pClass);
	var movehunt = false;
	$('.Card').each(function(index){
		if($(this).hasClass(pClass)){
			$(this).addClass('Active');
			if($(this).hasClass('Moved')){
				$(this).removeClass('Moved').animate({rotate: '0deg'}, 1000);
				movehunt = true;
			}else{
				$(this).animate({rotate: '0deg'}, 1000);
				return false;
			}
		}else{
			if($(this).hasClass('Active')){
				$(this).removeClass('Active');
			}
			if(!$(this).hasClass('Moved')){
				if(movehunt == true){
					return false;
				}else if(movehunt == false){
					$(this).addClass('Moved').delay(index*200).animate({rotate: 180 + Math.random()*40 - index*20}, 1000);
				}
			}else{
				if(movehunt == true){
					$(this).removeClass('Moved').delay(index*200).animate({rotate: -10 + Math.random()*20}, 1000);
				}
			}

		}
	});
	return false;
}

function GoToBlog(target){
	$('.CardHolder').animate({scale: '0.1'}, 1000, function(){
		$('.CardHolder').hide();
		window.location = target;
	});
	return false;
}

function draw() {
      var canvas = document.getElementById("Background");
      if (canvas.getContext) {
        var ctx = canvas.getContext("2d");

        ctx.fillStyle = "rgb(200,0,0)";
        ctx.fillRect (10, 10, 55, 50);

        ctx.fillStyle = "rgba(0, 0, 200, 0.5)";
        ctx.fillRect (30, 30, 55, 50);
      }
    }
	
function AnalyticsCode(pClass){
	var pagename = '/' + pClass;
	if(pClass == 'Home'){
		pagename = '/';
	}
	try{
		_gaq.push(['_trackPageview', pagename]);
	}catch(e){}
}
