/* jQuery flaps plugin
 * 
 * HTML example::
 *   
 *   <dl class="flaps">
 *     <dt class="flap-open">flapheader</dt>
 *     <dd>flapcontent</dd>
 *     <dt id="custom-ref">flapheader</dt>
 *     <dd>flapcontent</dd>
 *   </dt>
 *   
 * JS example::
 * 
 *   $('dl.flaps').flaps()
 *
 * An open flap dt gets a class="flap-open", which may be set beforehand too
 * 
 * Each flap dt gets an ``id="flap-i-j"`` where ``i`` is the number 
 * of the flap container (the <dl>) and ``j`` the position of a single flap (<dt>) in a flap containter.
 * If a flap already has a custom id attribute it is preserved instead. 
 * You may use utility function ``hashClick`` onload to open a specific tab
 * defined by hash like e.g. ``http://...#flap-0-1``. ``hashClick`` **MUST** be called **AFTER** 
 * initialization of the flaps.
 *      
 */
jQuery.fn.flaps = function(options) {
    jQuery(this).each(function(i){
        var m = jQuery(this);
        //$('dd', m).hide();
        jQuery('dt', m).each(function(j) {
            var dt = jQuery(this)
            if (!dt.hasClass('flap-open')) {
                dt.next('dd').hide()
            }
            if (!dt.attr('id')) {
                dt.attr('id', 'flap-' + i + '-' + j)
            }      
            dt.click(function(){
                jQuery(this).next().slideToggle('fast', function() {
                    dt.toggleClass('flap-open');
                })
            })
        })
    })
}


/* jquery.tabset.js */
/* $Id: jquery.tabset.js 35 2008-06-03 08:49:57Z christofh $ */

/* jQuery tabset plugin
 * 
 * HTML example::
 *   
 *   <div class="tabset">
 *     <h2>tabheader</h2>
 *     <div class="tab-content">
 *       some content
 *     </div>
 *   </div>
 *   
 * JS example::
 * 
 *   $('.tabset').tabset({tabheaderSelector: '>h2', 
 *                        tabcontentSelector: '>div.tab-content'})
 *
 * options
 * -------
 * tabheaderSelector = '>h2'
 *      selector of element which contains content shown on tab header
 * tabcontentSelector = '>div.tab-content'
 *      selector of a tabs content
 * 
 *
 * The navigation tabs are generated as follows::
 *   
 *      <ol class="tabs inline clearfix">
 *          <li class="tab-open first" id="tab-0-0">tabhead</li>
 *          <li id="tab-1-1">tabhead</li>
 *          ...
 *      </ol>
 *      
 * So each tab is a ``li`` in an ``ol.tabs`` with an ``id="tab-i-j"`` where ``i`` is the number 
 * of the tabset and ``j`` the number of each tab in a tabset. 
 * You may use utility function ``hashClick`` onload to open a specific tab
 * defined by hash like e.g. ``http://...#tab-0-1``. ``hashClick`` **MUST** be called **AFTER** 
 * initialization of tab sets.
 * A tab gets a class ``tab-open`` if its content is visible and the first one has an 
 * additional class ``first``. Additionally each tab gets a class ``tab-hover`` added onmouseover.
 *      
 */
jQuery.fn.tabset = function(options) {
    var options = options || {}
    var tabheaderSelector = options.tabheaderSelector || '>h2'
    var tabcontentSelector = options.tabcontentSelector || '>div.tab-content'

    jQuery(this).each(function(i) {
        var tabset = jQuery(this)
        
        // add tabs from h1
        tabheaders = jQuery(tabheaderSelector, tabset)
        var tabs = ['<ol class="tabs inline clearfix">']
        for (var j = 0; j < tabheaders.length; j++) {
            var tab = jQuery(tabheaders[j])
            var id = tab.attr('id') || 'tab-' + i + '-' + j
            tab.hide()
            tabs.push('<li id="'+id+'">' + tab.html() + '</li>')
        }
        tabs.push('</ol>')
        tabset.prepend(tabs.join(''))
        
        // add highlight to open tab
        jQuery('ol.tabs li:eq(0)', tabset).addClass('first')
                                     .addClass('tab-open')
        // close all except 1st
        jQuery(tabcontentSelector + ':gt(0)', tabset).hide()
        
        // init tab clicks
        jQuery('ol.tabs li', tabset).click(function() {
            if (!jQuery(this).hasClass('tab-open')) {
                var tab = jQuery(this)
                
                // remove old highlight
                jQuery('li', tab.parent()).removeClass('tab-open')
                
                // set new highlight
                tab.addClass('tab-open')
                
                // toggle tab content   
                jQuery(tabcontentSelector + ':visible', tabset).hide()
                jQuery(tabcontentSelector + ':eq(' + tab.prevAll('li').size() + ')', tabset).show()
            }
        })
        jQuery('ol.tabs li', tabset).hover(
            function() { jQuery(this).addClass('tab-hover') }, 
            function() { jQuery(this).removeClass('tab-hover') })
    })
}

/**
* Get the value of a cookie with the given name.
*
* @example $.cookie('the_cookie');
* @desc Get the value of a cookie.
*
* @param String name The name of the cookie.
* @return The value of the cookie.
* @type String
*
* @name $.cookie
* @cat Plugins/Cookie
* @author Klaus Hartl/klaus.hartl@stilbuero.de
*/
jQuery.cookie = function(name, value, options) {
   if (typeof value != 'undefined') { // name and value given, set cookie
       options = options || {};
       if (value === null) {
           value = '';
           options = jQuery.extend({}, options); // clone object since it's unexpected behavior if the expired property were changed
           options.expires = -1;
       }
       var expires = '';
       if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
           var date;
           if (typeof options.expires == 'number') {
               date = new Date();
               date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
           } else {
               date = options.expires;
           }
           expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
       }
       // NOTE Needed to parenthesize options.path and options.domain
       // in the following expressions, otherwise they evaluate to undefined
       // in the packed version for some reason...
       var path = options.path ? '; path=' + (options.path) : '';
       var domain = options.domain ? '; domain=' + (options.domain) : '';
       var secure = options.secure ? '; secure' : '';
       document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
   } else { // only name given, get cookie
       var cookieValue = null;
       if (document.cookie && document.cookie != '') {
           var cookies = document.cookie.split(';');
           for (var i = 0; i < cookies.length; i++) {
               var cookie = jQuery.trim(cookies[i]);
               // Does this cookie string begin with the name we want?
               if (cookie.substring(0, name.length + 1) == (name + '=')) {
                   cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                   break;
               }
           }
       }
       return cookieValue;
   }
};

/* e7lib.js */
/* $Id: package.js 6 2008-04-14 16:09:27Z christofh $ */

var e7lib;
if (!e7lib) {
    e7lib = {};
}

jQuery.extend(e7lib, {
	/* Click on element defined by hash if available automatically. 
	 * May for example be used after defining a "tabset". 
	 */
    hashClick: function (){
		var hash = document.location.hash;
		if (hash) {
			var e;
			try {
				e = jQuery(hash);
			} 
			catch (ex) {}
			if (e) {
				e.click();
			}
		}
    }
})
/* package.js */
/* $Id: package.js 28 2008-04-22 07:41:14Z christofh $ */

var mq;
if (!mq) {
	mq = {}
}

jQuery.extend(mq, {
	/* called onload */ 
    init: function() {
		
		// init tabsets	
		jQuery('.tabset').tabset({tabheaderSelector: '>h3'})
		// add <span> in each li for tab backgrounds
		jQuery('ol.tabs li').each(function() {
			jQuery(this).wrapInner('<span></span>')
		})
		
		// init flaps 
		jQuery('dl.flaps').flaps()
		
		// add print link
		jQuery('.recommend').before('<a href="javascript:print()" class="right print">Drucken</a>')

		if (jQuery.browser.msie && jQuery.browser.version <= 6) {
			jQuery('.main-action').hover(
				function(){ jQuery(this).addClass('main-action-over') }, 
				function(){ jQuery(this).removeClass('main-action-over') }
			)
			jQuery('.action').hover(
				function(){ jQuery(this).addClass('action-over') }, 
				function(){ jQuery(this).removeClass('action-over') }
			)
		}

		// open tab or flap if given ID via hash
		e7lib.hashClick()

	    
		// these should be moved into the page directly, and use $(document).ready(function() {mycode});
		// to make it run after loading has finished
	    jQuery('#open_gesundheitspolitik').click(function() {
	       document.location.hash = 'gesundheitspolitik';
			e7lib.hashClick()
	       //return false;
		});
		    jQuery('#open_patientenpresse').click(function() {
	       document.location.hash = 'patientenpresse';
			e7lib.hashClick()
	       //return false;
		});

    }
})

jQuery(document).ready(function() {jQuery(mq.init)});
