 

var pathExpressInstallFile = escape("/lib/flash/expressinstall.swf");

function initPopups() {

    $.fn.nyroModal.settings.regexImg = '[^\.]\.(jpg|jpeg|png|tiff|gif|bmp)\s*$|image.aspx';
//    $.fn.nyroModal.settings.minWidth = 0;
//    $.fn.nyroModal.settings.minHeight = 0;
}

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 initFlash() {

    $('#flash_mute').flashembed(
	{
	    src: '/lib/flash/BGAudioPlayer.swf'
		, version: [9, 115]
		, height: 15
		, width: 75
		
	},
	{
	    lang: language
	    , mode: $.cookie('cookieFlashSound')
	});

	
    
    $('.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'
            });
        }
    );
	
	$('body.homepage #flash_projecten').flashembed(
	{
		src: '/lib/flash/gallery.swf'
		,version: [9,115]
		,height: 423
		,wmode: 'transparent'
		,expressInstall: pathExpressInstallFile
		,onFail: function(version) {
			closeGallery();
		}
	},
	{
	    galleryXml: escape('/lib/xml/gallery.ashx?taal=' + language)
		,algemeenXml: escape('/lib/xml/algemeen.ashx')
		, directlinkID: directlinkid
		, lang: language
	});
	
	$('body.media #flash_projecten').flashembed(
	{
		src: '/lib/flash/media.swf'
		,version: [9,115]
		,height: 423
		,wmode: 'transparent'
		,expressInstall: pathExpressInstallFile
		,onFail: function(version) {
			closeGallery();
		}
	},
	{
	    xmlPath: escape('/lib/xml/projectmedia.ashx?taal=' + language)
	     , algemeenXml: escape('/lib/xml/algemeen.ashx')
	     , lang: language
	});
	
	$('body.content #flash_projecten').flashembed(
	{
		src: '/lib/flash/MediaContent.swf'
		,version: [9,115]
		,wmode: 'transparent'
		,height: 423
		,expressInstall: pathExpressInstallFile
		,onFail: function(version) {
			closeGallery();
		}
	},
	{
	    xmlPath: escape('/lib/xml/sectiebackground.ashx?id=' + structuurid + '&taal=' + language)
	   
	});

	$('body.project_omschrijving #flash_projecten').flashembed(
	{
		src: '/lib/flash/project.swf'
		,version: [9,115]
		,wmode: 'transparent'
		,height: 423
		,expressInstall: pathExpressInstallFile
		,onFail: function(version) {
			closeGallery();
		}
	},
	{
	    projectXml: escape('/lib/xml/project.ashx?pid=' + projectid + '&taal=' + language)
		,algemeenXml: '/lib/xml/algemeen.ashx'
		,lang: language
		,page: '1'
		,enableKaart: '1'
	});
	
	$('body.project_ligging #flash_projecten').flashembed(
	{
		src: '/lib/flash/project.swf'
		,version: [9,115]
		,wmode: 'transparent'
		,height: 423
		,expressInstall: pathExpressInstallFile
		,onFail: function(version) {
			closeGallery();
		}
	},
	{
	    projectXml: escape('/lib/xml/project.ashx?pid=' + projectid + '&taal=' + language)
		,algemeenXml: escape('/lib/xml/algemeen.ashx')
		,lang: language
		,page: '2'
		,enableKaart: '1'
	});
	
	$('body.project_inplanting #flash_projecten').flashembed(
	{
		src: '/lib/flash/project.swf'
		,version: [9,115]
		,wmode: 'transparent'
		,height: 423
		,expressInstall: pathExpressInstallFile
		,onFail: function(version) {
			closeGallery();
		}
	},
	{
	    projectXml: escape('/lib/xml/project.ashx?pid=' + projectid + '&taal=' + language)
		,algemeenXml: escape('/lib/xml/algemeen.ashx')
		,lang: language
		,page: '3'
		,enableKaart: '1'
	});
	
	$('body.project_aanbod #flash_projecten').flashembed(
	{
		src: '/lib/flash/project.swf'
		,version: [9,115]
		,wmode: 'transparent'
		,height: 423
		,expressInstall: pathExpressInstallFile
		,onFail: function(version) {
			closeGallery();
		}
	},
	{
	    projectXml: escape('/lib/xml/project.ashx?pid=' + projectid + '&taal=' + language)
		,algemeenXml: escape('/lib/xml/algemeen.ashx')
		,lang: language
		,page: '4'
		,enableKaart: '1'
	});
	
	$('body.project_brochure #flash_projecten').flashembed(
	{
		src: '/lib/flash/project.swf'
		,version: [9,115]
		,wmode: 'transparent'
		,height: 423
		,expressInstall: pathExpressInstallFile
		,onFail: function(version) {
			closeGallery();
		}
	},
	{
	    projectXml: escape('/lib/xml/project.ashx?pid=' + projectid + '&taal=' + language)
		,algemeenXml: escape('/lib/xml/algemeen.ashx')
		,lang: language
		,page: '5'
		,enableKaart: '1'
	});
	
	$('body.project_contact #flash_projecten').flashembed(
	{
		src: '/lib/flash/project.swf'
		,version: [9,115]
		,wmode: 'transparent'
		,height: 423
		,expressInstall: pathExpressInstallFile
		,onFail: function(version) {
			closeGallery();
		}
	},
	{
	    projectXml: escape('/lib/xml/project.ashx?pid=' + projectid + '&taal=' + language)
		,algemeenXml: escape('/lib/xml/algemeen.ashx')
		,lang: language
		,page: '6'
		,enableKaart: '1'
	});
	
	$('body.project_lastenboek #flash_projecten').flashembed(
	{
		src: '/lib/flash/project.swf'
		,version: [9,115]
		,wmode: 'transparent'
		,height: 423
		,expressInstall: pathExpressInstallFile
		,onFail: function(version) {
			closeGallery();
		}
	},
	{
	    projectXml: escape('/lib/xml/project.ashx?pid=' + projectid + '&taal=' + language)
		,algemeenXml: escape('/lib/xml/algemeen.ashx')
		,lang: language
		,page: '7'
		,enableKaart: '1'
	});

}

function getFlashMovieObject(movieName) {
    if (window.document[movieName]) {
        return window.document[movieName];
    }
    if (navigator.appName.indexOf("Microsoft Internet") == -1) {
        //if (document.embeds && document.embeds[movieName]) return document.embeds[movieName];
        return document.getElementById(movieName).getElementsByTagName("object")[0];
    }
    else {
        //return document.getElementById(movieName);
        return document.getElementById(movieName).getElementsByTagName("object")[0];
    }
}
function SendDataToHomepageFlash(directlinkid) { getFlashMovieObject("flash_projecten").sendToActionScript(directlinkid);}

function closeGallery()
{
	//Functie die wordt aangeroepen in gallery.swf wanneer op het overzichtsicoontje wordt gedrukt.
	$('#flash_projecten').hide();
	$('#content').show();
	//$('#content').css('width','960px').css('height','423px');
}

function initProjectContentPaging() {

    var intContainerHeight = $('#project_text .paragraph').height();
    var intTextHeight = $('#project_text .paragraph .text').height();
    var intAantalPages = Math.floor(intTextHeight / intContainerHeight);
    var i;
    var dummy = 'intContainerHeight: ' + intContainerHeight + '\nintTextHeight: ' + intTextHeight + '\nintAantalPages: ' + intAantalPages;
	
	if (intAantalPages > 1) 
	{
		$('#project_text #pages').prepend('<ul></ul>');
		for (i = 0; i < intAantalPages; i++) {
		    var strActiveClass = '';
		    if (i == 0) strActiveClass = 'active';
		    $('#pages ul').append('<li><a href="#" class="' + strActiveClass + '" rel=' + i + '>' + (i + 1) + '</a>');
		}
	}

    if (i > 1) {
        $('#pages li a').each(
            function() {
                $(this).bind(
                    'click',
                    function() {
                        $('#pages a').removeClass('active');
                        $(this).addClass('active');
                        var intCurrentPage = $(this).attr('rel');
                        var intMarginTop = intCurrentPage * intContainerHeight + (2 * intCurrentPage)
                        $('#project_text .paragraph .text').animate({ marginTop: '-' + intMarginTop + 'px' }, { duration: 1000, easing: 'easeOutExpo' });
                        return false;
                    }
                );
            }
        );
    }
}

function initContentPaging() {
    var intContainerHeight = $('#content .paging_content_wrapper').height();
    var intTextHeight = $('#content .paging_content').height();
    var intAantalPages = Math.ceil(intTextHeight / intContainerHeight);
    var i;
    var dummy = 'intContainerHeight: ' + intContainerHeight + '\nintTextHeight: ' + intTextHeight + '\nintAantalPages: ' + intAantalPages;
    //alert(dummy); 
    //$('#frm_zoekwoord').val(dummy);
	
	
	if (intAantalPages > 1) 
	{
		$('#pages').prepend('<ul>');
		for (i = 0; i < intAantalPages; i++) {
		    var strActiveClass = '';
		    if (i == 0) strActiveClass = 'active';
		    $('#pages ul').append('<li><a href="#" class="' + strActiveClass + '" rel=' + i + '>' + (i + 1) + '</a>');
		}
	}
    
    if (i > 1) {
        $('#pages li a').each(
            function() {
                $(this).bind(
                    'click',
                    function() {
						$('#pages a').removeClass('active');
						$(this).addClass('active');
                        var intCurrentPage = $(this).attr('rel');
                        var intMarginTop = intCurrentPage * intContainerHeight + ( 2 * intCurrentPage )
                        //alert(intMarginTop);
                        $('#content .contentinner .paging_content').animate({ marginTop: '-' + intMarginTop + 'px' }, {duration: 1000, easing: 'easeOutExpo'});
                        return false;
                    }
                );
            }
        );
    }
}

function initHoofdmenu()
{
	
	$('#hoofdmenu .level2 img').error(function(){
		$(this).parent().find('span').show();
		$(this).parent().css('padding','8px');
		$(this).remove();
	});
	$('#hoofdmenu li.level1').hover(function(){
		$(this).addClass('level1hover');
		$(this).addClass('sfHover');
	}, function(){
		$(this).removeClass('level1hover');
		$(this).removeClass('sfHover');
	});
	
	$('#projectenmenu li').hover(function(){
		$(this).addClass('sfHover');
	}, function(){
		 $(this).removeClass('sfHover');
    });
}

function productOverviewExpose()
{
	$(".projectOverview .projectItem").hover(function() { 
        $(this).expose({color:"#000"});         
    }, function(){ 
		$.expose.close(); 
	});
}

function initNyroModalPopups()
{
	$.fn.nyroModal.settings.regexImg = '[^\.]\.(jpg|jpeg|png|tiff|gif|bmp)\s*$|image.aspx';
	$("#project_sidepanel a[href*='image.aspx']").nyroModal();
	$(".paragraph a[href*='flash.aspx']").nyroModal();
	$(".paragraph a[href*='.jpg']").nyroModal();
	$(".paragraph a[href*='.jpeg']").nyroModal();
	$(".paragraph a[href*='.gif']").nyroModal();
	$(".paragraph a[href*='.png']").nyroModal();
	$(".paragraph a[href*='.tiff']").nyroModal();
	$(".paragraph a[href*='.bmp']").nyroModal();
	$("a[href*='fid=']").click(function(){ 
		var PhotoBookURL = $(this).attr('href') + '#nyro';
		PhotoBookURL = PhotoBookURL.replace(/default\.aspx/,'zoeken.aspx');
		$.nyroModalManual({ 
			url: PhotoBookURL
			, height: '531'
			, width: '770'
		}); 
		return false; 
	});
	$("a[href*='flv.aspx']").click(function() { $.nyroModalManual({ url: $(this).attr('href') + '#nyro', height: '560', width: '674' }); return false; });

	$("a[href*='showmedia.aspx']").click(function() {
	    $.nyroModalManual({
	        url: $(this).attr('href') + '#nyro',
	        endFillContent: function() {
    	        $('#flash_mute').css('visibility', 'hidden');
	            getFlashMovieObject("flash_mute").turnOff();
	        }
	    });
	    return false;
	});
	
	$.fn.nyroModal.settings.showBackground = function(elts, settings, callback) {
		elts.bg.css({opacity:0,background:'#668da4'}).fadeTo(500, 0.65, callback);
	}
	//$.fn.nyroModal.settings.closeButton = '';
	$.fn.nyroModal.settings.addImageDivTitle = false;

	$.fn.nyroModal.settings.endFillContent = function() {
	    $('#flash_mute').css('visibility', 'hidden');
	}

	$.fn.nyroModal.settings.endRemove = function() {
	    $('#flash_mute').css('visibility', 'visible');
	   // alert($.cookie('cookieFlashSound'));
	    if (!($.cookie('cookieFlashSound') == 'off') ) {
	        //alert("modal is gone! and sound will be turned on");	    
	        getFlashMovieObject("flash_mute").turnOn();	    
	    }	    
	}
}

function FlashNyroModal(strURL, strOmschrijving) {
    if (strURL.indexOf('showmedia') > -1) {
        //alert('roep turnon aan');
        getFlashMovieObject("flash_mute").turnOff();
        $('#flash_mute').css('visibility', 'hidden');
    }
    $.nyroModalManual({ url: strURL, addImageDivTitle: true, manualTitle: strOmschrijving }); 
}
function FlashNyroModalRealpages(strURL) { $.nyroModalManual({ url: strURL, height: '502', width: '650', padding: 0 }); }

function initMediaScrolling()
{
	/* scrollfunctie voor mediaoverzicht in html versie */
	$("body.media div.scrollable").scrollable({ size: 3 });
	if ($('div.scrollable .items .item').length <= 3 ) $('a.next').hide();
	
	/* scrollfunctie voor mediaoverzicht van projecten in html versie */
	$("#project_sidepanel .scrollable").scrollable({ size: 2 });
	
}

function initContactFormValidation() {

    var strRequiredMessage;
    var strValidEmailMessage;

    switch(language)
    {
        case 'nl':
            strRequiredMessage = 'verplicht';
            strValidEmailMessage = 'geen geldig e-mail adres';
            break;
        case 'fr':
            strRequiredMessage = 'obligatoire';
            strValidEmailMessage = 'pas une adresse email valide';
            break
    }
    
    strRequiredMessage = '';
    strValidEmailMessage = '';

    $('form.contact').validate({
        rules: {
            geslacht: { required: true },
            naam: { required: true },
            emailadres: { required: true, email: true },
            telefoon: { required: true },
            opmerking: { required: true }
        },
        messages: {
            geslacht: { required: strRequiredMessage },
            naam: { required: strRequiredMessage },
            emailadres: { required: strRequiredMessage, email: strValidEmailMessage },
            telefoon: { required: strRequiredMessage },
            opmerking: { required: strRequiredMessage }
        }
    });
}

function initFlashSoundCookie() {

    if (!($.cookie('cookieFlashSound') == 'off')) {
        //alert('cookie wordt op "on" gezet');
        $.cookie('cookieFlashSound', 'on', { path: '/', expires: 1 });
    }
}

function FlashSetSoundCookie(mode) {
    //alert('flash zet nu de cookie op ' + mode + ' gezet');
    $.cookie('cookieFlashSound', mode, { path: '/', expires: 1 });
}

$(document).ready(function() {

    blnIE6 = (jQuery.browser.msie) && (jQuery.browser.version == 6);
    //Initialiseer hier je scripts
    initFlashSoundCookie();
    initFlash();
    initPopups();
    initProjectContentPaging();
    initContentPaging();
    initHoofdmenu();
    //productOverviewExpose(); werkt niet goed in IE7
    initNyroModalPopups();
    initMediaScrolling();
    initContactFormValidation();
    initHyperlinks();
    

    //$('.wrappercontainer').prepend('<a href="#" onclick="closeGallery();return false;" style="position: absolute; top: 0; left: 0; height: 10px; width: 10px; text-indent: -9999px; background: #fff;">zet flash uit</a>');

});
