//#####################
// definieren der Objecte und 
// Construktoren
//#####################

//#Region allgemeine Objekte
var slideme = new Object();
var PluginsLoader = new Object();
var blockquote = new Object();
var search_input = new Object();
var comment = new Object();
var directLink = new Object();
var LoginAuth = new Object();

var phpfile = new Object();
phpfile.items = new Object();
//#EndRegion

//#Region menuentry Objekte
var menu = new Object();
menu.submenu = menu.constructor;
menu.topmenu = menu.constructor;
menu.sidebox = menu.constructor;

menu.submenu.items = new Object();
menu.submenu.items[0] = 0;

menu.topmenu.items = new Object();
menu.topmenu.items[0] = 0;

menu.sidebox.news = new Object();
menu.sidebox.links = new Object();
//#EndRegion

//#Region dialog Objekte
var dialog = new Object();
dialog.error = new Object();
dialog.check = new Object();
dialog.quest = new Object();
dialog.attributs = {
    autoOpen: false,
    resizable: false,
    buttons: {
        "OK": function () {
            $(this).dialog("close");
        }
    },
    closeOnEscape: false,
    modal: true,
    width: 280,    
    dialogClass: "dialog",
    closeText: 'hide',
    draggable: false
};
//#EndRegion

//#Region globale Objekte
var global = new Object();
global.parahash = new Object();
global.parahash.kat_slug = "";
global.parahash.titel = "";
global.parahash.seite = "";
global.parahash.id = "";
//#EndRegion

//#Region request Objekte
var request = new Object();
request.ajax = request.constructor();
//#EndRegion

//#####################
// Dialog Boxen 
// dialog.error, dialog.check und 
// dialog.quest
//#####################

//#Region dialog.insert -> Einginden der 3 Dialogboxen am Ende des Bodys
dialog.insert = new function () {
    $(document).ready(function () {
        Dialogboxes = "<div id='Dialog_check' class='ui-state-check ui-corner-all Dialog_Box' style='margin:2px;'>" +
		        "<span class='ui-icon ui-icon-check' style='float: left; margin-right: .3em;'></span>" +
		        "<span id='DialogText_check'></span>" +
                "</div>" +
                "<div id='Dialog_failed' class='ui-state-error ui-corner-all Dialog_Box' style='margin:2px;'>" +
	                "<span class='ui-icon ui-icon-alert' style='float: left; margin-right: .3em;'></span> " +
	                "<span id='DialogText_failed'></span>" +
                "</div>" +
                "<div id='Dialog_quest' class='ui-state-blue ui-corner-all Dialog_Box' style='margin:2px;'>" +
	                "<span class='ui-icon ui-icon-help' style='float: left; margin-right: .3em;'></span>" +
	                "<span id='DialogText_quest'></span>" +
                "</div>";

        $("body").append(Dialogboxes);

        $('.Dialog_Box').dialog(dialog.attributs);
        $(".ui-dialog-content").css("height", "auto");
    });
}
//#EndRegion

//#Region dialog.error.show -> Dialogbox für Fehlermeldung
dialog.error.show = function (attr) {
    $("#DialogText_failed").html(attr.msg)    
    $('#Dialog_failed').dialog("option", "title", attr.titel);
    if (attr.button) {
        $("#Dialog_check").dialog("option", "buttons",
            attr.button
        );
    }
    $('#Dialog_failed').dialog("open");
    $(".Dialog_Box").bind("dialogclose", function (event, ui) {
        $(this).dialog(dialog.attributs);
    });

}
//#EndRegion

//#Region dialog.check.show -> Dialogboxen für Erfolgsmeldungen
dialog.check.show = function (attr) {
    $("#DialogText_check").html(attr.msg).css("height", "100px");
    $('#Dialog_check').dialog("option", "title", attr.titel);
    if (attr.button) {
        $("#Dialog_check").dialog("option", "buttons", 
            attr.button
        );
    }
    $('#Dialog_check').dialog("open");
    $(".Dialog_Box").bind("dialogclose", function (event, ui) {
        $(this).dialog(dialog.attributs);
    });
}
//#EndRegion

//#Region dialog.quest.show -> Dialogbox für Abfragen (z.b. Ja / Nein)
dialog.quest.show = function (attr) {
    $("#DialogText_quest").html(attr.msg).css("height", "100px");
    $('#Dialog_quest').dialog("option", "title", attr.titel);
    if (attr.button) {
        $("#Dialog_check").dialog("option", "buttons",
            attr.button
        );
    }
    $('#Dialog_quest').dialog("open");
    $(".Dialog_Box").bind("dialogclose", function (event, ui) {
        $(this).dialog(dialog.attributs);
    });
}
//#EndRegion

//#####################
// request Object 
// request.ajax
//#####################

//#Region request.ajax -> Ajaxrequest mit vordefinierten Paramtern, die genutzt werden, sollte der parameter der übergeben wurde leer sein
request.ajax = function (parameter) {
    method = $.extend({
        destination: "", // der Ort wo das serverseitige Script liegt.
        type: "json", // xml, json, text, html
        success: function (content) { }, // function was ausgeführt werden soll, wenn der ajaxrequest erfolgreich war
        error: function (err, errtext) {
            dialog.error.show({
                msg: "Ajaxerror " + errtext + " " + err.status + " in object " + parameter.requester + ".",
                titel: "Error while ajax Request"
            });
        }, // fuction die aufgerufen werden soll, wenn der ajaxrequest nicht erfolgreich war (Fehlermeldung erscheint unabhängig)
        complete: function () { }, // function die aufgerufen werden soll, wenn wenn der ajaxrequest abgeschlossen (nach success und error) ist
        requester: "" //Object von dem aus der request abgesetzt werden soll.
    }, parameter);

    if (method.requester == "") {
        dialog.error.show({
            msg: "Error: the property 'requester' in 'request.ajax' function may not be empty and are not optional!",
            titel: "Propertyerror"
        });
        return false;
    }
    else {
        for (var property in method) {
            if (method[property] == "") {
                dialog.error.show({
                    msg: "Error: the property '" + property + "' in 'request.ajax' may not be empty! <br /><br />Called object: '" + method.requester + "()'",
                    titel: "Propertyerror"
                });
                return false;
            }
        }
    }

    $.ajax({
        url: method.destination,
        dataType: method.type,
        success: method.success,
        error: method.error,
        complete: method.complete
    });
}
//#EndRegion
