$(document).ready(function(){

  $("body").kkCountDown({
    colorText:'#ccc',dayText:'dag',daysText:'dagen'   
  });
  
  jQuery.fn.exists = function(){return ($(this).length > 0);}

  if($.cookie("divopenhome") != 'true') {		
	$('#dialog').jqm().jqmShow({overlay: 70});
	$.cookie("divopenhome", "true", { path: '/', expires: 7 });		      
  }	  
  
  $('.aankondiging').click(function() {
    $('#dialog').jqm().jqmShow({overlay: 70});
  });
  
  $('.loginloading').hide();
  
  $('#CommentForm').submit(function(){
    $('.Melding').hide();
    $('#newcomment').hide();
    var dataString = $(this).serialize();
    $.ajax({ type: 'POST',url: '/ajax/NewsArticleAddComment.php',data: dataString,cache: false,success: function(html){
        if(html == 'nietok') {
          result = '<p class="meldingfout ui-corner-all">U bent niet ingelogd en kunt geen reactie plaatsen.</p>';
          $('.Melding').html(result).fadeIn();
        }
		else if (html == 'nietok1') {
          result = '<p class="meldingfout ui-corner-all">Uw reactie moet minimaal 4 tekens bevatten.</p>';		  
          $('.Melding').html(result).fadeIn();		
		}
        else {
          result = '<p class="meldinggoed ui-corner-all">Uw reactie is succesvol geplaatst.</p>';
          $('.Melding').html(result).fadeIn();
          
		  	  
		  $('#newcomment').append(html).fadeIn('slow');		  
		  
          $("#CommentForm textarea").val('');
          setTimeout(function(){ $('.Melding').fadeOut(2000); },3000);
        }
      }
    });
    return false;
  });  
    
  $(".sponsorslide").easySlider({
	auto: true,
	continuous: true,
	numeric: false
  });
  
	$.fn.tipsy.defaults = {
		delayIn: 0,      // delay before showing tooltip (ms)
		delayOut: 0,     // delay before hiding tooltip (ms)
		fade: false,     // fade tooltips in/out?
		fallback: '',    // fallback text to use when no tooltip text
		gravity: 'n',    // gravity
		html: false,     // is tooltip content HTML?
		live: false,     // use live event support?
		offset: 0,       // pixel offset of tooltip from element
		opacity: 0.8,    // opacity of tooltip
		title: 'alt',  // attribute/callback containing tooltip text
		trigger: 'hover' // how tooltip is triggered - hover | focus | manual
	};  
  
  $('img.tooltip').tipsy({gravity: 's'});

  $(".alltweets").html('<div style="padding: 20px; text-align: center;">Bezig met laden van Twitter berichten...</div>');		
    var hashcode = $('#hashcode').val()
    $.ajax({ type: 'GET',url: '/ajax/GetTweets.php?q='+hashcode,cache: false,success: function(html){
	  $(".alltweets").hide()				
	  $(".alltweets").html(html);
	  $(".alltweets").slideDown();				
    }
  }); 

  $('#getpassform').submit(function(){
    $('.message0').hide();
    var dataString = $(this).serialize();
    $.ajax({ type: 'POST',url: '/ajax/WachtwoordVergeten.php',data: dataString,cache: false,success: function(html){
        if(html == 'OK') { 
			$('#getpassform').hide(); result = '<p class="meldinggoed ui-corner-all">Wij hebben u een email gestuurd met een link waarmee u uw nieuwe wachtwoord moet bevestigen. Zonder uw nieuwe wachtwoord te bevestigen kunt u uw nieuwe wachtwoord niet gebruiken.</p>'; 
			$('#getpassform').fadeOut();
		}
        else { result = html; }
		$('.message0').html(result);
        $('.message0').fadeIn();        		
      }
    });
    return false;
  });  
  
  $('#SignupForm').submit(function(){
    $('#MeldingSignup').hide();
    var dataString = $(this).serialize();
    $.ajax({ type: 'POST',url: '/ajax/AccountAanmaken.php',data: dataString,cache: false,success: function(html){
        if(html == 'OK') {
          $('#SignupForm').fadeOut();
          $('#MeldingSignup').html('<p class="meldinggoed ui-corner-all">U heeft succesvol een nieuwe account aangemaakt. Wij hebben een bevestigingsemail naar uw opgegeven emailadres gestuurd. Klik op de link in deze email om uw account te bevestigen. Bekijk nu uw email...<br><br><strong>Let op:</strong><br>Indien u onze email niet heeft ontvangen, kijk dan eerst in uw ongewenste map (spam folder) om te kijken of onze email daarin terecht is gekomen.</p>').fadeIn();
          $('#MeldingSignup').fadeIn();
        }
        else {
          $('#SignupForm .password').val('');
          $('#MeldingSignup').html(html).fadeIn();          
        }
      }
    });
    return false;
  });  
  
});

function sure(text) {
    if(confirm(text)) { return true; }
    else { return false; }
}
