/*
	Eigen javascript functies verzameld in 1 document
*/

function updateCoords(c)
{
	$('#x').val(c.x);
	$('#y').val(c.y);
	$('#w').val(c.w);
	$('#h').val(c.h);
}

function checkCoords()
{
	if (parseInt($('#w').val())) return true;
	alert('Please select a crop region then press submit.');
	return false;
}


function lid(id){
		$(document).ready(function(){
    			$.get('lid.php?l='+id, function(data){
    				$("#left").html(data);
    			    $('html, body').animate({scrollTop:0}, 250);
			        return false;
			     });
		});
}
  
function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (
			anchor.getAttribute("href") && ( 
			anchor.getAttribute("rel") == "external" || 
			anchor.getAttribute("rel") == "external nofollow" || 
			anchor.getAttribute("rel") == "nofollow external" )
			)
		anchor.target = "_blank";
	}
}
window.onload = function() {
	externalLinks();
}



/*functies voor de lange nieuwsberichten af te korten en te volledig weer te geven op vraag van de lezer.
	*showChar zijn het aantal karakters dat weergegeven wordt in de korte versie
	*ellipstext is value van de string dat er nog meer is "dus er is nog..."
	*moretext is value van de link om meer te laten zien
	*lesstext is value van de link om minder te laten zien
*/
$(document).ready(function() {
    
    $('#cropbox').Jcrop({
					aspectRatio: 200/250,
					onSelect: updateCoords,
                    bgOpacity: .4               
				});
    
    //datepicker openen
    $("#datepicker").datepicker({autoSize:true});
    
    var showChar = 500;
    var ellipsestext = "...";
    var moretext = "<br />lees meer";
    var lesstext = "<br />minder";
    $('.tekst').each(function() {
        var content = $(this).html();
 
        if(content.length > showChar) {
 
            var c = content.substring(0, showChar);
            var h = content.substring(showChar);
 
            var html = c + '<span class="moreelipses">'+ellipsestext+'</span><span class="morecontent"><span>' + h + '</span><a href="" class="morelink">'+moretext+'</a></span>';
 
            $(this).html(html);
        }
 
    });
 
$(".morelink").click(function(){
        if($(this).hasClass("less")) {
            $(this).removeClass("less");
            $(this).html(moretext);
        } else {
            $(this).addClass("less");
            $(this).html(lesstext);
        }
        $(this).parent().prev().slideToggle(350);
        $(this).prev().slideToggle(350);
        return false;
    });
    $("a.image").fancybox({
				'transitionIn'	:	'elastic',
				'transitionOut':	'none',
				'speedIn'		:	300, 
				'speedOut'		:	400, 
				'overlayShow'	:	true,
				'hideOnContentClick': true,
				'showCloseButton': false
    });
    $("a.video").fancybox({
				'transitionIn'	:	'elastic',
				'transitionOut':	'none',
				'speedIn'		:	300, 
				'speedOut'		:	400, 
				'overlayShow'	:	true,
				'hideOnContentClick': true,
                'type'  :   'swf',
                'swf'			: {
			   	 'wmode'		: 'transparent',
				'allowfullscreen'	: true
			}
    });
    
    //functies voor bierfeest.guri.be
    $(document).ready(function(){
            $("a.iframe").fancybox({
                'width': '100%',
                'height':'100%',
                'scrolling':'auto'
            });
            $("a.boekske").fancybox({
				'transitionIn'	:	'elastic',
				'transitionOut':	'none',
				'speedIn'		:	300, 
				'speedOut'		:	400, 
				'overlayShow'	:	false,
				'hideOnContentClick': false,
                'width' :   680,
                'height':   333,
                'type'  :   'swf',
                'swf'			: {
  	             'wmode'		: 'transparent',
				'allowfullscreen'	: true
			     }
            });
        });
    



});
