// ### SET VARIABLES ###
//var cat_array = Array('anzeigen', 'vertrieb', 'digital', 'medienpolitik', 'people');
var index = 0;
var active_expand_menu = null;

$(document).ready(function() {
    // ### COMMON FUNCTIONS ###
    mac_os_fix();
//    init_top_news();
    init_content_menu();
    startseite_vdztv_thumbs();
});

//### MAC OS CSS fix ###
//Sascha - aberratio GmbH - 11.02.2011
function mac_os_fix()
{
    if($.client.os == 'Mac'){
        $('#content .box.top .kategorie_navigation').addClass('mac_os');
    }
}

// ### TOP NEWS ###
//Sascha - aberratio GmbH - 19.11.2010
/*
function init_top_news()
{
    //startseite
    show_top_news('digital');

    $('#link_anzeigen').click(function() {
        show_top_news('anzeigen');
        return false;
    });
    $('#link_vertrieb').click(function() {
        show_top_news('vertrieb');
        return false;
    });
    $('#link_digital').click(function() {
        show_top_news('digital');
        return false;
    });
    $('#link_medienpolitik').click(function() {
        show_top_news('medienpolitik');
        return false;
    });
    $('#link_people').click(function() {
        show_top_news('people');
        return false;
    });
    $('#skip_l').click(function() {
        top_news_skip('left');
        return false;
    });
    $('#skip_r').click(function() {
        top_news_skip('right');
        return false;
    });

}
function show_top_news(cat)
{
    index=0;
    while(cat_array[index] != cat){
        index++;
    }
    hide_all_top_news();
    $('.top_'+cat).show(200);
    $('#link_'+cat).addClass('active');
}
function hide_all_top_news()
{
    for (i=0;i<cat_array.length;i++) {
        hide_top_news(cat_array[i]);
    }
}
function hide_top_news(cat)
{
    $('#link_'+cat).removeClass('active');
    $('.top_'+cat).hide(200);
}
function top_news_skip(direction){
    switch(direction){
        case 'right':
            index++;
            if(index>=cat_array.length){
                index = 0;
            }
            break;
        default :
            index--;
            if(index<0){
                index = cat_array.length-1;
            }
            break;
    }
    show_top_news(cat_array[index]);
}
*/

//Expand Menu
function init_content_menu(){

    $('<div class="expand_content"></div>').appendTo('.expand_menu');

    var parents = $('.expand_menu');
    $.each(parents, function(){
        var parent = $(this);
        var target = $(this).find('.expand_content');
        var kids = $(this).children().not('.csc-header:first').not('.expand_content');
        $.each(kids, function(){
              $(this).appendTo($(target));
        });
    });

    $('.expand_menu > .csc-header').click(function() {
        if(active_expand_menu == this){
            active_expand_menu = null;
            hide_all_content_menu_text();
        } else {
            active_expand_menu = this
            show_content_menu_text(this);
        }
        return false;
    });

    //Nur bei den Expand-Kontakt boxen
    $('.expand_menu .expand_content').find('.kontakt:odd').addClass('odd');

    hide_all_content_menu_text(0);

}
function hide_all_content_menu_text(speed){
      $('.expand_menu .expand_content').slideUp(speed);
      $('.expand_menu .expand_content').slideUp(speed);
}
function show_content_menu_text(headline){
    hide_all_content_menu_text(400);
    $(headline).parent().find('.expand_content').slideDown(400);
    $(headline).parent().find('.expand_menu').slideDown(400);
    timeout_var = window.setTimeout(function () { scroll_up_function(headline); }, 400);
    //scroll nach oben
}
function scroll_up_function(headline){
    var top_position = $(headline).position();
    $('html,body').animate({scrollTop: top_position.top-80}, 500);
    window.clearInterval(timeout_var);
}

function startseite_vdztv_thumbs(){
    $('#bodyID_502 #content #spalte_haupt .csc-textpic-imagewrap ul li:last-child').addClass('last');
}


function open_tipafriend_popup (url) {
    fenster = window.open(url, "Popupfenster", "width=536,height=428,resizable=yes");
    fenster.focus();
    return false;
}
