// Function for getting window sizes for all browsers
    function getSizes() {
        if( typeof( window.innerWidth ) == 'number' ) {
    	//Non-IE
    	myWidth = window.innerWidth;
    	myHeight = window.innerHeight;
    	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    	//IE 6+ in 'standards compliant mode'
    	myWidth = document.documentElement.clientWidth;
    	myHeight = document.documentElement.clientHeight;
    	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    	//IE 4 compatible
    	myWidth = document.body.clientWidth;
    	myHeight = document.body.clientHeight;
    	}
    }


// Normal scroller

var speed = 50;
var pic, numImgs, arrLeft, i, totalWidth, n, myInterval; 

jQuery(window).load(function(){
	pic = jQuery("#header-img").children("img");
	numImgs = pic.length;
	arrLeft = new Array(numImgs);

	for (i=0;i<numImgs;i++){
		
		totalWidth=0;
		for(n=0;n<i;n++){
			totalWidth += jQuery(pic[n]).width();
		}

		arrLeft[i] = totalWidth;
		jQuery(pic[i]).css("left",totalWidth);
	}

	myInterval = setInterval("flexiScroll()",speed);
	jQuery(pic).show();
	
});

function flexiScroll(){
	for (i=0;i<numImgs;i++){
		arrLeft[i] -= 1;		

		if (arrLeft[i] == -(jQuery(pic[i]).width())){
			totalWidth = 0;
			for (n=0;n<numImgs;n++){
				if (n!=i){
					totalWidth += jQuery(pic[n]).width();
				}
			}
			arrLeft[i] =  totalWidth;
		}
		jQuery(pic[i]).css("left",arrLeft[i]);
	}
}

// Scroller aanbod page

var pic2, numImgs2, arrLeft2, i2, totalWidth2, n2, myInterval2, pos;
var currentprog = 0;
var imgwidth = 200;
var scrollrate = imgwidth * 2;

jQuery(window).load(function(){
	pic2 = jQuery("#header-img2 ul").children("li");
	numImgs2 = pic2.length;
	arrLeft2 = new Array(numImgs2);

	for (i2=0;i2<numImgs2;i2++){
		
		totalWidth2=0;
		for(n2=0;n2<i2;n2++){
			totalWidth2 += jQuery(pic2[n2]).width();
		}

		arrLeft2[i2] = totalWidth2;
		jQuery(pic2[i2]).css("left",totalWidth2);
	}

	jQuery("#next").click(function(){
		flexiScroll2(false);
	});
	jQuery("#prev").click(function(){
		flexiScroll2(true);
	});
	
	jQuery(pic2).show();
	jQuery(".fbimg").animate({opacity: 0.7},"fast");
	jQuery(".fbimg").hover(function() {
		jQuery(this).animate({opacity: 1.0},"fast");
	}, function(){
		jQuery(this).animate({opacity: 0.7},"fast");
	});

});

function flexiScroll2(add){
	
	getSizes();

	
	pos = (imgwidth*numImgs2) - (myWidth+currentprog);
	
		for (i2=0;i2<numImgs2;i2++){
			
			if (add == false) {
				
				if (pos > 0) {
					if (pos < scrollrate) {
						
						arrLeft2[i2] -= pos;
						if (i2 == 0) {
							currentprog += pos;
						}
					} else {
						arrLeft2[i2] -= scrollrate;
						if (i2 == 0) {
							currentprog += scrollrate;
						}
					}
				}
				
			} else if (add == true) {	
				if (currentprog > scrollrate) {
					arrLeft2[i2] += scrollrate;	
					if (i2 == numImgs2-1) {
						currentprog -= scrollrate;
					}
				} else if (currentprog > 0) {
					arrLeft2[i2] += currentprog;
					if (i2 == numImgs2-1) {
						currentprog = 0;
					}
				}
				
			}
				
	
			if (arrLeft2[i2] == -(jQuery(pic2[i2]).width())){
				totalWidth2 = 0;
				for (n2=0;n2<numImgs2;n2++){
					if (n2!=i2){
						totalWidth2 += jQuery(pic2[n2]).width();
					}
				}
				arrLeft2[i2] =  totalWidth2;
			}
			
			jQuery(pic2[i2]).animate({ left: arrLeft2[i2] },"slow", "swing");
		}
}


// News page

jQuery(document).ready(function() {
	jQuery(".newsi").click(function(){
		var postid = jQuery(this).attr("postid");
		var postsrc = jQuery(this).attr("sourcei");
		jQuery("#newsc"+postid).attr("src", postsrc);
	});
});

