$(document).ready(function() {

    // Alle links met rel="external" in een nieuw venster openen
    $("a[rel=external]").each(function(i){
        this.target="_blank";
    });

    //Pngfix alle divjes die de class "png" hebben
    $(".png").pngFix();

    //Font replacement
    Cufon.replace('.cufon');
    Cufon.replace('#rightCol h2:not(.nocufon)');
    Cufon.replace('#rightCol h3:not(.nocufon)');
    
    // Stretch footer
    stretchFooter();
    $(window).resize(stretchFooter);
    
    // Videos laden
    var aVideos = $('#fotoalbums-video .video');
    var iVideos = aVideos.length;
    while (iVideos--) {
        new Video(aVideos[iVideos]);
    }                                              
    
    //maak zoekformulier
    makeSearchform();
        
});


/*
 * Video class
 * Bepaal wat voor video (vimeo/youtube) er is geinclude
 * Laad het filmpje op de pagina.
 */
var Video = $.Class.create({
    
    initialize:         function (elVideoContainer) {
                            
                            //haal container en url op
                            this._elVideoContainer = elVideoContainer;
                            this._sUrl = $(this._elVideoContainer).find('a').attr('href');
                                                      
                            //is dit een youtube video
                            if(this._sUrl.indexOf('youtube') > -1) {
                                this.embedYouTube();
                            }
                            //is dit een vimeo video
                            if(this._sUrl.indexOf('vimeo') > -1) {
                                this.embedVimeo();
                            }
                            
                        },
    
    embedYouTube:        function() {
                            
                            //maak url
                            this._sUrl = this._sUrl.replace('/watch?v=', '/v/');
                            this._sUrl = this._sUrl.replace('nl.youtube.com', 'www.youtube.com');
                            this._sUrl += '&hl=nl&fs=1&rel=0';
                            
                            //stel hoogte en breedte in
                            this._iWidth = 480;
                            this._iHeight = 385;
                            
                            //maak code die video moet tonen
                            sCode = '<object width="'+ this._iWidth +'" height="'+ this._iHeight +'"><param name="movie" value="'+ this._sUrl +'"></param><param name="wmode" value="transparent"></param><param name="allowFullScreen" value="true"></param><embed src="'+ this._sUrl +'" type="application/x-shockwave-flash" allowfullscreen="true" wmode="transparent" width="'+ this._iWidth +'" height="'+ this._iHeight +'"></embed></object>';
                            sCode = unescape(sCode).replace(/\+/g, ' ');

                            //vervang content door video
                            this._elVideoContainer.innerHTML = '<span>' + sCode + '</span>';
        
                        },
                        
    embedVimeo:            function() {
                            
                            //maak url
                            this._sUrl = this._sUrl.replace('vimeo.com/', 'vimeo.com/moogaloop.swf?clip_id=');
                            this._sUrl += '&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1';
                            
                            //stel hoogte en breedte in
                            this._iWidth = 480;
                            this._iHeight = 385;
                            
                            //maak code die video moet tonen
                            sCode = '<object width="'+ this._iWidth +'" height="'+ this._iHeight +'"><param name="allowfullscreen" value="true"></param><param name="allowscriptaccess" value="always"></param><param name="movie" value="'+ this._sUrl +'"></param><embed src="'+ this._sUrl +'" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="'+ this._iWidth +'" height="'+ this._iHeight +'"></embed></object>';
                            sCode = unescape(sCode).replace(/\+/g, ' ');
                                                              
                            //vervang content door video          
                            $(this._elVideoContainer).css('height', this._iHeight);     
                            this._elVideoContainer.innerHTML = '<span>' + sCode + '</span>';
        
                        }
                        
});


function makeSearchform() {

    //maak veld leeg als focus
    $("#searchForm input.text").focus( function() {
        if (($("#searchForm input.text").val() == 'Zoeken...')) {         
            $("#searchForm input.text").val('');
        }
    });
    
    //zet zoeken... terug als blur en leeg
    $("#searchForm input.text").blur( function() {
        if ($("#searchForm input.text").val() == '') {   
            $("#searchForm input.text").val('Zoeken...');
        }
    });
    
    //check invoer onsubmit
    $("#searchForm").submit( function() {
        if ($("#searchForm input.text").val() == '') {
            return false;
        } else {
            return true;    
        }
    });

}

function stretchFooter() {
    
    var docHeight = $(document).height();
    var elHeight = $("#fullContainer").height();         
    
    //zet nieuwe height van footer
    $("#footer").css('height', docHeight-elHeight+'px'); 
        
}
