var Chopper = {};

Chopper.resizeThumbnails = function(){
	$('li>img').each(function(index, value){
		var newwidth = parseInt(50 - $(this).css('width').replace('px', ''));
		if(newwidth < 0){
			newwidth = 10;
		}
		$(this).css('margin-right', newwidth+'px');
	});
};

Chopper.loadLoginForm = function(){
	$('#quickLoginUsername').click(function(){
		 if($('#quickLoginUsername').val() == "Benutzername"){
			 $('#quickLoginUsername').val('');
		 }
	});
	$('#quickLoginUsername').blur(function(){
		if($('#quickLoginUsername').val() == ""){
			 $('#quickLoginUsername').val('Benutzername');
		 }
	});
	$('#quickLoginPassword').click(function(){
		 if($('#quickLoginPassword').val() == "******"){
			 $('#quickLoginPassword').val('');
		 }
	});
	$('#quickLoginPassword').blur(function(){
		if($('#quickLoginPassword').val() == ""){
			 $('#quickLoginPassword').val('******');
		 }
	});
	
	$('#login').animate({
	    top: '5px'
	}, 1500, function() {
	    // Animation complete.
	});
}

Chopper.slider = function(elementID){
	var element = $(elementID);
	var completeWidth = 0;
	$(elementID+'>ul>li>a>img').each(function(i, eachElement){
		completeWidth += $(this).width();
	});
	
	completeWidth += 1 // Safety first!
	
	$(elementID+'>ul').css('width', completeWidth+'px');
	
	if(completeWidth > element.width()){
		// created sliders
		element.append('<div id="slider-left-icon"></div>');
		element.append('<div id="slider-right-icon"></div>');
		
		$('#slider-left-icon').click(function(){
			$(elementID+'>ul').animate({
			    marginLeft: '0px'
			}, 300, function() {
			    // Animation complete.
			});
		});
		$('#slider-right-icon').click(function(){
			var marginLeft = parseInt(element.width() - completeWidth);
			$(elementID+'>ul').animate({
			    marginLeft: marginLeft+'px'
			}, 300, function() {
			    // Animation complete.
			});
		});
	}
	
}

$(document).ready(function(){
	Chopper.resizeThumbnails();
	
	if(userID == 0){
		Chopper.loadLoginForm();
	}
	
	if($('#pictures').length > 0){
		$("#pictures>ul>li>a").fancybox();
		Chopper.slider('#pictures');
	}
});
