﻿function init_browser() {
    isIE7=false;if (window.XMLHttpRequest){if(document.all){isIE7=true}}
    isIE6=(navigator.userAgent.indexOf("MSIE 6.") != -1) 
};
function init_browser_fixes() {
    $("#menu li:last").css("border-bottom","0px #FFF solid")    
    if ($.browser.mozilla) {
        $("#search_panel span").css("position","relative").css("top","3px")
        $(".jquery-selectbox").css("width", "100px")
        $(".jquery-selectbox .jquery-selectbox-list").css("width", "87px")
    }
    if (jQuery.browser.safari) {
        $("#language-select").css("left", "3px")
        $("#header .header-foot").css("height","9px")
        $("#choose_language .jquery-selectbox-currentItem").css("line-height","12px")
        $(".jquery-selectbox").css("width", "100px")
    }
    if (isIE6) {
        $(".box4").css("margin-top", "-3px")
        $("#footer").css("margin-top", "-24px")
        $(".jquery-selectbox").css("width", "100px")
        $(".jquery-selectbox .jquery-selectbox-list").css("width", "81px")
        //$("#menu li.hl ul").css('padding-top','5px')
        $("#menu li.hl ul a").css('margin-left','25px')
        $("#menu li.hl ul li.hl ul a").css('margin-left','16px')
    }
    if (isIE7) {
        $("#header .header-visual").css("padding-bottom", "25px")
        $("#footer").css("margin-top", "-7px")
        $(".jquery-selectbox").css("width", "100px").css("top", "0px")
        $(".jquery-selectbox .jquery-selectbox-list").css("width", "87px")
    }
}
function init_language_selectbox() {
    select_field = $("#language-select")
    if (jQuery.browser.mozilla) { select_field.css("width", "114px") }
    if (jQuery.browser.explorer) { select_field.css("width", "90px") }
    if (jQuery.browser.safari) { select_field.css("width", "92px") }
    select_field.selectbox() //.bind('change', function(){ $(this).remove() });
};
function init_rahmen_button() {
    $("#button").toggle(
        function() {
            $("#layout,#button").animate({ marginLeft: "-918px" }, 1500);
            $("body").css({ backgroundPosition: "0 0" }).animate({ backgroundPosition: "-918px 0px" }, 1500);
            $("#turner").css({ backgroundPosition: "918px 0px" }).animate({ backgroundPosition: "0px 0px" }, 1500, function() { $("#copy").fadeIn() });
        },
        function() {
            $("#copy").fadeOut(
                function() {
                    $("#layout,#button").animate({ marginLeft: "0px" }, 1500);
                    $("body").animate({ backgroundPosition: "0px 0px" }, 1500);
                    $("#turner").animate({ backgroundPosition: "918px 0px" }, 1500);
            })
        }
    );
};
function equal_box_heights(selector) {
    var boxes = $(selector); // $('#box2wrap').equalHeights();
    if (boxes.length > 0) {
        if ( $(boxes[0]).height() > $(boxes[1]).height() ) { $(boxes[1]).height( $(boxes[0]).height() ) }
        if ( $(boxes[1]).height() > $(boxes[0]).height() ) { $(boxes[0]).height( $(boxes[1]).height() ) }
    }
};

//
function init_global_rollover() {
    
      continents = $("#select_continent div.continent");
    if (continents.length >= 1) {
        
        continents.children("div.select_list").hide();
        continents.hover(
            function() { $(this).children("div.select_list").show(); },
            function() { $(this).children("div.select_list").hide(); }
        );
        if (isIE6 || isIE7) { // pngFix..
            continents.children("div.select_list").css('background-image').match(/\/website\/layout\/img\/design\/(.+)\"\)/);
            match = RegExp.$1;
            try { continents.children("div.select_list").css('background-image','none') } catch(e) {};
            if (match) { try { continents.children("div.select_list").css('filter',"progid:DXImageTransform.Microsoft.AlphaImageLoader (src='/website/layout/img/design/"+ match + "', sizingMethod='scale');") } catch(e) {}; };
        };
        
    }
};
//


//
function init_menu() {
    if (isIE7 || jQuery.browser.safari || jQuery.browser.mozilla) {
        var menu = $("#menu"); if (menu) {
            menu.addClass("sf-menu sf-vertical")
            //menu.supersubs({ minWidth: 12, maxWidth: 300, extraWidth: 1 })
            menu.superfish({ delay: 500, speed: "fast", autoArrows: false, dropShadows: false });
        }
    }
}
//


function get_random_int(_i, _max) {
    _n = Math.floor( Math.random()*(_max) )
    // console.log("get_random_int: "+ _n);
    return (_i == _n) ? get_random_int(_i, _max) : _n;
}
function init_cookies() {
    try {
        // if ( !($.cookie('turner_state') == "sequenz") || !($.cookie('turner_state') == "random") ) {
        //     $.cookie('turner_state', "sequenz");
        //     $.cookie('turner_count', "0");
        // }
        if ( !$.cookie('turner_count') ) { $.cookie('turner_count', "0"); }
        if ( !$.cookie('turner_state') ) { $.cookie('turner_state', "sequenz"); }
        
        turner_id = parseInt( $.cookie('turner_count') );
        if ( $.cookie('turner_state') == "random" ) {
            _n = get_random_int(turner_id, 7)
            // console.log("random: "+ _n);
            $("#turner").css("background-image", "url('/website/layout/img/design/turner" + _n + ".jpg')");
            turner_id = _n;
        }
        if ( $.cookie('turner_state') == "sequenz" ) {
            // console.log("sequenz: "+ turner_id);
            $("#turner").css("background-image", "url('/website/layout/img/design/turner" + turner_id + ".jpg')");
            if (turner_id >= 6) {
                $.cookie('turner_state', "random")
                // console.log("sequenz => to random change");
            } else {
                turner_id++;
            }
        }
        $.cookie('turner_count', turner_id)
        
    } catch(e) {};
}

function init_FLIR() {
    $("div.header-visual h2").each( function() {
        if (isIE6) { this.innerHTML = this.innerHTML; }
        else { this.innerHTML = this.innerHTML; }
    });
    FLIR.init({ path: 'http://projekte.communicode.de/facelift/' });
    $("div.header-visual h2").each( function() { FLIR.replace(this, new FLIRStyle({ output:'gif', mode:'wrap', cFont:'univers55', cBackground: "FFFFFF" }) ) } );
    $("div.header-visual p").each( function() { FLIR.replace(this, new FLIRStyle({ output:'gif', mode:'wrap', cFont:'univers55', cBackground: "FFFFFF" }) ) } );
}

$(document).ready(function() {
    init_rahmen_button()
    init_browser()
    init_language_selectbox()
    init_browser_fixes()
    // init_sifr()
 //   $("div.context_col a").fancybox( { 'hideOnContentClick': true, 'overlayShow' :    true, 'overlayOpacity' : 0.0 } );
 //   $(".fancybox").fancybox( { 'hideOnContentClick': true, 'overlayShow' :    true, 'overlayOpacity' : 0.0 } );
    init_cookies()
    $('table span').parent('td').css('white-space','nowrap');
    $('table span').parent('td:first').css('white-space','normal');    
    // EQUAL HEIGHTS---------------------------------------
    $.ajax({
        type: 'GET',
        url: '/website/layout/misc/javascript/jquery.equalHeight.js',
        success: function() {
            $('.equal, .box1').equalHeights();
            $('.box2').equalHeights();
        },
        dataType: 'script',
        cache: true
    });
    //$('div.termine').pngFix();


// HOME SLIDESHOW---------------------------------------
    $.ajax({
        type: 'GET',
        url: '/website/layout/misc/javascript/jquery.cycle.all.min.js',
        success: function() {
                $('#slideshow').cycle({ 
                    fx:      'fade', 
                    timeout:  6000, 
                    before:   onBefore 
                }); 
                var totalSlideCount = 5; 
                function onBefore(curr, next, opts) { 
                    if (!opts.addSlide) 
                        return; 
                    var currentImageNum = parseInt(next.src.match(/slide(\d)/)[1]); 
                    if (currentImageNum == totalSlideCount) { 
                        opts.addSlide = null; 
                        return; 
                    } 
                    opts.addSlide('<img src="/website/layout/home_slide/slide'+(currentImageNum+1)+'.jpg" width="683" height="287" alt="" />'); 
                }; 
        },
        dataType: 'script',
        cache: true
    });

// SEARCH RESET---------------------------------------
$("#search_panel input").click(function () {
$(this).val("");
});
});

// Sprachwechsel Select Box ---------------------
function spkz() {
 location.href = document.change.go.value;
}
