$(document).ready(function() {
    openInNewWindow();

    // Javascript behaviour
    $('.contentSlideshow').parent().addClass('top10');
    $('#footer .container').prepend('<span class="shadow"></span>');
    $('#navigation').append('<span class="left"></span><span class="bottom"></span>');
    $('#navigation li a').hover(function() {
        $(this).parent().addClass('hover');
    }, function() {
        $(this).parent().removeClass('hover');
    });
    // Fix PNG for IE6
    $(document).pngFix();

    // Javascript behaviour
    if ($('#movie').length > 0) {
        var url = document.location.href;
        var surl = 'http://' + document.location.host + '/services/flashinfo.ashx';
        $('#movie').flash({
            src: '/include/video/main.swf',
            width: 530,
            height: 310,
            flashvars: { url: url, surl: surl },
            allowFullScreen: true,
            wmode: 'transparent' 
           },{ 
						version: '8.5'
			 });
    }

    // Slideshow
    if ($('#slideshow').length > 0) {
        $('#slideshow').fancyslideshow({
            slideshowNavigation: true,
            decimalNavigation: true,
            mousewheel: false,
            keyNavigation: false,
            startItem: 1,
            autoHeight: false,
            prevBtnTxt: 'Vorige',
            nextBtnTxt: 'Volgende',
            autoScroll: true,
            delay: 6000,
            easing: false
        });
    }
    
    // Company name copy
    $('.company input').blur(function() {
        var company = $(this).val();
        if ($('.companyShort input').val() == '') {
            $('.companyShort input').val(company.substr(0,12));
        }
    });
});

function openInNewWindow() {
	// external links
	$("a[rel=external]").each(function(){
		$(this).attr('title','Link opent in een nieuw venster');
		$(this).click(function() {
			window.open(this.href);
			return false;
		});
	});
}

function StartOptionVideo(optioncode)
{
    if ($('#movie').length > 0) {
        var url = document.location.href;
        var surl = 'http://' + document.location.host + '/services/flashinfo.ashx';
        $('#movie').flash({
            src: '/include/video/main.swf',
            width: 530,
            height: 310,
            flashvars: { url: url, surl: surl, code: optioncode },
            allowFullScreen: true,
            wmode: 'transparent'
        });
    }
}

function CustomRequired(source, arguments) {
    if (arguments.Value.length > 0) {
        arguments.IsValid = true;
    }
    else {
        arguments.IsValid = false;
    }
    SetErrorClass(source.controltovalidate, arguments.IsValid);
}

function CustomZipcode(source, arguments) {
    var elem = document.getElementById(source.controltovalidate);

    if (/^[0-9]{4}\s{0,1}[a-z|A-Z]{2}$/i.test(elem.value)) {
        arguments.IsValid = true;
    }
    else {
        arguments.IsValid = false;
    }
    SetErrorClass(source.controltovalidate, arguments.IsValid);
}

function CustomEmail(source, arguments) {
    var elem = document.getElementById(source.controltovalidate);

    if (/[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/i.test(elem.value)) {
        arguments.IsValid = true;
    }
    else {
        arguments.IsValid = false;
    }
    SetErrorClass(source.controltovalidate, arguments.IsValid);
}



function CustomImageType(source, arguments) {
    if (arguments.Value.toLowerCase().indexOf('.jpg') > 0 || arguments.Value.toLowerCase().indexOf('.gif') > 0){
        arguments.IsValid = true;
    }else {
        arguments.IsValid = false;
    }
    SetErrorClass(source.controltovalidate, arguments.IsValid);
}

function SetErrorClass(inputId, isValid) {
    var elem = document.getElementById(inputId);
    if (isValid) {
      elem.parentNode.className = elem.parentNode.className.replace(' error', '');
      if (elem.parentNode.className == 'error') {
				elem.parentNode.className = '';
      }
    }else {
				elem.parentNode.className = elem.parentNode.className.replace(' error', '') + ' error';
    }
}

