function setPeriod( datefrom, datetill, datefromDB, datetillDB, HowMany ){
	document.getElementById( 'SelectedDateFrom' ).value = datefrom;
	document.getElementById( 'SelectedDateTill' ).value = datetill;

	var req = jQuery.ajax({
		async: false,
		cache: false,
		url: AbsPath + "includes/Components/WeekladderItems.php?HowMany="+HowMany,
		data: {datefrom:datefromDB,datetill:datetillDB,HowMany:HowMany},
		dataType: 'text',
		type : 'POST'
	});
	if ( req.responseText != 'succes' ) {
		//document.getElementById( 'WeekladderItems' ).innerHTML = req.responseText;
		$( '#WeekladderItems' ).html( req.responseText );
		highLight();
		initWeeks();		
	} else {
		
	}
	
	changeClassname( 'DateSelector', 'Hide' )
	document.getElementById( 'SelectedDateFromSpan' ).innerHTML = datefrom;
	document.getElementById( 'SelectedDateTillSpan' ).innerHTML = datetill;
}

function toggleDiv( DivID ){
    if(document.getElementById( DivID ).className == 'Hide'){
    	document.getElementById( DivID ).className = 'Show';
    }else{
    	document.getElementById( DivID ).className = 'Hide';
    }
}

function highLight() {
	$( 'div.Item' ).bind( 'mouseenter', function(){
		$(this).addClass("Hover");
	}).bind('mouseleave', function(){
		$(this).removeClass("Hover");
	});	
}

$(document).ready(function(){
	highLight();
});

function goToURL( url ) {
	if( url.options[url.options.selectedIndex].value !== 'undefined'){	
		window.location = url.options[url.options.selectedIndex].value;
	}
}

/* 
$(document).ready(function(){
	$( 'div.Item' ).bind( 'mouseenter', function( ){

		$('div#Teaser').addClass('Show');
		$('#TeaserImage').attr('src', '/www.deventerschouwburg.nl/html/images/Teaser.jpg');
		$( this ).mousemove(function( e ) {
			var MousePos = e.pageY; 
			var BoxPos = parseInt( MousePos - 220  )
			$('div#Teaser').css({'margin-top': BoxPos });
		});
		$('div#Verwacht').addClass('Hide');
	});
	
	$( 'div.Column' ).bind('mouseleave', function(){
		$('div#Teaser').removeClass('Show');
		$('div#Verwacht').removeClass('Hide');
	});

*/ 

function initWeeks(){
	/** Weekladder **/
	$( 'div#Weekladder div.Item' ).bind( 'mouseenter', function( ){
		if ( ! ($(this).data('itemid') >= 0) ) {
			$(this).data('itemid', $(this).attr('id').substr(10));
		} 
		var id = $(this).data('itemid');
		var src = ImagePath + Images[ id ];
		
		if ( Images[ id ] != null && Images[id].length > 5 ) { 
			$('div#Teaser').addClass('Show');
			$('#TeaserImage').attr('src', src);
			$('div#Verwacht').addClass('Hide');
			$('div#Weekladder').data('currentItem', id);
		} else {
			$('div#Teaser').removeClass('Show');
			$('div#Verwacht').removeClass('Hide');
			$('div#Weekladder').data('currentItem', null);
		}
	}).bind('mouseleave', function() { 
		if ( $(this).data('itemid') == $('div#Weekladder').data('currentItem') ) {
			$('div#Weekladder').data('currentItem', null); // reset het id
		}
	});
		
	$('div#Weekladder div.Items').bind('mouseleave', function(){
		$('div#Teaser').removeClass('Show');
		$('div#Verwacht').removeClass('Hide');
		$('div#Weekladder').data('currentItem', null);
	});
	$( 'div#Weekladder' ).bind('mousemove', function(e) {
		if ( $(this).data('currentItem') != null) {
			var MousePos = e.pageY; 
			var BoxPos = parseInt( MousePos - 220  )
			$('div#Teaser').css({'margin-top': BoxPos });
		}
	});
}

$(document).ready(function(){
	
	initWeeks();
	
	
	/** Programma scroller **/
	if ( $('div.FixedColumn').size() > 0 ) { // er moet minimaal 1 fixedcolumn zijn
	var scrollInterval = window.setInterval(function() {
		
		var getMaxMargin = function(m) { // TODO Performance gain
			var top = $('div.RightHolder').offset().top;
			var height = $('div.RightHolder').height();
			var total = top + height; // bottom pos
			
			var fcolh = $('div.FixedColumn').height();
			//var fcolt = $('div.FixedColumn').offset().top;
			//var total1 = fcolh + fcolt; // bottom pos
			
			//var maxLeft = total - total1;
			// scrolloffset mag niet groter zijn dan total - fcolh
			var offset = total - fcolh - 80;
			if ( m > offset ) {
				return offset;
			} else return m;
		};
				
		// calculate max margin height
		
		var scrollTop = $(document).scrollTop();
		scrollTop = parseInt(scrollTop);
		$('div.FixedColumn').animate({
			marginTop: getMaxMargin(scrollTop) + "px"
		}, {
			queue : false,
			duration: 1000,
			easing : "easeOutSine"
		});
	}, 1000);
	}
	
	$('#NieuwsbriefForm').each(function() {
		$(this).find("input[type='submit']").bind('click', function(ev) {
			ev.preventDefault();
			var form = $(this).closest('form');
			var url = form.attr('action');
			var email = form.find("input[name='Email']").attr('value');
			var result = jQuery.ajax({
				async : false,
				cache : false,
				dataType : 'html',
				data : {Email: email, SubmitNewsLetter: $(this).attr('value'), type: 'AJAX'},
				type : 'POST',
				url: url,
				error : function() {
					alert('Er is een fout onbekende fout opgetreden bij het verzenden van uw aanvraag.');
				}
			});
			var html = result.responseText;
			form.hide();
			form.find("input[type='text']").attr('value', '');// empty the input fields
			$('#NieuwsbriefResult').html(html).show();
			return false;
		});
	});
	
});

function loadBasket() {
	var Loc = AbsPath + 'includes/Components/Winkelmandje.php';
	$.ajax({
		type: "POST",
		url: Loc,
		data: {},
		contentType: "application/x-www-form-urlencoded; charset=UTF-8;",
		timeout: 5000,
		error: function(){
			alert( 'Error loading XML document' );
		},
		success: function( R ){
			var DIV = document.getElementById( 'Basket' );
			if ( DIV ) {
				if ( R != 'false' ) {
					//Gelukt, ik heb de HTML in var R
					DIV.innerHTML = R;
				} else {
					parent.location.reload();
					
				}
			} else {
				parent.location.reload();
			}
		}
	});
}

/*
var NewSrc = UploadPath + Images[album][image][0];

FotoHolder.appendChild( large );

$( '#Vergroting' ).attr( 'newSource', NewSrc ).fadeOut( 'slow', function() {
	var loader = new ImageLoader( $(this).attr( 'newSource' ));
	loader.element = $(this);
	loader.loadEvent = function( url, image, element ) {
		element.fadeIn( 'slow' );
	}
	loader.load(document.getElementById('Vergroting'));
} ); 


$( '#Vergroting' ).attr( 'newSource', NewSrc ).fadeOut( 'slow', function() {
var loader = new ImageLoader( $(this).attr( 'newSource' ));
loader.element = $(this);
loader.loadEvent = function( url, image, element ) {
	element.fadeIn( 'slow' );
}
loader.load(document.getElementById('Vergroting'));
} ); 
*/

