var pathExpressInstallFile = escape("/lib/flash/expressInstall.swf");

function initHyperlinks() {
    $("a[rel=external]").each(function() {
        $(this).click(function() { window.open($(this).attr("href")); return false; });
        if ($(this).attr("title") == "") $(this).attr("title", "Deze link wordt in een nieuw venster geopend.")
        else $(this).attr("title", "'" + $(this).attr("title") + "' wordt in een nieuw venster geopend.");
    });
}

function initContentFlash() {
    $('.contentflash').each(
        function() {
            var strId = $(this).attr('id');
            var strParams = $(this).find('a').attr('rel').split('|');

            $('#' + strId).flashembed(
            {
                src: strParams[0],
                version: [strParams[1]],
                width: strParams[2],
                height: strParams[3],
                expressInstall: pathExpressInstallFile,
                wmode: 'transparent',
                scale: 'noscale'
            })
        }
    );
}

function initSlideshow() {
    $('#flash').flashembed(
    {
        src: '/lib/flash/comma_homepage.swf',
        version: [9, 0],
        width: '390',
        height: '620',
        expressInstall: pathExpressInstallFile,
        wmode: 'transparent',
        scale: 'scale'
    }, {
        
    })
}



function initNyromodal() {
	$.fn.nyroModal.settings.regexImg = '[^\.]\.(jpg|jpeg|png|tiff|gif|bmp)\s*$|image.aspx';
	$.fn.nyroModal.settings.minWidth = 0;
	$.fn.nyroModal.settings.minHeight = 0;
	
	
	
    if ($.browser.msie && $.browser.version == "6.0") {
        $.fn.nyroModal.settings.minWidth = '500';
        $.fn.nyroModal.settings.minHeight = '500';
    }
    else {
        $.fn.nyroModal.settings.minWidth = '100';
        $.fn.nyroModal.settings.minHeight = '100';
    }

    $("a[href*='#nyro']").click(function() {

        var url = $(this).attr('href');
        if (url.indexOf("googlemaps") > 0) {
            //url = url.substring(0, url.length - 5);
            //speciale template voor IE7 omdat IE7 geen javascript uitvoert bij nyromodal request, en dit is wel vereist voor googlemaps.
            url = "/?template=googlemaps_nyro.htm";
        }
      
        $.nyroModalManual({
            url: url
        });
        return false;
    });


	$("a[href*='fid=']").click(function() {
		var PhotoBookURL = $(this).attr('href') + '#nyro';
		$.nyroModalManual({
			url: PhotoBookURL
			,height: '545'
			,width: '790'
		});
		return false;
	});

}

function initIE6() {
	$('#nav li').each(function() {
		$(this).hover(function() {
			$(this).addClass('sfhover');
		}, function() {
			$(this).removeClass('sfhover');
		});
	});
}

function initForms()
{var container = $('div.containererreurtotal');

	$('form.validate').validate();
	$('form.validate_alert').validate({
		onfocusout: false

		,showErrors: function(errorMap, errorList) {
			var error = 'Er zijn ' + this.numberOfInvalids() + ' fouten gevonden:\n\n';
			for (var i in errorList)
			{
				error = error + errorList[i].element.name + ':' + errorList[i].message + '\n';
			}
			alert(error);
	}
	});
}
function plaatjeBreed() {
    var Window = $(window).width();
    $('#headerimage').css({ width: Window })
}

$(function() {
    if ($.browser.msie && $.browser.version == '6.0') {
        $('.kommaPLaatjes').each(function() {
            var src = $(this).attr('src').split('.');
            $(this).attr('src', src[0] + '_ie6.png');
        });
    }

    $('.slider_wrapper').hover(function() {
        var theImg = $(this).find('.sliderImg');
        var curPos = Math.floor(theImg.position().left);
        var ToAnimate = (theImg.width() - 176) * -1;
        var PixelsAnimate = (ToAnimate - curPos) * -1;
        var MiliSeconden = PixelsAnimate * 16;

        $(this).find('.sliderImg').animate({
            left: ToAnimate + 'px'
        }, MiliSeconden, 'linear');
    }, function() {
        $(this).find('.sliderImg').stop();
    });

    $('.sliderHeader').hover(function() {
        var theImg2 = $(this).parent().find('.' + $(this).attr('data-slider'));

        var curPos = Math.floor(theImg2.position().left);
        var ToAnimate = (theImg2.width() - 176) * -1;
        var PixelsAnimate = (ToAnimate - curPos) * -1;
        var MiliSeconden = PixelsAnimate * 16;

        theImg2.animate({
            left: ToAnimate + 'px'
        }, MiliSeconden, 'linear');
    }, function() {
        $(this).parent().find('.' + $(this).attr('data-slider')).stop();
    });

})

$(document).ready(function() {

    //Initialiseer hier je scripts
    initHyperlinks();
    initIE6();
    initContentFlash();
    initNyromodal();
    initForms();
    plaatjeBreed();
    initSlideshow();
    $(window).resize(function() { plaatjeBreed() });
});
