$(document).ready(
	function(){
		$("#slideshow").innerfade({
		speed: 750,
		timeout: 7500,
		type: "random_start",
		containerheight: "120px"
		});

		$("#nieuwslideshow").innerfade({
		speed: "fast",
		timeout: 7500,
		type: "random_start",
		containerheight: "170px"
		});

		$(".teamfotocmv").innerfade({
		animationtype: "slide", 
		speed: 750,
		timeout: 5000,
		type: "random_start",
		containerheight: "200px"
		});

		$('#ballensponsor').innerfade({ 
		animationtype: 'slide', 
		speed: 750, 
		timeout: 4000, 
		type: 'random', 
		containerheight: '1em'
		});

		$('#sponsoren').innerfade({ 
		speed: 'slow', 
		timeout: 5500, 
		type: 'random', 
		containerheight: '120px'
		});

	$("#slidetabsmenu div").hide(); // Hide all divs
	$("#slidetabsmenu div:first").show(); // Show the first div
	$("#slidetabsmenu ul li:first").addClass("active"); // Set the class for active state
	$("#slidetabsmenu ul li a").click(function(){ // When link is clicked
		$("#slidetabsmenu ul li").removeClass("active"); // Remove active class from links
		$(this).parent().addClass("active"); //Set parent of clicked link class to active
		var currentTab = $(this).attr("href"); // Set currentTab to value of href attribute
		$("#slidetabsmenu div").hide(); // Hide all divs
		$(currentTab).show(); // Show div with id equal to variable currentTab
		return false;
	});

	$("#tip img").tooltip({
		track: true,
		delay: 0,
		showURL: false,
		showBody: " - "
	});

	$("#tip *").tooltip({
		track: true,
		delay: 0,
		showURL: false,
		showBody: " - "
	});

	$(".teamoverzicht").hover(
		function() {
			$(this).addClass("hoverteam");
		},
		function() {
			$(this).removeClass("hoverteam");
		}
	);

	$("ul.sf-menu").superfish().find("ul").bgIframe({opacity:false});
});

$(function(){
	var loader=$('#loader');
	var pollcontainer=$('#pollcontainer');
	loader.fadeIn();
	//Load the poll form
	$.get('data/functies/poll.php', '', function(data, status){
		pollcontainer.html(data);
		animateResults(pollcontainer);
		pollcontainer.find('#viewresult').click(function(){
			//if user wants to see result
			loader.fadeIn();
			$.get('poll.php', 'result=1', function(data,status){
				pollcontainer.fadeOut(1000, function(){
					$(this).html(data);
					animateResults(this);
				});
				loader.fadeOut();
			});
			//prevent default behavior
			return false;
		}).end()
		.find('#pollform').submit(function(){
			var selected_val=$(this).find('input[name=poll]:checked').val();
			if(selected_val!=''){
				//post data only if a value is selected
				loader.fadeIn();
				$.post('data/functies/poll.php', $(this).serialize(), function(data, status){
					$('#formcontainer').fadeOut(100, function(){
						$(this).html(data);
						animateResults(this);
						loader.fadeOut();
					});
				});
			}
			//prevent form default behavior
			return false;
		});
		loader.fadeOut();
	});
	
	function animateResults(data){
		$(data).find('.bar').hide().end().fadeIn('slow', function(){
							$(this).find('.bar').each(function(){
								var bar_width=$(this).css('width');
								$(this).css('width', '0%').animate({ width: bar_width }, 1000);
							});
						});
	}
});

var win=null;
function NewWindow(mypage,myname,w,h,scroll,pos){
if(pos=="random"){LeftPosition=(screen.availWidth)?Math.floor(Math.random()*(screen.availWidth-w)):50;TopPosition=(screen.availHeight)?Math.floor(Math.random()*((screen.availHeight-h)-75)):50;}
if(pos=="center"){LeftPosition=(screen.availWidth)?(screen.availWidth-w)/2:50;TopPosition=(screen.availHeight)?(screen.availHeight-h)/2:50;}
if(pos=="default"){LeftPosition=50;TopPosition=50}
else if((pos!="center" && pos!="random" && pos!="default") || pos==null){LeftPosition=0;TopPosition=20}
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
win=window.open(mypage,myname,settings);
		if(win.focus){win.focus();}}
