$(document).ready(function(){
	/* The following code is executed once the DOM is loaded */
	function arrowToggle(object){
        if(object.listitem == 'up'){
            object.style.background= 'url("../templates/images/toonprojecten.png") no-repeat';
            object.listitem = '';
        }else{
            object.style.background= 'url("../templates/images/verbergprojecten.png") no-repeat';
            object.listitem = 'up';
        }
    }

	$('#flipbutton').bind("click",function(){
		
		// $(this) point to the clicked .sponsorFlip element (caching it in elem for speed):
		
		var elem = $('#sponsorFlip');

		// data('flipped') is a flag we set when we flip the element:
		if(elem.data('flipped')){
			// If the element has already been flipped, use the revertFlip method
			// defined by the plug-in to revert to the default state automatically:
			elem.revertFlip();
			
			// Unsetting the flag:
			elem.data('flipped',false)
			
			var button = document.getElementById("flipbutton");
			button.innerHTML = '<img src="../templates/images/flip.png"/> Ga naar bedrijfsinformatie';
			
		}else{
			// Using the flip method defined by the plugin:
			var button = document.getElementById("flipbutton");
			button.innerHTML = '<img src="../templates/images/flip.png"/>Ga naar contactformulier';
			elem.flip({
				direction:'bt',
				speed: 350,
                bgColor : 'black',
                toColor : 'black',
                color : 'black',
                dontChangeColor: 'black',
				onBefore: function(){
					// Insert the contents of the .sponsorData div (hidden from view with display:none)
					// into the clicked .sponsorFlip div before the flipping animation starts:
					
					elem.html(elem.siblings('.sponsorData').html());
					
				},
                onEnd: 	        function(){   
	            
                $("#toggle_kaarten").hide();
                $("#toggle_click_kaarten").click(function(){
                    $("#toggle_kaarten").slideToggle(500);
                    arrowToggle(document.getElementById('toggle_click_kaarten'));
            	});		
            }
			});
			
			// Setting the flag:
			elem.data('flipped',true);
		}
	});
	
});
