/*
    SiteComponents version:
    Id: site.js,v 1.7 2009/05/08 13:28:17 kurt Exp 
    Name: SC_6_6_0 

    Disclaimer
    
    While we make every effort to ensure that this code is fit for its intended
    purpose, we make no guarantees as to its functionality. CoreTrek AS will
    accept no responsibility for the loss of data or any other damage or
    financial loss caused by use of this code.


    Copyright
    
    This programming code is copyright of CoreTrek AS. Permission to run this
    code is given to approved users of CoreTrek's publishing system CorePublish.
    
    This source code may not be copied, modified or otherwise repurposed for use
    by a third party without the written permission of CoreTrek AS.
    
    Contact webmaster@coretrek.com for information.
    
*/

currentOpenElementID = null;

document.observe('dom:loaded', function(event) {

	// Toggling the categorized article list 
	$$('a.category-toggler').each(function(element) {
		element.observe('click', function(event) {

			Event.stop(event);

			var observeElementID = Event.element(event).id;

			var commonElementID = observeElementID.replace("categorized-list-link-", "");

			toggleElementID = "categorized-list-" + commonElementID;

			//hide all open elements before toggling
			$$('div.categorized').each(function(element) {
				if (element.id != toggleElementID) {
					element.hide();
				}
			});		

			//remove class name of all header links
			$$('a.category-toggler').each(function(element) {
				element.removeClassName('open');
			});

			//toggle correct elements
			if ($(toggleElementID) != null) {
				$(toggleElementID).show();
				$(observeElementID).addClassName('open');
				//add a css-classname for open divs, used for styling
				if (observeElementID != currentOpenElementID) {
					currentOpenElementID = observeElementID;
				} else {
					currentOpenElementID = null;
				}
				// The sub-elements should be displayed by default 
				var childNodes = $(toggleElementID).childNodes;
				for(var i = 0; i < childNodes.length; i++){
				    if(childNodes[i].tagName === "DIV"){
				        $(childNodes[i]).show();
				    }
				}
			}

		});
	});
});


/**
 * Configuration for site components javascript
 *
 * Configuration array structure:
 * {<component>: {<parameter>: value, <parameter>: value, ... }, ...}
 */
var siteComponentsConfig = {
    
    // Configuration for the keyword module.
    
    'keywords': {
        'elements': ['placeholder-content'],
        'skiptags': ['h1','h2','h3','h4','h5','h6'],
        'usetooltip': true
    }
    // Remember to add a comma above when enabling more options
    
    /*
    // Use this to move the collapsed debug position to the left, instead
    // of the default right.
    'debug': {
        'collapsedPageInfoPosition': 'left'
    }
    */
    
    /*
    // Use this to override the default position for tooltip.
    // Valid values is:
    //   mouse (default), tooltip follows mouse
    //   element, tooltip is attached to the title element
    
    'tooltip': {
        'positionby': 'mouse'
    }
    */
    
    /*
    // Use this to override the default fontsizes in the fontsize selector
    // (html/lib/fontsize.js)
    
    'fontsize': {
        'sizes': ["10pt", "15pt", "24pt"]
    }
    */
    
};
