/*
* Check for long default/content pages; if so -> init accordion
*/
initPageLoad = true;
this.initAccordion = function(items){
	titleElems = $("table.contentpaneopen td.pagecontent h3");
	if(titleElems.length >= items) {
		$("table.contentpaneopen td.pagecontent h3").addClass("accordion");
		
		$("table.contentpaneopen td.pagecontent h3").each(function(){
			var $this = $(this).next();
			var $curElem = $this;
			
			while(!$curElem.next().is("h3") && !$curElem.next().is("h4") && $curElem.next().html()) {
				$this = $this.add($curElem.next());
				var $curElem = $curElem.next();
			}
			$this.wrapAll('<div class="accordion"></div>');
		});
		
		$("table.contentpaneopen td.pagecontent").accordion({
			icons: {
    			header: "inactive",
   				headerSelected: "active"
			},
			header: 'h3',
			autoHeight: false,
			active: false,
			collapsible: true,
			changestart: function(event, ui){
				if(initPageLoad) {
					clearTimeout(initSet);
					initPageLoad = false;
				}/* else {
					var headLink = ui.newHeader.html();
					if(headLink != null)
						pageTracker._trackPageview($.url.attr("directory")+"/"+headLink.replace(/<SPAN.*<\/SPAN>/gi,""));
				}*/
			}
		});
	}
	initSet = setTimeout('$("table.contentpaneopen td.pagecontent").accordion("activate", 0)', 1500);
}


/* starting the scripts on page load */
$(document).ready(function(){
	/* check for contentBox elements and init accordion when h4-count >= passed number */
	initAccordion(4);
});
