﻿/* Functions common to closerlook projects */

function getDirectoryForHREF(href) {
    var endIndex = href.lastIndexOf("/");
    if (endIndex < 0)
        return href;
    
    return href.substring(0, endIndex + 1);
}

/* This function creates the accordion-style menu 
   with the correct section open and link highlighted
*/
var windoo0;

window.addEvent('domready', function() {
    var intSectionID = 0;
    
    // Build an array of all the lists in the menu
    var arrSections = new Array();
    arrSections = $('menu').getElements('ul');
    
    // Loop through each list
    arrSections.each(function(section, sectionIndex){
        
        // Build an array of all the links in this list
        var arrLinks = new Array();
        arrLinks = section.getElements('a');

        // Loop through the links in this list
        arrLinks.each(function(item, index){
                                    
            // See if it matches our current URL
            var strCurrentPath = getDirectoryForHREF(window.location.href);
            var strItemPath = getDirectoryForHREF(item.href);
            
            if (strCurrentPath == strItemPath) {
                // Highlight this link
                item.setStyle('font-weight', 'bold');
                // Update the section ID passed to the accordion object
                intSectionID=sectionIndex;
            };
        });
    });
    
    //Apply the accordion effect to the menu
    var accordion = new Accordion('h3.atStart', 'ul.atStart', {
        show: intSectionID,
        opacity: false,
        onActive: function(toggler, element) {
            //Swap in a minus for the plus in the toggler
            var togglerText=toggler.getText();
            togglerText = togglerText.replace('+','-');
            toggler.setText(togglerText);
                     
            //Make the text darker
            toggler.setStyle('color', '#f9e3ed');
       },
       onBackground: function(toggler, element) {
            //Swap in a plus for the minus in the toggler
            var togglerText = toggler.getText();
            togglerText = togglerText.replace('-','+');
            toggler.setText(togglerText);
            
            //Make the text lighter
            toggler.setStyle('color', '#ffffff');
       }
    }, $('menu'));

    //This code handles the interstitial for first-time visitors
    if ($('hcpLinkHeader2')) {
	    windoo0 = new Windoo({
			    width: 600,
			    height: 200,
			    modal: true,
			    positionAtCenter:true,
			    destroyOnClose: false,
			    container: false,
			    shadow: false,
			    resizable: false,
			    buttons: {close:false, maximize:false, minimize:false},
			    ghost: {resize: false, move: true},
			    title: ' '
		    }).adopt($('interstitial'));

		$('hcpLinkHeader2').addEvent('click', function(ev) {
            $('interstitial').setStyle('display','block');
            windoo0.setPosition((window.getWidth() - 600) / 2, ((window.getHeight() - 380) / 2) + window.getScrollTop());
            windoo0.show();
        });
	    
	    $('btnYes').addEvent('click', function(ev){
            windoo0.close();
	    });
	    
	    $('btnNo').addEvent('click', function(ev){
            windoo0.close();
	    });
    }

    if ($('hcpLinkHeader')) {
	    windoo0 = new Windoo({
			    width: 600,
			    height: 200,
			    modal: true,
			    positionAtCenter:true,
			    destroyOnClose: false,
			    container: false,
			    shadow: false,
			    resizable: false,
			    buttons: {close:false, maximize:false, minimize:false},
			    ghost: {resize: false, move: true},
			    title: ' '
		    }).adopt($('interstitial'));
		    
		 $('hcpLinkHeader').addEvent('click', function(ev) {
            $('interstitial').setStyle('display', 'block');
            windoo0.setPosition((window.getWidth() - 600) / 2, ((window.getHeight() - 380) / 2) + window.getScrollTop());
            windoo0.show();
        });

        $('btnYes').addEvent('click', function(ev){
            windoo0.close();
	    });
	    
	    $('btnNo').addEvent('click', function(ev){
            windoo0.close();
	    });
	}
    
    
    
});



/*
This function is used to show or hide the glossary terms.
*/
function showOrHide(el) {
    var element = $(el);
    var arrow = $(el+'arrow');

    if (element.getStyle('display')=='none') {
		arrow.removeClass('arrowclosed');
		arrow.addClass('arrow');
        element.setStyle('display', 'block');
    } else {
		arrow.removeClass('arrow');
		arrow.addClass('arrowclosed');
        element.setStyle('display', 'none');
    }
}


