var categories = new Object();
categories['all']  = '0,1,2,3,4,5,6,7,8,9';
categories['news'] = '1';
categories['tour'] = '2';
categories['media'] = '3';
categories['presse'] = '4';
categories['kontakt'] = '5';
categories['impressum'] = '6';


var loadAtATime = 5;
var filtered = false;
var endofdata = false;
var filter = '';


$(document).ready(function() {
	// $('.item').hide();
	
	$('a.lightwindow').lightBox({fixedNavigation:true});
	
	$('.anchor').remove();
	
	if(document.location.hash == ''){
		$('.item').first().show();
	} else {
		showArea(location.hash.substr(1));
	}	

	$(window).hashchange( function(){
		showArea(location.hash.substr(1));
	})
	
	$('#footer').html('mehr laden');
	$('#footer').click(function(){loadContent()});
		
});


function showArea(showId){

	if('' == showId){
		$('.item').show();
		filtered = false;
		$('#content-inner').html('');
		$('#footer').show();
		endofdata = false;
		loadContent();
		
		$('#main-menu a').removeClass('act');
		$('#main-menu a:[href=#]').addClass('act');		
		filtered = false;
		return;
	}
	
	$('#footer').show();
	endofdata = false;

	$('.item').not('.'+showId).not('.all').fadeOut(1000);
	
	$('.'+showId+':hidden').fadeIn(1000,
		function(){
				
		}
	);
	
	window.setTimeout(function(){
					if($('body').height()-($('#footer').offset().top)-$('#footer').height() > 0){
						loadContent();
					}		
	}, 1100);
	
	$('#main-menu a').removeClass('act');
	$('#main-menu a:[href=#'+showId+']').addClass('act');
	
	filtered = true;

}

 $(function () {
             var $win = $(window);
             $win.scroll(function () {
             	if ($win.height() + $win.scrollTop() == $(document).height()) {
                     if(!endofdata)
                     	loadContent();
                 }
             });
         });


function loadContent(){	
	// showArea('');

	$('#footer').addClass('loading');

	filter = location.hash.substr(1);
	if('' == filter) filter = 'all';
    current = countAreas(filter);
	jQuery.get(
		'index.php?type=77&max='+loadAtATime+'&begin='+current+'&cat='+categories[filter], 
		function(data){
			
			
			if(data == ''){
				endofdata = true;
				$('#footer').hide();
			}
			
			data = '<div class="newajax" style="display:none">'+data+'</div>';
			$('#content-inner').append(data);
			
			$('.newajax a.lightwindow').lightBox({fixedNavigation:true});
			
			$('.newajax').fadeIn(1000);
			$('.newajax').removeClass('newajax');
			
			$('#footer').removeClass('loading');
			
			update_twitter();
		}
	);	
}


function countAreas(cat){
	if('all' == cat){
		return $('.item').length;
	} else {		
		return $('.'+cat).length;
	}	
}



function update_twitter(){
	   $(".tweet").tweet({
            username: "jack_beauregard",
            join_text: "auto",
            avatar_size: 32,
            count: 3,
            auto_join_text_default: "we said,",
            auto_join_text_ed: "we",
            auto_join_text_ing: "we were",
            auto_join_text_reply: "we replied to",
            auto_join_text_url: "//",
            loading_text: "loading tweets..."
        });
    }



function debug(str){
	$('#footer').html(str);
}

