function slide(dropStart, dropEnd, duration){
	drop("header", dropStart, dropEnd, duration);
}

function drop(id, dropStart, dropEnd, duration) {
    var timer = 0;
    if (dropStart > dropEnd) {
		var dropspeed = (dropStart-dropEnd) / (duration/10);	
    	for (i = 0; i <= (duration/10); i++){
		setTimeout("changePosition("+(dropStart - (dropspeed*timer))+",'"+id+"')",(timer * 10));
		timer++;
	}
    }else if (dropStart < dropEnd) {
    	var dropspeed = (dropEnd-dropStart) / (duration/10);	
    	for (i = 0; i <= (duration/10); i++){
			setTimeout("changePosition("+(dropStart + (dropspeed*timer))+",'"+id+"')", (timer * 10));
			timer++;
		}
    }
}
function changePosition(pos, id) {
	var object = document.getElementById(id);
	if (object != null){
		object.style.height = pos+"px";
	}
}

// background resize 

var defaultBackImageWidth = 1641;
var defaultBackImageHeight = 840;



$(document).ready(function() {
	
	function resizeBackground(){
		$('#background').width('');
		$('#background').height('');
	
		var aspectRatio = defaultBackImageHeight / defaultBackImageWidth;
		
		var windowWidth = $(document).width();
		var windowHeight = $(document).height();
		
		$('#background').width(windowWidth);
		$('#background').height(windowHeight);
		
		if (Math.round(windowWidth * aspectRatio) < windowHeight){
			$('#background img').attr({width:(windowHeight / aspectRatio), height:windowHeight});
		}else if (Math.round(windowHeight * aspectRatio) < windowWidth){
			$('#background img').attr({width:windowWidth, height:(windowWidth * aspectRatio)});
		}
		
		// center image
		$('#background img').css('left', (windowWidth/2) - ($('#background img').width()/2));
	}

	
    // arr with possible backgrounds
    var bg_arr = new Array();
    bg_arr.push({imgname:"bg__siyou.jpg", width: 1680, height:1260});
    bg_arr.push({imgname:"bg_pand1.jpg", width: 1680, height:1117});
    bg_arr.push({imgname:"bg_pand2.jpg", width: 1680, height:1117});
    bg_arr.push({imgname:"bg_pand3.jpg", width: 1680, height:1680});
    //bg_arr.push({imgname:"bg_pand4.jpg", width: 1680, height:1178});
	
	// choose a background
	var choosen = 0;
	if (window.location.pathname.indexOf('projecten') > -1){
		choosen = 2;
	}else{
		choosen = Math.round(Math.random() * (bg_arr.length-1));
		if (choosen > bg_arr.length-1 || choosen == undefined){
			choosen = 0;
		}
	}
    
	
	

   	defaultBackImageWidth = bg_arr[choosen].width;
	defaultBackImageHeight = bg_arr[choosen].height;;
    // add img to background layer
    $("#background").append("<img src='http://www.siyou.nl/images/"+ bg_arr[choosen].imgname + "' />");
    
    //alert('http://www.siyou.nl/images/'+ bg_arr[choosen].imgname);

    $(window).resize(function(){
		resizeBackground();
	});
	resizeBackground();

});



