
$(document).ready(function() {
	
	$('#wrap').css('min-height', $(window).height() - (40 + $('#footer').outerHeight(true)));
	
	/* Foreskin */
	var lock = false;
	$('#unlocker').attr('title', (!foreskin_open) ? 'slide to unlock sidebar' : 'slide to lock sidebar');
	function toggleForeskin() {
		if(!lock) {
			lock = true;
			var bgpos = (foreskin_open) ? '-185px' : '0';
			$("body").animate({ 
				backgroundPosition: bgpos
			},
			800,
			function() { 	
				foreskin_open = (foreskin_open) ? false : true;
				lock = false;
				cookieVal = (foreskin_open) ? 'open' : 'closed';
				plstkCookie('plstk-Foreskin-Cookie', cookieVal);
			});	
			
			if(!foreskin_open) {
				$('#unlocker').animate({ 
					marginLeft: '185px'
					}, 800	);
				$('#unlocker').attr('title', 'slide to lock sidebar');
			}
			else {
				$('#unlocker').animate({ 
					marginLeft: '0'
					}, 800	);
			}
			var foreskin_width = (foreskin_open) ? '0' : '185px';
			$("#wrap_right").animate({ 
				width: foreskin_width
				},
				800	);			
			$('#unlocker').attr('title', 'slide to unlock sidebar');
		}			
	}	
	
	$('#go').click(function () {
		toggleForeskin();
   });

	
	/* Drag unlocker */
	$('#unlocker_inside').draggable({
		axis:	'x',
		containment: 'parent',		
		stop: function(e,ui) {			
			//alert($(this).position().left);
			if(!foreskin_open) {
				if($(this).position().left == '46') {	
					$(this).animate( { opacity:'0.3' }, 300)
					.animate( { opacity:'1.0' }, 100, 
					function() {
						toggleForeskin();
					})
				}
				else {
					$(this).animate({left: 2}, 200 );
				}
			}
			else {
				if($(this).position().left == '2') {
					$(this).animate( { opacity:'0.3' }, 300)
					.animate( { opacity:'1.0' }, 100, 
					function() {
						toggleForeskin();
					})
				}
				else {
					$(this).animate({left: 46}, 200 );
				}
			}
		}
	});
	
	/** Pagination */
	$(".pagination_inside").mousemove(function(e){
			var box_offset = $(this).offset().left;
      var ix = e.pageX
			var bg_position = ix-box_offset;
			$('#test').html(ix-box_offset);
			$('.pagination_box span.current').animate ({ 
				backgroundPosition: 'top ' + bg_position
			},
			200);
    });

	
	/** Anchors */
	$("a.anchor").click(function(event) {		
		event.preventDefault();	
		var goto = $(this).attr('hash');
		$.scrollTo( goto, 800, {offset: 0});
	});
	
	/** Go to top */
	$("img.gotop ").attr('title', 'nach oben');
	$("img.gotop ").click(function() {		
		$.scrollTo( '#top', 800, {offset: 0});	
	});
	
	/* Set cookie */
	function plstkCookie(cookie_name, val) {
		var options = { path: '/', expires: 365 };
		$.cookie(cookie_name, val, options);
	}

	
});
