if ( linkpath == undefined ) var linkpath = '';

jQuery.fn.dataTableExt.aTypes.unshift(
	function ( sData )
	{
		if (sData.match(/^(0[1-9]|[12][0-9]|3[01])-(0[1-9]|1[012])-(19|20|21)\d\d$/))
		{
			return 'nl_date';
		}
		return null;
	}
);

jQuery.fn.dataTableExt.oSort['nl_date-desc']  = function(a,b) {
	var nlDatea = a.split('-');
	var nlDateb = b.split('-');

	var x = (nlDatea[2] + nlDatea[1] + nlDatea[0]) * 1;
	var y = (nlDateb[2] + nlDateb[1] + nlDateb[0]) * 1;

	return ((x < y) ? -1 : ((x > y) ?  1 : 0));
};

jQuery.fn.dataTableExt.oSort['nl_date-asc'] = function(a,b) {
	var nlDatea = a.split('-');
	var nlDateb = b.split('-');

	var x = (nlDatea[2] + nlDatea[1] + nlDatea[0]) * 1;
	var y = (nlDateb[2] + nlDateb[1] + nlDateb[0]) * 1;

	return ((x < y) ? 1 : ((x > y) ?  -1 : 0));
};

$(document).ready(function(){

	// flash inladen
	// als een div aangemaakt wordt met als class "flash",
	// en als inhoud het absolute pad naar de flash en de variable
	// wordt deze automatisch ingeladen
	$('.flash').each(function(){
		slideshowvars = $(this).find('.flashlink').html();
		flashvars = $(this).find('.flashvars').text();
		slideshowheight = $(this).css('height');
		slideshowwidth = $(this).css('width');
		$(this).html("");
		$(this).flash({
	    	src: slideshowvars,
	    	width: slideshowwidth ,
	    	height: slideshowheight,
			wmode: "transparent",
			flashvars: {clickTAG: flashvars, clickTag: flashvars }
		});
	});

	// variabele headings
	$('.flashfont').each(function(){
		slideshowwidth = $(this).css('width');

		blueText = $(this).find('.blue').html();
		blueText = blueText.replace('&amp;','%26');

		blackText = $(this).find('.black').html();
		blackText = blackText.replace('&amp;','%26');

		detailText = $(this).find('a').attr('title');
		detailText = detailText.replace('&amp;','%26');

		linkUrl = $(this).find('a').attr('href');

		$(this).html("");
		$(this).flash({
			src: linkpath+'/public/flash/flashfont.swf?blueText=' + blueText + '&amp;blackText=' + blackText + '&amp;detailText=' + detailText + '&amp;linkUrl=' + linkUrl,
			width: slideshowwidth,
			height: '35px',
			wmode: 'transparent'
		});
	});

	$('.cufonfont').find('a[href!=""]').append(' &raquo;');

    $('a.js_banner').click(function(){
    	var link = $(this);
    	_gaq.push(['_trackEvent', 'Banner', 'Click', $(this).attr('data-title')]);
    	_gaq.push(function(){
    		window.open(link.attr('href'));
	    });
    	return false;
    });

	// verzend links in formulieren maken
	$('.verzendlink').click(function(){
		$(this).parents('form').submit();
	});

	//field hints
	$(".js_hintfield").each(function() {
        var beginStyle = $(this).attr("style");
		$(this).addClass("js_hint");
		$(this).val($(this).attr("title"));

        $(this).bind("focus", function(e) {
            if ($(this).val() == $(this).attr("title")) {
                $(this).val("");
				$(this).removeClass("js_hint");
            }
        });
        $(this).bind("blur", function(e) {
            if ($(this).val() == "") {
				$(this).addClass("js_hint");
				$(this).val($(this).attr("title"));
            } else {
				$(this).removeClass("js_hint");
			}
        });
    });

	// links in "_blank" i.p.v. via HTML i.v.m. valid XHTML
	$('.blankwindow').attr('target','_blank');

	$(".tell_a_friend").click(function(){
		$("#reactie_form").css('display', 'none');
		$("#taf_form").css("display", 'block');
	});

	$(".add_reactie").click(function(){
		$("#taf_form").css("display", "none");
		$("#reactie_form").css('display', 'block');
	});

	$(".page_field_topvideos").blur(function()
	{
		var page 	= $(this).val() - 1;
		window.location=linkpath+'/topvideos/'+page;
	});

	$(".page_field").blur(function()
	{
		var page 	= $(this).val() - 1;
		var url		= $(".url").val();
		window.location=linkpath+'/bedrijvengids/'+url+'page='+page;
	});

	$(".page_field_zoeken").blur(function()
	{
		var page 	= $(this).val() - 1;
		var url		= $(".url").val();
		window.location=linkpath+'/'+url+'page='+page;
	});


	$("#starter").click(function(){
		$("#failliet_items").slideUp();
		$("#starter_items").slideDown();

	});


	$("#failliet").click(function(){
		$("#starter_items").slideUp();
		$("#failliet_items").slideDown();
	});


	$(".fs_item").click(function(){
		var list = $(this).find('.fs_item_list');
		list.toggle();

	});

	$("#commerce_username").focus(function(){
		$(this).val('');
	});

	$("#commerce_username").blur(function(){
		if($(this).val()=='')
			$(this).val('gebruikersnaam');
	});

	$("#commerce_password").blur(function(){
		if($(this).val()=='')
			$(this).val('wachtwoord');
	});

	$("#commerce_password").focus(function(){
		$(this).val('');
	});

	/*

	Meetbaar maken van Spotlights en Bedrijvenbanner

	*/

	$(".visit").click(function(){
		var aId 	= $(this).attr('id').split('_');
		var bron 	= aId[1];
		var id 		= aId[2];

		$.ajax({
			type: "POST",
			url: linkpath+"/ajax/ajax.add_bekeken.php",
			data: 'bedrijf_id='+id+'&bron='+bron,
			dataType: "html",
			success: function(result)
			{ 	}
		});
	});

	$('.js_poll').click(function(){
		var pollId = $(this).attr('rel').substr("js_poll_".length);
		var pollcookie = $.cookie('wijlimburg_poll');
	    if (pollId == pollcookie) {
			alert('U heeft al gestemd in deze poll');
			return;
		}
		var answer = $(this).attr('id').substr("js_poll_antw".length);
		var date = new Date();
		date.setTime(date.getTime() + (30 * 24 * 60 * 60 * 1000));
		$.cookie('wijlimburg_poll', pollId, {path: '/', expires: date});
		pollcookie = $.cookie('wijlimburg_poll');
		if('' != pollcookie) {
			$.ajax({
				type: "POST",
				url: linkpath+'/ajax/ajax.poll.php',
				data: 'antwoord='+answer,
				dataType: "xml",
				success: function(result) {
					window.location = window.location;
				}
			});
		}
	});

    $('.submenuknop').mouseover(function(){
        $(this).children('ul').addClass('show');
	});

    $('.submenuknop').mouseleave(function(){
        $(this).children('ul').removeClass('show');
	});

    $('.subsubmenuknop').mouseover(function(){
        $(this).children('ul').addClass('show');
	});

    $('.subsubmenuknop').mouseleave(function(){
        $(this).children('ul').removeClass('show');
	});

    $('.js_datatable').dataTable({
    	"iDisplayLength": 25,
    	"aLengthMenu": [[25, 50, 100, 200, -1], [25, 50, 100, 200, "All"]],
    	"sPaginationType": "full_numbers",
    	"oLanguage": {
			"sLengthMenu": "Toon _MENU_ items per pagina",
			"sZeroRecords": "Geen items gevonden",
			"sInfo": "Toon item _START_ tot _END_ van _TOTAL_",
			"sInfoEmpty": "Geen items gevonden",
			"sInfoFiltered": "(geselecteerd van _MAX_ items)",
			"sSearch" : "Zoek",
			"oPaginate": {
				"sFirst":    "Eerste",
				"sPrevious": "Vorige",
				"sNext":     "Volgende",
				"sLast":     "Laatste"
			}
		}
    });

    $('.js_sheetline').live('click',function(){
    	var html_id = $(this).attr('id');
    	var line_id = html_id.replace('line_','');

    	var html_sheet_id = $(this).closest('.js_datatable').attr('id');
    	var sheet_id = html_sheet_id.replace('datatable_','');

    	document.location = '/datatable/'+sheet_id+'/'+line_id;
    });

    if( 1 == $('#googlemap_canvas').length ) {
    	loadScript();
    }

});

function submitform()
{
	document.getElementById('zoekform').submit();
}

