function getPageSize()
{

    var xScroll, yScroll;

    if (window.innerHeight && window.scrollMaxY) {
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }

    var windowWidth, windowHeight;
    if (self.innerHeight) {	// all except Explorer
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }

    // for small pages with total height less then height of the viewport
    if(yScroll < windowHeight) {
        pageHeight = windowHeight;
    } else {
        pageHeight = yScroll;
    }

    // for small pages with total width less then width of the viewport
    if(xScroll < windowWidth) {
        pageWidth = windowWidth;
    } else {
        pageWidth = xScroll;
    }


    arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
    return arrayPageSize;
}




function copyDimensions(source, target)
{
	if (!$(source) || !$(target))
		return false;

	var height = $(source).getHeight();
	$(target).setStyle({
		height: height + 'px'
	});

	return true;

}

function gotourl(url)
{
	window.location.href = url;
}
var flashContainer = "flashintro";
var mainContainer = "main";
var container = "container";
var skipButton = "mcskip";
function hideIntro()
{
	if ($(flashContainer)) $(flashContainer).hide();
	if ($(skipButton)) $(skipButton).hide();
	if ($(container)) $(container).removeClassName('container-home');
}

function showIntro(cookieOverride)
{
	var cookieOverride = (cookieOverride) ? true : false;
	if (!cookieOverride && hasCookie()){
		if ($(container)) $(container).removeClassName('container-home');
		return false;
	} 

	if (!copyDimensions(mainContainer, flashContainer)) return false;

	if ($(skipButton))
	{
		$(skipButton).show();
		Event.observe ( skipButton, "mousedown", hideIntro );
	}

    var introSwf = new SWFObject("fileadmin/template/swf/mcintro.swf", "introSwf", "100%", "100%", "7", "#ffffff","","high","","","");
    introSwf.addParam("menu", "false");
    introSwf.addParam("wmode", "transparent");
    introSwf.write(flashContainer);

	$(flashContainer).show();
}

function hasCookie()
{
    if (Cookie.get("intro"))
      return true;
    else
    {
//        Cookie.set("intro","intro",(60*12)); // ein halber tag
        Cookie.set("intro","intro");
        return false;
    }
}










function checkAjaxLinks()
{
//    var myAjaxLinks = document.getElementsByClassName("ajax-content");
    var myAjaxLinks = $$(".ajax-content");
	myAjaxLinks.each(function(myAjaxLink)
	{
		var href = $(myAjaxLink).getAttribute("href");
		$(myAjaxLink).href = "#";
		Event.observe (myAjaxLink, "click", function (){
		    getAjaxContent(href);
        });
	});

	// links of pictures
//	var myAjaxLinks = document.getElementsByClassName("ajax-popup");
	var myAjaxLinks = $$(".ajax-popup");
	myAjaxLinks.each(function(myAjaxLink)
	{
		var myAnchors = $(myAjaxLink).getElementsByTagName("a");
		$A(myAnchors).each(function(myAnchor)
		{;

			var href = $(myAnchor).getAttribute("href");
			$(myAnchor).href = "#";
			Event.observe (myAnchor, "mouseover", function (){
			    getAjaxContent(href, 'popup');
	        });
			Event.observe (myAnchor, "mouseout", function (){
				closeAjaxWindow();
	        });
		});
	});

}
popup = false;
function getAjaxContent(url, myPopup)
{
    var func = 'showAjaxContent(transport.responseText);'
    if ($("ajax")) Element.show("ajax");
	$('ajax-placeholder').update("");

	if (myPopup)
		popup = myPopup;
	else
		popup = false;

	if (popup)
	{
		$('ajax-placeholder').addClassName(popup);
		$('ajax-mask').removeClassName("visible");
		func += '$("ajax-close").hide();';
	}
	else
	{
		$('ajax-placeholder').removeClassName(popup);
		$('ajax-mask').addClassName("visible");
		func += '$("ajax-close").show();';
	}

    var url = url + "&type=2";
    loadAjaxContent(url, func);
}
function loadAjaxContent(url, myFunction)
{
    new Ajax.Request(url, {
        method: 'get',
        onSuccess: function(transport) {
            eval(myFunction);
        }
    });
}
function showAjaxContent(html)
{
    $('ajax-placeholder').update(html);
    Event.observe ("ajax-closer", "click", function (){
         closeAjaxWindow();
    });

    resizeAjaxWindow();
}
function resizeAjaxWindow()
{
    var ajaxInnerH = $('ajax-container').scrollHeight ;
    var ajaxMask = $('ajax-mask');
    $('ajax-placeholder').setStyle({
       'height' : + ajaxInnerH + 'px'
    });
	if (!popup)
	{
		var myPageSize = getPageSize();
	    ajaxMask.setStyle({
	       'height' : + myPageSize[1] + 'px'
	    });
	}
}
function closeAjaxWindow()
{
    $('ajax-placeholder').update("");
    $('ajax-placeholder').setStyle({
       'height' : '300px'
    });
    if ($("ajax")) Element.hide("ajax");
}
function keyFunction(ev){
    if (!ev) ev=window.event; // für IE
    switch(ev.keyCode) {
        case Event.KEY_ESC:
        closeAjaxWindow();
        return ;
    }
}













var NewslistScroller = Class.create();
NewslistScroller.prototype = {

    initialize: function() {
        theObj = this;

        theObj.container = $('secondary-navigation');
		theObj.isHome = $('home');
        if (!theObj.container || !theObj.isHome)
            return false;
			
		 
        theObj.items = $$('#secondary-navigation .csc-bulletlist li');
        if (theObj.items.size() <= 1)
            return false;

        theObj.currentIndex = 0;

        theObj.items.each(function(item, index){
            if (index > theObj.currentIndex)
                Element.hide(item);
            else {
                theObj.item = item;
                theObj.hideItem();
            }
       });
	},

	hideItem: function(){
        theObj = this;
        window.setTimeout(function() {
            Effect.Fade(theObj.item, {duration:'0.4'});
            theObj.showItem();
        }, 5000);
    },

    showItem: function(){
        theObj = this;
        window.setTimeout(function() {
            theObj.getNextItem();
            theObj.item = theObj.items[theObj.currentIndex];
            Effect.Appear(theObj.item, {duration:'0.4'});
            theObj.hideItem();

        }, 400);
    },

    getNextItem: function(){
        theObj.currentIndex = ( theObj.currentIndex + 1 >= theObj.items.size() ) ? 0 : theObj.currentIndex + 1;
        theObj.item = theObj.items[theObj.currentIndex];
    }
}






















// body onload handler
Event.observe (window, "load", function(){
	myNewslistScroller = new NewslistScroller;
	checkAjaxLinks();
});

// tastenbehaviour
Event.observe ( window, "keypress", keyFunction.bindAsEventListener(  ) );
