var Global = {

	init: function(){
        	this.initModalWindows();
        	this.initFonts();
        	this.initNav();
        if( $('#content table').length != 0 ) {
            $("#content table tr:nth-child(odd)").addClass("odd");
        }
        
        var visheight = 0;
        
        if($("#visual").length > 0){
        	visheight = $("#visual").height();
        }
        
        $(".vervolg #maincontent").height($("#content").height()-visheight-45);
    },
    
    initFonts:function(){
        //exception   
        //Cufon.replace('#nav li a, #visual .title, .related_title, .title', { hover: true,textShadow: '#f8f8f8 1px 1px ' });
    },
    
    initModalWindows: function(){
        var thumbnails = 'a:has(img)[href$=".bmp"],a:has(img)[href$=".gif"],a:has(img)[href$=".jpg"],a:has(img)[href$=".jpeg"],a:has(img)[href$=".png"],a:has(img)[href$=".BMP"],a:has(img)[href$=".GIF"],a:has(img)[href$=".JPG"],a:has(img)[href$=".JPEG"],a:has(img)[href$=".PNG"]';	
		if( thumbnails.length != 0 ) { 
            $(thumbnails).addClass("modalbox").attr("rel","modalbox");
            $("a.modalbox, a.size-thumbnail").colorbox({transition:"fade", maxWidth:"95%", maxHeight:"95%", slideshowAuto:false, slideshow:true });
        }
    },
    
    initNewWindowLinks: function(){
        $(function(){
            $('a.twitter-link').click(function(){
                window.open(this.href);
                return false;
            });
        });
        
    },
    
    initNav: function(){
    
    	if($("#maincontent").height() < $("#subnav").height()){
		$("#maincontent").height($("#subnav").height());
	}
	
        var trigger= $('#subnav > ul > li');
		
		if(trigger.length!=0){
		
			$(trigger).each(
				function(i){
					if(!$(this).hasClass('active') && !$(this).hasClass('parent_active')){
						$("ul",this).css("display","block");
						$("ul",this).addClass("eventsListing");
					}else {
						$("ul",this).css("display","block");
					}
					/*$(this).mouseover(function(){
						if(!$(this).hasClass('active') && !$(this).hasClass('parent_active')  && $(this).hasClass('parent')){
						var next=$(this).children('ul');
							next.css('height','');
							next.stop(true,false).slideDown('fast');
							$(this).addClass("down");
						}
					}).mouseleave(function(){
						if(!$(this).hasClass('active') && !$(this).hasClass('parent_active')  && $(this).hasClass('parent')){
							$(this).find('ul').stop(true,false).delay(20).slideUp('fast',function(){$(this).removeAttr("style");$(this).css("display","block");$(this).parent().removeClass("down");});
							
						}
					});*/
					
				}
			);
		}
		
		
		$('li').has('ul').addClass("parent");
		
		
		
        
    },
    
    initSliders: function(){
        
        var i_animSpeed = 300;
        var i_pauseTime = 3000;
        
        if($('body.home').length != 0){
            $('#slider').nivoSlider({
                effect:'fade', //Specify sets like: 'fold,fade,sliceDown'
                animSpeed:i_animSpeed, //Slide transition speed
                pauseTime:i_pauseTime,
                directionNav:false, //Next &amp; Prev
                directionNavHide:false, //Only show on hover
                controlNav:false, //1,2,3...
                controlNavThumbs:false, //Use thumbnails for Control Nav
                controlNavThumbsFromRel:false //Use image rel for thumbs

            });
        } 
        else if($('body.vervolg').length != 0){
            $('#slider').nivoSlider({
                controlNavThumbs:true,
                controlNavThumbsFromRel:true,
                directionNav:false,
                animSpeed:i_animSpeed,
                pauseTime:i_pauseTime,
                effect:'fade'
            });
        }
        
        // custom script: slide controller for thumbnails >> E.Mahieu
        var originalTop = $('.nivo-controlNav').css('top');
        $('.nivo-controlNav a').live('click', function(e){
        	
            var i = 0;
            var i_thumbAnimSpeed = 800;
            var topPos;
            var margin = 5;
            var holderHeight = ($('.nivo-controlNav').parent().css('height').replace("px","")*1);
            var picHeight = ($('.nivo-controlNav').css('height').replace("px","")*1);

            if($('.nivo-controlNav').css('height') == "auto") {
                var picHeight = document.getElementById('nivcnt').offsetHeight*1+margin;
            }
            var maxScroll = (holderHeight-picHeight)-margin;
            $('.nivo-controlNav a').each(function(el) {
                if(i == 1) {
                    firstPos = $(this).position().top;
                }
                if(i == 2) {
                    topPos = $(this).position().top;
                }
                lastPos = $(this).position().top;
                i++;
            });
            var elPos = $(e.target).parent().position().top;
            var newTopPos = firstPos-elPos;
            var goTop;
            if(newTopPos < 0) {
                if(newTopPos > maxScroll) {
                    goTop = (topPos-elPos);
                } else {
                    goTop = maxScroll;
                }
            } else {
                goTop = originalTop;
            }
            if(goTop) {
                $('.vervolg .nivo-controlNav').animate({
                    top: goTop
                }, i_thumbAnimSpeed, function() { });
            }

        });
        // END custom  >> E.Mahieu

    }
}; //end of global

$(document).ready(function() { 
    Global.init();
});

//to window ready stuff on the window load (images etc.), ok its dirty, maybe an own Global?
$(window).load(function() {
    if( $('#slider').length != 0 ){ 
        Global.initSliders();
    }            
});
