$(document).ready(function(){
    if (window.pagetype=='tvshow' || window.pagetype=='operation' || window.pagetype=='demonstration'|| window.pagetype=='howitsmade_page') writePlayer(s,n);
    //~ else if (window.pagetype=='operation' || window.pagetype=='demonstration') writeOperationPlayer(s,n);

    // Operations scroll BEGIN

    $("#operations_up").click(function(){
        $("#id_operations_scroll").scrollTo({
            top:'-=302px',
            left:'0px'
        }, 500 );
    });

    $("#operations_down").click(function(){
        $("#id_operations_scroll").scrollTo({
            top:'+=302px',
            left:'0px'
        }, 500 );
    });


    // Operations scroll END



    // Operations scroll BEGIN
    $("#articles_up").click(function(){
        $("#id_articles_scroll").scrollTo({
            top:'-=302px',
            left:'0px'
        }, 500 );
    });


    $("#articles_down").click(function(){
        $("#id_articles_scroll").scrollTo({
            top:'+=302px',
            left:'0px'
        }, 500 );
    });


    // Operations scroll END




    // HIDE SHOW HEADER
    $(".header").click(function () {
        if ($(this).parent().is ('.selected')) {
            $(this).parent().removeClass('selected');
            $(this).parent().children('.retractable').slideToggle("slow");
        }else{
            $(this).parent().addClass('selected');
            $(this).parent().children('.retractable').slideToggle("slow");
        }
    });
    // HIDE SHOW HEADER


    //FORUM




    var offset = 0;
    var max_offset = 4;

    $(".m_cat").click(function(){
        offset = 0;
        $('.older_treats').fadeIn(500);
        $('.m_cat').removeClass('selected');
        $(this).addClass('selected');
        var forum_cat=$(this).attr('id');
        getForum(forum_cat,offset);
    });

    $(".older_treats").click(function(){
        var forum_cat=$('.menu_categories > .selected').attr('id');
        if (!forum_cat) {
            forum_cat = 'nonhome';
        }
        if(offset <= max_offset){
            offset += 1;
        }else{
            $('.older_treats').fadeOut(500);
        }

        getForum(forum_cat,offset);
    });

    //FORUM END

    //AUTORUN

    if(pagetype!='home'){
        getForum('nonhome',0); //Вземаме инфо за форума ако страницата не е 'home'
    }else{
        $('#lastpost').click(); // Вземаме инфо за форума ако страницата е 'home'
    }



    $('#'+selectedMenu).addClass('selected');




    //SPODELI JUMPY LINKS

    $('.share > a').hover(function(){
        $(this).stop().animate({
            top:'-10px'
        },100);
    },function(){
        $(this).stop().animate({
            top:'0px'
        },500,'easeOutBounce');
    });


});

function getForum(forum_cat,offset){
    $('#id_forum_content').html('<div style="text-align:center;padding-top:155px;padding-bottom:190px;"><img src="/images/loading.gif" /><div>');
    if(pagetype != 'home') {
        size = 'small'
    }else{
        size = '';
    }
    $.post('/php/getForum.php',{
        forum_cat:forum_cat,
        offset:offset,
        size:size
    },
    function(res) {
        if (res=='error') {
            alert('Грешка');
        }else{
            $('#id_forum_content').html(res);
        }
    }
    );
}

function addComment() {
    var author=$('#id_comment_author').val();
    var text=$('#id_comment_text').val();
    var object_id=$('#id_object_id').val();

    $.post('/php/addComment.php',{
        author:author,
        text:text,
        object_id:object_id
    },
    function(res) {
        if (res=='ok') {
            $('#add_comment').fadeOut('slow');
            updateComentars(object_id);
        }else{
            alert(res);
        }
    }
    );

}

function updateComentars(object_id) {
    $.post('/php/updateCommentars.php',{
        object_id:object_id
    },
    function(res) {
        $('#id_commentars').replaceWith(res);
        
        $("#id_commentars > div > .header").click(function () {
            if ($(this).parent().is ('.selected')) {
                $(this).parent().removeClass('selected');
                $(this).parent().children('.retractable').slideToggle("slow");
            }else{
                $(this).parent().addClass('selected');
                $(this).parent().children('.retractable').slideToggle("slow");
            }
        });
        
    }
    );

}

function sendMail(){
    var error = false;
    var sender_info = $('#sender_info').val();
    var name = $('#name').val();
    var mail = $('#mail').val();
    var message = $('#message').val();

    $('.rooms_table_input').css('border-color','');
    if (!name || name=='') {
        $('#name').css('border-color','#F25757');
        error = true;
    }
    if (!message || message=='') {
        $('#message').css('border-color','#F25757');
        error = true;
    }
    if(error == true) {
        $('#cand_error').show();
        return false;
    }else{
        $('.rooms_table_input').attr('disabled', true);
        $('#send_button').attr('disabled', true);
        $.post('/php/sendInternalMessage.php',{
            name:name,
            mail:mail,
            message:message
        },
        function(res) {
            $('.respond').fadeIn(200);
            $('.respond').html(res);
        }
        );
        return true;
    }

}


function openxBanner(zoneID){
    var m3_u = (location.protocol=='https:'?'https://www.misiamoiatdom.com/openx/www/delivery/ajs.php':'http://www.misiamoiatdom.com/openx/www/delivery/ajs.php');
    var m3_r = Math.floor(Math.random()*99999999999);
    if (!document.MAX_used) document.MAX_used = ',';
    document.write ("<scr"+"ipt type='text/javascript' src='"+m3_u);
    document.write ("?zoneid="+zoneID);
    document.write ('&amp;cb=' + m3_r);
    if (document.MAX_used != ',') document.write ("&amp;exclude=" + document.MAX_used);
    document.write (document.charset ? '&amp;charset='+document.charset : (document.characterSet ? '&amp;charset='+document.characterSet : ''));
    document.write ("&amp;loc=" + escape(window.location));
    if (document.referrer) document.write ("&amp;referer=" + escape(document.referrer));
    if (document.context) document.write ("&context=" + escape(document.context));
    if (document.mmm_fo) document.write ("&amp;mmm_fo=1");
    document.write ("'><\/scr"+"ipt>");
}



<!--
function cyr2lat(kvo){
    var out = "";
    msg=kvo;
    k=msg.length;
    for (var i=0; i<k; i++)
    {
        if (msg.charAt(i)==" "){ //това е спейс
            out +="_"
        }
        else if (msg.charAt(i)=="а"){
            out +="a"
        }
        else if (msg.charAt(i)=="б"){
            out +="b"
        }
        else if (msg.charAt(i)=="в"){
            out +="v"
        }
        else if (msg.charAt(i)=="г"){
            out +="g"
        }
        else if (msg.charAt(i)=="д"){
            out +="d"
        }
        else if (msg.charAt(i)=="е"){
            out +="e"
        }
        else if (msg.charAt(i)=="ж"){
            out +="j"
        }
        else if (msg.charAt(i)=="з"){
            out +="z"
        }
        else if (msg.charAt(i)=="и"){
            out +="i"
        }
        else if (msg.charAt(i)=="й"){
            out +="y"
        }
        else if (msg.charAt(i)=="к"){
            out +="k"
        }
        else if (msg.charAt(i)=="л"){
            out +="l"
        }
        else if (msg.charAt(i)=="м"){
            out +="m"
        }
        else if (msg.charAt(i)=="н"){
            out +="n"
        }
        else if (msg.charAt(i)=="о"){
            out +="o"
        }
        else if (msg.charAt(i)=="п"){
            out +="p"
        }
        else if (msg.charAt(i)=="р"){
            out +="r"
        }
        else if (msg.charAt(i)=="с"){
            out +="s"
        }
        else if (msg.charAt(i)=="т"){
            out +="t"
        }
        else if (msg.charAt(i)=="у"){
            out +="u"
        }
        else if (msg.charAt(i)=="ф"){
            out +="f"
        }
        else if (msg.charAt(i)=="х"){
            out +="h"
        }
        else if (msg.charAt(i)=="ц"){
            out +="c"
        }
        else if (msg.charAt(i)=="ч"){
            out +="ch"
        }
        else if (msg.charAt(i)=="ш"){
            out +="sh"
        }
        else if (msg.charAt(i)=="щ"){
            out +="sht"
        }
        else if (msg.charAt(i)=="ъ"){
            out +="a"
        }
        else if (msg.charAt(i)=="ь"){
            out +="y"
        }
        else if (msg.charAt(i)=="ю"){
            out +="yu"
        }
        else if (msg.charAt(i)=="я"){
            out +="ya"
        }
        else if (msg.charAt(i)=="А"){
            out +="A"
        }
        else if (msg.charAt(i)=="Б"){
            out +="B"
        }
        else if (msg.charAt(i)=="В"){
            out +="V"
        }
        else if (msg.charAt(i)=="Г"){
            out +="G"
        }
        else if (msg.charAt(i)=="Д"){
            out +="D"
        }
        else if (msg.charAt(i)=="Е"){
            out +="E"
        }
        else if (msg.charAt(i)=="Ж"){
            out +="J"
        }
        else if (msg.charAt(i)=="З"){
            out +="Z"
        }
        else if (msg.charAt(i)=="И"){
            out +="I"
        }
        else if (msg.charAt(i)=="Й"){
            out +="Y"
        }
        else if (msg.charAt(i)=="К"){
            out +="K"
        }
        else if (msg.charAt(i)=="Л"){
            out +="L"
        }
        else if (msg.charAt(i)=="М"){
            out +="M"
        }
        else if (msg.charAt(i)=="Н"){
            out +="N"
        }
        else if (msg.charAt(i)=="О"){
            out +="O"
        }
        else if (msg.charAt(i)=="П"){
            out +="P"
        }
        else if (msg.charAt(i)=="Р"){
            out +="R"
        }
        else if (msg.charAt(i)=="С"){
            out +="S"
        }
        else if (msg.charAt(i)=="Т"){
            out +="T"
        }
        else if (msg.charAt(i)=="У"){
            out +="U"
        }
        else if (msg.charAt(i)=="Ф"){
            out +="F"
        }
        else if (msg.charAt(i)=="Х"){
            out +="H"
        }
        else if (msg.charAt(i)=="Ц"){
            out +="C"
        }
        else if (msg.charAt(i)=="Ч"){
            out +="Ch"
        }
        else if (msg.charAt(i)=="Ш"){
            out +="Sh"
        }
        else if (msg.charAt(i)=="Щ"){
            out +="Sht"
        }
        else if (msg.charAt(i)=="Ъ"){
            out +="A"
        }
        else if (msg.charAt(i)=="Ю"){
            out +="Yu"
        }
        else if (msg.charAt(i)=="Я"){
            out +="Ya"
        }

        else {
            out+=msg.charAt(i);
        }

    }
    return out;
}