/**
 * Short plugin to manage expandable content boxes for simply
 * toggeling on|off respectively control arrow icons up|down.
 *
 * @author michael.kuck@h2g.ch
 * @version 1.00 12-04-2011
 */
(function($) {
	var o = false;
	// initialize expandable box plugin
	$.fn.expandable = function(options) {
		// build main options before initial procedure
		var opts = $.extend({}, $.fn.expandable.defaults, options);
		// initialize expandable box plugin
		return this.each(function() {
			// build element specific options
			o = $.meta ? $.extend({}, opts, this.data()) : opts;
			// adding hover function to header part
			$(this).find("h1").hover(function() {
				var src = $(this).find("img").attr('src');
				$(this).find("img").attr({
					'src': src.replace(/_off/g, '_on')
				});
			}, function() {
				var src = $(this).find("img").attr('src');
				$(this).find("img").attr({
					'src': src.replace(/_on/g, '_off')
				});
			});
			// adding click toggle function
			$(this).find("h1").toggle(function() {
				var img = $(this).find("img");
				var box = $(this).parentsUntil(".expandable").next();
				$(box).fadeIn('slow', function() {
					var src = $(img).attr('src');
					$(img).attr({'src':src.replace(/_down/g, '_up')});
				}).show();
			}, function() {
				var img = $(this).find("img");
				var box = $(this).parentsUntil(".expandable").next();
				$(box).fadeOut('fast', function() {
					var src = $(img).attr('src');
					$(img).attr({'src':src.replace(/_up/g, '_down')});
				}).hide();
			});
		});
	};
	function debug(msg) {
		if (window.console && window.console.log)
			window.console.log('debug: '+msg);
	};
	$.fn.expandable.defaults = {
		
	};
})(jQuery);
