$(document).ready(function() {
	
	// Search from focus, blur default text config
	$('input[type="text"],#zoekoprubriek').each(function(){
		this.value = $(this).attr('rel');
    $(this).focus(function(){
	    if(this.value == $(this).attr('rel')) {
				this.value = '';
	    }
    });    
    $(this).blur(function(){
	    if(this.value == '') {
				this.value = $(this).attr('rel');
	    }
    });
	});
	
	$("#zoekfotograaf").submit(function(e) {
		//alert('NAAM:'+$('#zoekopnaam').val()+' PCODE:'+$('#zoekoppostcode').val()+' PLAATSNAAM:'+$('#zoekopplaatsnaam').val());
			var varMethod = "get";			
			var varUrl  = 'inc/functions/ajax_search.php';
			var varParam = 'rubriekid=' + $('#zoekoprubriek').val() + '&naam=' + $('#zoekopnaam').val() + '&pc=' + $('#zoekoppostcode').val() + '&plaats=' + $('#zoekopplaatsnaam').val();
			var varContent = "#ajaxcontent";
			var varWait = "#loading";			
			AjaxMainHandler(varMethod, varUrl, varParam, varContent, varWait);
 			e.preventDefault(); 
	});	
	
	$('#cntFetchMore').live('click', function() {
		//alert($('#zposition').val());
		
		 $('#btnFetchMore').attr('value', '<img src="http://www.f1toto.com/img/loading.gif" style="width:16px;height:16px;padding:0;margin:0;">Een moment aub...');
		// $('#btnFetchMore').val('Een moment aub...');
		 $('#btnFetchMore').attr('disabled', true);
	});
	
	
	
	//Tooltips
	$(".tip_trigger").hover(function(){
	    tip = $(this).find('.tip');
	    tip.show(); //Show tooltip
	}, function() {
	    tip.hide(); //Hide tooltip
	}).mousemove(function(e) {
	    var mousex = e.pageX + 20; //Get X coodrinates
	    var mousey = e.pageY + 20; //Get Y coordinates
	    var tipWidth = tip.width(); //Find width of tooltip
	    var tipHeight = tip.height(); //Find height of tooltip
	
	    //Distance of element from the right edge of viewport
	    var tipVisX = $(window).width() - (mousex + tipWidth);
	    //Distance of element from the bottom of viewport
	    var tipVisY = $(window).height() - (mousey + tipHeight);
	
	    if ( tipVisX < 20 ) { //If tooltip exceeds the X coordinate of viewport
	        mousex = e.pageX - tipWidth - 20;
	    } if ( tipVisY < 20 ) { //If tooltip exceeds the Y coordinate of viewport
	        mousey = e.pageY - tipHeight - 20;
	    }
	    //Absolute position the tooltip according to mouse position
	    tip.css({  top: mousey, left: mousex });
	});    

});

function AjaxMainHandler(varRequestMethod, varPostTo, frmParams, varAjaxContent, varAjaxWait) {

	$.ajax({
		method: varRequestMethod, url: varPostTo, data: frmParams,   
		beforeSend: function(){$(varAjaxContent).html('').hide("slow"); $(varAjaxWait).show('slow',function(){ if(jQuery.browser.msie) this.style.removeAttribute('filter');});},
		complete: function(){ $(varAjaxWait).hide("slow");},
		error: function(){ $(varAjaxContent).html('error').show('slow',function(){ if(jQuery.browser.msie) this.style.removeAttribute('filter');});},
		success: function(html){ $(varAjaxContent).html(html).show('slow',function(){ if(jQuery.browser.msie) this.style.removeAttribute('filter');}); }   
	});

	//return false;			
};
