
/*
 Project 	: Prins Bernard Cultuurfonds: Jaaroverzicht 2010 
 Start   	: 16 Mei 2011
 Author	 	: D. de Zeeuw - TamTam.nl


      _______________
____/ jQuery Scripts \___________________________________
*/

Cufon.replace('h1, #nav > h2, .popUP >h2, .popUP >h3, .section >h2, .infoBlock >h2, .cols > div >h2 , .section > h3, .infoBlock > h3, .cols > div > h3');
Cufon.replace('.cufon, #metaNav li>a, #mainNav li a', { hover: true });

$(document).ready(function () {

    $('#nav').localScroll();

    //check external links and open them in new window
    $("a[href^='http']").click(function () { window.open(this.href); return false; });

    $('.external').click(function () { window.open(this.href); return false; }); 

    /* Navigation items*/
    $('#mainNav li > a.active:first').after('<div class="arrow"></div>');
    

    /*Meta menu expand block*/
    $.each($('#metaNav li'), function () {
        //hide block
        $(this).find('.extra').hide();
        // hover function
        $(this).hover(function () {
            $(this).find('a').addClass('hover');
            $(this).find('.extra').fadeIn(500);
        }, function () {
            $(this).parent().find('a').removeClass('hover');
            $(this).find('.extra').fadeOut(500, function () {
            });
        });

        //click function (does the same for tablets)
        $(this).find('#metaNav a').click(function (e) {
            if ($(this).parent().find('.extra').is('*')) {
                $(this).parent().find('.extra').slideToggle(500);
                e.preventDefault();
            }
        });
    });

    /* Contentpage dropdown menu */
    $('.dropdown').find('ul').hide();
    $('.dropdown > a').toggle(function () {
        $(this).parent().find('ul').slideDown(500);
        $(this).parent().addClass('activedropdown');
    }, function () {
        $(this).parent().find('ul').slideUp(500, function () {
            $(this).parent().removeClass('activedropdown');
        });
    });

    $(".section:odd").addClass('header_0');
    $('#intro, #header').removeClass('header_0')

    /* Terug naar boven */
    $.each($('.section'), function () {
        if ($(this).attr('id') != 'header' && $(this).attr('id') != 'intro') {
            $(this).append('<div class="back_container"><a href="#header" class="backtotop"> Terug naar boven </a></div>');
        }
    });

 
    /*set up close button with LIVE functionality*/
    $('.close').live('click', function () {
        $(this).parent().fadeOut(500, function () {
            $('.overlay').fadeOut(300, function () { $(this).remove() });
            if ($(this).hasClass('popUP')) $(this).remove();
        });
    });

    /*search and active popup links*/
    $('.popUP_link, .infographic .more_info').live('click', function (e) {
        popUP($(this));
        e.preventDefault();
    });
})

//lightbox like functionality
function popUP(element){
	
    /*create var for element*/
	var P = '.'+ $(element).attr('rel');
    
	/*build up container*/
	var HTML = $(P).html();

	$('#scrollContainer').prepend('<div class="overlay hidden">&nbsp;</div>');
	$('#scrollContainer').prepend(' <div class="popUP hidden"> <div class="close">close</div> <div class="content">' + HTML + '</div> </div>');
    
    
	/* fade in menu*/
	$('.overlay').fadeIn(300,function(){
	    $('.popUP').fadeIn(500);
        Cufon.replace('.popUP h2, .popUP h3')
		Cufon.now();
	});


}


