/* Author: Richard J Keys */
$(document).ready(function(){
	$("#notThatRichardKeys").hide();
	
	var isiPad = navigator.userAgent.match(/iPad/i) != null;
	//setting section heights
	
	if(!isiPad)
	{
	height = $(window).height();
	if(height>=820)
		$("#landing").height(height);
	else
		$("#landing").height(820);
	
	$("section").height(height*0.75).css({'margin-bottom':height*0.25+'px'});
	}
	else
	{
		//$("#landing").css({'height':'1024px','margin-bottom':'100px'});
		//$("section").css({'height':'1024px','margin-bottom':'100px'});
	}
	

	var paper = Raphael(document.getElementById("wheel"), 460, 460);	
	var needle = paper.image("images/needle.png", 50, 50, 360, 360);
		
	needle.click(function () {
	    var random = Math.floor(Math.random()*10);
	    switch (random)
	    {
	    case 0:
	    	href = "#about";
	    	break;
	    case 1:
	    	href = "#contact";
	    	break;
	    case 2:
	    	href = "#education";
	    	break;
	    case 3:
	    	href = "#interests";
	    	break;
	    case 4:
	    	href = "#links";
	    	break;
	    case 5:
	    	href = "#location";
	    	break;
	    case 6:
	    	href = "#music";
	    	break;
	    case 7:
	    	href = "#occupation";
	    	break;
	    case 8:
	    	href = "#photos";
	    	break;
	    case 9:
	    	href = "#twitter";
	    	break;
	    }
	    rotation = (random * 36) + 1098;
	    if(!isiPad)
	    {
	    	var t = setTimeout(function(){$.scrollTo(href,1000);},2400);
	    }
	    else
	    {
	    	var t = setTimeout(function(){window.location = href},2800);
	    }
	    var t2 = setTimeout(function(){needle.rotate(-1080);},3000);
	    needle.animate({rotation: rotation},2400,"backOut");
	});
	
	$("#wheel li a").click(function(e){
		
			
				e.preventDefault();
				
				var buttonIndex = $(this).parent().index();
				var href = $(this).attr("href");
				
				rotation = (buttonIndex * 36) + 18;
			if(!isiPad)
			{
				var t = setTimeout(function(){$.scrollTo(href,1000)},800);
			}
			else
			{
				var t = setTimeout(function(){window.location = href},1200);
			}
			
		
		needle.animate({rotation: rotation},800,"backOut");
		
	});
	
	$(".backToWheel").click(function(e){
		e.preventDefault();
		if(!isiPad)
		{
			$.scrollTo("#landing",1000);
		}
		else
		{
			window.location = "#landing";
		}
		
	});
	
	$(".internalScroll").click(function(e){
		e.preventDefault();
		if(!isiPad)
		{
			$.scrollTo($(this).attr("href"),1000);
		}
		else
		{
			window.location = $(this).attr("href");
		}
	});	
		
	//Get Delicious Links
	$.ajax({
		type: 'GET',
		url: 'http://feeds.delicious.com/v2/json/richardjkeys?count=10',
		dataType: 'jsonp',
		success: function(data){
			$("#links p:last-child").before('<ul></ul>');
			$.each(data, function(i,obj){
				$("#links ul").append('<li><a href="'+obj.u+'">'+obj.d+'</a></li>');
			});
		}
	});
	var h = 0;
	$("ol.tweets li").each(function(){
		height = $(this).height();
		if($(this).height()>h)
		{
			h = $(this).height();
			
		}		
	});
	$("ol.tweets li").height(h);
	
	//Get Last.fm top albums
//	$.ajax({
//		url: 'http://ws.audioscrobbler.com/2.0/?method=user.gettopalbums&user=richardjkeys&api_key=163b8f2e8ef7c239fd06814287589122&limit=36&format=json',
//		dataType: "jsonp",
//		success: function(data) {
//			$("#music p:last-child").before('<ol class="thumbs"></ol>');
//			
//			$.each(data.topalbums.album,function(i,album){
//				switch (i)
//				{
//				case 0:
//					className = "grid_1 alpha";
//					break;
//				case 11:
//					className = "grid_1 omega";
//					break;
//				case 12:
//					className = "grid_1 alpha";
//					break;
//				case 23:
//					className = "grid_1 omega";
//					break;
//				case 24:
//					className = "grid_1 alpha";
//					break;
//				case 35:
//					className = "grid_1 omega";
//					break;
//				default:
//					className = "grid_1";
//					break;
//				}
//				if(i<36)
//				{
//					$("#music ol.thumbs").append('<li class="'+className+'"><a href="'+album.url+'" title="Link to Last.fm - '+album.artist['name']+' - '+album.name+'"><img src="'+album.image[1]['#text']+'" width="59" alt="'+album.name+'"/></a></li>');
//				}
//			});
//		}
//	});
});
