$(document).ready(function() {
$('.smilies,.smilies2').hover(
                            function() { post.showIcons(); },
                            function() { post.hideIcons(); }
                        )
    $('.smilies img,.smilies2 img').click(function(e) {
        post.insertSmile(this);
    });
    $('#posta').click(function(e) {
        $('#text_area').focus();
    });
    $('#text_area').focus().vertigro();
});


var post = {};
/// <summary>deklarace namespace</summary>

post.timer = null;
/// <summary>casovac pro zpozdene zobrazovani smajliku</summary>

post.showIconsInterval = 500;
/// <summary>zpozdeni zobrazovani smajliku</summary>


post.showIcons = function() {
    /// <summary>zobrazeni smajliku</summary>
    clearInterval(post.timer);
    post.timer = window.setTimeout(function() { post.showIconsCore(); }, post.showIconsInterval);
};
post.showIconsCore = function() {
    /// <summary>zobrazeni smajliku</summary>
    post.positioningSmiles();
    $(post.selectorSmilies()).slideDown("fast");  // "slow", "fast"
};

post.hideIcons = function() {
    /// <summary>skryti smajliku</summary>
    clearInterval(post.timer);
    post.timer = window.setTimeout(function() { post.hideIconsCore(); }, post.showIconsInterval);
}
post.hideIconsCore = function() {
    /// <summary>skryti smajliku</summary>
    $(post.selectorSmilies()).slideUp("fast") //hide();, "slow", "fast"
};

post.positioningSmiles = function() {
    /// <summary>zobrazeni smajliku</summary>
    var p = $(".smilies");
    var position = p.offset();
    $(".smilies2").css({ left: (position.left+1) + 'px', top: (position.top + p.height()) + 'px' });
    $("#smilies2f").width($("#smilies2").outerWidth(true));
    $("#smilies2f").height($("#smilies2").outerHeight(true));

};

post.selectorSmilies = function() {
    /// <summary>IE vyzaduje pod absolutne pozicovane elementy iframe, jinak neprekryjeelementy select</summary>
//    return jQuery.browser.msie ? ".smilies2" : "#smilies2";
    return "#smilies2";
};

post.insertSmile = function(imgSmile) {
    /// <summary>vlozina misto kurzoru pozadovany smajlik (nebo nahradi jim oznaceny text)
    ///          V pripade barvy obarvi vybrany text</summary>
    /// <param name="imgSmile" type="htmlImg">Obrazek, ze ktereho bude vzat smajlik</param>
    /// <remarks>Definici smajliku nebo barvy ocekava v atributu alt. Ma-li delku 1, predpoklada barvu, jinak to je smajlik</remarks>
    var pAlt = $(imgSmile).attr('alt');
    if (pAlt.length == 1 && pAlt >= '0' && pAlt <= '9') {   //jedna se o barvu
        var pomSelection = $('#text_area').getSelection().text;
        $('#text_area').replaceSelection('*c' + pAlt + '*' + ((pomSelection.length>0)?(pomSelection + '*/c*'):''));
    } else {    //jedna se o smajlik
        $('#text_area').replaceSelection('*' + pAlt + '*');
    }
};

post.text_area_rows = function() {
    /// <summary>zvetseni nebo zmenseni editbox</summary>
    document.getElementById("text_area").rows = (document.getElementById("text_area").rows > 5) ? 5 : 30;
}


