$(document).ready(
	function()
	{
		if ($.browser.version.charAt(0) < 7 && $.browser.msie){$("#mainnav li, #subnav li").hover(function(){$(this).addClass('hover');},function(){$(this).removeClass('hover');});}
		//doFlash();
        
        //Roteer header sponsoren
        doHeaderSponsors(-1);
        
        //Wisselen van nieuwsberichten
        headLineTogle();
		
		//Twitter
        doTwitter();
        
        //Roteer footer sponsoren
        doFooterSponsors();
        
        //Countdown in footer
        countdown();
        
        //Flogs popup;
        doFlogsModal();
        
        //Fotoalbum
        //Start Gallery modal
        $('.gallery-thumbs-img').lightBox();
    }
);


function doTwitter()
{
	getTwitters('twitter', { 
  	id: 'yelmercom', 
  	count: 2, 
  	enableLinks: true, 
  	ignoreReplies: false, 
  	clearContents: true,
  	template: '<a href="http://twitter.com/%user_screen_name%"><img class="twitter-image" src="%user_profile_image_url%"/></a><span class="twitter-text">%text%</span><span class="twitter-links"><a class="twitter-time" href="http://twitter.com/%user_screen_name%/status/%id_str%/" target="_blank">%time%</a> <a class="twitter-reply" href="http://twitter.com/?status=@%user_screen_name%%20&in_reply_to_status_id=%id_str%&in_reply_to=%user_screen_name%/" target="_blank">reply</a></span>'
	});
}


function countdown()
{
    var tmplRaceDate = $('#race-date').html().split(',');
    raceDate = new Date(tmplRaceDate[0],tmplRaceDate[1],tmplRaceDate[2], tmplRaceDate[3], tmplRaceDate[4]);
    parseInt(tmplRaceDate[0])
    raceDate = new Date(parseInt(tmplRaceDate[0]),parseInt(tmplRaceDate[1]),parseInt(tmplRaceDate[2]),parseInt(tmplRaceDate[3]),parseInt(tmplRaceDate[4]));
    
    
    $('p.countdown-content span.days').countdown(
        {until: raceDate,
        layout: '{d10}{d1}'
        });
    
    $('p.countdown-content span.hours').countdown(
        {until: raceDate,
        layout: '{h10}{h1}'
        });
    
    $('p.countdown-content span.minutes').countdown(
        {until: raceDate,
        layout: '{m10}{m1}'
        });
}

function headLineTogle()
{
    $('#showHeadlines a').click(function(event){
        event.preventDefault();
        $('#home-archief').fadeOut(300, function(){
            $('#home-headlines').fadeIn(300);    
        });
        
        $('#showArchive').removeClass('active');
        $('#showHeadlines').addClass('active');
    });
    
    $('#showArchive a').click(function(event){
        event.preventDefault();
        $('#home-headlines').fadeOut(300, function(){
            $('#home-archief').fadeIn(300);    
        });
        
        $('#showHeadlines').removeClass('active');
        $('#showArchive').addClass('active');
    });
}


/* Sponsoren
 ***********************************/
function doHeaderSponsors(current)
{
   
    next = current +1;
    if(next >= $('ul#header-logos li').size())
    {
        next = 0;
    }
   
   if(current == -1)
    {
        $('ul#header-logos li:eq('+next+') > a img').fadeIn(750);
    }else{
        selector = 'ul#header-logos li:eq('+current+') > a img';
        $(selector).fadeOut(750, function(){
            $('ul#header-logos li:eq('+next+') > a img').fadeIn(750);
        });    
    }
    
    //herstarten
    headerSponsor = setTimeout("doHeaderSponsors(" + next + ")", 5000);
}

function doFooterSponsors()
{
    var selector        = "ul#footer-logos";
    
    $(selector).animate({
		left: "-135px"
	},
	3000,'linear',
	function()
	{
        $(selector + " li:first").appendTo(selector);
    	$(selector).css("left", "0px");
        doFooterSponsors();
	});	
}

/* Flogs modal met agenda
 **********************/
function doFlogsModal()
{
    var iDocWidth   = $(document).width();
    var iDocHeight  = $(document).height();
    var iFlogsLeft  = (iDocHeight / 2) - 321;
    
    $("#header-flogs-icons a").click(function(e){
        e.preventDefault();
        
        //Posities instellen.
        $("#modal-bg").css("width",iDocWidth).css("height",iDocHeight);
        $("#flogs-modal").css("left", iFlogsLeft);
        centerModal();
        $("#modal-bg").fadeIn(750);
        $("#flogs-modal").fadeIn(750);
    });
    
    $("#flogs-modal-close a").click(function(e){
        e.preventDefault();
        
        $("#modal-bg").fadeOut(750);
        $("#flogs-modal").fadeOut(750);

    });
    
}

function centerModal()
{        
    var topPos = $("#flogs-modal").offset().top;
    topPos += 20;
    $("#flogs-modal").css("top", topPos);
    $("#flogs-modal").css("position", "absolute");    
}
