// ### SET VARIABLES ###

// Sascha - aberratio GmbH - 25.06.2010
var active_day;
var active_page_a_und_h;
var session_array = Array('a', 'b', 'c', 'd', 'e', 'f');

$(document).ready(function() {
    // ### COMMON FUNCTIONS ###

    // Jan - aberratio GmbH - 14.07.2010
    if (jQuery.inArray('zt-check-in', $(location).attr('href').split('/')) == 5) {
        $.cookie('logged', 'ja', { path: '/' });
    }

    // Sascha - aberratio GmbH - 25.06.2010
    // alert($.cookie('logged'));
    hide_kontakt_layer();
    init();

    // Jan - aberratio GmbH - 06.07.2010
    $(function() {
        $('#image_single a').lightBox();
    });

    // ### WATERMARKS ###

    // Jan - aberratio GmbH - 30.06.2010
    if ($('#login_lastname').length > 0 && $('#login_code').length > 0) {
        $('#login_lastname').watermark('IHR NACHNAME');
        $('#login_code').watermark('IHR CODE');
    }

    // Jan - aberratio GmbH - 30.06.2010
    if ($('#login_lastname_site').length > 0 && $('#login_code_site').length > 0) {
        $('#login_lastname_site').watermark('IHR NACHNAME');
        $('#login_code_site').watermark('IHR CODE');
    }

    // Sascha - aberratio GmbH - 05.07.2010
    if ($('#zt_strasse').length > 0 && $('#zt_plz').length > 0 && $('#zt_ort').length > 0) {
        $('#zt_strasse').watermark('Ihre Straße');
        $('#zt_plz').watermark('Ihre Postleitzahl');
        $('#zt_ort').watermark('Ihr Wohnort');
    }

    // Sascha - aberratio GmbH - 05.07.2010
    if ($('#pn_strasse').length > 0 && $('#pn_plz').length > 0 && $('#pn_ort').length > 0) {
        $('#pn_strasse').watermark('Ihre Straße');
        $('#pn_plz').watermark('Ihre Postleitzahl');
        $('#pn_ort').watermark('Ihr Wohnort');
    }

    // ### DISPLAY/HIDE CHECK-IN ###

    // Jan - aberratio GmbH - 12.07.2010
    if ($("input[name='nimmt_teil']:checked").val() == 'N') {
        $('#check-in-block').hide();
    }

    // Jan - aberratio GmbH - 12.07.2010
    if (!($("input[name='tag1']").is(":checked"))) {
        $('#sessions').hide();
    }

    // Jan - aberratio GmbH - 12.07.2010
    $("input[name='nimmt_teil']").click(function() {
        if ($("input[name='nimmt_teil']:checked").val() == 'N') {
            $('#check-in-block').hide();
        } else {
            $('#check-in-block').show();
        }
    });

    // Jan - aberratio GmbH - 12.07.2010
    $("input[name='tag1']").click(function() {
        if ($("input[name='tag1']").is(":checked")) {
            $('#sessions').show();
        } else {
            $('#sessions').hide();
        }
    });

    // ### NEWS LIST ITEMS ###

    // Jan - aberratio GmbH - 14.07.2010
    $('.news-list-item').mouseover(function() {
        clearTimeout(this.timer); // den Timer in diesem DIV l�schen
        $(this).children('.news-list-content').show();
        $(this).children('h3').css('font-weight', 'bold');
    });

    // Jan - aberratio GmbH - 14.07.2010
    // Erweiterung Delay - Sascha - 26.07.2010
    $('.news-list-item').mouseout(function() {
        var div_obj = this; //Div merken
        this.timer = setTimeout(function() { //einen Delay in diesem DIV ablegen um flackern im IE zu vermeiden
            $(div_obj).children('.news-list-content').hide();
            $(div_obj).children('h3').css('font-weight', 'normal');
        }, 10);
    });

    // ### LOGIN AND CONTACT LAYER ###

    // Jan - aberratio GmbH - 19.07.2010
    $('#box_logout').click(function() {
        $.cookie('logged', null, { path: '/' });
    });

    // Jan - aberratio GmbH - 19.07.2010
    $('#content_logout').click(function() {
        $.cookie('logged', null, { path: '/' });
    });

    // Jan - aberratio GmbH - 14.07.2010
    $('.suckerfish').mouseover(function() {
        if ($(this).attr('id') == 'box_anmelden') {
            if ($.cookie('logged') == 'ja') {
                return false;
            }
            $(this).css('width', '276px');
//            $(this).css('height', '230px');
            $(this).css('height', '260px');
            $(this).children('#box_login').css('margin-left', '61px');
            $(this).children('div').show();
        } else {
            $(this).css('height', '230px');
            $(this).children('div').children('ul').show();
        }
    });

    // Jan - aberratio GmbH - 14.07.2010
    $('.suckerfish').mouseout(function() {
        if ($(this).attr('id') == 'box_anmelden') {
            $(this).css('width', '215px');
            $(this).css('height', '120px');
            $(this).children('#box_login').css('margin-left', '0');
            $(this).children('div').hide();
        } else {
            $(this).css('height', '120px');
            $(this).children('div').children('ul').hide();
        }
    });

    //Sascha - aberratio GmbH - 21.07.2010
    $('.reiter').children('a').click(function() {
        btn = $(this).attr('id');
        id = btn.substring(btn.length-1, btn.length);
        show_session(id);
        return false;
    });
});

// ### LOGIN AND CONTACT LAYER ###

// Sascha - aberratio GmbH - 08.07.2010
function init_kontakt_layer()
{
    $('#kontakt_layer').hide(0);
}

// Sascha - aberratio GmbH - 08.07.2010
function hide_kontakt_layer()
{
    $('#kontakt_layer').hide(500);
}

// Sascha - aberratio GmbH - 08.07.2010
function open_kontakt_layer(name, uid)
{
    $('#kontakt_layer').show(500);
    $('#name_empf').html(name);
    $("input[name='empf_uid']").val(uid);
    $("input[name='layer_subject']").watermark('Betreff');
    $("textarea[name='layer_message']").watermark('Ihre Nachricht');
}

// ### INITIALIZE AND SET LOGIN AND NAVIBOXES ###

// Sascha - aberratio GmbH - 25.06.2010
function init()
{
    if ($.cookie('logged') == 'ja') {
        // $('#box_logout').show();
    }

    // $('#box_zeitschriftentage').css('height', '120px');
    // $('#box_zeitschriftentage').children('div').children('ul').hide();

    // $('#box_publishers_night').css('height', '120px');
    // $('#box_publishers_night').children('div').children('ul').hide();

    // $('#box_anmelden').css('width', '215px');
    // $('#box_anmelden').css('height', '120px');
    // $('#box_anmelden').children('#box_login').css('margin-left', '5px');
    // $('#box_anmelden').children('div').hide();
}

// ### DISPLAY/HIDE EVENTS PER DAY ###

// Sascha - aberratio GmbH - 02.07.2010
function show_day(id)
{
    if (active_day != id) {
        active_day = id;
        if (id == 2) {
            active = 2;
            inactive = 1;
        } else {
            active = 1;
            inactive = 2;
        }

        $('#day_'+active).show(0);
        $('#day_'+active+'_btn').addClass('active');

        $('#day_'+inactive).hide(0);
        $('#day_'+inactive+'_btn').removeClass('active');

        show_session('a');
    }
}

// Sascha - aberratio GmbH - 02.07.2010
function show_session(id)
{
    hide_all_sessions();
    $('#session_btn_'+active_day+'_'+id).addClass('active');
    $('#session_'+active_day+'_'+id).show(10);
}

// Sascha - aberratio GmbH - 02.07.2010
function hide_session(id)
{
    $('#session_btn_'+active_day+'_'+id).removeClass('active');
    $('#session_'+active_day+'_'+id).hide(10);
}

// Sascha - aberratio GmbH - 02.07.2010
function hide_all_sessions()
{
    for (i=0;i<session_array.length;i++) {
        hide_session(session_array[i]);
    }
}

// ### DISPLAY/HIDE HOTELS AND APPROACH ###

// Sascha - aberratio GmbH - 02.07.2010
function select_page_a_und_h(id)
{
    if (active_page_a_und_h != id) {
        active_page_a_und_h = id;
        if (id == 'hotel') {
            active = 'hotel';
            inactive = 'anfahrt';
        } else {
            active = 'anfahrt';
            inactive = 'hotel';
        }

        $('#'+active).show(0);
        $('#'+active+'_btn').addClass('active');

        $('#'+inactive).hide(0);
        $('#'+inactive+'_btn').removeClass('active');
    }
}
