/* hoverIntent r6 // 2011.02.26 */
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev])}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev])};var handleHover=function(e){var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t)}if(e.type=="mouseenter"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob)},cfg.timeout)}}};return this.bind('mouseenter',handleHover).bind('mouseleave',handleHover)}})(jQuery);

var addthis_config = {
     ui_language: "nl"
}

$(function() {
    /* tooltips */
   $('.priceToolTip img').each(function(e) // Select all elements with the "tooltip" attribute
	{
   		$(this).qtip({ 
   			content: $(this).attr('title'),
   			position: {
                  corner: {
                     tooltip: 'rightMiddle', // Use the corner...
                     target: 'leftMiddle' // ...and opposite corner
                  }
               },
               style: { 
      width: 200,
      padding: 5,
      background: '#fff',
      color: '#007AC1',
      textAlign: 'left',
      'font-size': 11,
      border: {
         width: 1,
         color: '#000'
      }}
             
   		
   		
   		}); 
   		$(this).attr('title','');
   		
   		// Retrieve the tooltip attribute value from the current element
	});
	$('.priceToolTipWide img').each(function(e) // Select all elements with the "tooltip" attribute
	{
   		$(this).qtip({ 
   			content: $(this).attr('title'),
   			position: {
                  corner: {
                     tooltip: 'rightMiddle', // Use the corner...
                     target: 'leftMiddle' // ...and opposite corner
                  }
               },
               style: { 
      width: 200,
      padding: 5,
      background: '#fff',
      color: '#007AC1',
      textAlign: 'left',
      'font-size': 11,
      border: {
         width: 1,
         color: '#000'
      }}
             
   		
   		
   		}); 
   		$(this).attr('title','');
   		
   		// Retrieve the tooltip attribute value from the current element
	});

	$('.pdfInnerTable td h2').each(function(e) {
		$(this).qtip({ 
			content: $(this).attr('title'),
			position: {
				corner: {
					tooltip: 'bottomMiddle', // Use the corner...
					target: 'topMiddle' // ...and opposite corner
				},
				adjust: {
					resize: true,
					scroll: true
				}
			},
			tip: true,
			style: {
				padding: 10,
				background: '#f1f1f1',
				width: {max: 200},
				color: '#333',
				textAlign: 'center',
				'font-size': 11,
				border: {
					width: 1,
					color: '#555',
					radius: 3
				}
			}
		}); 
		$(this).attr('title','');
	});
    
    
	/* Lacoselecter tabs */
	$('.lacoSelecterContent').tabs().show();
    
    /* valid email */
    function isValidEmail(a){a=Trim(a);var b=a.indexOf("@");if(a.length>5){if(a.indexOf(" ")==-1){if(b>0&&b<a.length-4){b=a.indexOf("@",b+1);if(b==-1){b=a.length-a.lastIndexOf(".");if(b>2&&b<6){return true}}}}}return false}function Trim(a){var b=0;var c=a.length;while(b<c&&a.charAt(b)==" "){b++}while(c>0&&a.charAt(c-1)==" "){c--}return a.substring(b,c)}
    
    /* rel external */
    //$('a[rel*=external]').click(function(){window.open(this.href);return false;});
    
    /* rel fancybox */
    

	
	/* Nieuws & Sport vandaag tabs */
	$('.tabWidget').tabs();
	
	/* Lacoselecter dropdown */
	$('select#lacoSelect').uniform({selectClass: 'lacoSelectBig'});
	$('select#lacoSelect2').uniform({selectClass: 'lacoSelectBig'});
	
	/* Default dropdown */
	$('.defaultForm select').uniform({selectClass: 'defaultSelect'});
	$('#smoelenboekSort select').uniform({selectClass: 'defaultSelect'});
	
	/* Wizzard Radiobuttons */
	$('.wizzardRadio').uniform({radioClass: 'wizzardRadio'});

	/* Lacoselecter dropdownSmall */
	$('select#lacoSelectRadius, select#lacoSelectRadius2, select#lacoSelectActivities, select#lacoSelectSpecific').uniform({selectClass: 'lacoSelectSmall'});
	
	/* Dropdown menu */
	$('#dropdownMenu').hoverIntent(function(){$('.navigationMain2DropdownMenu').slideDown(100);$('#dropdownMenu').addClass('active');},function(){$('.navigationMain2DropdownMenu').slideUp('fast');$('#dropdownMenu').removeClass('active');});$('#dropdownMenu').click(function(){return true;});
	
	/* Resizing text Use the "resize" class to set the fontsize */
	//$('.textDown').click(function () {
//        var currentFontSize = $('.resize').css('font-size');
//        var currentFontSizeNum = parseFloat(currentFontSize, 10);
//        $('.resize').css('font-size', (currentFontSizeNum - 1) + 'px !important');
//        return false;
//    });
//    $('.textUp').click(function () {
//        var currentFontSize = $('.resize').css('font-size');
//        var currentFontSizeNum = parseFloat(currentFontSize, 10);
//        $('.resize, .resize *').css('font-size', currentFontSizeNum + 1 + 'px !important');
//        return false;
//    });
 
      // Increase Font Size
      $(".textUp").click(function(){
        var currentFontSize = $('.resize').css('font-size');
        var currentFontSizeNum = parseFloat(currentFontSize, 10);
        var newFontSize = currentFontSizeNum*1.2;
        $('.resize, .resize *, .mainTitle *').css('font-size', newFontSize);
        return false;
      });
      // Decrease Font Size
      $(".textDown").click(function(){
        var currentFontSize = $('.resize').css('font-size');
        var currentFontSizeNum = parseFloat(currentFontSize, 10);
        var newFontSize = currentFontSizeNum*0.8;
        $('.resize, .resize *, .mainTitle *').css('font-size', newFontSize);
        return false;
      });
    
    
    /** Navigation &amp; replace with <br/>&amp; */
    $('.navigationMain ul li').each(function(){$(this).find('a').html($(this).find('a').html().replace("&amp;","<br/>&amp;"));});
    
    /** Accomodation dropdown hrefonclick */
    $('#lacoSelect').change(function(){if($(this).val().length>1){location.href=$(this).val();}});
    
    /** Branch Call Processor */
    
    $('.lacoSelectPostal').keyup(function(){
        $(this).val(($.trim($(this).val())).toUpperCase());
    });
    
    $('#brancheResultCount,#brancheResultCount2').html('').hide();
    
    $('#postal').keyup(function(){
        if ($(this).val().length>=4) {
            branchCallLocation();
        } else {
        	$('#more_results_trigger').hide();
            $('#branchResponse,#brancheResultCount').html('').hide();
        }
        
        $('#postal2').val($('#postal').val());
    });
    
    $('a[href=#tabs-1]').click(function(){
        if ($('#postal').val().length>=4) {
            branchCallLocation();
        } else {
        	$('#more_results_trigger').hide();
            $('#branchResponse,#brancheResultCount').html('').hide();
        }
    });
    
    $('a[href=#tabs-2]').click(function(){
        if ($('#postal2').val().length>=4) {
            ActivityCall();
        } else {
        	$('#more_results_trigger2').hide();
            $('#branchResponse2,#brancheResultCount2').html('');
            $('#brancheResultCount2').html('').hide();
        }
    });
    
    $('#postal2').keyup(function(){

        ActivityCall();
        $('#postal').val($('#postal2').val());
    });
    
    $('#lacoSelectRadius').change(function(){

    	$('#lacoSelectRadius2').find('option').each(function(){
    		if ($(this).val()==$('#lacoSelectRadius').val()) {
    			$(this).attr('selected',true);
    			$('#uniform-lacoSelectRadius2').find('span').html($(this).val()+' Km');
    		} else {
    			$(this).attr('selected',false);
    		}
    	});
    	
    	//$('select#lacoSelectRadius, select#lacoSelectRadius2, select#lacoSelectActivities, select#lacoSelectSpecific').uniform({selectClass: 'lacoSelectSmall'});
		
    	
        if ($('#postal').val().length>=4) {
            branchCallLocation();
        } else {
        	$('#more_results_trigger').hide();
            $('#branchResponse,#brancheResultCount').html('');
            $('#brancheResultCount').hide();
        }
    });
    
    $('#lacoSelectRadius2').change(function(){

    	$('#lacoSelectRadius').find('option').each(function(){
    		if ($(this).val()==$('#lacoSelectRadius2').val()) {
    			$(this).attr('selected',true);
    			$('#uniform-lacoSelectRadius').find('span').html($(this).val()+' Km');
    		} else {
    			$(this).attr('selected',false);
    		}
    	});
    });
    
    $('#more_results_trigger').click(function(){
        $('#branchResponse').fadeIn();
        $('#more_results_trigger').hide();
        return false;
    });
    
    $('#more_results_trigger2').click(function(){
        $('#branchResponse2').fadeIn();
        $('#more_results_trigger2').hide();
        return false;
    });
    
    $('#lacoSelectActivities').change(function(){
        if ($(this).val()>0) {
            fetchSpecificActivity();
            $(this).prev().html($(this).prev().html().replace(/amp;/,'').replace(/amp;/,''));
        } else {
            $('#lacoSelectSpecific').html('').parent().find('span').html('');
        }
    });
    
    
    
    $('#lacoSelectRadius2,#lacoSelectSpecific,#lacoSelectActivities').change(function(){
        ActivityCall();
    });
    
    function fetchSpecificActivity()
    {
        $('#lacoSelectSpecific').html('<option value="0">Selecteer</option>');
        $.post('specific_activity.html',{ activity: $('#lacoSelectActivities').val()},function(data){
           $('#lacoSelectSpecific').parent().find('span').html('');
           if (data.length>0) {
            $('#lacoSelectSpecific').html('<option value="0" selected="selected">Geen</option>');
                $('#lacoSelectSpecific').parent().find('span').html('Geen');
                for (i=0;i<data.length;i++) {
                    
                    //'+((i==0)?('selected="selected"'):(''))+'
                    $('#lacoSelectSpecific').append('<option value="'+data[i].id+'">'+data[i].title+'</option>');
                   /* if (i==0) {
                        $('#lacoSelectSpecific').parent().find('span').html(data[i].title);
                        $('#lacoSelectSpecific').val(data[i].id);
                    }*/
                }
           } else {
                $('#lacoSelectSpecific').parent().find('span').html('Geen resultaten');
           }
        },'json');
    }
    
    function ActivityCall()
    {
        if (($('#postal2').val().length>3)&&($('#lacoSelectRadius2').val()>0)&&$('#lacoSelectActivities').val()>0) {
            //branch_activity_ajax_handler
            //alert('activity'+$('#lacoSelectActivities').val()+'specific'+ $('#lacoSelectSpecific').val());
            $.post('branche_ajax_handler.html',{ postal: $('#postal2').val(), range: $('#lacoSelectRadius2').val(), activity: $('#lacoSelectActivities').val(), specific: $('#lacoSelectSpecific').val()},function(data){
                $('#branchResponse2').html('');
                var sOutput = '';
                $('#brancheResultCount2').show().html(data.length+' resultaten gevonden');  
                if (data.length>0) {
                for (i=0;i<data.length;i++) {
                    sOutput += '<li><a href="'+data[i].link+'">'+data[i].title+'</a></li>';
                }
                if (data.length>4) {
                    $('#more_results_trigger2').show();
                    $('#branchResponse2').hide();
                } else {
                    $('#more_results_trigger2').hide();
                    $('#branchResponse2').fadeIn();
                }
                
                $('#branchResponse2').html('<ul>'+sOutput+'</ul>');
                                             
                //alert(data[0].title);
                //data.each(function(){
    //                    alert(data);
    //                });
                }
                },'json');
        } else {
            $('#branchResponse2').html('');
            $('#brancheResultCount2').html('').hide(); 
        }
    }
    
    
    function branchCallLocation()
    {
        $.post('branche_ajax_handler.html',{ postal: $('#postal').val(), range: $('#lacoSelectRadius').val()},function(data){
            $('#branchResponse').html('');
            var sOutput = '';
            $('#brancheResultCount').show().html(data.length+' resultaten gevonden');           
            if (data.length>0) {
                for (i=0;i<data.length;i++) {
                    sOutput += '<li><a href="'+data[i].link+'">'+data[i].title+'</a></li>';
                }
                if (data.length>4) {
                    $('#more_results_trigger').show();
                    $('#branchResponse').hide();
                } else {
                    $('#more_results_trigger').hide();
                    $('#branchResponse').fadeIn();
                }
                
                $('#branchResponse').html('<ul>'+sOutput+'</ul>');
                                             
                //alert(data[0].title);
                //data.each(function(){
    //                    alert(data);
    //                });
            }
        },'json');
        //$('#branchResponse').prepend('<br/>call with postal:'+$('#postal').val()+' and range is '+$('#lacoSelectRadius').val());
    }
    
    //Subscripe module
    function checkFormSubscriptionValue(){if($("#form_set_subscription").val()!=undefined){$($("#subscriptionList  option").get($("#form_set_subscription").val())).attr("selected","selected");$.uniform.update()}}function disableBackLink(){$(".wizzardWidgetBack").click(function(){return false})}function initUniformWizzardRadio(){$(".wizzardRadio").uniform({radioClass:"wizzardRadio"})}function initFancybox(){$("a[rel*=fancybox]").fancybox({width:874,height:550,autoScale:false,transitionIn:"none",transitionOut:"none",type:"iframe"})}function initRadioButtonAjax(){$(".wizzardRadio,.wizzardWidgetBack").bind("click",function(){if($(this).attr("rel")!=undefined){$(".wizzardWidget").load($(this).attr("rel"),function(){initRadioButtonAjax();initFancybox();initUniformWizzardRadio();disableBackLink();checkFormSubscriptionValue()})}})}initRadioButtonAjax();initFancybox()
    
    //Form validation
    $(".signup_button").click(function(){var a="";var b=true;if($("#Naam").val().length<=1){a+="Naam";b=false}if(!isValidEmail($("#Email").val())){if(a.length<=1){a+="Email"}else{a+=", Email"}b=false}if($("#subscriptionList").val().length<1){if(a.length<=1){a+="Abonnement"}else{a+=", Abonnement"}b=false}if(b==false){$(".message").html('<div class="errors"><strong>Er zijn fouten gevonden in uw formulier:</strong><br> De volgende verplichte veld(en) ontbreken: '+a+"<br></div>")}return b})
    
    
    
    
});
