var Site = function(){
	
	$(document).ready(function(){ Site.init(); });
	
	return {
		init: function() {
			
			var prev = parseInt( $('div#PostData a[rel=bookmark]').attr('title'),10)-1;
			prev = (prev>0)?prev:false;
			
			if(prev)$('div#Navigation.index div#Prev').html(['<a href="/',prev,'/" title="',prev,'">',prev,'</a>'].join(''));
			
			if (!jQuery.browser.msie || parseInt(jQuery.browser.version, 10) > 6) {
				$('div#Sidebar h3').mouseover(function(e){
					$('div#Sidebar h3').stop().animate({color: "rgb(0,148,224)", backgroundPosition:"(0 28px)"},{duration:200});
					$(this).stop().animate({color: 'black', backgroundPosition:"(0 0)"},{duration:200});
				});	
				$('div#Sidebar h3').mouseout(function(e){
					if (!$(this).hasClass('active')) {
						$('div#Sidebar h3.active').stop().animate({color: "black",backgroundPosition: "(0 0)"}, {duration: 200});
						$(this).stop().animate({color: 'rgb(0,148,224)',backgroundPosition: "(0 28)"}, {duration: 200});
					}
				});
			}
			
			$('div#Sidebar h3').click(function(){
				if (!$(this).hasClass('active')) {					
					$('div#Tab'+$('div#Sidebar h3.active')[0].id).hide('fast');
					$('div#Tab'+$(this)[0].id).show('fast');
					$('div#Sidebar h3.active').removeClass('active')
					$(this).addClass('active');
				}
			})
			
			$('div#TabWerk a').fancyZoom({scaleImg: false, closeOnClick: true,directory: '/images'});
		}
	};
}();

var ArchivePager = function(){
	
	$(document).ready(function(){ ArchivePager.init(); });
	
	var links = false; 
	var offset = 15;
	var offsetUnit = 15;
	return {
		prev: function() { 
			if( offset > 15){
				links.hide();
				offset=offset-15;
				for( var k = offset; k>=offset-15;k--){					
					links.eq(k).show();
//					console.debug( links[k] ) 
				}				
			}		
		},
		next: function() { 
			if( offset < links.length){
				links.hide();
				
				for( var k = offset; k<=offset+15;k++){
					links.eq(k).show();
//					console.debug( links[k] ) 
				}
				offset=offset+15;	
			}
		},
		set: function( _num ){		
			var zone = Math.floor( _num / offsetUnit );  // 1
			links.hide();			
			if( _num%15 == 0 ){zone = zone-1 }			
//			console.log(zone,_num,offsetUnit)
			for( var k = (offsetUnit*zone) ; k < (offsetUnit*(zone+1) ) ; k++ ){
			    //console.log(k)
				links.eq(k).show();
				if(k+1 == parseInt( $('div#PostData a[rel=bookmark]').attr('title'),10) ) {
					links.eq(k).addClass('current');
				}
			}	
			offset=(zone+1)*offsetUnit;	
			
		},
		init: function() {
			links = $('div#Archives a:not(.today)');			
			if(links.length > 15){				 
				 $('div#Archives').append('<span id="PagesPrev" onclick="ArchivePager.prev();"></span><span id="PagesNext" onclick="ArchivePager.next();"></span>')
			}
			this.set( parseInt( $('div#PostData a[rel=bookmark]').attr('title'),10) )
		}
		
	}
	
}();
