var directory_url = "http://hochitom.at/wp-content/themes/hochitom2011/";

$(function(){
	$("#jquery-test").html("jQuery is loaded");
});

$(document).ready(function(){
	//Artikelleiste
	$('#newer').hide();
	
	$('#older').click(function(){
		var page = $('div#latest_articles').attr('class');
		$('#group-'+page).hide(0);
		
		var next_page = parseInt(page) + 1;
		var next_page = "#group-"+next_page;
		var next_page_class = $(next_page).attr('class');
		if(next_page_class == undefined)
		{
			var newpage = page;
			newpage++;
			$.get(directory_url+"js-pagination.php?newpage="+newpage, function(data){
				$('#latest_articles').append(data);
			});
		}
		else
		{
			var newpage = page;
			newpage++;
			$(next_page).fadeIn('normal');
		}
		
		$('#newer').fadeIn('normal');
		
		// checkt ob weitere Artikel vorhanden sind	
		var check_class = 0;
		check_class = $('#group-'+newpage+" div.box-4").attr('class');
		if(check_class == undefined)
		{
			$('#older').fadeOut();
		}
			
		$('div#latest_articles').attr('class', newpage);
		return false;
	});
	
	
	
	$('#newer').click(function(){
		var page = $('div#latest_articles').attr('class');
		var hide_class = "#group-"+page;
		var show = parseInt(page) - 1;
		var show_class = "#group-"+show;
		
		$('#older').fadeIn('normal');
	
		$(hide_class).hide(0);
		$(show_class).fadeIn('normal');
		$('div#latest_articles').attr('class', show);
		
		if(page == 2)
		{
			$('#newer').fadeOut();
		}
		
		return false;
	});

	
	
	
	// Socialbox
	$('#social-content .hide').hide(0);
	$('#about-content').show(0);
	
	$('#social-box ul li a').click(function(){
		$('#social-content .hide').hide(0);
	
		var social_class = $(this).attr('class');
		var social_class = '#'+social_class+'-content';
		
		// Twitter-Tab
		if(social_class=="#tw-content")
		{
			// checkt ob die Daten bereits geladen wurden
			var check_if_empty = $("#tw-content").attr('class');
			var check_if_empty = check_if_empty.split(" ");
			if(check_if_empty[1] == "empty")
			{
				$("#tw-content").html("<p>Daten werden geladen...</p>");
				var url = "https://twitter.com/status/user_timeline/hochitom.json?count=1&callback=?";
				$.getJSON(url, function(data){
				    $.each(data, function(i, item) {
				        $("#tw-content").html('<div id="activity"><p><span class="status">'+item.text+'</span><br><span class="date">vor '+item.created_at+'</span></div><div id="profile"><img src="'+item.user["profile_image_url"]+'" class="profile_image" alt="Hochitoms Twitter Avatar"><div class="updates"><p><span class="count">'+item.user["statuses_count"]+'</span><span class="description">Tweets</span></p></div><div class="following"><p><span class="count">'+item.user["friends_count"]+'</span><span class="description">Friends</span></p></div><div class="followers"><p><span class="count">'+item.user["followers_count"]+'</span><span class="description">Followers</span></p></div></div>'); 
				    });	
				  $("#tw-content").removeClass('empty');  
				});
			}
			
		}
		
		// Facebook-Tab
		
		// Foursquare-Tab
		if(social_class=="#fsq-content")
		{
			// checkt ob die Daten bereits geladen wurden
			var check_if_empty = $("#fsq-content").attr('class');
			var check_if_empty = check_if_empty.split(" ");
			if(check_if_empty[1] == "empty")
			{
				$("#fsq-content").html("<p>Daten werden geladen...</p>");
				$.get("http://hochitom.at/wp-content/themes/hochitom2011/parse-4square.php", function(data){
					$("#fsq-content").html(data);
				});
				$("#fsq-content").removeClass('empty');
			}
			
		}
		
		// Instagram Tab
		
		// Lastfm Tab
		if(social_class=="#lfm-content")
		{
			// checkt ob die Daten bereits geladen wurden
			var check_if_empty = $("#lfm-content").attr('class');
			var check_if_empty = check_if_empty.split(" ");
			if(check_if_empty[1] == "empty")
			{
				$("#lfm-content").html("<p>Daten werden geladen...</p>");
				$.get("http://hochitom.at/wp-content/themes/hochitom2011/parse-lastfm.php", function(data){
					$("#lfm-content").html(data);
				});
				$("#lfm-content").removeClass('empty');
			}
		}
		
		$(social_class).fadeIn('normal');
		return false;
	});
});

