/**
 * Project: Valleibouw
 * Datum: 23 April 2010
**/
(function($){

	$.fn.extend({
	});
	
	$.extend({
		WatchClose: function(){
			$('.close').live('click', function(event){
				event.preventDefault();
				$(this).parent().parent().fadeOut('slow');
			});
		},
		NewsScroll: function(){
			if($('.box-container').size() < 4) $('.arrows').hide();
			else {
				$('.scrollup').live('click', function(event){
					event.preventDefault();
					
				});
				$('.scrolldown').live('click', function(event){
					event.preventDefault();
					
				});
			}
		},
		backgroundControl: function(){
			var access = false;
			if($('.menu a.active').attr("href") == "index.asp"){
				$('.background-selector img').bind('click', function(e){
					e.preventDefault();
					$('#background img').attr('src', $(this).attr('src'));
					
					$.ajax({
						url: 'setBg.asp',
						data: 'set-bg=' + $(this).attr('class'),
						async: false
					});
					
					access = false;
					if($(this).attr("id").indexOf("no-animate") == -1) access = true;
					else {
						if($(this).attr("id") == "no-animate2" && $(this).css('left').replace('px','') == 0) access = true;
						else if($(this).attr("id") == "no-animate15" && $(this).css('left').replace('px','') == 78) access = true;
					}
					
					if(access){
						if($(this).css('left').replace('px','') == 0){
							var leftPos = $(this).css('left');
							$('.background-selector img').each(function(){
								$(this).animate({
									'left': '+=26px'
								}, 500);
							});
						} else if($(this).css('left').replace('px','') >= 52){
							var leftPos = $(this).css('left');
							$('.background-selector img').each(function(){
								$(this).animate({
									'left': '-=26px'
								}, 500);
							});
						} else if($(this).css('left').replace('px','') <= 26){
							var leftPos = $(this).css('left');
							$('.background-selector img').each(function(){
								$(this).animate({
									'left': '+=26px'
								}, 500);
							});
						}
					}
				});
			}
		}
	});
	
	$(document).ready(function(){
		getPageHeight();
		$.WatchClose();
		$.NewsScroll();
		$.backgroundControl();
	});
	
})(jQuery);
