$(document).ready(function(){

    // farbige Boxen vor den Überschriften
    $("h3.fa").prepend('<img src="/img/hippo_marker_fa.jpg">&nbsp;');
    $("h3.za").prepend('<img src="/img/hippo_marker_za.jpg">&nbsp;');
    $("h3.aa").prepend('<img src="/img/hippo_marker_aa.jpg">&nbsp;');
    $("h3.uro").prepend('<img src="/img/hippo_marker_uro.jpg">&nbsp;');
    $("h3[class=]").prepend('<img src="/img/hippo_marker.jpg">&nbsp;');
    
    // Gruppenfarben an Stellen wo die Gruppen-CSS nicht geladen wird
    $("h3.theme_no_css").each( function() {
        $(this).prepend('<span class="box_sprite theme_box_' + $(this).attr("theme") + '"></span>&nbsp;');
    });
    
    // Gruppenfarben an Stellen wo die Gruppen-CSS geladen wird
    $("h3.themed").prepend('<span class="box_sprite theme_box"></span>&nbsp;');
    $("span.box_headline").prepend('<img src="/img/hippo_marker.jpg">&nbsp;');
    $("span.box_headline_themed").prepend('<span class="box_sprite theme_box"></span>&nbsp;');
    
    $("span.box_headline + span").after('<div class="clearfloat"></div>')
                                 .css("float", "right")
                                 .prev("span.box_headline").css("float", "left");
                                 
    $("span.box_headline_themed + span").after('<div class="clearfloat"></div>')
                                        .css("float", "right")
                                        .prev("span.box_headline").css("float", "left");                             
    
    $(".rate_closedtab").click(function() {
        $(".history_select").blur();
        $(".rate_opentab").removeClass('rate_opentab').addClass('rate_closedtab');
        $(this).removeClass('rate_closedtab').addClass('rate_opentab');
    });
    
    // Verlaufskarte bei "Leser bewerten XXX"
    $('#history_pic').load(function() {  
        $("#history_loading").css('visibility', 'hidden');
        $("#history_blank").animate({ "opacity": 0.0 }, "slow");
    }); 
    
    $("[starttab|=thisone]").removeClass('rate_closedtab').addClass('rate_opentab');


    $(".search_box2").focus( function() {
        document.onkeyup = '';
    });
    $(".search_box2").blur( function() {
        document.onkeyup = alertkey;
    });
    
    $("#lang_select").click(function () {
        $("#lang_select_box").slideToggle("fast");
    });
    
    // "Bearbeiten" bei "mein Profil"
    $("a.profile_edit_open").click(function() {
        $(this).parents(".profile_group").next().toggle();
        $(this).parents(".profile_group").toggle();
        
    });
    $(".profile_edit_close").click(function() {
        $(this).parents(".profile_group").toggle();
        $(this).parents(".profile_group").prev().toggle();
    });
    
    $("#mod_contacts_toggle").click(function () {
        $("#mod_contacts").toggle();
    });
    
    // Bewertungen im Forum (Daumen & Sterne)
    $("span.rate").hover(
        function () { activate_stars($(this).attr("rating"), $(this).attr("cat")); },
        function () { deactivate_stars($(this).attr("cat")); }
    );
    
    // "Download hinzufügen"-Div aufklappen
    $("a#adlink").click(function () {
        $("#addownload").toggle("slow");
    });
    
    // Sprites für Firefox 2.0
    if ($.browser.mozilla && (parseFloat($.browser.version) < 1.9)) {
        $('.forum_action_sprite').addClass('forum_action_sprite_ff20')
                                 .removeClass('forum_action_sprite')
                                 .parent().after("<div class='cleardiv'></div>");
                                 
        //$('.forum_action_sprite_breit').addClass('forum_action_sprite_breit_ff20')
        //                               .removeClass('forum_action_sprite_breit')
        //                               .parent().after("<div class='cleardiv'></div>");

        $('.rating_sprite').addClass('rating_sprite_ff20')
                           .removeClass('rating_sprite');
    }

    

});

// Alle Sterne/Daumen deaktivieren (Forum)
function deactivate_stars(cat) {
    if (cat.match(/stars.*/)) { $("span.rate[cat=\""+cat+"\"]").removeClass("rating_mitgelb").addClass("rating_weiss"); }
    if (cat.match(/thumbup.*/)) { $("span.rate[cat=\""+cat+"\"]").removeClass("rating_dmitgelb").addClass("rating_dgrau"); }
    if (cat.match(/thumbdown.*/)) { $("span.rate[cat=\""+cat+"\"]").removeClass("rating_mitgelb").addClass("rating_dgrauu"); }
    
}
// Die entsprechenden Sterne/Daumen aktivieren
function activate_stars(rating, cat) {
    deactivate_stars(cat);
    if (cat.match(/stars.*/)) {
        $("span.rate[rating=\""+rating+"\"][cat=\""+cat+"\"]").removeClass("rating_weiss").addClass("rating_mitgelb");
        $("span.rate[rating=\""+rating+"\"][cat=\""+cat+"\"]").prevAll().removeClass("rating_weiss").addClass("rating_mitgelb")
    }
    if (cat.match(/thumbup.*/)) {
        $("span.rate[rating=\""+rating+"\"][cat=\""+cat+"\"]").removeClass("rating_dgrau").addClass("rating_dmitgelb");
        $("span.rate[rating=\""+rating+"\"][cat=\""+cat+"\"]").prevAll().removeClass("rating_dgrau").addClass("rating_dmitgelb")
    }
    if (cat.match(/thumbdown.*/)) {
        $("span.rate[rating=\""+rating+"\"][cat=\""+cat+"\"]").removeClass("rating_dgrauu").addClass("rating_ddkblau");
        $("span.rate[rating=\""+rating+"\"][cat=\""+cat+"\"]").prevAll().removeClass("rating_dgrauu").addClass("rating_ddkblau")
    }
}

// Gibt die Personen mit dem gewählten Buchstaben aus ("Leser beweten Politiker")
function show_alphabet(show_char) {
    var script = '/scripts/ajax/get_persons_by_alphabet.phpa?char=';
    $.get(script + show_char, function(resp) {
        $("#alphabet_box").html(resp);
    });
}

// Stimmabgabe ("Leser beweten Politiker")
function rate_cast_vote(category, value) {
    $.get('/scripts/ajax/cast_vote.phpa?category=' + category + '&value=' + value);
}

// rating KV
function show_alphabetkv(show_char) {
    var script = '/scripts/ajax/get_persons_by_alphabetkv.phpa?char=';
    $.get(script + show_char, function(resp) {
        $("#alphabet_box").html(resp);
    });
}

// Stimmabgabe ("Leser beweten KVen")
function rate_cast_votekv(category, value) {
    $.get('/scripts/ajax/cast_votekv.phpa?category=' + category + '&value=' + value);
}

function toggleDiv(div) {
    $('#' + div).toggle("slow");
    
}

// eine Person zu den Kontakten hinzufügen
function addContact(queryString, div) {
    var script = '/scripts/ajax/add_contact.phpa?';
    $.get(script + queryString, function(resp){
        $('#' + div).html(resp);
    });
}

function ratePost(queryString, span, div) {
    var script = '/scripts/ajax/rate.phpa?';
    $.get(script + queryString, function(resp){
        $('#' + span).html(resp);
        if (resp != 'Error') {
            $('#' + div).fadeOut(1000, function(){ 
                $('#' + div).hide();
                $('#' + span).html(resp);
            });
        } else {
            $('#' + div).html(resp);
        }
    });
}
function thumbPost(queryString, span, div) {
    var script = '/scripts/ajax/suggest.phpa?';
    $.get(script + queryString, function(resp){
        $('#' + span).html(resp);
        if (resp != 'Error') {
            $('#' + div).fadeOut(1000, function(){ 
                $('#' + div).hide();
                $('#' + span).html(resp);
            });
        } else {
            $('#' + div).html(resp);
        }
    });
}

// "Leser bewerten Politiker" ausgeben
function set_ratebox(div) {
    $.get('/scripts/ajax/ratebox.phpa', function(resp){
       $('#' + div).html(resp); 
    });
    
}
// "Leser bewerten KVen" ausgeben
function set_rateboxkv(div) {
    $.get('/scripts/ajax/rateboxkv.phpa', function(resp){
       $('#' + div).html(resp); 
    });
    
}

// Leser-Test Medizintechnik ausgeben
function set_medirate(div) {
    $.get('/scripts/ajax/rbox.phpa?medirate=1', function(resp){
       $('#' + div).html(resp); 
    });
    
}

function set_aBox(queryString, div, tab, tabs) {
    var script = '/scripts/ajax/abox.phpa?div=' + div + '&tab=' + tab + '&';
    
    $.get(script + queryString, function(resp){
        $('#' + div).html(resp);
    });
    for (var i=1; i<=tabs; i++) {
        $('#' + div + '_' + i).removeClass();
        $('#' + div + '_' + i).addClass('closetab');
    }
    $('#' + div + '_' + tab).removeClass();
    $('#' + div + '_' + tab).addClass('opentab');
}

function set_rBox(queryString, div, tab, tabs, withpic) {
    var script = '/scripts/ajax/rbox.phpa?div=' + div + '&tab=' + tab + '&withpic=' + withpic + '&';
    
    $.get(script + queryString, function(resp){
        $('#' + div).html(resp);
    });
    for (var i=1; i<=tabs; i++) {
        $('#' + div + '_' + i).removeClass();
        $('#' + div + '_' + i).addClass('closetab');
    }
    $('#' + div + '_' + tab).removeClass();
    $('#' + div + '_' + tab).addClass('opentab');
}

function set_headlines(div, cat, withpic) {
    var script = '/scripts/ajax/rbox.phpa?c=' + cat + '&n=3&d=7' + '&withpic=' + withpic;
    $.get(script, function(resp) {
        $("#" + div).html(resp);
    });
}

function set_za_headlines(div) {
    var script = '/scripts/ajax/rbox.phpa?lg=82&f=all&n=3&d=7' + '&withpic=0';
    $.get(script, function(resp) {
        $("#" + div).html(resp);
    });
}

function set_uro_headlines(div) {
    var script = '/scripts/ajax/rbox.phpa?uroforum=1';
    $.get(script, function(resp) {
        $("#" + div).html(resp);
    });
}

function set_hippotipps(div) {
    var script = '/scripts/ajax/rbox.phpa?hippotipps=1';
    $.get(script, function(resp) {
        $("#" + div).html(resp);
    });
}

function set_arztanzeigen(div, num) {
    var script = '/scripts/ajax/rbox.phpa?arztanzeigen=1&num=' + num;
    $.get(script, function(resp) {
        $("#" + div).html(resp);
    });
}

function set_nets(div, nets, n, withpic) {
    var script = '/scripts/ajax/rbox.phpa?nets=' + nets + '&n=' + n + '&withpic=' + withpic;
    $.get(script, function(resp) {
        $("#" + div).html(resp);
    });
}

function set_auktionen(div, num) {
    var script = '/scripts/ajax/rbox.phpa?auktionen=1&n=' + num;
    $.get(script, function(resp) {
        $("#" + div).html(resp);
    });
}

function set_keywords(div) {
    var script = '/scripts/ajax/rbox.phpa?keywords=all';
    $.get(script, function(resp) {
        $("#" + div).html(resp);
    });
}

function count_redview(span, aid) {
    var script = '/scripts/ajax/count_redview.phpa?aid=' + aid;
    
    $.get(script, function(resp){
        $('#' + span).html(resp);
    });
}

function focusi(elem, text) {
    if (elem.value == text) {
        elem.value = '';
        elem.style.color = 'black';
    }
    return true;
}
function focust(elem, text) {
    if (elem.innerHTML == text) {
        elem.innerHTML = '';
    }
    return true;
}
function bluri(elem, text) {
    if (elem.value == '') {
        elem.value = text;
        elem.style.color = '#999';
    }
    return true;
}
function blurt(elem, text) {
    if (elem.value == '') {
        elem.innerHTML = text;
    }
    return true;
}

