$(document).ready(function() {
	
	var search_input = '';
	$('.search_input').focus();
	$('.search_input').keyup(function() {
		
		search_input = $('.search_input').val();

	}).keyup();
	$('.search_button').click(function(event){
		
		event.preventDefault();
		
		if(search_input != '') {
			
			window.location = 'http://www.zengerink.com/links/search/'+search_input;			
		}
	});
	
	/*
	* Update the Url in the database
	*/
	function update_url(id, href) {
		
		// Call click.php for storing it in the database
		$.get('http://www.zengerink.com/links/update_usage/'+id, function(id){
			
			window.location = href;
		});
	}
	
	/* *
	* Replace click on an .external anchor with a function
	*/
	$(".external").click(function(event){
		
		// Prevent default anchor action
		event.preventDefault();
		
		// Run php script to update mysql database
		update_url(this.id, this);
	
	});
	
	/* *
	* Show message
	*/
	$('div.message_container').slideDown('normal');
	
	/* *
	* Hide message
	*/
	$('div.message').click(function(event){
		
		// Prevent default anchor action
		event.preventDefault();
		
		$(this).slideUp('normal');
		
	});
	
	/* *
	* Toggle Log On
	*/
	$('.log_on_link').click(function(event) {
		event.preventDefault();
		
		$('.log_on_form').toggle();
	});
	
	$('.barblock').mouseover(function(event){
		
		$(this.id).show();
		
	});
	
	$('.barblock').mouseout(function(event){
		
		$(this.id).hide();
		
	});
	
	/* *
	* search hover
	*/
	$('.search_row > td > .external').mouseover(function(event){
		
		$('#tr_'+this.id).css('background-color','#DDEEFF');
	});
	$('.search_row > td > .external').mouseout(function(event){
		
		$('#tr_'+this.id).css('background-color','#FFFFFF');
	});
	$('.option_view').mouseover(function(event){
		
		$('#tr_'+this.id).css('background-color','#FFFDBD');
		$('#tr_'+this.id+' td > a').css('color','#999030');
	});
	$('.option_view').mouseout(function(event){
		
		$('#tr_'+this.id).css('background-color','#FFFFFF');
		$('#tr_'+this.id+' td > a').css('color','#0000FF');
	});
	$('.option_edit').mouseover(function(event){
		
		$('#tr_'+this.id).css('background-color','#99FF99');
		$('#tr_'+this.id+' td > a').css('color','#009900');
	});
	$('.option_edit').mouseout(function(event){
		
		$('#tr_'+this.id).css('background-color','#FFFFFF');
		$('#tr_'+this.id+' td > a').css('color','#0000FF');
	});
	$('.tag').mouseover(function(event){
		$(this).css({'background-color':'#990000','color':'#FFFFFF','padding':'3px','text-decoration':'none'});
	});
	$('.tag').mouseout(function(event){
		$(this).css({'background-color':'','color':'#0000FF','padding':'0px','text-decoration':'underline'});
	});
	
	/* *
	* DELETE
	*/
	$('.option_delete').mouseover(function(event){
		
		$('#tr_'+this.id).css('background-color','#FF9999');
		$('#tr_'+this.id+' td > a').css('color','#990000');
	});
	$('.option_delete').mouseout(function(event){
		
		$('#tr_'+this.id).css('background-color','#FFFFFF');
		$('#tr_'+this.id+' td > a').css('color','#0000FF');
	});
	$('.option_delete').click(function(event){
		event.preventDefault();
		sure_to_delete = confirm('Weet je het zeker?');
		if(sure_to_delete) {
			window.location = 'http://www.zengerink.com/links/delete/'+this.id;	
		}
	});
});

