/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


/*Open read more **/
$(document).ready(function(){   
	$('.readon').click(function(){
       
		var prev = $(this).prev();
		if (prev.hasClass('about_box'))
		{
			prev.removeClass('about_box');
			prev.addClass('about_text_read');
			// replace text innerhtml
			$(this).html('Sluiten');
			return false;
		}
		if (prev.hasClass('about_text_read'))
		{
			prev.removeClass('about_text_read');
			prev.addClass('about_box');
			// replace text innerhtml
			$(this).html('Lees meer ');
			return false;
		}
	});

	$('.nutrion_link').click(function(){

		var prev = $(this).prev();
		if (prev.hasClass('nutrion_text'))
		{
            prev.removeClass('nutrion_text');
			prev.addClass('nutrion_text_open');
            // replace text innerhtml
			$(this).html('Sluiten');
            return false;
		}
		if (prev.hasClass('nutrion_text_open'))
		{
			prev.removeClass('nutrion_text_open');
			prev.addClass('nutrion_text');
            			// replace text innerhtml
			$(this).html('Lees meer');
			return false;
		}
	});
    
    if ($('div.nutrion').is(':visible')) {

        var url     = document.location.toString();
        var anchor  = url.indexOf('#');
        if (anchor > 0) {
            // Get anchor
            var key = url.substr(anchor + 1);
            // Shows the selected article
            $('a[name='+key+']').parent().siblings('.nutrion_link').click();
        }

    }

    // Read More (Over Changing Diabetes >> Projecten)
    if ($('div.content_project').is(':visible')) {
        
        $('div.project_bg a.readon').click(function (){

            var show = true;
            if ($(this).parent().siblings('div.project_text_long').is(':visible')) {
                show = false;
            }

            // Shows only the summaries
            $('div.project_text_long').hide();
            $('div.project_bg a.readon').html('Lees meer');

            if (show) {
                // Shows the full project
                $(this).parent().siblings('div.project_text_long').show();
                $(this).html('Sluiten');
            }

            return false;
        });

        var bbar = $('div.project_bg:first');
        if (bbar.find('a.readon').is(':visible')) {
            bbar.find('a.readon').click();
        }

        var url     = document.location.toString();
        var anchor  = url.indexOf('#');
        if (anchor > 0) {
            // Shows the selected article
            var key = url.substr(anchor + 1);
            $('div.content_project a[name='+key+']').parent().find('a.readon').click();
        }
    }

    //Examples of how to assign the ColorBox event to elements
    $("a.young_link").bind("click", function() {
        $("embed").attr('src', $(this).attr('href'));
    });
    $(".young_link").colorbox({width:"500px",height:"300px", inline:true,href:".movie"});
    
    //Example of preserving a JavaScript event for inline calls.
    $("#click").click(function(){
        $('#click').css({"background-color":"#f00", "color":"#fff", "cursor":"inherit"}).text("Open this window again and this message will still be here.");
        return false;
    });

    /*--------------------------------------
    bij bladeren naar eerste of laatste pagina gaan
    --------------------------------------*/
    $("div.paging div").click(function() {
        if ($(this).attr('id') == 'lt') {
            $("input#page").val(1);
        } else if($(this).attr('id') == 'gt') {
            $("div.paging div").last().html();
            $("input#page").val($("div.paging div").eq($("div.paging div").length - 2).attr('id'));
        } else {
            $("input[name=page]").val($(this).attr('id'));
        }
        $("form[name=search_search_form]").submit();
    });

    /*--------------------------------------
    Redirects (Header)
    --------------------------------------*/
    $('select.redirect').change(function() {
        if ($(this).val()) {
            window.open($(this).val());
        }
    });


    /*--------------------------------------
    Videobox
    --------------------------------------*/
    if($('.vidbox').is(':visible')) {
        $(".vidbox").jqvideobox({
            'width' :       600,
            'height':       500,
            'getimage':     false,
            'navigation':   false
        });
    }

    /*--------------------------------------
    Vervangen subscript R
    --------------------------------------*/
    $.fn.addSuperScript = function() {
        var pos     = 0;
        var oldText = $(this).html();
        var newText = '';

        while (oldText.indexOf('®') > 0) {
            // Haalt de positie in de tekst op van '®'
            pos = oldText.indexOf('®') + 1;

            // Plaatst de '®' in <sup> element
            newText += oldText.substr(0, pos).replace('®', '<sup>®</sup>');
            
            // Zorgt ervoor dat alle '®' worden vervangen
            oldText  = oldText.substr(pos);

            if (oldText.indexOf('®') < 0) {
                newText += oldText;
                break;
            }
        }
        $(this).html(newText);
    };

    $.each($("h1:contains('®'), h2:contains('®'), h3:contains('®'), h4:contains('®'), h5:contains('®'), h6:contains('®')"), function() {
        $(this).addSuperScript();
    });

    $.each($("a:contains('®')"), function() {
        $(this).addSuperScript();
    });

    $.each($("p:contains('®')"), function() {
        $(this).addSuperScript();
    });

});


 

