
sfHover = function() {
	var sfEls = document.getElementById("navi").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" navHover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" navHover\\b"), "");
		}
	}
}

Event.observe(window, 'load', function() {
	if ($('previewImage')) $('previewImage').height = ( $('previewImage').height < 300 ) ? $('previewImage').height : "300";
	$$('#images li a').each(function(item) {
		Event.observe(item, 'mouseover', function() {
			var newImage = item.href;
			$('previewImage').src = newImage;
			$('previewImage').height = "300";			
		});
	});
});

var bd = {};
bd.main = {};
bd.main.currentOpen;
bd.main.openSingle = function(toOpenHeader, isFixedHeight) {
	var toHideHeader = bd.main.currentOpen;
	if ( !toHideHeader ) toHideHeader = getCloseElement( toOpenHeader );
	if ( isFixedHeight && toOpenHeader == toHideHeader ) {
		exit;
	}
	if ( !isFixedHeight && toOpenHeader == toHideHeader ) {
		toggleSingle(toOpenHeader);
		bd.main.currentOpen = null;
		exit;
	}
	//alert(toHideHeader);
	function accordionOnComplete() {
		headerComplete( toOpenHeader );
		if( toHideHeader ) {
			headerComplete( toHideHeader );		}
	};
	var options = { autoHeight: isFixedHeight, complete: accordionOnComplete };
	bd.main.animateAccordion(toOpenHeader, toHideHeader, options);
	bd.main.currentOpen = toOpenHeader;

	function toggleSingle(currentElement) {
		headerComplete( currentElement );
	    var nextElement = currentElement.nextSibling;
	    while (nextElement.nodeType != 1)
	    {
	        nextElement = nextElement.nextSibling;
	    }
	    // set the speed of opening speed : closing speed
	    var speed = ( currentElement.className == "faq_header open" ) ? 500 : 500;
	    bd.main.animateElement( nextElement, "slideToggle", speed );
	}

	function getCloseElement(currentElement) {
		var parentElement = currentElement.parentNode;
		var currentTagName = currentElement.tagName;
		var h5s = parentElement.getElementsByTagName(currentTagName);
		var toHideHeaderNew;
		for(i=0; i<h5s.length;i++) {
			if ( h5s[i].className == "faq_header open" ) {
				toHideHeaderNew = h5s[i];
				break;
			}
		}
		return toHideHeaderNew;		
	}
	
	function headerComplete( currentElement ) {
		if ( currentElement.className == "faq_header" ) {
			//bd.main.animate(currentElement, { fontSize:"15px" } );
			currentElement.className = "faq_header open";
		} else {
			//bd.main.animate(currentElement, { fontSize:"13px" } );
			currentElement.className = "faq_header";
		}
			

	}

}


bd.main.animateElement = function( element, action, speed, callback ) {
    var j = jQuery(element);
    switch( action ) {
        case "toggle":    j.toggle(speed, callback);
                    break;
        case "slideToggle": j.slideToggle(speed, callback);
                    break;
        case "slideUp": j.slideUp(speed, callback);
                    break;
        case "slideDown": j.slideDown(speed, callback);
                    break;
        default:    break;
    }
}

/**
 * Animate an accordion.
 * @param toShowHeader the header whose section is to be opened
 * @param toHideHeader the header whose section is to be closed
 * @param options optional. Define accordion speed, autoHeight and on complete function. By default speed 300 miliseconds, autoHeight true, and on complete function empty
 */

bd.main.animateAccordion = function(toShowHeader, toHideHeader, options) {
	var toShow = jQuery(toShowHeader).next(),
	    toHide = jQuery(toHideHeader).next();

	options = jQuery.extend({duration: 500, autoHeight: true, complete: function() {} }, options);
	if ( !toHideHeader ) {
        	toShow.animate({height: "show"}, options.duration, options.complete);
		return;
	}
	// fix width before calculating height of hidden element. otherwise there could be a discrepency b/w manual height and autoheight.
	var s = toShow;
	originalWidth = s[0].style.width;
	s.width( parseInt(s.parent().width(),10) - parseInt(s.css("paddingLeft"),10) - parseInt(s.css("paddingRight"),10) - (parseInt(s.css("borderLeftWidth"),10) || 0) - (parseInt(s.css("borderRightWidth"),10) || 0) );

    // IE fix for 0px height. Manually set height to 11px which is what Firefox set for empty accordion
    var hideHeight = ( toHide.height() == 0 ) ? "11" : toHide.height(),
	showHeight = toShow.height(),
	difference = showHeight / hideHeight,
	//padding = toShow.outerHeight() - toShow.height(),
	padding = 0;
	margin = toShow.css('marginBottom'),
	overflow = toShow.css('overflow'),
	tmargin = toShow.css('marginTop');
	toShow.css({ height: 0, overflow: 'hidden', marginTop: 0, marginBottom: -padding }).show();
	toHide.animate({height:"hide"},{
		step: function(now) {
			var current = (hideHeight - now) * difference;
			if (jQuery.browser.msie || jQuery.browser.opera) {
				current = Math.ceil(current);
			}
			toShow.height( current );
		},
		duration: options.duration,
		complete: function() {
			toShow.css({marginTop: tmargin, marginBottom: margin, overflow: overflow});
			if ( !options.autoHeight ) {
				toShow.css("height", "auto");
			}
			options.complete();
		}
	});

}

bd.main.animate = function(element, options) {
	jQuery(element).animate(options);
}


