//###############################
// Construktoren
//###############################
menu.sidebox.news.insert = function () {
    $.ajax({
        url: phpfile.items.news,
        dataType: "json",
        success: function (json) {
            json.sort(sort_by('NODE_TIMESTAMP', true, parseInt));

            var ListNews = "";
            var table_Class = "";
            if ($.browser.msie) {
                table_Class = "Menulinkstyle_IE";
            }
            else {
                table_Class = "Menulinkstyle";
            }            

            for (i = 0; i < json.length; i++) {
                if ($.browsercheck()) {
                    var Date_Insert = "<span style='float:right;'>" + json[i].NODE_DATE_DAY + "</span>";
                }
                else {
                    var Date_Insert = "<span style='position:absolute; right:0px;'>" + json[i].NODE_DATE_DAY + "</span>";
                }

                ListNews += "<a style='cursor:pointer;' id='" + json[i].ID + "' rel='" + json[i].NODE_SLUG + "' class='Menulink Menulink_hover Menunews'>" +
						"<table style='margin-bottom:0.9em; position:relative;'><tr><td valign='middle'>" +
						"<div style='position:relative;'><div class='Menulinkdiv ui-corner-all'>" +
						"</div><table class='Menulinktext " + table_Class + "'><tr>" +
						"<td class='_marker' style='color:#FFCC00; width:10px;' align='left' valign='middle'></td>" +
						"<td class='Menu_Node_Titel' valign='middle'>" + json[i].NODE + Date_Insert +
						"</td></tr></table></div></td></tr></table></a>";
            }
            $("#news-Menu").append(ListNews);
        },
        error: function (jqXHR, textStatus, errorThrown) {
            $("#news-Menu").html(textStatus + ": " + errorThrown);
        },
        complete: function () {
            $("#news-Menu").addClass("menu-entry-news");
            $(".Menulink_news").bind("click", function () {
                $("._marker").html("");
                $("._marker").parents(".Menulink_hover").find(".Menulinktext").css({ "font-weight": '' });

                $("._selected").removeClass("_selected");
                $(this).addClass("_selected");

                $(this).find("._marker").html("<font style='color:#FFCC00;'><b>&lt;</b></font>");
                $(this).find(".Menulinktext").css({ "font-weight": "bold" });

                var this_id = $(this).attr("id");

                $.ajax({
                    url: phpfile.items.node_file + "?id=" + this_id,
                    dataType: "json",
                    success: function (json) {
                        var insert_this = "";
                        if (json[0].NODE_TXT.indexOf("<!-- next -->") >= 0) {
                            var insert_text = json[0].NODE_TXT.replace("<p><!--more--></p>", "").split("<!-- next -->");

                            for (i = 0; i < insert_text.length; i++) {
                                page = i + 1;

                                insert_this = insert_this + "<div id='p" + page + "' style='display:none;' class='_pages'>" + insert_text[i] + "</div>";
                            };
                        }
                        else if (json[0].NODE_TXT.indexOf("<p><!--nextpage--></p>") > 0) {
                            var insert_text = json[0].NODE_TXT.replace("<p><!--more--></p>", "").split("<p><!--nextpage--></p>");

                            for (i = 0; i < insert_text.length; i++) {
                                page = i + 1;

                                insert_this = insert_this + "<div id='p" + page + "' style='display:none;' class='_pages'>" + insert_text[i] + "</div>";
                            };
                        }
                        else {
                            insert_this = json[0].NODE_TXT.replace("<p><!--more--></p><br />", "");
                        }

                        $("#node-text").html(insert_this);

                        if (json[0].NODE_COMMENT == "open") {
                            comment.install({ id: this_id })
                        }

                        $("#Node-Titel").html(" <font style='color:#FFCC00;'><b>&gt;</b></font> " + json[0].NODE_TITEL);
                        var kat_hash = global.parahash.kat_slug; //kategorie[0].toString().toLowerCase().replace(/\s/g, "-");
                        var titel_hash = ""; //json[0].NODE_TITEL.toString().toLowerCase().replace(/\s/g, "-").replace(/&uuml;/g, "ü").replace(/&Uuml;/g, "Ü").replace(/&auml;/g, "ä").replace(/&Auml;/g, "Ä").replace(/&ouml;/g, "ö").replace(/&Ouml;/g, "Ö").replace(/&szlig;/g, "ß");

                        location.hash = "!/" + kat_hash;
                    },
                    error: function (data, Errortext) {
                        $("#Node-Titel").html(" <font style='color:#FFCC00;'><b>&gt;</b></font> AJAX " + Errortext + " - " + data.status);
                        $("#node-text").html(Errortext + " - " + data.status);
                    },
                    complete: function () {
                        PluginsLoader.run()
                    }
                });
            });
        }
    });
}

menu.sidebox.links.insert = function () {        
    $.ajax({
        url: phpfile.items.links,
        dataType: "json",
        success: function (json) {            
            var ListLink = "";
            if ($.browser.msie) {
                var table_Class = "Menulinkstyle_IE";
            }
            else {
                var table_Class = "Menulinkstyle";
            }

            for (i = 0; i < json.length; i++) {
                if ($.browsercheck()) {
                    var Date_Insert = "<span style='float:right;'>" + json[i].DESCR + "</span>";
                }
                else {
                    var Date_Insert = "<span style='position:absolute; right:0px;'>" + json[i].DESCR + "</span>";
                }

                ListLink += "<a target='" + json[i].TARGET + "' style='cursor:pointer;' id='" + json[i].ID + "' class='Menulink_externLink Menulink_hover' href='" + json[i].LINK + "'>" +
						"<table style='margin-bottom:0.9em; position:relative;'><tr><td valign='middle'>" +
						"<div style='position:relative;'><div class='Menulinkdiv ui-corner-all'>" +
						"</div><table class='Menulinktext " + table_Class + "'><tr>" +
						"<td class='_marker' style='color:#FFCC00; width:10px;' align='left' valign='middle'></td>" +
						"<td class='Menu_Node_Titel' align='left' valign='middle'>" + json[i].LINKNAME +  Date_Insert +
						"</td></tr></table></div></td></tr></table></a>";
            }
            $("#links").append(ListLink);
        },
        error: function (jqXHR, textStatus, errorThrown) {
            $("#links").html(textStatus + ": " + errorThrown);
        },
        complete: function () {            
        }
    });
}

menu.sidebox.show = function () {   
    if ($(".Menunews").length == 0) {        
        menu.sidebox.news.insert()
        menu.sidebox.links.insert()
    }
}

menu.submenu.complete = function () {
    $("#pager").html("");
    $("#node-text").html("<img id='loading_gif' src='IMG/loading_content.gif' />");                

    var url_para = location.href.split("?");
    var indexer = 0;

    //Parameter holen
    if (location.hash != "" && location.hash != "!") {
        var split_location = location.hash.substr(2, location.hash.length).split("/");
        for (i = 0; i < split_location.lenght; i++) {
            split_location[i] = split_location[i].replace("/", "");
        }

        if (split_location.length == 4) {
            global.parahash.kat_slug = split_location[1].toLowerCase();
            global.parahash.titel = split_location[2].toLowerCase();
            global.parahash.seite = split_location[3];
        }
        else if (split_location.length == 3) {
            global.parahash.kat_slug = split_location[1].toLowerCase();
            global.parahash.titel = split_location[2].toLowerCase();
            global.parahash.seite = "";
        }
        else if (split_location.length == 2) {
            global.parahash.kat_slug = split_location[1].toLowerCase();
            global.parahash.titel = "";
            global.parahash.seite = "";
        }
    }
    else if (url_para[1]) {
        if (url_para[1].substr(url_para[1].length - 1, 1) == "#") {
            url_para = url_para[1].substr(0, url_para[1].length - 1).split("=");
        }
        else {
            url_para = url_para[1].split("=");
        }

        global.parahash.kat_slug = "";
        global.parahash.titel = parseInt(url_para[1]);
        global.parahash.seite = "";
    }

    var Found = 0;
    
    //Link clicken
    if (global.parahash.titel != "" && global.parahash.kat_slug != "") {
        $("#" + global.parahash.kat_slug + "-Menu").find(".Menulink_hover").each(function () {
            if ($(this).attr("rel") == global.parahash.titel){ //html().toLowerCase().indexOf(global.parahash.titel) > -1) {
                if (!$(this).hasClass("_selected")) {
                    directLink.load();
                    Found = 1;
                }
            }
        });
    }
    else if (global.parahash.titel != "" && global.parahash.kat_slug == "") {
        $(".Menulink").each(function () {
            if ($(this).attr("id") == global.parahash.titel) {                
                if (!$(this).hasClass("_selected")) {
                    directLink.load();
                    Found = 1;
                }
            }
        });
    }
    else if (global.parahash.titel == "" && global.parahash.kat_slug != "") {
        $("input[name='Radio-Menu']").each(function () {
            if ($(this).val() == global.parahash.kat_slug + "-Menu") {
                if ($(this).attr("checked") == false) {                    
                    $(this).click();
                    Found = 1;
                }
            }
        });
    }
    else if (global.parahash.titel == "" && global.parahash.kat_slug == "") {
        if (indexer == 0) {
            $("#iRadio-Menu-H").click();
            Found = 1;
            indexer++;
        }
    }
	
    if (Found == 0 || parseInt(url_para[1]) == 404) {		
        $("#node-text").load("fehler/fehler.htm #404");
    }
    else if (parseInt(url_para[1]) == 401) {
        $("#node-text").load("fehler/fehler.htm #401");
    }
    else if (parseInt(url_para[1]) == 400) {
        $("#node-text").load("fehler/fehler.htm #400");
    }
    else if (parseInt(url_para[1]) == 403) {
        $("#node-text").load("fehler/fehler.htm #403");
    }
    else if (parseInt(url_para[1]) == 500) {
        $("#node-text").load("fehler/fehler.htm #500");
    }

    //$("#iRadio-Menu-H").click();
    $(".menu-button-set").buttonset("refresh");
}

menu.submenu.insert = function (index) {
    var myVal = menu.topmenu.items[index];

    if (index != undefined) {        
        var myNameArr = myVal.split("-");
        var myName = myNameArr[0];

        var SubMenu = "<div style='display:none;' class='menu-entry' id='" + myVal + "'></div>";

        $("#menu-entry-div").prepend(SubMenu);

        $.ajax({
            url: phpfile.items.menu_file + "?m=" + myName,
            dataType: "json",
            success: function (json) {
                json.sort(sort_by('NODE_TIMESTAMP', true, parseInt));

                var List = "";
                if ($.browser.msie) {
                    var table_Class = "Menulinkstyle_IE";
                }
                else {
                    var table_Class = "Menulinkstyle";
                }

                for (i = 0; i < json.length; i++) {
                    if ($.browsercheck()) {
                        var Date_Insert = "<span style='float:right;'>" + json[i].NODE_DATE_DAY + "</span>";
                    }
                    else {
                        var Date_Insert = "<span style='position:absolute; right:0px;'>" + json[i].NODE_DATE_DAY + "</span>";
                    }

                    List += "<a style='cursor:pointer;' id='" + json[i].ID + "' rel='" + json[i].NODE_SLUG + "' class='Menulink Menulink_hover'>" +
						"<table style='margin-bottom:0.9em; position:relative;'><tr><td valign='middle'>" +
						"<div style='position:relative;'><div class='Menulinkdiv ui-corner-all'>" +
						"</div><table class='Menulinktext " + table_Class + "'><tr>" +
						"<td class='_marker' style='color:#FFCC00; width:10px;' align='left' valign='middle'></td>" +
						"<td class='Menu_Node_Titel' valign='middle'>" + json[i].NODE + Date_Insert +
						"</td></tr></table></div></td></tr></table></a>";
                }

                $("#" + myVal).html(List);
            },
            error: function (jqXHR, textStatus, errorThrown) {
                $("#" + myVal).html(textStatus + ": " + errorThrown);
            },
            complete: function () {
                if (index < menu.topmenu.items[0]) {
                    index++;
                    menu.submenu.insert(index)
                }
                else {
                    menu.sidebox.show()                                       
                    menu.submenu.complete()
                }
            }
        });
    }

    $(".menu-button-set").button("update");
}

//Run / Ausführ Klassen
slideme.run = function (slider_file) {
    var destination = $(".slideshow").html();
    
	if (destination != null){
		$.ajax({
			url: slider_file + "?destination=" + destination,
			dataType: "json",
			success: function (json) {
				var insert = "";
				for (i = 0; i < json.length - 1; i++) {
					if (json[i].Pic_Name.substr(0, 2) != "00") {
						insert += "<img class='ui-corner-all' src='slideshows/" + destination + "/full/" + json[i].Pic_Name + "' alt='' />";
					}
				}

				$(".slideshow").css({ "visibility": "visible", "position":"relative", "margin":"auto", "width":"440px","height":"330px" });            
				$(".slideshow").html(insert);
			},
			error: function (Err, Errstatus) {
				alert(Err + ": " + Errstatus) //-> Error Handler
			},
			complete: function () {            
				$(".slideshow").jSlider({
					width: 440, // Gesamtbreite der Bilder
					height: 330, // Gesamthöhe der Bilder
					thumb_width: 80,
					thumb_height: 60,
					sleep: 3500,
					fadespeed: 1000,
					prevbox:"round"
				});
			}
		});
	}
}

PluginsLoader.run = function () {
    $("#pager").fadeOut("slow").html("").fadeIn("slow", function () {
        $("#node-text").pagethis();
    });

    blockquote.install.call()
    
    if (_global.hasInterval == true) {
        clearInterval(_global.SlideInterval)
        _global.hasInterval = false;
    }

    slideme.run(phpfile.items.slider_file);
    $("._zoompic").zoompics();

    if ($("#Node-Table").css("display") == "none") {        
        $("#Node-Table").fadeIn("slow");
    }
	
	$("pre").each(function(){
		$(this).wrapInner("<code />");
	});	
	
	$('pre code').each(function(i, e) {hljs.highlightBlock(e, '    ')});
		
	$(".alignleft").each(function(){
		if ($(this).hasClass("first-letter") == false){			
			$(this).wrap("<span class='alignleft_border'></span>").after("<p style='text-align:center; font-size:0.85em;'>"+$(this).attr("alt")+"</p>").addClass("align_border");
		}
	});
	$(".alignright").each(function(){
		if ($(this).hasClass("first-letter") == false){
			$(this).wrap("<span class='alignright_border'></span>").after("<p style='text-align:center; font-size:0.85em;'>"+$(this).attr("alt")+"</p>").addClass("align_border");
		}
	});
	$(".aligncenter").each(function(){
		if ($(this).hasClass("first-letter") == false){		
			$(this).wrap("<span class='aligncenter_border'></span>").after("<p style='text-align:center; font-size:0.85em;'>"+$(this).attr("alt")+"</p>").addClass("align_border");
		}
	});
}

blockquote.install = function () {
    if($("blockquote").find(".border-top").length == 0){
		$("blockquote").prepend("<div class='border-top'></div>");
		$("blockquote").append("<div class='border-bottom'></div>");

		$("blockquote address").html("<b>Zitat:</b> " + $("blockquote address").html());
		$("blockquote p").css({ "padding-left": "10px", "padding-right": "10px" });
	}
}

search_input.install = function () {
    var TitelArray = new Array();
    var leiste = "<span class='ui-corner-all' id='SuchleistenRand' style='border:1px solid #FBF0B7; background:#542008; float:right; position:relative; top:5px; margin-right:0.3em; box-shadow: inset 2px 0px 0.8em #542008;'>" +
                 "<span class='ui-icon' style='background:url(IMG/search.png) no-repeat; width:16px; height:16px; float:left;'></span>" +
                 "<input maxlength='50' style='border:none; background:transparent; color:#FBF0B7;' type='text' name='Suchleiste' value='' id='iSuchleiste' />" +
                 "</span>";
				
    $("#menu").append(leiste);   
	
	$(".Menu_Node_Titel").each(function(){		
		TitelArray.push($(this).html())
	});
	
	$("#iSuchleiste").autocomplete({
		source: TitelArray
	});
	
	$(".ui-autocomplete").css({"width":"300px", "font-size":"0.8em", "border":"1px solid #FBF0B7"});
	
	$(".ui-menu-item").live("click",function(){
		alert($(this).children("a").html());
	});
}

comment.install = function (para) {
    if ($.browsercheck()) {
        var css = "";
        var top_trennlinie = "43px";
        var captcha_font_size = "0.85em";
        var max_font_size = "1.2em";
        var captcha_left = "-30px";
    }
    else {
        var css = "display:none;";
        var top_trennlinie = "46px";
        var captcha_font_size = "0.7em";
        var max_font_size = "0.85em";
        var captcha_left = "0px";
    }

    var Preview = "<table style='margin:auto; display:none; width:700px;' id='comment_prev_table' class='_Com_submit_hidden'><tr><td id='comment_prev_name'></div></td></tr>" +
                  "<tr><td id='comment_prev_titel'></td></tr>" +
                  "<tr><td><p id='comment_prev_text' style='text-align:justify;'></p></td></tr>" +
                  "<tr><td class='Comm_Form_Buttons_td'><a class='dyn_button Comm_Form_Buttons' style='float:left; font-size:" + max_font_size + ";' id='Back_to_Form_Comment'>Abbrechen</a>" +
                  "</td></tr></table>";

    var Captcha = "<div id='captcha_test' style='width:350px; position:relative;" + css + "'>" +
                  "<div style='width:250px; height:17px; background: url(IMG/captcha.png); display:table-cell; vertical-align:middle;' class='captcha ui-corner-all'>" +
                  "<div id='captchaslider' style='width:17px; height:17px; position:absolute; left:0px;' class='ui-corner-all ui-button ui-widget ui-state-default'></div>" +
                  "<div id='captchachecked' style='float:right; width:17px; height:17px;'></div>" +
                  "</div> <img id='captcha_locker' src='styles/images/16/063.png' style='position:absolute; right:50px; top:0px;' />" +
                  " <span style='font-size:" + captcha_font_size + "; position:relative; left:" + captcha_left + ";'>Bitte den Regler ganz nach rechts schieben (<a target='_blank' href='http://de.wikipedia.org/wiki/CAPTCHA'>CAPTCHA-Test</a>)</span>" +
                  "</div>";

    var New_Comment_Form = "<div style='margin-top:0.9em; overflow:hidden; height: 0px;' id='New_Comment_Formular'>" +
						   "<div style='display:none; padding-top:50px;' id='submit_response_div'><div id='submit_response_text' style='margin:auto; height:100px; width:400px; border:1px solid #FBF0B7; padding-top:55px;' class='ui-corner-all'></div></div>" +
                           "<table style='width:700px; margin:auto;' id='Comment_Form_Table' class='_Com_submit_hidden'><tr><td colspan='2'>" +
                           "<input class='_Com_Form' type='hidden' name='comment_parent' id='comment_form_parent' value='0' />" +
                           "</td></tr> " +
                           "<tr><td colspan='2'><input maxlength='50' placeholder='Dein Name' class='_Com_Form InputIcon_dyn_200 _requiert' type='text' name='comment_author' id='comment_form_name'/></td></tr> " +
                           "<tr><td colspan='2'><input maxlength='50' placeholder='Deine E-Mail (wird im Post nicht angezeigt)' class='_Com_Form InputIcon_dyn_200 _requiert' type='text' name='comment_author_email' id='comment_form_email' /></td></tr> " +
                           "<tr><td colspan='2'><input maxlength='150' placeholder='Deine HP (Optional)' class='_Com_Form NoInputIcon_dyn_200' type='text' name='comment_author_url' id='comment_form_hp' /></td></tr> " +
                           "<tr><td id='Captcha_test_td'></td><td style='vertical-align:bottom; text-align:right; font-size:" + max_font_size + ";'>m&ouml;gliche Zeichenanzahl: <b><span id='textarea_maxlength_comment_form'>500</span></b></td></tr> " +
                           "<tr><td colspan='2'><textarea wrap='physical' maxlength='500' rows='6' cols='0' style='width:300px;' class='textareaIcon_dyn_200 ui-corner-all _Com_Form _requiert' name='comment_content' id='comment_form_text'></textarea></td></tr>" +
                           "<tr><td  colspan='2' class='Comm_Form_Buttons_td'><a class='dyn_button Comm_Form_Buttons' style='float:left; " + css + "; font-size:" + max_font_size + ";' id='Preview_Comment'>Vorschau</a>" +
                           "</td></tr>" +
                           "</table>" +
                           Preview +
                           "</div>";

    var Comment_div = "<div style='margin-top:0.9em; display:none;' id='Comment_block'>" +
					  "<img style='position:relative; top:" + top_trennlinie + ";' src='IMG/trennlinie_sub1.png' />" +
                      "<div id='New_Comment'>" +
                      "<input type='button' class='dyn_button' id='new_comment_button' value='Kommentar schreiben' style='position:relative; left:-280px; top:-15px;'/>" +
					  New_Comment_Form +
                      "</div>" +
					  "<img src='IMG/trennlinie_sub2.png' />" +
                      "<div id='Comments'></div>" +
                      "</div>";

    if ($("#Comment_block").length == 0) {
        $("#node-text").append(Comment_div);
        if (!$.browsercheck()) {
            $("#New_Comment_Formular").css("height", "1px");
        }
    }

    $(".InputIcon_dyn_200").IconCheck({
        icon: true, // true, false                   
        glow: true,
        length: 300 // Gesamtlaenge der Boxen (Input u. Select) in Pixel                
    });

    $(".NoInputIcon_dyn_200").IconCheck({
        icon: false, // true, false                   
        glow: true,
        length: 300 // Gesamtlaenge der Boxen (Input u. Select) in Pixel                
    });

    $(".textareaIcon_dyn_200").IconCheck({
        tag: "textarea",
        icon: false, // true, false
        glow: true,
        length: 600 // Gesamtlaenge der Boxen (Input u. Select) in Pixel                            
    });

    $.ajax({
        url: phpfile.items.comment_file + "?id=" + para.id,
        dataType: 'json',
        success: function (json) {
            var Comments = "";
            var Comments_sub = "";

            for (i = 0; i < json.length; i++) {
                if (json[i].COMMENT_PARENT == 0) {
                    Comments += "<blockquote style='position:relative;' id='com_" + json[i].COMMENT_ID + "' class='Posted_Comment'><p style='text-align:justify;'>" +
							"<p>" + json[i].COMMENT_CONTENT + "</p>" +
							"<p><span style='float:left;'><b>Von:</b> " + json[i].COMMENT_AUTHOR + "</span><span style='float:right;'>" + json[i].COMMENT_DATE + "</span></p>" +
                            "</p></blockquote>";
                }
            }

            $("#Comments").html(Comments);

            for (i = 0; i < json.length; i++) {
                Comments_sub = "";
                if (json[i].COMMENT_PARENT > 0) {
                    Comments_sub = "<blockquote style='position:relative; margin-left:50px;' id='com_" + json[i].COMMENT_ID + "' class='Posted_Comment'><p style='text-align:justify;'>" +
                            json[i].COMMENT_CONTENT +
							"<p><span style='float:left;'><b>Von:</b> " + json[i].COMMENT_AUTHOR + "</span><span style='float:right;'>" + json[i].COMMENT_DATE + "</span></p>" +
                            "</p></blockquote>";
                }

                $("#com_" + json[i].COMMENT_PARENT).after(Comments_sub)
            }

            $("#Comments").find("blockquote").each(function () {
                $(this).append("<span style='position:absolute; bottom:8px; right:8px; display:none; z-index:10;'><a style='font-size:0.9em;' class='dyn_button post_antwort'>Antworten</a></span>");
            });
        },
        error: function (Err, Errtext) {
            alert(Err + " -> " + Errtext);
        },
        complete: function () {
            $(".dyn_button").button();

            if (!$.browsercheck()) {
                $("input[placeholder]").placeholder({ placeholderTextColour: "#999" });
            }
            blockquote.install.call()
            $("#New_Comment_Formular").slideUp("fast");
            $("#Comment_block").fadeIn("slow");
        }
    });

    $("#new_comment_button").live("click", function () {
        $("#submit_response_div").fadeOut("fast");
        if ($("#New_Comment_Formular").height() <= 1) {
            $("#Captcha_test_td").html(Captcha);
            $("#captchaslider").draggable({
                axis: "x",
                containment: "parent",
                revert: "invalid"
            });

            $("#captchachecked").droppable({
                drop: function (event, ui) {
                    $("#captcha_locker").attr("src", "styles/images/16/064.png");
                    $("#Submit_Comment").remove();
                    if ($("#Submit_Comment").length == 0) {
                        $(".Comm_Form_Buttons_td").append("<a class='dyn_button Comm_Form_Buttons' style='float:right; font-size:" + max_font_size + ";' id='Submit_Comment'>Antworten</a>");
                        $("#Submit_Comment").bind("click", function () {
                            var check = true;
                            $("#Comment_Form_Table").find("._requiert").each(function () {
                                if ($(this).is("input")) {
                                    if ($(this).parent().hasClass("ui-state-error-soft")) {
                                        check = false;
                                        $(this).focus();
                                        return false;
                                    }
                                }
                                else {
                                    if ($(this).val() == "") {
                                        check = false;
                                        $(this).focus();
                                        return false;
                                    }
                                }
                            });

                            if (check == true) {
                                LoginAuth.check(function () {
                                    comment.send(para)
                                });
                            }
                        });
                    }
                    $(".dyn_button").button();
                }
            });

            if (!$.browsercheck()) {
                $("input[placeholder]").placeholder({ placeholderTextColour: "#999" });
                var Comment_Formular_height = "290px";
            }
            else {
                var Comment_Formular_height = "285px";
            }

            $("#Comment_Form_Table").fadeIn("slow", function () {
                $("#New_Comment_Formular").animate({
                    "height": Comment_Formular_height,
                    "padding": "0.5em"
                }, "slow", function () {
                    if (!$.browsercheck()) {
                        $(".Comm_Form_Buttons").fadeIn("fast");
                        $("#captcha_test").fadeIn("fast");
                    }
                });
            });

            $("#new_comment_button").val("Kommentar abbrechen");
        }
        else {
            if (!$.browsercheck()) {
                $("#captcha_test").fadeOut("fast", function () {
                    $("#captcha_test").remove();
                    $(".Comm_Form_Buttons").fadeOut("fast", function () {
                        $("#New_Comment_Formular").animate({
                            "height": "1px",
                            "padding": "0"
                        }, "slow");
                        $("#Comment_Form_Table").fadeIn("slow");
                    });
                });

            }
            else {
                $("#New_Comment_Formular").animate({
                    "height": "0px",
                    "padding": "0"
                }, "slow");
                $("#Comment_Form_Table").fadeIn("slow");
            }

            $("#new_comment_button").val("Kommentar schreiben");
            $("._Com_Form").val("");
            //$("#textarea_maxlength_comment_form").html($("#textarea_maxlength_comment_form").attr("maxlength"))
            $("#comment_form_text").keyup();
            $("#Submit_Comment").remove().unbind("click");
            $(".textareaIcon_dyn_200").IconCheck("update");
        }
    });

    $(".Posted_Comment").live("mouseenter", function () {
        //$(this).css("border", "1px solid #FF9900");
        $(this).find(".post_antwort").parent().fadeIn("fast");

    }).live("mouseleave", function () {
        //$(this).css("border", "1px solid #FBF0B7");
        $(this).find(".post_antwort").parent().fadeOut("fast");
    });

    $(".post_antwort").live("click", function () {
        Comment_ID = $(this).parents(".Posted_Comment").attr("id").split("_");
        $("#comment_form_parent").val(Comment_ID[1]);
        if ($("#New_Comment_Formular").height() == 0) {
            $("#new_comment_button").click();
        }
    });

    $("#Preview_Comment").live("click", function () {
        $("#Comment_Form_Table").fadeOut("slow", function () {
            $("#comment_prev_titel").html($("#comment_form_titel").val());
            $("#comment_prev_name").html($("#comment_form_name").val());
            $("#comment_prev_text").html($("#comment_form_text").val());
            $("#comment_prev_table").fadeIn("slow");
        });

    });

    $("#Back_to_Form_Comment").live("click", function () {
        $("#comment_prev_table").fadeOut("slow", function () {
            $("#Comment_Form_Table").fadeIn("slow");
        });
    });

    $("#comment_form_text").live("keyup", function () {
        var charleft = $(this).attr("maxlength") - $(this).val().length;
        var css = "";
        if (charleft <= 20) {
            css = "#EDCB41";
        }
        if (charleft <= 10) {
            css = "#FF9900";
        }
        if (charleft == 0) {
            css = "#FF0000";
        }

        $("#textarea_maxlength_comment_form").html(charleft).css("color", css);
        if ($(this).val().length >= $(this).attr("maxlength")) {
            $(this).val($(this).val().substr(0, $(this).attr("maxlength")));
        }
    });
}

comment.send = function(para){	
	$.ajax({
	    url: phpfile.items.set_comment_file + "?id=" + para.id + "&name=" + $("#comment_form_name").val() + "&mail=" + $("#comment_form_email").val() + "&hp=" + $("#comment_form_hp").val() + "&text=" + $("#comment_form_text").val().replace(/\n/g, "<br />") + "&parent=" + $("#comment_form_parent").val() + "&user=0",
		dataType: "json",	
		success: function (json) {			
			if (json[0].Success == true) {
				$("._Com_submit_hidden").fadeOut("slow", function () {
					$("#submit_response_text").html("Danke f&uuml;r dein Kommentar! Dein Eintrag wird angezeigt, sobald er von einem Admin freigeschaltet wurde!");
					$("#submit_response_div").fadeIn("slow");
				});
			}
		},
		error: function (Err, Errtext) {
			$("._Com_submit_hidden").fadeOut("slow", function () {
				$("#submit_response_text").html(Err + ": " + Errtext);
				$("#submit_response_div").fadeIn("slow");
			});
		}
	});
}

directLink.load = function () {
    if (global.parahash.kat_slug == "" && isFinite(global.parahash.titel)) {
		if ($("#" + global.parahash.titel).parent(".menu-entry").length > 0){
			var para_kat_slug = $("#" + global.parahash.titel).parent(".menu-entry").attr("id").split("-");
		}
		else if ($("#" + global.parahash.titel).parent(".menu-entry-news").length > 0){
			var para_kat_slug = $("#" + global.parahash.titel).parent(".menu-entry-news").attr("id").split("-");
		}
		
        global.parahash.kat_slug = para_kat_slug[0];
        global.parahash.id = global.parahash.titel;

        global.parahash.titel = $("#" + global.parahash.titel).attr("rel");
        //titel = $("#" + global.parahash.titel).find(".Menu_Node_Titel").html().split("<");
        //global.parahash.titel = titel[0].toLowerCase().replace(/\s/g, "-");
    }
    else if (global.parahash.kat_slug == "" && !isFinite(global.parahash.titel)) {
        $(".Menulinktext").each(function () {
            if ($(this).html().toLowerCase().indexOf(para.titel) > -1) {
                var para_kat_slug = $(this).parents(".menu-entry").attr("id").split("-");
                global.parahash.kat_slug = para_kat_slug[0];
            }
        });
    }

    if (global.parahash.kat_slug == "") {
        $("#iRadio-Menu-H").click();
    }
    else {
        $(".menu-entry").fadeOut("fast", function () {
            setTimeout(function () {
                $("#" + global.parahash.kat_slug + "-Menu").fadeIn("slow");
            }, 500);
        });

        $("#menu-entry-div").fadeOut("fast", function () {
            $("#menu-entry-div").css({ "background": "url(IMG/" + global.parahash.kat_slug + ".png) no-repeat top right" }).fadeIn("fast");
        });

        var Kat_Name = "";
        $("input[name='Radio-Menu']").each(function () {
            if ($(this).val() == global.parahash.kat_slug + "-Menu") {
                $(this).attr("checked", true);
                Kat_Name = $(this).attr("alt");
            }
        });

        if ($.browsercheck()) {
            if (Kat_Name != "Home") {
                $("title").html("Khyrindas diary > " + Kat_Name);
            }
            else {
                $("title").html("Khyrindas diary");
            }
        }

        var thisObj = global.parahash.id;

        if (global.parahash.titel != "") {
            if (isNaN(global.parahash.titel)) {
                $(".Menulink_hover").each(function () {
                    if ($(this).attr("rel") == global.parahash.titel) {  //html().toLowerCase().indexOf(global.parahash.titel) > -1) {
                        thisObj = $(this).attr("id");
                    }
                });
            }
            else {
                thisObj = global.parahash.id;
            }
        }

        $("._marker").html("");
        $("._marker").parents(".Menulink_hover").find(".Menulinktext").css({ "font-weight": '' });

        $("._selected").removeClass("_selected");
        $("#" + thisObj).addClass("_selected");

        $("#" + thisObj).find("._marker").html("<font style='color:#FFCC00;'><b>&lt;</b></font>");
        $("#" + thisObj).find(".Menulinktext").css({ "font-weight": "bold" });
        if ($("#" + thisObj).parents(".menu-entry").length > 0) {
            var kategorie = $("#" + thisObj).parents(".menu-entry").attr("id").split("-");
        }
        else if ($("#" + thisObj).parents(".menu-entry-news").length > 0) {
            var kategorie = $("#" + thisObj).parents(".menu-entry-news").attr("id").split("-");
        }

        var this_id = thisObj;

        $.ajax({
            url: phpfile.items.node_file + "?id=" + this_id,
            dataType: "json",
            success: function (json) {
                var insert_this = "";
                if (json[0].NODE_TXT.indexOf("<!-- next -->") >= 0) {
                    var insert_text = json[0].NODE_TXT.replace("<p><!--more--></p>", "").split("<!-- next -->");

                    for (i = 0; i < insert_text.length; i++) {
                        page = i + 1;

                        insert_this = insert_this + "<div id='p" + page + "' style='display:none;' class='_pages'>" + insert_text[i] + "</div>";
                    };
                }
                else if (json[0].NODE_TXT.indexOf("<p><!--nextpage--></p>") > 0) {
                    var insert_text = json[0].NODE_TXT.replace("<p><!--more--></p>", "").split("<p><!--nextpage--></p>");

                    for (i = 0; i < insert_text.length; i++) {
                        page = i + 1;

                        insert_this = insert_this + "<div id='p" + page + "' style='display:none;' class='_pages'>" + insert_text[i] + "</div>";
                    };
                }
                else {
                    insert_this = json[0].NODE_TXT.replace("<p><!--more--></p><br />", "");
                }

                $("#node-text").html(insert_this);

                if (json[0].NODE_COMMENT == "open") {
                    comment.install({ id: this_id })
                }

                $("#Node-Titel").html(" <font style='color:#FFCC00;'><b>&gt;</b></font> " + json[0].NODE_TITEL);
                if (global.parahash.seite != "") {
                    var seite = "/" + global.parahash.seite;
                }
                else {
                    var seite = "";
                }

                var url_para = location.href.split("?");
                if (!url_para[1]) {
                    location.hash = "!/" + global.parahash.kat_slug + "/" + global.parahash.titel.toLowerCase().replace(/\s/g, "-") + seite;
                }
                else {
                    if ($.browsercheck() && history.pushState) {
                        //alert(url_para[0] + "#!/" + global.parahash.kat_slug + "/" + global.parahash.titel + seite)
                        history.pushState("", global.parahash.titel, url_para[0] + "#!/" + global.parahash.kat_slug + "/" + global.parahash.titel.toLowerCase().replace(/\s/g, "-") + seite);
                    }
                    else {
                        location.href = url_para[0] + "#!/" + global.parahash.kat_slug + "/" + global.parahash.titel.toLowerCase().replace(/\s/g, "-") + seite;
                    }
                }
            },
            error: function (data, Errortext) {
                $("#Node-Titel").html(" <font style='color:#FFCC00;'><b>&gt;</b></font> AJAX " + Errortext + " - " + data.status);
                $("#node-text").html(Errortext + " - " + data.status);
            },
            complete: function (json) {
                //hash Wert in ajax-Request success gesetzt
                PluginsLoader.run() //.call()
            }
        });
    }

    $(".menu-button-set").buttonset("refresh");
}

LoginAuth.check = function (callback) {
    $.ajax({
        url: phpfile.items.ucheck,
        dataType: 'json',
        success: function (json) {
            var Passdings = "";
            var Nickdings = "";
            for (i = 0; i < json.length; i++) {
                if (json[i].nick.toLowerCase().indexOf($.trim($("#comment_form_name").val().toLowerCase())) > -1 && $.trim($("#comment_form_name").val()).length > 5) {
                    var Userdings = json[i].user;
                    var Nickdings = json[i].nick;
                }
            }

            if (Nickdings != "") {
                if ($("#jq_overlay").length == 0) {
                    $("body").prepend("<div style='display:none;' id='jq_overlay'></div>");
                }

                $("#jq_overlay").css({
                    "background": "#080808 url('../style/images/ui-bg_flat_0_080808_40x100.png') no-repeat 50% 50%",
                    "opacity": .6,
                    "filter": "Alpha(opacity=60)",
                    "zoom": 1,
                    "z-index": 900,
                    "height": "100%",
                    "width": "100%",
                    "position": "absolute",
                    "top": "0px",
                    "left": "0px"
                });

                var Messagebody = "<div id='jq_message' align='center' style='display:none;' class='ui-corner-all ui-widget-content'>" +
															  "<p style='text-align:justify;'>Dieser Name ist reserviert und kann nicht unangemeldet f&uuml;r Kommentare verwendet werden, bitte best&auml;tige deine Person!</p><br />" +
															  "<input placeholder='Username' class='_Com_Form_auth InputIcon_dyn_200 _requiert' type='text' name='comment_User_auth' id='comment_User_auth' /><br />" +
															  "<input placeholder='Passdingens' class='_Com_Form_auth InputIcon_dyn_200 _requiert' type='password' name='comment_pass_auth' id='comment_pass_auth' /><br />" +
															  "<a id='loginchecked' class='dyn_button' style='float:left;'>Ja, ich bins</a><a id='logincancle' class='dyn_button' style='float:right;'>lieber doch nicht</a>" +
															  "</div>";

                if ($("#jq_message").length == 0) {
                    $("body").prepend(Messagebody);
                }

                $("#jq_message .InputIcon_dyn_200").IconCheck({
                    icon: true,
                    glow: true,
                    length: 300
                });

                $("#jq_message .dyn_button").button();

                if (!$.browsercheck()) {
                    $("#jq_message input[placeholder]").placeholder({ placeholderTextColour: "#999" });
                }

                $("#jq_message").css({
                    "padding": "0.9em",
                    "top": "30%",
                    "left": parseInt($(window).width()) / 2 - 150 + "px",
                    "height": "200px",
                    "width": "300px",
                    "margin": "auto",
                    "border": "1px solid #FBF0B7",
                    "zoom": 1,
                    "z-index": 1000,
                    "position": "absolute"
                });

                $("#jq_overlay").fadeIn("slow", function () {
                    $("#jq_message").fadeIn("slow");
                });

                $("#loginchecked").bind("click", function () {
                    $.ajax({
                        url: phpfile.items.ucheck + "?pass=" + $("#comment_pass_auth").val() + "&u=" + $("#comment_User_auth").val(),
                        dataType: 'json',
                        success: function (json) {

                            if (json[0].passwortcheck == true && $("#comment_User_auth").val() == Userdings) {
                                $("#jq_message").fadeOut("slow", function () {
                                    $("#jq_overlay").fadeOut("slow").remove();
                                    $("._Com_Form_auth").val("");
                                    $(".InputIcon_dyn_200").IconCheck("update");

                                    $("#comment_form_name").val(Nickdings);
                                    if (callback) {
                                        callback.call()
                                    }
                                }).remove();
                            }
                            else {
                                $("#jq_message").effect("bounce", { direction: 'down', times: 5 }, 100);
                                $("._Com_Form_auth").val("");
                                $(".InputIcon_dyn_200").IconCheck("update");
                            }
                        },
                        error: function (Err, Errtext) {
                            alert("Error bei Login, Ajax-Request: " + Err + " \n " + Errtext)
                        }
                    });
                });

                $("#logincancle").bind("click", function () {
                    $("#jq_message").fadeOut("slow", function () {
                        $("#comment_form_name").val("");
                        $("#jq_overlay").fadeOut("slow").remove();
                        $("._Com_Form_auth").val("");
                        $(".InputIcon_dyn_200").IconCheck("update");
                    }).remove();
                });
            }
            else {
                if (callback) {
                    callback.call()
                }
            }
        },
        error: function (Err, Errtext) {
            alert("Error bei Userverifizierung, Ajax-Request:" + Err + " \n " + Errtext)
        }
    });
}
