Cufon.replace("#nav > li > a, h2, h5", {hover: {color: "#59b9e8"}});

var slideInterval;
function slide(el) {

	li = el.find(".nav > li.active").removeClass("active").next();
	if(!li.size())
		li = el.find(".nav > li:first")
	li.addClass("active");
	
	el.find("ul:first").animate({top: li.parent().find("> li").index(li) * -199 + "px"}, 600);

}

function quickEffect() {
	
	$("#quick li").each(function() {
	
		$("img:first", this).fadeIn(400);
		$("img:first", this).fadeOut(400);
	
	});

};

$(function() {
	
	$("#quick img").hover(function() {
	
		$(this).attr("src", $(this).attr("src").replace(".png", "_effect.png"));
	
	}, function() {
	
		$(this).attr("src", $(this).attr("src").replace("_effect.png", ".png").replace("_effect.png", ".png").replace("_effect.png", ".png").replace("_effect.png", ".png").replace("_effect.png", ".png"));
	
	}).each(function() {
		
		$(this).before('<img src="' + $(this).attr("src").replace("_effect.png", ".png").replace("_effect.png", ".png").replace(".png", "_effect.png") + '" alt="" style="position: absolute; top: 0; left: 1px;" />').prev().hide();
		
	});
	
	setInterval(quickEffect, 10000);
	
	$("li").hover(function() {
		$(this).addClass("hover");
	}, function() {
		$(this).removeClass("hover");
	});
	
	$("#visual").each(function() {
		
		$("> ul", this).addClass("items");
		$(this).append('<ul class="nav"></ul>');
		
		visualSize = $("#visual > ul > li").size();
		for(i = 0; i < visualSize; i++) {
			$("> .nav", this).append('<li><a href="#" title="Naar ' + (i+1) + '">' + (i+1) + '</a></li>');
		}
		$("> .nav > li:first", this).addClass("active");
		
		$("> .nav > li > a", this).click(function() {
			
			clearInterval(slideInterval);
			el = $("#visual");
			slideInterval = setInterval("slide(el);", 8000);
			
			$(this).parent().parent().find("> li").removeClass("active");
			$(this).parent().addClass("active");
			$(this).parent().parent().prev().animate({top: $(this).parent().parent().find("> li > a").index(this) * -199 + "px"}, 600);
			return false;
		});
		
		el = $(this);
		slideInterval = setInterval("slide(el);", 8000);

	});
	
	$(".dynamic").each(function() {
	
		$(this).next().find("> li").hide().fadeOut(0);
		$(this).next().find("> li:eq(" + $("> li", this).index($("> li.active", this)) + ")").fadeIn(0);
		
		$("a", this).click(function() {

			if($(this).parent().attr("class") != "active hover") {
			
				$(this).parent().parent().next().css("height", $(this).parent().parent().next().height() + "px");
				
				$(this).parent().parent().find("> li").removeClass("active");
				$(this).parent().addClass("active");
				
				$(this).parent().parent().next().find("> li:visible").hide();
				$(this).parent().parent().next().find("> li:eq(" +  $(this).parent().parent().find("> li").index($(this).parent()) + ")").fadeIn(500);
			
				$(this).parent().parent().next().css("height", "auto");
			
			}
			
			return false;
			
		});
	
	});
    
	$(".dynamic2").each(function() {
	
		$(this).next().find("> li").hide().fadeOut(0);
		$(this).next().find("> li:eq(" + $("> li", this).index($("> li.active", this)) + ")").fadeIn(0);
		
		$("a", this).click(function() {

			if($(this).parent().attr("class") != "active hover") {
			
				$(this).parent().parent().next().css("height", $(this).parent().parent().next().height() + "px");
				
				$(this).parent().parent().find("> li").removeClass("active");
				$(this).parent().addClass("active");
				
				$(this).parent().parent().next().find("> li:visible").hide();
				var theLi = $(this).parent().parent().next().find("> li:eq(" +  $(this).parent().parent().find("> li").index($(this).parent()) + ")");
                if(theLi.hasClass('empty')){
                    theLi.removeClass('empty');
                    var day = theLi.html();
                    theLi.html('Loading....');

                    $.get('/radiogids/ajax/'+day, function(data) {
                      theLi.html(data);
                    });
                }
                
                theLi.fadeIn(500);
			
				$(this).parent().parent().next().css("height", "auto");
			
			}
			
			return false;
			
		});
	
	});
	
});

var dropmenuTick = false;
var dropmenuTicker = 0;

$(document).ready(function(){
    $('#dropmenu_back').click(function(){
        $(this).css('display', 'none');
    });
    $('#dropmenu_container').click(function(e){
        e.stopPropagation();
    });
    
    $('#dropmenu_container').mouseover(function(e){
        $('#debug').html('over');
        dropmenuTick = false;
    });
    
    $('#dropmenu_container').mouseout(function(e){
        $('#debug').html('out');
        dropmenuTicker = 100;
        //dropmenuTick = true;
    });
    setInterval(function(){
        if(dropmenuTick && dropmenuTicker>0){
            dropmenuTicker--;
            if(dropmenuTicker==0){
                $('#dropmenu_back').css('display', 'none');
            }
        }
    }, 10);
    $('#dropmenu_container a').click(function(){
        $('#dropmenu_back').css('display', 'none');
    });
})

function showMenu(ele, page, width){
    var debug = '';
    var btn = $(ele);
    var back = $('#dropmenu_back');
    var container = $('#dropmenu_container');
    
    back.css('display', 'block');
    
    var screen = {width: back.width(), height: back.height()};
    
    var pos = btn.offset();
    pos.top+= btn.height();
    
    debug+= 'left: '+pos.left+'px<br />';
    debug+= 'top: '+pos.top+'px<br />';
    
    container.css('left', pos.left);
    container.css('top', pos.top);
    container.css('width', width);
    
    debug+= 'length: ' + $('#dropmenu_container > *').length + '<br />';
    $('#dropmenu_container > *').css('display', 'none');
    
    
    debug+= 'pageid: ' + page + '<br />';
    $('#' + page).css('display', 'block');

}
function nieuws_icon(){
    $('.nieuws_icon').each(function(){
        if(!$(this).hasClass('hover_installed')){

            $(this).hover(function(){
                /*$(this).stop().animate({
                    opacity: 1
                }, 300);*/
                $(this).stop().fadeTo('300', 1, function(){
                    //$(this).addClass('nontransparant');
                    //$(this).css('opacity', '');
                    //$(this).css('filter', '');
                    $(this).html($(this).html());
                });
        
            }, function(){
                /*$(this).stop().animate({
                    opacity: 0.5
                }, 300);*/
                $(this).stop().fadeTo('300', 0.5, function(){
                    //$(this).removeClass('nontransparant');
                    //$(this).css('opacity', '');
                    //$(this).css('filter', '');
                    $(this).html($(this).html());
                });
            });
        }
    });
}

$(document).ready(function(){
    nieuws_icon();
    /*
    $('.nieuws_icon').css('opacity', 0.5);
    $('.nieuws_icon').addClass('hover_installed');
    $('.nieuws_icon').hover(function(){
        $(this).stop().animate({
            opacity: 1
        }, 300);

    }, function(){
        $(this).stop().animate({
            opacity: 0.5
        }, 300);
    });*/
});





