// JavaScript Document
function start(){
	$("#arrows > div").css('opacity', '.1');
	$.get("xml/projects.xml", function(response){
		_data = response;
		$(_data).find('projects > project').each(function(index){
			var str = '<div id=project_"'+index+'"><a target="_blank" href="#"><img border="0" width="" height=""/></a></div>';
			
			var path = $(this).find('path').text();
			if(path == null || path == ""){
				
			} else {
				$("#right_column").append(str);	
				$("#right_column > div:last-child > a > img").attr('src', path);
				$("#right_column > div:last-child > a").attr('href', path);
				$("#right_column > div:last-child").append("<h5>"+$(this).find('name').text()+"</h5>");	
				$("#right_column > div:last-child").addClass('project');
				$("#right_column > div:last-child").append('<p>'+$(this).find('description').text()+'</p>');
				if((index + 1) % 3 == 0){
					$("#right_column > div:last-child").addClass('last');
				}
				if($(this).find("links > link").length == 1){
					$("#right_column > div:last-child").append('<p class="view"><a target="_blank" href="'+$(this).find("links > link").text()+'">View It &raquo;</a></p>');
					
				} else if($(this).find("links > link").length == 0){
					//console.log('real bad: ' + $(this).find('name').text());
				} else {
					var toApp = '<p class="view">View It:</p>';
					$(this).find("links > link").each(function(count){
						toApp += '<div class="number"><p><a href="'+$(this).text()+'" target="_blank">'+(count+1)+"</a></p></div>";	   
					});
					$("#right_column > div:last-child").append(toApp);
				}
				if($(this).find("links > link").length) $("#right_column > div:last-child > a").attr('href', $($(this).find("links > link")[0]).text());
			}
		});	
		$("#right_column img").mouseover(function(){
													
			$(this).css('border', '1px solid #ffd11a');										
		});
		$("#right_column img").mouseout(function(){
													
			$(this).css('border', '1px solid #000');										
		});
		Cufon.refresh();
		
		/*$.get("ws.audioscrobbler.com/2.0/?limit=6&period=7day&method=user.gettopartists&user=gr8one884&api_key=2126313075d2569a95b902fddb104e95", function(res){
			alert($(res).find('artist').length());											  
		});*/
		$('div[rel=tooltip]').mouseover(
				function(e){   
					
					var tip = $(this).attr('title');  
					if(tip != '' && tip != null){
						$(this).attr('title',''); 
						$(this).append('<div id="tooltip"><div class="tipHeader"></div><div class="tipBody">' + tip + '</div><div class="tipFooter"></div></div>');      
						$('#tooltip').css('top', (e.pageY - 20)+'px' );   
						$('#tooltip').css('left', (e.pageX + 20)+'px' );   
						//$('#tooltip').fadeIn('500');   
						//$('#tooltip').fadeTo('10',0.8); 
					}
				}
			)
			$('div[rel=tooltip]').mouseout(
				function(e){
					
					//Put back the title attribute's value   
					$(this).attr('title',$('.tipBody').html());   
	
					//Remove the appended tooltip template   
					$(this).children('div#tooltip').remove(); 
				}
			)
			$('div[rel=tooltip]').mousemove(
				function(e){
					
					$('#tooltip').css('top', (e.pageY - 20)+'px' );   
					$('#tooltip').css('left', (e.pageX + 20)+'px' );   
				}
			)
	});
}

var _data;

Cufon.now();
	
window.JS = {start: start};
