/*################################################################################
 D E B U G
 ################################################################################*/

var debugModus = 0; // Debugmodus EIN = 1 || AUS = 0
flyOutVisible = false;

function debug(txt) {
    if (!debugModus || typeof(console) != "object") {
        return;
    }
    else {
        console.log(txt);
    }
}
debug("debugModus = true");


/*################################################################################
 F U N C T I O N S
 ################################################################################*/

function scaleFlyOutContent() {
    flyOutContentHeight = 0;

    var scaleable = $('.flyOutContent');
    var ammount = scaleable.height;

    for (i = 0; i < ammount; i++) {
        if (flyOutContentHeight < scaleable[i].offsetHeight) {
            flyOutContentHeight = scaleable[i].offsetHeight;
        }
    }

    for (i = 0; i < ammount; i++) {
        scaleable[i].style.height = flyOutContentHeight + "px";
    }

    flyOutVisible = true;
}
;


function flyOut() {
    $('.jz__mainNavi.flyout').hover(function () {
        if (flyOutVisible) {
            return true;
        }

        var position = ($('#jz__mainNavi').position());
        $('#jz__flyOutContainer').css('top', position.top + 68);

        $('#jz__flyOutContainer').fadeIn();
        scaleFlyOutContent();

        $('#jz__flyOutContainer').mouseleave(function () {
            $('#jz__flyOutContainer').fadeOut("slow", function () {
                flyOutVisible = false;
            });
        });

    });
}

function flyOutLogin() {
    $('.jz__home_login').click(function () {
        var position = ($('#jz__mainNavi').position());
        $('#jz__flyOutContainerLogin').fadeIn();
        scaleFlyOutContent();

        $('#jz__flyOutContainerLogin').mouseleave(function () {

            $('#jz__flyOutContainerLogin').fadeOut();

        });

    });
}

function toggleMessage() {
    $('.jz__sendMessage').click(function () {
        $(this).toggleClass('Active')
    });
}


$(document).ready(function () {
    flyOut();
    flyOutLogin();
    showOverlay();
    showFaq();
    showLink();
    toggleMessage();
    messages();
    profileSlide();
    showCalendarDetail();
    tabs();
});


// O V E R L A Y


var showOverlay = function () {
    $("a[rel]").overlay({mask:{
        color:'#ebecff',
        loadSpeed:200,
        opacity:0.9
    },

        closeOnClick:false});
}


// A D D  N E T W O R K  T O  P R O F I L E


var showFaq = function () {
    $('.toggle_container').hide();
    $('.trigger').click(function () {

        var trig = $(this);
        if (trig.hasClass('trigger_active')) {
            trig.next('.toggle_container').slideToggle('slow');
            trig.removeClass('trigger_active');
        } else {

            $('.trigger_active').next('.toggle_container').slideToggle('slow');

            $('.trigger_active').removeClass('trigger_active');

            trig.next('.toggle_container').slideToggle('slow');
            trig.addClass('trigger_active')

        }
        ;
        return false;
    });
}

var profileSlide = function () {
    $('.toggle_containerP').hide();
    $('.triggerP').click(function () {
        var trig = $(this);
        if (trig.hasClass('trigger_active')) {
            trig.next('.toggle_containerP').slideToggle('slow');
            trig.removeClass('trigger_active');
        } else {

            $('.trigger_active').next('.toggle_containerP').slideToggle('slow');

            $('.trigger_active').removeClass('trigger_active');

            trig.next('.toggle_containerP').slideToggle('slow');
            trig.addClass('trigger_active')

        }
        ;
        return false;
    });
}

var messages = function () {
    $('.toggle_containerM').hide();
    $('.triggerM').click(function () {

        var trig = $(this);
        if (trig.hasClass('trigger_active')) {
            trig.parent().parent().next('.toggle_containerM').slideToggle('slow');
            trig.removeClass('trigger_active');
        } else {

            $('.trigger_active').parent().parent().next('.toggle_containerM').slideToggle('slow');

            $('.trigger_active').removeClass('trigger_active');

            trig.parent().parent().next('.toggle_containerM').slideToggle('slow');
            trig.addClass('trigger_active')

        }
        ;
        return false;
    });
}


var showLink = function () {
    $('#jz__followTrigger').mouseenter(
        function () {
            $('#jz__follow').css('display', 'block');
        }).mouseleave(function () {
            $('#jz__follow').css('display', 'none');
        });
}

function showCalendarDetail() {
    $('.eventCalender').mouseenter(function () {

        var thisID = this.id;
        var newPosition = $("#" + thisID).offset();
        var showThis = this.id + "DIV";

        $("#" + showThis).fadeIn('fast');
        $("#" + showThis).css('left', newPosition.left + 10);
        $("#" + showThis).css('top', newPosition.top + 30);

        $('.eventCalender').mouseout(function () {
            $("#" + showThis).fadeOut('fast');
        });

    });


}


// overlay
/*var showCalendarDetail = function() {
 $('.eventCalender').each(function(thumb) {
 var layer = this.id+'DIV';

 $(this).mouseenter(function() {
 $('#'+layer).fadeIn('fast');
 });

 $(this).mouseout(function() {
 $('#'+layer).fadeOut('fast');
 });

 });
 }*/


var tabs = (function () {
//    $("#jz__tabs").tabs("#jz__panes > div", { history: true });
    $("#jz__tabs").tabs({ history:true });
});


