var searchValue = "Zoek op trefwoord";

$(document).ready(function() {
	// tekstwolk van joost
	showCloud('<div id="overlay"></div><div id="cloud"><p>Hallo, ik ben Joost. Ik ben 21 jaar en sinds kort klant bij Woningstichting Alphons Ari&euml;ns.</p><p>Goed nieuws. Ik heb niet alleen net een mooie huurwoning gekregen in m\'n eigen dorp, ik kan ook aan de slag hier in de omgeving.</p><p>Alphons Ari&euml;ns maakt het allemaal mogelijk, samen met haar partners.</p></div>');
	
	/*
	$("#reclameoverlay").flash({
	    src: webroot+'swf/banner.swf',
	    width: 234,
	    height: 60
	});
	*/

	// zoeken
    $("#searchform").submit(function() { return checkInput() });
    $('#submitsearchform').click(function() { 
        if (checkInput()==false){
            return checkInput();
        }
        else{
            $("#searchform").submit();
        }
        
    });
    
    $('form#searchform input').val(searchValue);
    $('form#searchform input').focus(function() {
        if ($(this).val()==searchValue){
            $(this).val('');
        }
    });
    $('form#searchform input').blur(function() {
        if ($(this).val()==''){
            $(this).val(searchValue);
        }
    });
    
    // poll
    $('form#pollform').submit(function(){
    	var val = $('input[type=radio]:checked').attr('value');
    	if (val==undefined) {
    		$('form#pollform label').css('color', '#f00');
    		$('input[type=radio]').change(function(){
    			$('form#pollform label').css('color', null);
    		});
    	}
    	else{
			$.ajax({
				type: "POST",
				url: webroot+"poll/vote/",
				data: "val="+val,
				success: function(rslt){
					if (rslt == 0){
						$('#pollblock').html('<p>Het is niet gelukt om uw stem door te voeren.</p>');
					}
					else if (rslt == 1){
						$('#pollblock').html('<p>U heeft al gestemd.</p>');
					}
					else{
						// set html
						$('#pollblock').html(rslt);
						
						// set vars
						var divs = jQuery.makeArray($('table.pollresult tr td div.poll_stem_status'));
						var widths = new Array();
						
						// set all status divs to default and animte to original
						for (var i = 0; i < divs.length; i++){
							widths[i] = $(divs[i]).innerWidth();
							$(divs[i]).css('width', '20px');
							$(divs[i]).animate({width: widths[i]+"px"}, { duration: 500, queue: false });
						};
					}
				}
			});
    	}
    	return false;
    });
    
});

function checkInput (){
    if ($('form#searchform input').val()==searchValue || $('form#searchform input').val()==''){
        $('form#searchform input').addClass('empty');
        return false;
    }
}

function showCloud(string) {
	$('#top a.readmore').click(function() {
		$(string).appendTo('#wrapper').show('slow', function() {
			$('#overlay').click(function() {
				$('#cloud').hide('fast', function() {
					$(this).remove();
					$('#overlay').remove();
				});
			});
		});
		return false;
	});	
}


var slideUpTimer = true;

$(document).ready(function(e){
	
	$(document).delay(500,function(){
		slideBannerDown();
		$("#overlay-banner").delay(7500,function(){
			if (slideUpTimer == true){
				slideBannerUp();
				$(this).delay(1200,function(){
		    		slideButtonDown();
		    	});
			}
		});
	});
	
	$("#overlay-banner #close").click(function(){
		slideBannerUp();
		$(this).delay(1200,function(){
    		slideButtonDown();
    	});
		return false;
    });
    $("#banner-reversebutton").click(function(){
    	slideButtonUp();
    	$(this).delay(1000,function(){
    		slideBannerDown();
    	});
		return false;
    });
	
});

function slideBannerDown() {
	$('#overlay-banner').animate({
		top: "20px"
	}, { "duration": 1500, queue: false, "easing": "easeOutBounce" } );
}
function slideBannerUp() {
	$('#overlay-banner').animate({
		top: "-683px"
	}, { "duration": 1000, queue: false, "easing": "easeInOutExpo"} );
	slideUpTimer = false;
}
function slideButtonDown() {
	$('#banner-reversebutton').animate({
		top: "-0px"
	}, { "duration": 1000, queue: false, "easing": "easeOutBounce" } );
}
function slideButtonUp() {
	$('#banner-reversebutton').animate({
		top: "-21px"
	}, { "duration": 1000, queue: false, "easing": "easeInOutExpo" } );
}