function clickclear(thisfield, defaulttext) {
    if (thisfield.value == defaulttext) {
        thisfield.value = "";
    }
}
function clickrecall(thisfield, defaulttext) {
    if (thisfield.value === "") {
        thisfield.value = defaulttext;
    }
}
c_over = function(el) {
    $(el).addClass('over');
    $(el).css('background-image', 'url('+b_url+'images/v.gif)');
}
c_out = function(el) {
    $(el).removeClass('over');
    $(el).css('background-image', 'url('+b_url+'images/vp.gif)');
}
c_a_over = function(el) {
    $(el).css('background-image', 'url('+b_url+'images/arrow2.gif)');
}
c_a_out = function(el) {
    $(el).css('background-image', 'url('+b_url+'images/arrow1.gif)');
}
placiau = function(id) {
    var i=$(id).attr('id');
    var id='prod_'+i;
    $('#'+id+"> #pr_img").fadeOut("fast");
    $("#pr_descr_"+i).fadeOut("fast", function() {
        $("#pr_descr_l_"+i).fadeIn("fast");
        $('a[id="'+i+'"].plac').hide("fast", function () {
            $('a[id="'+i+'"].b_plac').show("fast");
        })
    });
}
sumazinti = function(id) {
    var i=$(id).attr('id');
    var id='prod_'+i;
    $("#pr_descr_l_"+i).fadeOut("slow", function() {
        $('#'+id+" > #pr_img").fadeIn('normal')
        $("#pr_descr_"+i).fadeIn('normal', function() {
            $('a[id="'+i+'"].b_plac').hide("fast", function() {
                $('a[id="'+i+'"].plac').show("fast")
            });
        });
    });
}
onAfter=function() {
    if($('img', this).size() > 0) {
        $('#m_text').fadeOut(function() {
            $('#m_text').html($('img', this).attr('alt'))
        });
        $('#m_text').fadeIn("slow");
    }
    else {
        $('#m_text').html($(this).attr('alt'))
    }
}
vadyb = function(f) {
    var i=$(f).attr('id');
    var id='prod_'+i;
    if($("#vadyb_form_"+i+" :visible")) {
        $("#vadyb_form_"+i).hide(function() {
            $('#'+id+"> #pr_img").fadeIn("fast");
            $("#pr_descr_"+i).fadeIn("fast");
        });
    }
    else {
        $('#'+id+"> #pr_img").fadeOut("fast");
        $("#pr_descr_"+i).fadeOut("fast", function() {
            $("#vadyb_form_"+i).show();
        });
    }
}
n_popup = function(id) {
    $.ajax({
        type: "GET",
        url: b_url+"index.php/news/id/"+id,
        dataType: 'json',
        data: '',
        success: function(msg){
            $("#p_cont2").html(msg.p_text);
            $('.w_title2').text(msg.title);
            $('#window2').jqmShow();
        }
    });
}
lol = function() {
    $(document).ready(function() {
        $('#window2').jqm({
            trigger: false,
            overlayClass: 'ov2',
            modal: true
        });
        $('#window1').jqm({
            trigger: false,
            overlayClass: 'ov2',
            toTop: true,
            modal: true,
            onShow: function(h) {
                $('#window1').show(500);
            }
        });
        $('#pics').cycle({
            fx:    'fade',
            speed:  2000,
            timeout: 15000,
            delay: -3000,
            after: onAfter,
            fit: 1
        });
        $('.vad_form').each(function(i, el) {
            var f=$(el).attr('id');
            var t=$('#'+f).parent().parent().parent();
            var p=$('a[title="placiau"]', t).attr('id');
            var g=$('#msg_'+p);
            var v_form=$('#'+f);
            $('#'+f).ajaxForm({
                target: g,
                dataType: 'json',
                success: function(r, s) {
                    if(r.c) {
                        $('table tr:last td img',v_form).remove();
                        $('table tr:last td',v_form).prepend(r.c);
                        $(g).html(r.t);
                    }
                    else {
                        $('table',v_form).hide()
                        $(g).html(r.t);
                        setTimeout("location.reload(true);",3000);
                    }
                }
            });
        });
        $('a[title="vadyb"]').click(function() {
            var id='prod_'+$(this).attr('id');
            var i=$(this).attr('id');
            $('#'+id+"> #pr_img").fadeOut("fast")
            $("#pr_descr_"+i).fadeOut("fast", function() {
                $("#vadyb_form_"+i).show();
            });
        });
        $('a.men').click(function() {
            if($(this).attr('title') != '0' && $(this).attr('title')!='4') {
                $('<div></div>').html('<img src="'+b_url+'images/loading.gif" border="0" />').appendTo('#p_cont');
                $.ajax({
                    type: "GET",
                    url: b_url+"index.php/main/p_text/"+$(this).attr('title'),
                    dataType: 'xml',
                    data: '',
                    success: function(msg){
                        var nauj = $(msg).find('p_text').text()
                        var title = $(msg).find('p_title').text()
                        $("#p_cont").empty()
                        $("#p_cont").html(nauj);
                        $('.w_title').text(title);
                        $('#window1').jqmShow();
                    }
                });
            }
            if($(this).attr('title') == '4'){
                $('<div></div>').html('<img src="'+b_url+'images/loading.gif" border="0" />').appendTo('#p_cont');
                $.ajax({
                    type: "GET",
                    url: b_url+"index.php/page/atstovai",
                    dataType: 'json',
                    data: '',
                    success: function(msg){
                        $("#p_cont").empty()
                        $("#p_cont").html(msg.page);
                        $('.w_title2').text(msg.title);
                        $('#window1').jqmShow();
                    }
                });
                $('#men').removeClass()
                $('#men').addClass('men');
            }
        });
        $('.news').click(function() {
            var id=$(this).attr('title');
            if($("#new_"+id+":visible").size() > 0) {
                $("#new_"+id).hide('normal');
                return false;
            }
            $.ajax({
                type: "GET",
                url: b_url+"index.php/main/news_id/"+id,
                dataType: 'xml',
                data: '',
                success: function(msg){
                    var nauj = $(msg).find('nauj').text()
                    $("#new_"+id).empty()
                    $("#new_"+id).html(nauj).show('normal');
                }
            });
        });
        $('a[id="new_a"]').click(function() {
            $('#n_dir').wrapInner('<div id="n_hide" style="display: none"></div>');
            var s=$('#n_dir').html();
            $('#n_dir').hide('normal', function() {
                $.ajax({
                    type: "GET",
                    url: b_url+"index.php/main/get_news/0",
                    dataType: 'xml',
                    data: '',
                    success: function(msg){
                        var nauj = $(msg).find('nauj').text()+s
                        $("#n_dir").empty()
                        $("#n_dir").html(nauj).show('normal');
                        lol();
                    }
                });
            });
        });
        $('a[id="new_a_c"]').click(function() {
            var h=$('#n_hide').html();
            $('#n_dir').hide('normal', function() {
                $("#n_dir").empty()
                $("#n_dir").html(h).show('normal');
                lol();
            });
        });
	  
    });
};
hide_n = function(i) {
    $('#new_'+i).hide('normal')
}
close_w = function() {
    $('#window1').css({
        visibility: "hidden",
        width: "1px",
        height: "1px"
    });
    $('#window2').css({
        visibility: "hidden",
        width: "1px",
        height: "1px"
    });
    $('#overlay').hide();
};

tree_map = function() {
    tree = $('#myTree');
    $('li.treeItem', tree.get(0)).each(
        function()
        {
            subbranch = $('ul', this);
            if (subbranch.size() > 0) {
                if (subbranch.eq(0).css('display') == 'none') {
                    $('.folderImage', this).attr('src', '../../css/images/folder.png');
                    $('.expandImage', this).attr('src', '../../css/images/plus.gif');
                } else {
                    $('.folderImage', this).attr('src', '../../css/images/folder.png');
                    $('.expandImage', this).attr('src', '../../css/images/minus.gif');
                }
            } else {
                $('.folderImage', this).attr('src', '../../css/images/folder.png');
                $('.expandImage', this).attr('src', '../../images/spacer.gif');
            }
        }
        );
    $('img.expandImage', tree.get(0)).click(
        function()
        {
            if (this.src.indexOf('spacer') == -1) {
                subbranch = $('ul', this.parentNode).eq(0);
                if (subbranch.css('display') == 'none') {
                    subbranch.show('normal');
                    this.src = '../../css/images/minus.gif';
                } else {
                    subbranch.hide('normal');
                    this.src = '../../css/images/plus.gif';
                }
            }
        }
        );
}