var currentSmallId = '';
function SetSmallMenu(id, onoff) {
    if (currentSmallId == id && onoff < 1) {
        return;
    }
    var anim = new Fx.Morph($(id), { duration: 300, transition: Fx.Transitions.Circ.easeIn });
    if (onoff == 1) {
        anim.start({ 'background-color': '#3c58a4' });
    }
    else {
        anim.start({ 'background-color': '#fe8a07' });
    }
}
function DisplayContent() {
    if (currentSite.indexOf('teamdates') > -1 || currentSite.indexOf('teamtable') > -1) {
        $('sisWaiter').morph({ 'left': -1000 });
    }
    var anim = new Fx.Morph($('mainContent'), { duration: 300, transition: Fx.Transitions.Circ.easeIn });
    anim.start({ 'opacity': 1 });
    try {
        InitModul();
    } catch (e) { }

}
function LoadFrame(site) {
    $('mainContent').load('subframe.php?src=' + escape(site));
}
function LoadSite(id, site, menuCall) {
    if (menuCall == true) {
        if (currentId != '') {
            SetMenu(id, 2);
        }
        currentId = id;
    }
    currentSite = site;
    if (currentSite.indexOf('teamdates') > -1 || currentSite.indexOf('teamtable') > -1) {
        $('sisWaiter').set('morph', { duration: 'long', transition: 'cubic:out' });
        $('sisWaiter').morph({ 'top': window.getSize().y / 2 - 20, 'left': window.getSize().x / 2 - 50 });
    }
    var anim = new Fx.Morph($('mainContent'), { duration: 300, transition: Fx.Transitions.Circ.easeIn });
    anim.start({ 'opacity': 0 }).chain(function() { SetSite() });
}
function SetSite() {
    var rndi = Math.random() * 20345;
    if (currentSite.indexOf('?') > -1) {
        currentSite += '&rnd=' + rndi;
    } else {
        currentSite += '?rnd=' + rndi;
    }
    /*if (currentSite.indexOf('htm') > 0) {
        debugger;
    }*/
    var req = new Request.HTML({ url: currentSite,
        onSuccess: function(html, htmltree,htmltext) {
            $('mainContent').set('text', '');
            $('mainContent').adopt(html);            
            DisplayContent();
        },
        onFailure: function() {
            $('mainContent').set('text', 'Fehler beim laden der Unterseite.');
        }
    });
    req.get();

}

var currentSite = '';
var currentId = '';
function SetMenu(id, onoff) {
    if (currentId == id) {
        return;
    }
    if (onoff == 1) {
        $(currentId).setStyle('background-Image', 'url(Bilder/buttonOrangeBackground.png)');
        $(currentId.replace('mnu', 'img')).src = $(currentId.replace('mnu', 'img')).src.replace('-over.gif', '.gif');
    }
    else {
        $(currentId).setStyle('background-Image', 'url(Bilder/buttonBlueBackground.png)');
        $(currentId.replace('mnu', 'img')).src = $(currentId.replace('mnu', 'img')).src.replace('-over.gif', '.gif');
    }
}

var currentMainId = '';
function SetMainMenu(id, onoff) {
    if (currentMainId == id) {
        return;
    }
    if (onoff == 1) {
        $(currentMainId.replace('main', 'img')).src = $(currentMainId.replace('main', 'img')).src.replace('-over.gif', '.gif');
    }
    else {
        $(currentMainId.replace('main', 'img')).src = $(currentMainId.replace('main', 'img')).src.replace('-over.gif', '.gif');
    }
}
function mainMenuOver(id) {
    if (currentMainId != id) {
        $(id.replace('main', 'img')).src = $(id.replace('main', 'img')).src.replace('.gif', '-over.gif');
    }
}
function mainMenuOut(id) {
    if (currentMainId != id) {
        $(id.replace('main', 'img')).src = $(id.replace('main', 'img')).src.replace('-over.gif', '.gif');
    }
}
function LoadQuickInfo(teamid) {
    var rndi = Math.random() * 20345;
    var req = new Request.HTML({ url: 'quickinfo.php?tid=' + teamid + '&r=' + rndi, evalScripts: true, evalResponse: true,
        onSuccess: function(htmltree, _elements, htmls, scripts) {
            $('quickInfo').set('text', '');
            $('quickInfo').set('html', htmls);
            Slimbox.scanPage();
            $('birthdays').load('birthdays.php');
        },
        onFailure: function() {
            $(menuobj).set('text', 'Fehler beim laden des Menues.');
        }
    });
    req.send();
}
function subMenuOver(id) {
    if (currentId != id) {
        $(id).setStyle('background-Image', 'url(Bilder/buttonOrangeBackground.png)');
        $(id.replace('mnu', 'img')).src = $(id.replace('mnu', 'img')).src.replace('.gif', '-over.gif');
    }
}
function subMenuOut(id) {
    if (currentId != id) {
        $(id).setStyle('background-Image', 'url(Bilder/buttonBlueBackground.png)');
        $(id.replace('mnu', 'img')).src = $(id.replace('mnu', 'img')).src.replace('-over.gif', '.gif');
    }
}
function LoadSubMenu(menuobj, teamid) {
    currentId = '';

    if (currentMainId != '') {
        SetMainMenu('main' + teamid + 'Mannschaft', 2);
    }
    currentMainId = 'main' + teamid + 'Mannschaft';
    var req = new Request.HTML({ url: 'submenu.php?tid=' + teamid, evalScripts: true, evalResponse: true,
        onSuccess: function(htmltree, _elements, htmls, scripts) {
            $(menuobj).set('text', '');
            $(menuobj).set('html', htmls);
            LoadSite('mnustart', 'teamstart.php?tid=' + teamid);
            LoadQuickInfo(teamid);
           
        },
        onFailure: function() {
            $(menuobj).set('text', 'Fehler beim laden des Menues.');
        }
    });
    req.send();
}

function SetFrame() {
    var size = window.getSize();
    var width = 1024;
    if (size.x > 1024) {
        width = size.x;
    }
    $('headRepeater').setStyle('width', width - 647);
    $('mainMenuTable').setStyle('width', width - 20);
    $('tdmainContent').setStyle('width', width - 20 - $('tdSubMenuTable').getSize().x - $('quickInfo').getSize().x);
    $('mainContent').setStyle('width', width - 40 - $('tdSubMenuTable').getSize().x - $('quickInfo').getSize().x);
    $('mainContent').setStyle('height', size.y - $('mainMenuTable').getSize().y - $('mainMenuTable').getPosition().y);
    $('mainMenuSpacer').setStyle('width', $('mainContent').getPosition().x);
    $('mainSite').setStyle('width', width - 20);
    $('sponsorenScroller').setStyle('width', width - 372);

}
function SetSponsoren() {
    var opt = {
        duration: 6000,
        delay: 2000,
        slides: 'qslide',
        auto: true,
        transition: Fx.Transitions.Sine.easeOut, 
        onMouseEnter: function() { this.stop(); },
        onMouseLeave: function() { this.play(); }
    }
    var scroller = new QScroller('sponsorenScroller',opt);
    scroller.load();
    //Fx.Transitions.Cubic.easeOut;
}
/* Give it a selector and onmouseenter, the image will enlarge. onmouseleave, it will revert to its original
Please set a width and height in the html otherwise it won't work properly
Usage:
<img src="image.gif" width="200" alt="" class="bigImage" />
var images = new bigImages({selector:'img.bigImage', fxOptions:{duration:1000,enlargeBy:1.2}}); // Or whatever
*/
var bigImages = new Class({
    Implements: [Options],
    options: {
        selector: 'img.hoverEnlarge',
        enlargeBy: 2,
        fxOptions: {}
    },
    initialize: function(options) {
        this.setOptions(options);
        this.elements = $$(this.options.selector);
        this.elements.each(function(el) {
//            var posX = el.getPosition($('mainSite'));
//            el.setStyle('position', 'absolute');
//            el.setStyle('left', pos.x);
        //            el.setStyle('top', pos.y);
        el.set('morph', { duration: 500, transition: 'bounce:out' });
        });
        this.elements.addEvent('mouseenter', function() {
            //zoom an image when hoverd

            this.setStyle('zIndex', 2);
            var morph = this.get('morph');
            morph.start({ 'width': 125, 'height': 125 });

        }).addEvent('mouseleave', function() {
            this.setStyle('zIndex', 1);
            var morph = this.get('morph');
            morph.start({ 'width': 110, 'height': 110 });
        });
    }
});