// functions
$(function() {
	var VidSlider = new Object();

	function newVidSlider (name,direction) {
		var myHeight;
		totalMovies = $('#'+name+' li').size();
		if (direction !="H") {
			myHeight = parseInt($('#'+name+' img').attr('height'));
			VidSlider[name] = new Object({ 'direction' : 'V', 'imgHeight' : myHeight, 'animating' : false, 'animateBack' : Object(),'totalMovies' : totalMovies, 'calculatedHeight' : Math.round((parseInt($('#'+name).css('height'))-myHeight)/(totalMovies))});
		}else {
			myHeight = parseInt($('#'+name+' img').attr('width'));
			VidSlider[name] = new Object({ 'direction' : 'H', 'imgHeight' : myHeight, 'animating' : false, 'animateBack' : Object(),'totalMovies' : totalMovies, 'calculatedHeight' : Math.round((parseInt($('#'+name).css('width'))-myHeight)/(totalMovies))});
		}
		initVidSlider(name);
	}

	function setHeights(name){
		var returnObject = "";
		$('#'+name+' li').each(function(index){
										
			if (VidSlider[name].direction !="H") {
						
				if (parseInt($(this).children().css('height')) != VidSlider[name].calculatedHeight) {
					returnObject = $(this);
				}
			}else {
				if (parseInt($(this).children().css('width')) != VidSlider[name].calculatedHeight) {
				returnObject = $(this);
				}
			}
		})
		return returnObject;
	}
	
	
function initVidSlider(name) {
	$('#'+name+' li').each(function(index){
		$(this).click(function(){ 
			if (!VidSlider[name].animating && $(this).attr('class') != "start") {
				
				$('#'+name+' li').each(function(index) { $(this).removeClass('start') });
				$(this).addClass('start');
				
				
				VidSlider[name].animating = true;
				VidSlider[name].animateBack = setHeights(name);
			
			
				if (VidSlider[name].direction !="H") {
					if ($(this) != VidSlider[name].animateBack) {
						$(this).children().animate({ 'height' : VidSlider[name].imgHeight}, 900,function(){VidSlider[name].animating = false});
					}
					if (typeof(VidSlider[name].animateBack) == 'object') {
					VidSlider[name].animateBack.children().animate({ 'height': VidSlider[name].calculatedHeight}, 900);
					}
				}else {
					if ($(this) != VidSlider[name].animateBack) {
						$(this).children().animate({ 'width' : VidSlider[name].imgHeight}, 900,function(){VidSlider[name].animating = false});
					}
					if (typeof(VidSlider[name].animateBack) == 'object') {
					VidSlider[name].animateBack.children().animate({ 'width': VidSlider[name].calculatedHeight}, 900);
					}
				}
			}

		});


	});
	setHeights(name);
	if (VidSlider[name].direction !="H") {

		$('#'+name+' li').each(function(index){
			$(this).children().css({'height': VidSlider[name].calculatedHeight});
		});
		
		$('#'+name+' .start').children().css({'height': VidSlider[name].imgHeight+'px'});
	}else {
		$('#'+name+' li').each(function(index){
			$(this).children().css({'width': VidSlider[name].calculatedHeight});
		});
		
		$('#'+name+' .start').children().css({'width': VidSlider[name].imgHeight+'px'});
	}


}

 // inits
	$.easing.def = "easeOutBounce";
	newVidSlider('watligtjeSlider');
	newVidSlider('studentenlevenSlider');
	newVidSlider('studielevenSlider',"H");
	newVidSlider('avansenzoSlider',"H");
	
});