// fd.js
// zeitform Internet Dienste 2010


$(function() {
    
    // open external links in a new window
    $('a[rel=external],a[rel=ext]').attr("target", "_blank").attr("title", "Externer Link offnet in neuem Tab/Fenster");

    // menus
    $('#subnavi div.inner').css('display', 'none');//.css('opacity','0.8');

    // find current active menu
    var current = $('a.active', $('#nav'))[0];
    var cls;

    if (cls = $(current).attr('rel')) {
      $('#subnavi div.' + cls).show();
    }

    // close menu
    $('body').click(function(){
      $('#subnavi div.inner').not('.' +cls).slideUp('slow');
      $('#subnavi div.' + cls).slideDown('slow');
    });

    // click menu
    $('a', $('#nav')).each(function(){

      // cls is the myclass key for this menu
      var cls = $(this).attr('rel');
      var e = this;

      if (cls) {

	// click on menu link
	$(this).click(
	    function(){
	      $('#subnavi div.inner').not('.' +cls).slideUp('slow'); 
	      $('#subnavi div.' + cls).slideDown('slow');
	      return false;
            }
        );

      }

    });


    if (window.location.search.match(/^.*hilite=([^&]+)&?.*$/i)) {
      var query = decodeURIComponent(RegExp.$1);
      query = query.replace(/\'|"/, ''); // "\' fix syntax hilite
      query = query.split(/[\s,\+\.]+/);
      //console.log(query);
      for (var i=0; i < query.length; ++i) {
        $('#main').highlight(query[i]);
      }
    }

    // popups
    $("a[rel^='popup']").prettyPopin({
       modal : true, /* true/false */
       width : false, /* false/integer */
       height: false, /* false/integer */
       opacity: 0.8, /* value from 0 to 1 */
       animationSpeed: 'fast', /* slow/medium/fast/integer */
       followScroll: true, /* true/false */
       loader_path: '/images/loader.gif', /* path to your loading image */
       start_callback: function() { /* required zeitform version */
	  //$('#overlay').bgiframe(); // ie6
	  $('.prettyPopin').height('800px'); // looks like this fixes height problems in IE7 
      
       },
       callback: function() { 
	  //$('#tooltip').hide();
       }
    });

    // popups
    $("a[rel^='video']").prettyPopin({
       modal : true, /* true/false */
       width : false, /* false/integer */
       height: false, /* false/integer */
       opacity: 0.8, /* value from 0 to 1 */
       animationSpeed: 'fast', /* slow/medium/fast/integer */
       followScroll: true, /* true/false */
       loader_path: '/images/loader.gif', /* path to your loading image */
       start_callback: function() { /* required zeitform version */
	  //$('#overlay').bgiframe(); // ie6

	  // start projekktor
	  var videoContainer = $('video');        
	  for(var i=0; i<videoContainer.length; i++) {        
            PROJEKKTOR[i] = new projekktor();
            PROJEKKTOR[i].initialize(videoContainer[i],i);
	  }

	  $('.prettyPopin').height('800px'); // looks like this fixes height problems in IE7 
      
       },
       callback: function() { 
	  //$('#tooltip').hide();
       }
    });

});  

