﻿ //15-7-2008 Wilbert Corts
 //Zorgt voor de popup.
 //De code wordt dynamisch toegevoegd aan de pagina, zonder js staat er een anchor naar de popuptekst.
 popupcountnr=0;
 // Wait until the Dom is fully loaded.
 $(document).ready(function(){
 $(".ref_lit_container").hide();
                //The popup in the left botttom corner.
                //Get all the links that should have popup behaviour. These have a class 'popup'.
                var popups =  $(".nw_uo_popup");
                //Prevent the default action, which would direct the page to the anchor.
                popups.click(function(event)
                {
                    event.preventDefault();
                });
                // smerige code om het pad naar de pictures map te bepalen, kan nl. door nieuwe urls best diep zijn.
                var csslinks=$("link");
                sRelativePath="/vtvredactieguipublic";
                boolfound=false;
                for(var ij=0 ; ij<csslinks.length; ij++ ) 
                {
                if (boolfound==false){
                
                    try
                    {
                        if ($(csslinks[ij]).attr("type")=="text/css")
                        {
                
                               sRelativePath= $(csslinks[ij]).attr("href").substring(0,$(csslinks[ij]).attr("href").indexOf("css"));
                                                         boolfound=true;
                        }
                    }
                    catch (e)
                            {
                            }}
                }
                for(var i=0 ; i<popups.length; i++ ) 
                {
                       //Add an eventlistener to all those links with the class popup.
                       
                       sHrefattr=popups[i].href;
                        sMessageLocal="";
                        if ($(getIdFromHref(sHrefattr)).get(0).nodeName.toLowerCase()=='dt') // afkortingen, defities
                        {
                        sMessageLocal="<dl class='textDefinitionlist'>";
                        sMessageLocal+="<dt>" + $(getIdFromHref(sHrefattr)).html() + "</dt>";
                        sMessageLocal+="<dd class='DefinitionData'>" + $(getIdFromHref(sHrefattr)).next().html() + "</dd>";
                        try
                        {
                            if($(getIdFromHref(sHrefattr)).next().next().get(0).nodeName.toLowerCase()=='dd')
                            {
                                sMessageLocal=sMessageLocal + "<dd class='DefinitionDataDescription'>" + $(getIdFromHref(sHrefattr)).next().next().html() + "</dd>";
                            }
                        }
                        catch (ElementNotFound)
                        {
                        }
                        sMessageLocal+="</dt>";
                        
                        
                       
                        // sMessageLocal="<strong class='textDefinitionName'>" + $(getIdFromHref(sHrefattr)).html()+ "</strong>" + "<span class='textDefinitionDesc'>" + $(getIdFromHref(sHrefattr)).next().html() + "</span>";
                        //if($(getIdFromHref(sHrefattr)).next().next().get(0).nodeName.toLowerCase()=='dd')
                        // {
                        //     sMessageLocal=sMessageLocal + "<span class='textDefinitionMemo'>" + $(getIdFromHref(sHrefattr)).next().next().html() + "</span>";
                        // }
                        
                        //showHelp(sMessageLocal ,sRelativePath + '/pictures/allsites/definition_1.gif',200,200,10);
                        }
                        else  // literatuur
                        {
                        sMessageLocal=$(getIdFromHref(sHrefattr)).html();
                        ///    showHelp($(getIdFromHref(sHrefattr)).html(), sRelativePath + '/pictures/allsites/definition_1.gif',200,200,10);
                        }
                         popupcountnr++;
                         $(popups[i]).after("<div style=\"display:none\" id=\"nw_popup_message_" + popupcountnr + "\"><div  class=\"nw_text_popup_container\">" + sMessageLocal + "</div></div>");
                         //$("nw_popup_message_" + popupcountnr ).hide();
                         
                         $(popups[i]).easytooltip($(popups[i]).next().attr("id"), {event: "click"});
                         $(popups[i]).attr("title","");
                        //Shows a popup 
                        
                        
                        //alert(getTextFromElement(getIdFromHref(sHrefattr)));
                       
                }
                
       
                
                //The reference and literature and bronnen popup:
                //Get all the links that open a reference or definition popup. These have a class '.indexLiterature'.
                
                var openRefLitLink =  $(".indexLiterature");
                   $(".indexLiterature").click(function(event) {
                    event.preventDefault();
                        $("#bronnenliteratuur").toggle();
                    });
                var openDefLitLink =  $(".indexDefinition");
                   $(".indexDefinition").click(function(event) {
                    event.preventDefault();
                        $("#afkortingendefinities").toggle();
                    });
                    
              
                //Get all the buttons that close a reference or definition popup. These have a class '.close_ref_lit'.
                var closebutton =  $(".close_ref_lit");
                 for(var i=0 ; i<closebutton.length; i++ ) 
                {
                        $(closebutton[i]).click(function(event)
                        {
                           
                            //Close the popup.
                            this.parentNode.parentNode.style.display='none';
                        });
                }
                
 });
//                function getTextFromElement(sId)
//                {
//                    //Returns the text of an element with the given id.
//                    var elm = $(elm);
//                    var text= elm.text();
//                    return text;
//                    
//                }
                function getIdFromHref(sHref)
                {
                    //Returns the Id of the given anchors href attribute.
                    return sHref.substring(sHref.indexOf("#"),sHref.length)
                }


