// +------------------------------------------------------------------------+
// | GLOBALS                                                                |
// +------------------------------------------------------------------------+
try {
    GLOBALS.ie6 == GLOBALS.ie7;
}
catch (eExc)
{
    var GLOBALS = {
        ie6: false,
        ie7: false,
		ie8: false
    };
}



// +------------------------------------------------------------------------+
// | Page                                                                   |
// +------------------------------------------------------------------------+
var Page = {

    /**
     * @var integer
     */
    iScope : 0,

    /**
     * @var element
     */
    eSection : null,

    /**
     * Initialize website.
     *
     * @return void
     */
    init : function ()
    {
        Object.extend(
            GLOBALS,
            {
                page: env.getPageSize()
            }
        );

        Behaviour.apply();
        Page.scrolling();
        
        if (document.location.hash.match(/^#([a-z0-9_-]+)/i))
        {
          Page.scrollTo(RegExp.$1);
        }
    },
    
    /**
     * Open external links in a new window.
     *
     * @param  object _oEvent Fired event
     * @return void
     */
    externalLinks : function (_oEvent)
    {    
        if (GLOBALS.ie6 || GLOBALS.ie7 || GLOBALS.ie8)
            window.open(Event.element(_oEvent));
        else
            window.open(this.href);

        if (_oEvent)
            Event.stop(_oEvent);
    },

    /**
     * Window resize event handler.
     *
     * @return void
     */
    resize : function ()
    {
        GLOBALS.page = env.getPageSize();

        Page.scrolling();
    },

    /**
     * Check page scrolling. Fix header and footer if neccessary.
     *
     * @return void
     */
    scrolling : function ()
    {
        // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        // Best pal IE6 needs special treatment
        // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        if (GLOBALS.ie6)
        {
            Page.scrollingIE6();
            return;
        }

        var eBody      = document.getElementsByTagName('body')[0];
        var eFooter    = $('footer');
        var iScope     = Element.getHeight($('container'));

        if (iScope <= GLOBALS.page[3] || GLOBALS.page[2] < 1004)
        {
            Element.removeClassName(eBody, 'fixItems');
            Element.setStyle(eFooter, {top: 'auto'});
        }
        else
        {
            var iTop = GLOBALS.page[3] - Element.getHeight(eFooter);

            Element.addClassName(eBody, 'fixItems');
            //Element.setStyle(eFooter, {top: iTop+'px'});
            Element.setStyle(eFooter, {bottom:'0px'});
        }
    },

    /**
     * Check page scrolling for IE6. Fix header and footer if neccessary.
     *
     * @return void
     */
    scrollingIE6 : function ()
    {
        var eHtml      = document.getElementsByTagName('html')[0];
        var eBody      = document.getElementsByTagName('body')[0];
        var eContainer = $('container');
        var iScope = Element.getHeight(eContainer);

        if (iScope > GLOBALS.page[3] && GLOBALS.page[2] >= 1004)
        {
            Element.addClassName(eHtml, 'fixItems');
            Element.addClassName(eBody, 'fixItems');

            eBody.insertBefore($('header'), eContainer);
            eBody.insertBefore($('footer'), eContainer);
        }
    },
    
    /**
     * Scroll to element
     *
     * @param string
     * @return void
     */
    scrollTo : function (_sIdentifier)
    {
        var aOffset = Position.cumulativeOffset($(_sIdentifier));
        
        document.location.hash = _sIdentifier;

        var iNewOffset = aOffset[1] - 132;
        
        if (Element.hasClassName(document.getElementsByTagName('body')[0], 'fixItems'))
        {        
          if (GLOBALS.ie6)
            $('container').scrollTop = iNewOffset;
          else  
            window.scrollTo (0, iNewOffset);
        }
    },
    
    focusSearchField : function (_oEvent)
    {
      this.value = '';
    },
    
    leaveSearchField : function (_oEvent)
    {
      this.value = this.className;
    }
}

/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * Rule set for quickfinder entries
 */
var rsQuickfinder = {

    /**
     * Get quickfinder areas and fill selectbox
     *
     * @param element _eElement Input element.
     * @return void
     */
    '.quickfinderbereiche' : function (_eElement)
    {
       var sUrl = '';

       new Ajax.Request (sUrl,
                   {
                         onSuccess: function (transport) {
                             alert (transport.responseText);
                         }
                   }
       );

    }

}

Behaviour.register(rsQuickfinder);

var Gallery = {

  switchImage : function (_iImageNo)
  {
    aCurrentImages = $('galleryCurrentImage').getElementsByTagName('img');
    aThumbnails    = $('galleryImages').getElementsByTagName('div');
    aDescriptions  = $('galleryImageDescription').getElementsByTagName('p');

    for (var i = 0; i < aCurrentImages.length; i++)
    {
      if (aCurrentImages[i].className == 'no' + _iImageNo)
      {
        Element.setStyle (aThumbnails[i],
                           {
                             display: 'none'
                           }
                         );

        Element.setStyle (aCurrentImages[i],
                           {
                             display: 'block'
                           }
                         );

        Element.setStyle (aDescriptions[i],
                           {
                             display: 'inline'
                           }
                         );
      }
      else
      {
        Element.setStyle (aCurrentImages[i],
                           {
                             display: 'none'
                           }
                         );

        Element.setStyle (aDescriptions[i],
                           {
                             display: 'none'
                           }
                         );

        Element.setStyle (aThumbnails[i],
                           {
                             display: 'block'
                           }
                         );
      }
    }
  },

  nextImage : function ()
  {
    aCurrentImages = $('galleryCurrentImage').getElementsByTagName('img');
    aThumbnails    = $('galleryImages').getElementsByTagName('div');
    aDescriptions  = $('galleryImageDescription').getElementsByTagName('p');
	iNoImages	   = aCurrentImages.length - 1;	

    for (var i = 0; i < aCurrentImages.length; i++)
    {
      if (Element.getStyle (aCurrentImages[i], 'display') == 'block')
      {
        Element.setStyle (aThumbnails[i],
                           {
                             display: 'block'
                           }
                         );

        Element.setStyle (aDescriptions[i],
                           {
                             display: 'none'
                           }
                         );

        Element.setStyle (aCurrentImages[i],
                           {
                             display: 'none'
                           }
                         );

        var next = i + 1;

        if (i == iNoImages)
        {
          next = 0;
        }
      }
    }

    Element.setStyle (aCurrentImages[next],
                       {
                         display: 'block'
                       }
                     );

    Element.setStyle (aDescriptions[next],
                       {
                         display: 'inline'
                       }
                     );

    Element.setStyle (aThumbnails[next],
                       {
                         display: 'none'
                       }
                     );

    aThumbnails[next].className = 'no' + (i + next) + ' active';
  },

  prevImage : function ()
  {
    aCurrentImages = $('galleryCurrentImage').getElementsByTagName('img');
    aThumbnails    = $('galleryImages').getElementsByTagName('div');
    aDescriptions  = $('galleryImageDescription').getElementsByTagName('p');
	iNoImages	   = aCurrentImages.length - 1;	

    for (var i = 0; i < aCurrentImages.length; i++)
    {
      if (Element.getStyle (aCurrentImages[i], 'display') == 'block')
      {
        aThumbnails[i].className = 'no' + (i + 1);

        Element.setStyle (aThumbnails[i],
                           {
                             display: 'block'
                           }
                         );

        Element.setStyle (aDescriptions[i],
                           {
                             display: 'none'
                           }
                         );

        Element.setStyle (aCurrentImages[i],
                           {
                             display: 'none'
                           }
                         );

        var next = i - 1;

        if (i == 0)
        {
          next = iNoImages;
        }
      }
    }

    Element.setStyle (aCurrentImages[next],
                       {
                         display: 'block'
                       }
                     );

    Element.setStyle (aDescriptions[next],
                       {
                         display: 'inline'
                       }
                     );

    Element.setStyle (aThumbnails[next],
                       {
                         display: 'none'
                       }
                     );

    aThumbnails[next].className = 'no' + (i + next) + ' active';
  }
}

var Common = {

    /**
     * Adjust footer and header position when page is scrolled
     *
     * @param boolean _bResized Window was resized.
     * @return void
     */
    scrolling : function (_bResized)
    {
            var aPageSize       = env.getPageSize();
            var iFooterTop      = ($('footer').offsetTop + Element.getHeight($('footer')));
            var iNewFooterTop   = aPageSize[3] - 25 + document.documentElement.scrollTop;

            if (aPageSize[3] <= iFooterTop || (aPageSize[3] <= iFooterTop && _bResized == true))
            {
                if (env.is_ie ()) { sPosition = 'absolute'; } else { sPosition = 'fixed'; }

                // Position footer at the bottom side of the window
                Element.setStyle($('footer'),
                                    {
                                        'position': sPosition,
                                        'top': iNewFooterTop + 'px',
                                        'zIndex': '9999'
                                    }
                                );

                // Position header at the top side of the window
                Element.setStyle($('header'),
                                    {
                                        position: sPosition,
                                        top: document.documentElement.scrollTop + 'px',
                                        zIndex: '9999'
                                    }
                                );

                // Position body between header and footer
                Element.setStyle($('container'),
                                    {
                                        paddingTop: Element.getHeight($('header')) + 'px',
                                        paddingBottom: Element.getHeight($('footer')) + 'px'
                                    }
                                );
            }
        }
}

var Quickfinder = {

  switchLinks : function (_sAreaName)
  {
    eBereichLabel   = $('quickfinderBereicheDropdown').getElementsByTagName("span");
    eDropdownList   = $('quickfinderLinks').childNodes;
    aLinkDropdowns  = new Array ();

    for (var i = 0; i < eDropdownList.length; i++)
    {
      if (eDropdownList[i].nodeType == 1)
      {
        aLinkDropdowns.push (eDropdownList[i]);
      }
    }

    for (var i = 0; i < aLinkDropdowns.length; i++)
    {
//      if (aLinkDropdowns[i].getAttribute("name") == _sAreaName)
      if (Element.hasClassName(aLinkDropdowns[i],_sAreaName))
      {
        Element.removeClassName(aLinkDropdowns[i], 'hidden');
      }
      else
      {
        Element.addClassName (aLinkDropdowns[i], 'hidden');
      }
    }

    eBereichLabel[0].firstChild.nodeValue = _sAreaName;
  }

}

var Highlights = {

  switchFeature : function (_iFeature)
  {
    var aFeatures = new Array();
    var aChildnodes = $('productComponents').childNodes;
    var aPagination = new Array();
    var aPagChildnodes = $('featurePagination').childNodes;
    var ePrevFeature = $('prevFeature');
    var eNextFeature = $('nextFeature');

    for (var i = 0; i < aChildnodes.length; i++)
    {
      if (aChildnodes[i].nodeType == 1)
      {
        aFeatures.push (aChildnodes[i]);
      }
    }

    for (var i = 0; i < aPagChildnodes.length; i++)
    {
      if (aPagChildnodes[i].nodeType == 1 && !aPagChildnodes[i].id)
      {
        aPagination.push (aPagChildnodes[i]);
      }
    }

    for (var i = 0; i < aFeatures.length; i++)
    {
      Element.setStyle (aFeatures[i],
                         {
                           display: 'none'
                         }
                       );

      aFeatures[i].className = 'componentBlock';
      aPagination[i].className = '';


      if (aFeatures[i].id == 'cmp' + _iFeature)
      {

        aPagination[i].className = 'crnt';

        if ((i + 1) == aFeatures.length)
        {
          Element.setStyle (eNextFeature,
                             {
                               display: 'none'
                             }
                           );

          eMoreLink = $('cmp' + (i+1)).getElementsByTagName('a');

          Element.setStyle (eMoreLink[0],
                             {
                               display: 'none'
                             }
                           );
        }
        else
        {
          Element.setStyle (eNextFeature,
                             {
                               display: 'block'
                             }
                           );

          eMoreLink = $('cmp' + (i+1)).getElementsByTagName('a');

          Element.setStyle (eMoreLink[0],
                             {
                               display: 'block'
                             }
                           );
        }

        if (i == 0)
        {
          Element.setStyle (ePrevFeature,
                             {
                               display: 'none'
                             }
                           );
        }
        else
        {
          Element.setStyle (ePrevFeature,
                             {
                               display: 'block'
                             }
                           );
        }

        Element.setStyle (aFeatures[i],
                           {
                             display: 'block'
                           }
                         );

   	    aFeatures[i].className = 'componentBlock crnt';
      }
    }
  },

  nextFeature : function ()
  {
    var aFeatures = new Array();
    var aChildnodes = $('productComponents').childNodes;
    var aPagination = new Array();
    var aPagChildnodes = $('featurePagination').childNodes;
    var eNextFeature = $('nextFeature');
    var ePrevFeature = $('prevFeature');

    for (var i = 0; i < aChildnodes.length; i++)
    {
      if (aChildnodes[i].nodeType == 1)
      {
        aFeatures.push (aChildnodes[i]);
      }
    }

    for (var i = 0; i < aPagChildnodes.length; i++)
    {
      if (aPagChildnodes[i].nodeType == 1 && !aPagChildnodes[i].id)
      {
        aPagination.push (aPagChildnodes[i]);
      }
    }

    for (var i = 0; i < aFeatures.length; i++)
    {
      aPagination[i].className = '';

      if (Element.hasClassName(aFeatures[i],'crnt'))
      {
        iNext = i+1;

        Element.setStyle (aFeatures[i],
                           {
                             display: 'none'
                           }
                         );

        Element.removeClassName(aFeatures[i],'crnt');

        Element.setStyle (ePrevFeature,
                           {
                             display: 'block'
                           }
                         );
      }
    }

    Element.addClassName(aPagination[iNext],'crnt');
    Element.addClassName(aFeatures[iNext],'crnt');

    Element.setStyle (aFeatures[iNext],
                       {
                         display: 'block'
                       }
                     );

    if ((iNext + 1) == aFeatures.length)
    {
      Element.setStyle (eNextFeature,
                         {
                           display: 'none'
                         }
                       );

        eMoreLink = $('cmp' + (iNext + 1)).getElementsByTagName('a');

        Element.setStyle (eMoreLink[0],
                           {
                             display: 'none'
                           }
                         );
    }
  },

  prevFeature : function ()
  {
    var aFeatures = new Array();
    var aChildnodes = $('productComponents').childNodes;
    var aPagination = new Array();
    var aPagChildnodes = $('featurePagination').childNodes;
    var eNextFeature = $('nextFeature');
    var ePrevFeature = $('prevFeature');

    for (var i = 0; i < aChildnodes.length; i++)
    {
      if (aChildnodes[i].nodeType == 1)
      {
        aFeatures.push (aChildnodes[i]);
      }
    }

    for (var i = 0; i < aPagChildnodes.length; i++)
    {
      if (aPagChildnodes[i].nodeType == 1 && !aPagChildnodes[i].id)
      {
        aPagination.push (aPagChildnodes[i]);
      }
    }

    for (var i = 0; i < aFeatures.length; i++)
	{
      if (Element.hasClassName(aFeatures[i],'crnt'))
      {
        iNext = i-1;

        Element.setStyle (aFeatures[i],
                           {
                             display: 'none'
                           }
                         );

        Element.removeClassName(aFeatures[i],'crnt');
      }
	}

    for (var i = 0; i < aFeatures.length; i++)
    {
      aPagination[i].className = '';

      if (iNext == 0)
      {
        Element.setStyle (ePrevFeature,
                           {
                             display: 'none'
                           }
                         );
      }

      Element.setStyle (eNextFeature,
                         {
                           display: 'block'
                         }
                       );
    }

    Element.addClassName(aPagination[iNext],'crnt');
    Element.addClassName(aFeatures[iNext],'crnt');

    Element.setStyle (aFeatures[iNext],
                       {
                         display: 'block'
                       }
                     );
  }
}

var DropDown = {

    /**
     * DropDown box stack.
     *
     * @var array
     */
    aBox : new Array(),

    /**
     * Document event observer registered or not.
     *
     * @var boolean
     */
    bDocumentEvent : false,

    /**
     * Push box to DropDown stock.
     *
     * @param  element _eLabel
     * @param  element _eItem
     * @return void
     */
    pushBox : function (_eLabel, _eItem)
    {
        Event.observe(
            _eLabel,
            'click',
            DropDown.check
        );

        DropDown.aBox.push(
            {
                label  : _eLabel,
                item   : _eItem,
                active : false
            }
        );
    },

    /**
     * Returns the stock-index of given box.
     *
     * @param  element         _eLabel
     * @return integer|boolean
     */
    getIndex : function (_eLabel)
    {
        var iLength = DropDown.aBox.length;
        var iIndex  = 0;

        while (iLength--)
        {
            if (DropDown.aBox[iIndex++].label == _eLabel)
                return iIndex;
        }

        return false;
    },

    /**
     * Open external links in a new window.
     *
     * @param  object _oEvent Fired event
     * @return void
     */
    check : function (_oEvent)
    {
        var eTarget = Event.element(_oEvent);
        var iIndex  = DropDown.getIndex(eTarget);

        if (iIndex && false == DropDown.aBox[iIndex-1].active)
        {
            DropDown.close(null);
            Event.stop(_oEvent);

            DropDown.show(iIndex-1);
        }
    },

    /**
     * Show DropDown items
     *
     * @param  integer _iIndex
     * @return void
     */
    show : function (_iIndex)
    {
        // ~~~~~~~~~~~~~~~~~
        // Show DropDown box
        // ~~~~~~~~~~~~~~~~~
        DropDown.aBox[_iIndex].active = true;

        Element.setStyle(DropDown.aBox[_iIndex].item,{display:'block'});

        // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        // If not already registered, register document event observer
        // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        if (!DropDown.bDocumentEvent)
        {
            DropDown.bDocumentEvent = true;

            Event.observe(document, 'click', DropDown.close);
        }
    },

    /**
     * Hide all DropDown items
     *
     * @param  object _oEvent
     * @return void
     */
    close : function (_oEvent)
    {
        // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        // Unregister document event observer
        // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        DropDown.bDocumentEvent = false;

        Event.stopObserving(document, 'click', DropDown.close);

        // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
        // Run all boxes to close them
        // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
        var iLength = DropDown.aBox.length;
        var iIndex  = 0;

        while (iLength--)
        {
            if (false == DropDown.aBox[iIndex++].active)
                continue;

            DropDown.aBox[iIndex-1].active = false;

            Element.setStyle(
                DropDown.aBox[iIndex-1].item,
                {display : 'none'}
            );
        }
    }
}

var Streumaster = {

  switchDownload : function (_sUrl, _iId, _sLanguage)
  {
    eDownloadButton = $('streumasterDownload' + _iId);
    eDownloadButton.href = _sUrl;

    eDropdownLabel = $('dropdownLabel' + _iId);
    eDropdownLabel.firstChild.nodeValue = _sLanguage;
  },
  
  /*  funktion prueft inhalt des Links auf # und setzt einen Fehler in der Anzeige*/
  
  showError : function (_oEvent)
  {
	eTarget = Event.element(_oEvent);	
	sURL = eTarget.getAttribute('href');
	// substring des href: im letzten byte steht bei nicht gesetzer URL eine #
	
	
	iLengthURL = sURL.length;
	iStartURL = iLengthURL - 1;
	
	if (sURL.substring(iStartURL,iLengthURL) == '#')
		{				
			sErrorID = eTarget.getAttribute('id');			
			eElement = $(sErrorID + 'error');			
			Element.setStyle(eElement,{display : 'inline'});
		}
  },
  
  hideError : function (_oEvent)
  {
	eTarget = Event.element(_oEvent);	
	sErrorID = eTarget.getAttribute('id');			
	eElement = $(sErrorID + 'error');			
	Element.setStyle(eElement,{display : 'none'});
	
  },  
  preventClick : function (_oEvent)
  {
	eTarget = Event.element(_oEvent);	
	sURL = eTarget.getAttribute('href');
	// substring des href: im letzten byte steht bei nicht gesetzer URL eine #
		
	iLengthURL = sURL.length;
	iStartURL = iLengthURL - 1;
	
	if (sURL.substring(iStartURL,iLengthURL) == '#')
		{				
			Event.stop(_oEvent);								
		}
	else
		{			
        if (GLOBALS.ie6 || GLOBALS.ie7 || GLOBALS.ie8)
				window.open(Event.element(_oEvent));
			else
				window.open(this.href);
			if (_oEvent)
				Event.stop(_oEvent);
		}
  }
}

var Jobreports = {

  switchDownload : function (_iId, _sUrl, _sLanguage)
  {
    eDownloadButton = $('jobreportDownload' + _iId);
    eDownloadButton.href = _sUrl;

    eDropdownLabel = $('dropdownLabel' + _iId);
    eDropdownLabel.firstChild.nodeValue = _sLanguage;
  }

}

var videoportal = {

  switchDownload : function (_iId, _sUrl, _sLanguage)
  {
    eDownloadButton = $('videoLink_' + _iId);
    eDownloadButton.href = _sUrl;

    eDropdownLabel = $('dropdownLabel_' + _iId);
    eDropdownLabel.firstChild.nodeValue = _sLanguage;
  }

}

var Fairs = {
  
  switchYear : function (_iYear)
  {
    eDropdown = $('fairYear').getElementsByTagName('span');    
    eDropdown[0].innerHTML = _iYear;
  },
  
  switchMonth : function (_iMonth)
  {
    eDropdown = $('fairMonth').getElementsByTagName('span');    
    eDropdown[0].innerHTML = _iMonth;
  },
  
  jump : function (_sUrl)
  {
    iMonth = $('fairMonth').getElementsByTagName('span')[0].innerHTML; 
    iYear = $('fairYear').getElementsByTagName('span')[0].innerHTML;

    try
    {
        $(iMonth + iYear).nodeType == 1;

        var aOffset = Position.cumulativeOffset($(iMonth + iYear));

        document.location.hash = iMonth + iYear;
        window.scrollTo(0, aOffset[1] - 130);
    }
    catch (exc) {}
  }
  
}

var Branches = {

  switchBranch : function (_sBranch)
  {

    $('branchDropDownContact').getElementsByTagName('span')[0].innerHTML = _sBranch;
    $('inputBranch').value = _sBranch;
  }
}

var Contact = {

  switchLanguage : function (_sLanguage, _iBranchIndex, _sOverwrite)
  {    
    if (_sLanguage == '')
      sLabel = _sOverwrite;
    else
      sLabel = _sLanguage;
    
    $('langDropDown[' +_iBranchIndex+ ']').getElementsByTagName('span')[0].innerHTML = sLabel;

    $('brochureLanguage[' +_iBranchIndex+ ']').value = _sLanguage;
  
      /*$('BrochureLangDropDown').getElementsByTagName('span')[0].innerHTML = _sLanguage;
                 $('brochureLang').value = _sLanguage;*/
  }
}

var RuleSet = {

  /**
     * Open external links in a new window.
     *
     * @param  element _eElement Anchor element.
     * @return void
     */
    'a.ext' : function (_eElement)
    {
        Event.observe(_eElement, 'click', Page.externalLinks);
    },

	'div.streumasterDownload a.ext' : function (_eElement)
	{	
	  Event.stopObserving(_eElement, 'click', Page.externalLinks);
	  Event.observe(_eElement, 'mouseover', Streumaster.showError);	
	  Event.observe(_eElement, 'click', Streumaster.preventClick);		  
	  Event.observe(_eElement, 'mouseout', Streumaster.hideError);
	},
	'div.jobreportsDL a.downloadLink' : function (_eElement)
	{	
	  Event.stopObserving(_eElement, 'click', Page.externalLinks);
	  Event.observe(_eElement, 'mouseover', Streumaster.showError);	
	  Event.observe(_eElement, 'click', Streumaster.preventClick);		  
	  Event.observe(_eElement, 'mouseout', Streumaster.hideError);
	},	
	'div.jobreportsDL a.downloadLink' : function (_eElement)
	{	
	  Event.observe(_eElement, 'mouseover', Streumaster.showError);		  
	  Event.observe(_eElement, 'mouseout', Streumaster.hideError);
	},	
	
  /**
     * Drop down boxes
     *
     * @param  element _eElement Anchor element.
     * @return void
     */
    'span.dropDownLabel' : function (_eElement)
    {
        DropDown.pushBox(
            _eElement,
            Element.next(_eElement, 'div.dropDownItems')
        );
    },
    
    '#search input' : function (_eElement)
    {
      Event.observe(_eElement, 'focus', Page.focusSearchField);
      Event.observe(_eElement, 'blur', Page.leaveSearchField);
    }
}

Behaviour.register(RuleSet);

/*
function init ()
{
    if (env.is_ie())
    {
        window.onscroll = function (e) { Common.scrolling (); };
    }
    window.onresize = function (e) { Common.scrolling (true); };
    Behaviour.apply();
}
*/

Event.observe(window , 'load', Page.init);
Event.observe(window , 'resize', Page.resize);
//Event.observe(window, 'load', init);

// +------------------------------------------------------------------------+
// | Search                                                                 |
// +------------------------------------------------------------------------+

function checkSearchField(_sDefault,_sMsg)
{
	if (document.getElementById("search").getElementsByTagName("input")[0].value == "" ||
		document.getElementById("search").getElementsByTagName("input")[0].value == _sDefault) 
	{
	    alert(_sMsg);
	    document.getElementById("search").getElementsByTagName("input")[0].focus();
	    return false;
	}
    return true;
}

jQuery(document).ready(function(){
	jQuery('#videoportal a.downloadLink, .captionNew a.video_link, .videoMenu ul li a, ul.flow li.video_link.active, ul li a.box_link_video_lang').live('click',function(event) {
		var myPlayer = jQuery(this).attr("rel");
		var myCloseButton = jQuery(this).attr("rev");
		var myFLV = jQuery(this).attr("href");
		event.preventDefault();
		event.stopPropagation();
		//notbremse f�r flashbox bei nicht ausgew�hltem Video (href endet dann auf #)	
		iLengthMyFLV = myFLV.length;
		iStartMyFLV = iLengthMyFLV - 1;
		
		if (myFLV.substring(iStartMyFLV,iLengthMyFLV) != '#') {

			// IE css special
			if(jQuery.browser.msie) {			
				jQuery('body').attr("style","overflow:visible !important;");					
			}
			// Masse holen und ablegen
			var iBodyWidth = jQuery('html').width();
			var iBodyHeight = jQuery(document).height();
			
			// Differenzen (erstmal static)
			var iTopOffset = (iBodyHeight - 360) / 2;
			// Offset fuer Overlay (body ist relative)
			var iLeftOffset = ((iBodyWidth - jQuery('body').width()) / 2);
			jQuery('body').append('<div id="jquery-overlay" style="left:-'+iLeftOffset+'px; background-color: rgb(0, 0, 0); width:'+iBodyWidth+'px; height:'+iBodyHeight+'px;"/><div id="jquery-lightbox"><div id="lightbox-container-image-box" style="background-color: transparent;top:'+iTopOffset+'px;"><div id="lightbox-container-image" style="background-color: white;"></div></div></div>');
			jQuery('#lightbox-container-image-box').height(380);
			jQuery('#lightbox-container-image-box').width(500);
			jQuery('#lightbox-container-image').flash({
					swf: myPlayer,
					width: '480',
					height: '360',
					wmode: 'transparent',
					quality: 'high',
					allowfullscreen: 'true',
					flashvars: {   
								width: '480',
								height: '360',
								allowfullscreen: 'true',
								autostart: 'true',
								frontcolor: '0XFFFFFF',
								backcolor: '0x8D969F',
								file: myFLV	
							}
				});			
			jQuery('#lightbox-container-image-box').append('<p id="lightbox-secNav-btnClose" style="color:white;cursor:pointer;height:10px;padding-top:5px;text-align:right;width:auto;"><strong>X '+myCloseButton+'</strong></p>');		
			jQuery('#lightbox-secNav-btnClose,#jquery-overlay').live('click', function(event) {		
				jQuery('#jquery-overlay').remove();
				jQuery('#jquery-lightbox').remove();
			// IE css special
			if(jQuery.browser.msie) {				
				jQuery('body').attr("style","");					
			}
			});
		}
	});
});