var Website = {

    init: function(){    
        
        // jsEnabled class for body
        $(document.body).addClass('jsEnabled');
        
        // External links
        $$('a[rel="external"]').addEvent('click', function(){ 
			$$('a[rel="external"]').setProperties({ target: '_blank' }); 
		});
		
		// Form check fields
		var aCheckFields = $$('.swisCheckField');
		var iCheckFields = aCheckFields.length;
		while (iCheckFields--) {
		    if (aCheckFields[iCheckFields].value == '') {
		        aCheckFields[iCheckFields].value = 'swis_check_ok';
		    }
		}
		
		// Videos
		var aVideos = $$('.ytVideoContainer');
		var iVideos = aVideos.length;
		while (iVideos--) {
			new Video(aVideos[iVideos]);
		}
		
		// Form errors
		var aErrors = $$('ul.errors');
		var i = aErrors.length;
		while (i--) {
			aErrors[i].getParent('div').addClass('errorContainer');
		}
	
    }
    
};

/**
* init
**/
window.addEvent('domready', function(){
	Website.init();
});



var Video = new Class({
    
    initialize:         function (elVideoContainer) {
							
							this._elVideoContainer = elVideoContainer;
							
							if(elVideoContainer.hasClass('sideVideo')) {
								this._iWidth = 246;
							} else {
								this._iWidth = 440;
							}
							
							
							this._sUrl = this._elVideoContainer.getElement('a').getProperty('href');
							
							if(this._sUrl.indexOf('youtube') > -1) {
								this.embedYouTube();
							}
							if(this._sUrl.indexOf('vimeo') > -1) {
								this.embedVimeo();
							}
						    
                        },
    
    embedYouTube:		function() {
							
							
							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';
							
							this._iHeight = this._iWidth * 0.755;
							this._iHeight = Math.ceil(this._iHeight);
							
							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, ' ');

							this._elVideoContainer.innerHTML = '<span>' + sCode + '</span>';
		
    					},
    					
    embedVimeo:			function() {
							
							
							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';
							
							this._iHeight = this._iWidth * 0.755;
							this._iHeight = Math.ceil(this._iHeight);
							
							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, ' ');

							
							this._elVideoContainer.setStyle('height', this._iHeight);
							this._elVideoContainer.innerHTML = '<span>' + sCode + '</span>';
		
    					}
    					
    
});