/*
 * FarSEER JavaScript modul v0.1.0
 * Date: 2009-09-04
 * Revision: 1
 */

$.$fe=function()
{
    // alert('123');
    var farseer_r = Math.round(Math.random() * 100000);
    var $fr='';
    $("._dbclick").disableSelection();
    $("._dbclick").unbind();
    $("._shtor").disableSelection();
    $("._shtor").unbind();
    $("form[target]").disableSelection();
    $("form[target]").unbind();
    $(".ryad .ssel").disableSelection();
    $(".ryad .ssel").unbind();
    $(".ryad .rubil").disableSelection();
    $(".ryad .rubil").unbind();
    $(".ryad .vibor").disableSelection();
    $(".ryad .vibor").unbind();
    $("textarea").disableSelection().unbind();
    $(".sel .f_e_value .f_i_value").disableSelection();
    $(".sel .f_e_value .f_i_value").unbind();
    $(".f_i_value").disableSelection();
    $(".f_i_value").unbind();
    $("._scrollON").unbind();
    $activ_inp=$(".f_i_value");
    $activ_inp.bind("focus", function(e){
        $(this).addClass('_focus');
    });
    $activ_inp.bind("blur", function(e){
        $(this).removeClass('_focus');
    });
    $activ_inp.not("[readonly]").bind("change keyup", function(e){
        $(this).parent().find('.f_value').val($(this).val());
    });

    $("._shtor").click(function(e){
        $(this).next('div').slideToggle("fast");
    });
    $(".ryad .ssel").click(function(e){
        $(this).parent().parent().find(".f_i_value").click();
    });


    $(function ()
    {
         $("input[shabtext]").each(function (i){
            $(this).kontext();
         })
    });
    $(function ()
    {
         $(".pup ._click").each(function (i){
                $(this).data('target', $(this).attr('target'));
                $(this).data('href', $(this).attr('href'));
                $(this).click(function(e){
                    var tar=$(this).data('target');
                    if(!tar){
                        var tar=$(this).data("href");
                    }
                    mX=e.pageX;
                    mY=e.pageY;
                    if(tar){
                        $.$a('/jic/?fhash='+farseer_r+'&'+tar+'&plo='+$(".pup").attr("target")+'&sob=click',0);
                    }
                    return false;
                }).removeClass("_click").removeAttr("target").attr("href","/");
        });
    });


    $(function ()
    {
         $("._click").each(function (i){
                var farseer_r = Math.round(Math.random() * 100000);
                $(this).data('target', $(this).attr('target'));
                $(this).data('href', $(this).attr('href'));
                $(this).click(function(e){
                    var tar=$(this).data('target');
                    if(!tar){
                        var tar=$(this).data("href");
                    }
                    mX=e.pageX;
                    mY=e.pageY;
                    mW=$(this).innerWidth();
                    mH=$(this).innerHeight();
                    if(tar){
                        $.$a('/?fhash='+farseer_r+'&w='+mW+'&h='+mH+'&'+tar+'&sob=click',0);
                    }
                    return false;
                }).removeClass("_click").removeAttr("target").attr("href","/");
        });
    });

/*
    $("._click[exactive!=true]").attr({
        exactive2: true
    }).click(function(e){
        var tar=$(this).attr("target");
        if(!tar){
            var tar=$(this).attr("href");
        }
        if(tar){
            $.$a('/jic/?fhash='+farseer_r+'&'+tar+'&sob=click',0);
        }
        mX=e.pageX;
        mY=e.pageY;
        //alert('/jic/?fhash='+farseer_r+'&'+$(this).attr("target"));
        return false;
    });


    */
    $(".splu").disableSelection().unbind().click(function(e){
        $.$a('/?'+farseer_r+'&'+$(this).parent().parent().find(".fplu").attr("us"),0);
        return false;
    });


    $("._dbclick[exactive!=true]").attr({
        exactive2: true
    }).dblclick(function(e){
        $.$a('/?fhash='+farseer_r+'&'+$(this).attr("target"),0);
        mX=e.pageX;
        mY=e.pageY;
        //alert('/jic/?fhash='+farseer_r+'&'+$(this).attr("target"));
        return false;
    });

    $("._click a[exactive!=true]").attr({
        exactive2: true
    }).click(function(e){
        $.$a('/?fhash='+farseer_r+'&'+$(this).attr("target"),0);
        mX=e.pageX;
        mY=e.pageY;
        return false;
    });
    $(function ()
    {
        $(".ryad .rubil").click(function(e){
            var nr=$(this).parents().children(".f_value").attr('name');
            $("input[name='"+nr+"']").select(false);
            $("input[name='"+nr+"']").parents().children('.rubil').removeClass('rubil_sel');
            $(this).addClass('rubil_sel');
            $(this).parents().find('.f_value').select();
            var vr=$(this).parents().find('.f_value').val();
            $("input[name='"+nr+"']").removeAttr('checked');
            $("input[name='"+nr+"'][value='"+vr+"']").attr('checked', 'checked');
        });
        // активизируем отметки
        $(".ryad .vibor").click(function(e){

            var nr=$(this).parents().children(".f_value").attr('name');
            var vr=$(this).parents().find('.f_value').val();
            if($(this).hasClass('vibor_sel'))
            {
                $("input[name='"+nr+"'][value='"+vr+"']").removeAttr('checked');
            }else{
                $("input[name='"+nr+"'][value='"+vr+"']").attr('checked', 'checked');
            }
            $(this).toggleClass('vibor_sel');
        });
    });


    $('.ui-button:not(.no-bot)').hover(
        function(){
            $(this).addClass("ui-state-hover");
        },
        function(){
            $(this).removeClass("ui-state-hover");
        }
        ).mousedown(function(){
        $(this).addClass("ui-state-active");
    })
    .mouseup(function(){
        $(this).removeClass("ui-state-active");
    });
    $("div[gd=d]").addClass("ui-icon").addClass("dl").addClass("ui-icon-dir").removeAttr("gd");
    $("div[gd=p]").addClass("ui-icon").addClass("dl").addClass("ui-icon-page").removeAttr("gd");
    $fr=$(".resizew");
    $($fr).attr({
        exactive: true
    }).resizable({
        alsoResize: $($fr).parent(),
        autoHide: true,
        maxWidth: ($($fr).width()*1.5),
        minWidth: ($($fr).width()*0.8),
        handles: 'e'
    });
    function putclock(ui)
    {
        time=new Date();
        $(".pup .wp .time").text(time.getHours()+":"+time.getMinutes()+":"+time.getSeconds());
    //setTimeOut("putcl2(ui)",10);
    }
    /*function putcl2(ui)
    {
        time=new Date();
        $(ui).text(time.getHours()+" "+time.getMinutes()+" "+time.getSeconds());
       // setTimeOut("putcl(ui)",10);
    }*/
    $(function() {
        $(".accordionw").accordion({
            fillSpace: true,
            autoHeight: true
        });
    });
    $(function()
    {
        formn=$("._ctrlenter");
        $(formn).find('textarea').keydown(function (e) {
            if (e.ctrlKey && e.keyCode == 13) {
                $(formn).submit();
                return false;
            }
        });
    });
    $(function(){
        var $tabs = $(".tab[e!=t]").attr({
            "e":"t"
        }).tabs({
            tabTemplate: '<li><a href="#{href}">#{label}</a> <span class="ui-icon ui-icon-close">Remove Tab</span></li>'
        });
        $('.tab span.ui-icon-close').live('click', function() {
            var index = $('li',$tabs).index($(this).parent());
            $tabs.tabs('remove', index);
        });
    });
    $(function(){
        $(".systable tr").removeClass("e");
        $(".systable").find('tr.tbody:odd').addClass("e");
    });
    $(function() {
        $(".lists[ex!=true]").attr({
            ex: true
        }).click(function(e){

            if(!$(this).hasClass("ui-icon-listn"))
            {
                if($(this).attr("l")!="t")
                {
                    $(this).attr("l","t");
                    idu=$("#"+$(this).attr("pr"));
                    /*$(idu).html('<img border="0" src="http://img.farseer.info/sys/load_u.gif">');*/
                    $.$a('/jic/?act=porter&in=list&doo=pu&fhash='+farseer_r+'&id='+$(this).attr("pr")+'&list='+$(this).attr("target"),0);
                    $(idu).show();
                }else{
                    if($(this).attr("pr"))
                    {
                        idu=$("#"+$(this).attr("pr"));
                        $(this).removeClass("ui-icon-listp");
                        if($(idu).css("display")=="none")
                        {
                            $(this).removeClass("ui-icon-listp").addClass("ui-icon-listm");
                        }else{
                            $(this).removeClass("ui-icon-listm").addClass("ui-icon-listp");
                        }
                        $(idu).toggle();
                    }
                }
            }


            return false;
        });
    });


    $(function(){
        $("form").each(function (i){
            $tf=this;
            $($tf).find("input[kp!=true]").attr({
                kp:true
            }).keyup(function(e){
                if(e.which == 13){
                    $(this).change();
                    $($tf).submit();
                }
            });
        });
    });

    $(function()
    {
        $("form[target]").not("*[action]").submit(function (i){
            if($(this).attr('target')!='data')
            {
                if($(this).attr('target')!='porter')
                {
                    $(this).find(".f_i_value").change();
                    urll='/?'+$(this).attr('target')+"&p="+$("#pages").attr("content")+"&pg="+$("#pages").attr("content");
                    var options =
                    {
                        url: urll,
                        dataType: "json",
                        type:"POST",
                        beforeSubmit: function()
                        {
                            $("#mess_shto").show().animate({
                                opacity:  "0.1"
                            }, 1).animate({
                                opacity:  "1"
                            }, "slow");
                        },
                        success: function(d)
                        {
                            $.$d(d);
                            $.$fe();
                        }
                    };
                    $(this).ajaxSubmit(options);
                    return false;
                }
            }

        });


        $("._submit").disableSelection().unbind().submit(function(i)
        {
            $(this).find(".f_i_value").change();
            urll='/?'+$(this).attr('target')+"&pg="+$("#pages").attr("content")+'&sob=sbmt';
            var options ={
                url: urll,
                dataType: "json",
                type:"POST",
                success: function(d)
                {
                    $.$d(d);
                    $.$fe(1);
                }
            };
            $(this).ajaxSubmit(options);
            return false;
        });
    });
    /* активация наведения */
    $("._hover").disableSelection();

    $("._hover").hover(function()
    {
        $(this).addClass("_over");
    },function()
    {
        $(this).removeClass("_over");
    });
    /* активизируем инпуты */
    $(function() {
        var editiden='';
        $(".contedit").each(function(i){
            var $rrrrr=$(this);
            far_r = Math.round(Math.random() * 100000);
            $(this).addClass('ed'+ far_r);
            $(this).tinymce({
                script_url : 'http://stat.farseer.info/js/jquery/tinymce/3.4.7/tiny_mce.js',
                theme : "advanced",
                language : "ru",
                force_br_newlines : true,
                force_p_newlines : false,
                forced_root_block : '',
                plugins : "advimage,advlink,media,paste,bbcode",
                theme_advanced_buttons1 : "bold,italic,underline,link,|,image,media",
                theme_advanced_buttons2 : "",
                theme_advanced_buttons3 : "",
                theme_advanced_toolbar_location : "top",
                theme_advanced_toolbar_align : "left",
                theme_advanced_resizing : false,
                extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
              /*  template_external_list_url : "example_template_list.js",*/
                use_native_selects : true,
             /*   content_css : "http://stat.farseer.info/js/jquery/tinymce/content.css",*/
                setup : function(ed) {
                    ed.onChange.add(function(ed, l) {
                        $($rrrrr).parent().find('.f_value').val(l.content);
                    });
                    ed.onDblClick.add(function(ed, e) {
                         if('IMG'==e.target.nodeName)
                         {
                                ed.execCommand('mceAdvImage');
                         }
                    });
                }
            }).removeClass("contedit");
            $("#mce_0_ifr").css('max-height','30');
        });
    });
   $("._scrollON").each(function (i){

           // var sh=0;
            $(this).removeClass("_scrollON").addClass("_scroll");
            $(this).slimScroll({color: "#000",size: "15px",height: parseFloat($(this).css("height")),alwaysVisible: true,start: 'bottom'});
            $(this).bind("change", function(event){
                $(this).scrollTop(100000);
                if($(this).attr('target')=='t')
                {
                     var $datak=$(this).scrollTop();
                     if($(this).data("height")>0)
                     {
                        if($(this).data("onload")==true)
                        {
                            var $datakTo=$(this).scrollTop()-$(this).data("height");
                            $(this).scrollTop($datakTo);
                            $(this).mouseover();
                            $(this).next(".slimScrollBar").css('top',(1/$datak*$datakTo*parseFloat($(this).css('height')))-(parseFloat($(this).next(".slimScrollBar").css('height'))/2));
                            //alert((1/$datak*$datakTo*parseFloat($(this).css('height'))));
                            $(this).data("onload",false);
                        }
                     }
                    // alert($(this).scrollTop()+'-'+$(this).data("height"));
                     $(this).data("height",$datak);
                }else{
                    $(this).mouseover().hover().next(".slimScrollBar").css({bottom:0, top: 'auto'});
                }
            }).change();
            $(this).bind("scroll", function(event) {
                var topsc=parseFloat($(this).next(".slimScrollBar").css('top'));
                var bottomsc=top+parseFloat($(this).next(".slimScrollBar").css('height'))-parseFloat($(this).css('height'));
                if(topsc==0 & $(this).attr('target')=='t')
                {
                    $(this).data("onload",true);
                     $(this).find('._morescroll').click();
                }
                if( bottomsc>=0 & $(this).attr('target')=='b')
                {
                     $(this).data("onload",true);
                     $(this).find('._morescroll').click();
                }
            })

        });
    /*********** Подсказка ***********/
    //$(".sel .f_e_value .f_i_value[exactive!=true]").attr({exactive: true}).suggest();
    $(function(){
        $(".sel").unbind().each(function (i){
            $tel=this;

            if($($tel).attr("readonly"))
            {

                $($tel).autocomplete({
                    disabled: false,
                    focus: function(event, ui) {
                        $(this).parent().find(".f_value").val(ui.item.value);
                        $(this).val(ui.item.label);
                    },
                    close: function(event, ui) {
                        $(this).parent().find(".ssel").removeClass("ui-icon-sup").addClass("ui-icon-sdown");
                    },
                    source: "",
                    minLength: 0,
                    select: function(event, ui) {
                        $(this).parent().find(".f_value").val(ui.item.value).change();
                        $(this).val(ui.item.label).change();


                        // alert($(this).parent().find(".f_value").val());
                        /*if(ui.item.value==1000){
                                            $.$a("?sugdat&"+$(this).attr("us"));
                                        }*/
                        return false;

                    }
                }).click(function() {
                    $(".ui-autocomplete li").remove();

                    var projects = eval($(this).parent().find(".f_data").text());
                    $(this).parent().find(".ssel").removeClass("ui-icon-sdown").addClass("ui-icon-sup");
                    $(this).autocomplete({
                        source:projects
                    });
                    $(this).focus();
                    $(this).autocomplete("search","");
                    $(this).focus();
                });
            }else{
                $($tel).autocomplete({
                    disabled: false,
                    focus: function(event, ui) {
                        return false;
                    },
                    close: function(event, ui) {
                        $(this).parent().find(".ssel").removeClass("ui-icon-sup").addClass("ui-icon-sdown");
                    },
                    source: "?sugdat&r&"+$(this).attr("us")+"",
                    minLength: 2,
                    select: function(event, ui) {
                        $(this).parent().find(".f_value").val(ui.item.value).change();
                        $(this).val(ui.item.label);

                        if(ui.item.a){
                        // $.$a("?"+ui.item.a+'&temp=');

                        }
                        return false;
                    }
                }).click(function() {
                    $(".ui-autocomplete li").remove();
                    $(this).parent().find(".ssel").removeClass("ui-icon-sdown").addClass("ui-icon-sup");
                    $(this).autocomplete({
                        minLength:0,
                        source:"?sugdat&"+$(this).attr("us")+$(this).val()+"&"
                    });
                    $(this).focus();
                    $(this).autocomplete("search","");
                    $(this).autocomplete({
                        minLength:2
                    });

                }).parent().find(".ssel").click(function() {
                    //$(this).parent().find(".f_i_value").click();

                    });
            }
        });


    });
    $(function(){
        $("._chenge").change(function(){
            if($(this).is(".f_i_value"))
            {
                if($(this).is(".sel"))
                {
                    $.$a('?'+$(this).attr("us")+'&val='+$(this).parent().find(".f_value").val()+'&sob=chng');
                }else{
                    $.$a('?'+$(this).attr("us")+'&val='+$(this).val()+'&sob=chng');
                }
            }else{
                $.$a('?'+$(this).attr("target")+'&sob=chng');
            }
        });
        $("._keyup").bind('keyup change',function(){
            $("._keyup").stop();
             var farseer_r = Math.round(Math.random() * 100000);
            if($(this).is(".f_i_value"))
            {
               //  var farseer_r = Math.round(Math.random() * 100000);
                if($(this).is(".sel"))
                {
                    $.$a('?fhash='+farseer_r+'&'+$(this).attr("us")+'&val='+$(this).parent().find(".f_value").val()+'&sob=kyp',0,2);
                }else{
                    $.$a('?fhash='+farseer_r+'&'+$(this).attr("us")+'&sob=kyp','val='+$(this).val(),2);
                }
            }else{
                $.$a('?fhash='+farseer_r+'&'+$(this).attr("us")+'&sob=kyp','val='+$(this).val(),2);
            }
            $(this).removeClass("_keyup");
            return false;
        });
    });

    function showCoords( c ) {
        $( '#sizadata' ).val(c.x+":"+c.y+":"+c.w+':'+c.h);
    }

    $(function(){
        $("._jcrop").each(function (i){
            var farseer_r = Math.round(Math.random() * 100000);
            var id='imj'+farseer_r;
            $(this).attr('id',id);
            $(this).after("<input id='sizadata'  name='data' value='0:0:0:0' type='hidden' />")
            $(this).Jcrop({
                onChange: showCoords,
                onSelect: showCoords,
                minSize: [10,10],
                setSelect: [ 0, 0, 100, 100 ]

            }).removeClass("_jcrop");
        })

    });

    $(function(){
        $("._upload").each(function (i){
                $(this).imgeUPl();
        });
    });
    /*$("._suggesti").keyup(function(){
                 $.$a('?'+$(this).attr("suggest")+$(this).val());
		return false;
	});*/
    $(".opa09").animate({
        opacity:  "0.9"
    },0);
    $(".opa075").animate({
        opacity:  "0.75"
    },0);
    $(".opa065").animate({
        opacity:  "0.65"
    },0);
    /***************** редактор *********************/
    $('.column div.column_blok .ui-icon-closethick').attr({
        exactive: true
    }).click(function(){
        $(this).parent().parent().parent().parent().remove();
        $t=$(".column .column_blok").injson();
        //$.$a('?act=porter&do=shab&in=savemov&tmp='+$("#pedit").data("edata").tmp+'&opt='+$t);
        /*  $("#mess_shto").show().animate({
            opacity:  "1"
        }, 0);*/
        // var farseer_r = Math.round(Math.random() * 100000);
        // $.getJSON(adres,{}, function(json){$.$d(json);});
        //$.getJSON(adres+"&pg="+$("body").attr("s")+"&"+farseer_r,function(json){$.$d(json);});
        $.$a('?'+$(this).attr('target'),'&opt='+$t);
    // return false;
    /*  $.ajax({
            type: "POST" ,
            url: '?act=porter&do=shab&in=savemov&tmp='+$("#pedit").data("edata").tmp+"&pg="+$("body").attr("s")+"&"+farseer_r,
            data:'&opt='+$t,
            dataType: 'json',
            success: function(json){
                $.$d(json);
                return false;
            }
*//*
        });*/

    });


    $(function() {

        $("#modmenu div.column_blok").draggable({
           /* connectToSortable:".column",*/
             helper: "clone",
            revert:true,
            cursorAt: {top: -1, left: -1},
             dropOnEmpty: true,
            cursor:'crosshair',
            appendTo: "#windowss"
        });

        $( ".column" ).droppable({
            greedy: true,
            hoverClass: "hover",
            activeClass: "active",
            tolerance:"pointer",
            accept: ":not(.ui-sortable-helper)",
            drop: function( event, ui )
            {
                $( this ).find( ".placeholder" ).remove();
                $( ui.draggable ).clone().appendTo(this);
                $t=$(".column .column_blok").injson();
                $("#mess_shto").show().animate({
                        opacity:  "1"
                }, 0);
                var farseer_r = Math.round(Math.random() * 100000);
                $.ajax({
                    type: "POST" ,
                    url: '?act=porter&do=shab&in=savemov&page='+$(".ppg").attr("target")+'&tmp='+$("#pedit").data("edata").tmp+"&pg="+$("#pages").attr("content")+"&"+farseer_r,
                    data:'&opt='+$t,
                    dataType: 'json',
                    success: function(json){
                        $.$d(json);
                    }
                });
	}
        }).sortable({
            connectWith: ".column" ,
            containment:'.ppg',
            cursor: 'crosshair',
            revert: true,
            forceHelperSize: false,
            dropOnEmpty: true,
            tolerance:"pointer",
            handle: '.ui-icon-muve',
            sort: function() {
				$( this ).removeClass( "ui-state-default" );
	    },
            start: function(event, ui) {
                $(ui.item).addClass("selecmov");
            },
            stop: function(event, ui) {
                $(ui.item).removeClass("selecmov");
                $("#pedit .column_blok:hidden").remove();
                $t=$(".column .column_blok").injson();
                $("#mess_shto").show().animate({
                    opacity:  "1"
                }, 0);
                var farseer_r = Math.round(Math.random() * 100000);
                $.ajax({
                    type: "POST" ,
                    url: '?act=porter&do=shab&in=savemov&page='+$(".ppg").attr("target")+'&tmp='+$("#pedit").data("edata").tmp+"&pg="+$("#pages").attr("content")+"&"+farseer_r,
                    data:'&opt='+$t,
                    dataType: 'json',
                    success: function(json){
                        $.$d(json);
                    }
                });
            }
        });

        $( ".column" ).disableSelection();

    });

    $(function() {
        $(".accordion").accordion();
    });
    /****************************************/
    $(function() {
        $(".tabs").tabs({
            selected: 0,
            fx: {
                opacity: 'toggle'
            }
        }).find(".ui-tabs-nav").sortable({
            axis:'x'
        }).find(".ui-button[exactive!=true]").attr({
            exactive: true
        }).click(
            function(e){
                //$tabsel.tabs('remove',$(this).attr('index'));
                //var sel =$tabsel.tabs('option', 'selected');
                $d=$(this).parent().parent().parent();
                $t=$("#"+$d.attr("id")+".tabs");
                $t.tabs('select',$(this).attr('index'));
                //alert($d.attr("id")+' '+$(this).attr('index')+' '+$t.tabs('option', 'selected'));

                $t.tabs('remove',$t.tabs('option', 'selected'));
            //$tabsel.tabs('select' ,sel);
            }
            );
    });
    /******************************/
    $("._hovers").hover(function()
    {
        $(this).stop().animate({
            opacity:  "0.9"
        }, 0);
    },function()
    {
        $(this).stop().animate({
            opacity:  "0.65"
        }, 0);
    });
    /*******************/
    function polzunok()
    {
        var $polzunokZ=0;
        $activ_pol=$(".polzunok").attr({
            exactive: true
        });
        $activ_pol.mousedown( function(e)
        {
            $polzunokZ=1;
            $polzunokX=e.pageX;
            $polzunokY=e.pageY;
        });
        $activ_pol.mouseup( function(e)
        {
            $polzunokZ=0;
            $activ_pol.css('margin-left','0px');
        });
        $("body").mouseup( function(e)
        {
            $polzunokZ=0;
            $activ_pol.css('margin-left','0px');
        });
        $("body").mousemove( function(e)
        {

            if($polzunokZ!=0)
            {
                var pozx= e.pageX-$polzunokX;
                var $wozp=$activ_pol.parent().width();
                if((pozx>=0)&&(pozx<($wozp-$activ_pol.width())))
                {
                    $activ_pol.css('margin-left',pozx+'px');
                }
                if(pozx>($wozp-$activ_pol.width())-5)
                {
                    $activ_pol.parent().text('');
                }
            }
        });
    }
    polzunok()
    $(function() {
        $("#msystab").tabs({
            selected: 0,
            fx: {
                opacity: 'toggle'
            }
        })/*.draggable({ revert: true })*/.find(".ui-tabs-nav").sortable({
            axis:'x'
        });
    });
}
$.$a=function(adres,datas,tip)
{
    if(tip<2)
    {
        $("#mess_shto").show().animate({
            opacity:  "1"
        }, 0);
    }
    var farseer_r = Math.round(Math.random() * 100000);
    if(adres.lastIndexOf("ttp")>0 & adres.lastIndexOf("ttp")<3)
    {
        if(adres.lastIndexOf("jsoncallback")<=0)
        {
            adres=adres+'&jsoncallback=?'
        }
    }
    var reg=/.*\?(.*)/i;
    var arr=reg.exec(adres);

    if(arr[1]!=datas)
    {
        datas=arr[1]+'&'+datas
    }
    datas='&p='+$("#pages").attr("content")+'&'+datas
    $.ajax({
        type: "POST",
        url: adres+"&p="+$("#pages").attr("content"),
        dataType: "json",
        data: datas,
        timeout:5000,
        ifModified:true,
        success: function(json){
            $.$d(json);

        }
    });
}


$.$d=function(d)
{
    array=eval(d);
   /* if($.inArray(array)<=0)
    {
        aletr($.base64.decode(d));
    }*/

    //obj = jQuery.parseJSON(
    for (var key in array)
    {
        var val = array[key];
        if(val.m=='m')
        {
            if(val.i)
            {
                try
                {
                    var rrrr=val.i;
                    $(rrrr).data("flags",false);
                    //alert(rrrr);
                    $.get('?act=porter&do=mak&i='+val.c, function(data) {
                        $(rrrr).append(data).data("flags",true);
                    });
                    while ($(rrrr).data("flags")==false)
                    {

                }
                }catch(e)
                {
                }
            }
        }
        if(val.m=='u')
        {
            if(val.i)
            {
                try
                {
                    $(val.i).html(val.c).change();
                //alert(val.i);
                //$.$ra();
                //$.$fe
                }catch(e)
                {
                }
            }
        }
        if(val.m=='ue')
        {
            if(val.i)
            {
                try
                {
                    $(val.i).append(val.c).change();
                }catch(e)
                {
                }
            }
        }
        if(val.m=='uu')
        {
            if(val.i)
            {
                try
                {
                    $(val.i).prepend(val.c).change();
                }catch(e)
                {
                }
            }
        }
        if(val.m=='re')
        {
            if(val.i)
            {
                try
                {
                    var par=$(val.i).parent();
                    $(val.i).replaceWith(val.c);
                    par.change();
                }catch(e)
                {
                }
            }
        }
        if(val.m=='be')
        {
            if(val.i)
            {
                try
                {
                    $(val.i).before(val.c).parent().change();
                }catch(e)
                {
                }
            }
        }
        if(val.m=='af')
        {
            if(val.i)
            {
                try
                {
                    $(val.i).after(val.c).parent().change();
                }catch(e)
                {
                }
            }
        }
        if(val.m=='ur')
        {
            if(val.i)
            {
                try
                {
                    $(val.i).replaceWith(val.c).parent().change();
                }catch(e)
                {
                }
            }
        }
        if(val.m=='p')
        {
            if(val.i)
            {
                try
                {
                    $("#"+val.i).html(val.c);
                }catch(e)
                {
                }
            }
        }
        if(val.m=='s')
        {
            try
            {
                eval(val.c);
            }catch(e)
            {
            }
        }
        if(val.m=='a')
        {
            try
            {
                $.$a(val.c);
            }catch(e)
            {
            }
        }
        if(val.m=='d')
        {
            try
            {
                $('body').data(val.i,val.c)
            }catch(e)
            {
            }
        }
        if(val.m=='r')
        {
            try
            {
                $(val.i).attr(val.n,val.c).change();
            }catch(e)
            {
            }
        }
        if(val.m=='w')
        {
            try
            {
                $('#'+val.i).remove().disableSelection().unbind();
                $('#'+val.i+' *').remove().disableSelection().unbind();
                $('#windowss').prepend('<div id="'+val.i+'" class="dialog" title="' + val.n + '">&nbsp;</div>');
                if(val.c['buttons'])
                {
                    $.each(val.c['buttons'], function(key, value){
                        val.c['buttons'][key]=function(){
                            eval(value);
                        };
                    });
                }
                val.c['fade']=700;
                val.c['minHeight']=30;
                val.c['minWidth']=30;
                val.c['zIndex']=1050;
                val.c['close']=function(event, ui){$(this).dialog("destroy").remove();return false;};
                val.c['bgiframe']=true;

                if(!val.c['draggable'])
                {
                    val.c['draggable']=false;
                }
                if(!val.c['resizable'])
                {
                    val.c['resizable']=false;
                }
                if(!val.c['modal'])
                {
                    val.c['modal']=false;
                }else{
                    $("#bodycontent").addClass("BodyUnScroll");
                }
                var cent=false;
                if(val.c['center']){cent=val.c['center'];val.c['center']=''}
                $('#'+val.i).dialog(val.c);
                if(val.c['draggable']==false)
                {
                    $('#'+val.i).parent().css({"position":"fixed"});
                }
                var t=val.c['position'];
                var i=val.i;
                $('#'+val.i).bind('change', function(){
                          $(this).dialog("option" ,"position",t).bind('remove', function() {
                                if(!$(".ui-widget-overlay").is(".ui-widget-overlay"))
                                {
                                   $("#bodycontent").removeClass("BodyUnScroll");
                                }
                            });
                });
                 $(window).bind('resize', function(){
                          $('#'+i).dialog("option" ,"position",t);
                });

            }catch(e)
            {
            }
        }
    }
    $.$fe();
    $("#mess_shto").animate({
        opacity:  "hide"
    },300).hide();
}


$(document).ready(function(){
    var $yak=window.location.hash;
    if($.cookie('L')!=1)
    {
        $.$a('?act=api&do=logp&jsoncallback=?');
    }
    if($yak!=0)
    {
        $.$a('/?act=porter&do=l&'+$yak.replace('#',''),0);
    }
    $.$fe();
    $("._submit[exclick!=true]").attr({
        exclick: true
    }).click(function(){
        $(this).parents('form').submit();
    });
    return false;
});


(function($){
    $.fn.kontext = function(){
       $(this).prev("label").remove();
       var farseer_r = Math.round(Math.random() * 100000);
       $(this).before('<label class="addcon" id="pod'+farseer_r+'"><span class="text"></span><span class="dop"></span></label>');
       $(this).prev(".addcon").find(".text").text($(this).val());
       if($(this).val()!='')
       {
            $(this).prev().find(".dop").text($(this).attr('addtext'));
       }else{
            $(this).prev().find(".dop").text($(this).attr('shabtext'));
       }
       $(this).prev(".addcon").click(function(){
        $(this).next().focus();
       }).find(".dop").css('z-index',1);
       $(this).prev(".addcon").width($(this).width());
       $(this).bind('keyup change keydown',function(){
            $(this).prev(".addcon").find(".text").text($(this).val());
            if($(this).val()!='')
            {
                    $(this).prev().find(".dop").text($(this).attr('addtext'));
            }else{
                    $(this).prev().find(".dop").text($(this).attr('shabtext'));
            }
       });
    };
})(jQuery);




