//##input preddefined text show/hide
function open_disappear()
{
    $(function()
    {
        BUFFER['input']=Array();
        $('.disappear input[type="text"],.disappear input[type="password"]').each(function() {
            BUFFER['input'][$(this).attr('name')]=$(this).val();
        });
    });
    $(function() {
        $('.disappear input[type="text"],.disappear input[type="password"]').click(function() {
           if(BUFFER['input'][$(this).attr('name')] == $(this).val()) {
               $(this).val('');
           }
        });

        $('.disappear input[type="text"],.disappear input[type="password"]').blur(function() {
           if($(this).val() == '') {
               $(this).val(BUFFER['input'][$(this).attr('name')]);
           }
        });
    });
}
//##input preddefined text show/hide

//#show/hide
function open_wrapper()
{
    $('.wrapper-box .items').each(function() {
        if($(this).css('display')!='none')
        {
            $(this).parent().find('h4 a').addClass('open');
        }
    });
    $('.wrapper').click(function()
    {
        if($(this).hasClass('open'))
        {
            $(this).removeClass();
            $(this).addClass('wrapper');
            $($(this).attr('rel')).css('display','none');
        }
        else
        {
            $(this).addClass('open');
            $($(this).attr('rel')).css('display','block');
        }
    });
}
//#show/hide

//##tabs
function open_tabs()
{
    var tabContainers=$('div.s-tabs > div');
    tabContainers.hide().filter(':first').show();

    $('div.s-tabs ul.s-navigation a').click(function ()
    {
        tabContainers.hide();
        tabContainers.filter(this.hash).show();
        $('div.s-tabs ul.s-navigation a').removeClass('selected');
        $(this).addClass('selected');
        return false;
    }).filter(':first').click();

    var tabContainersB=$('div.s-tabsB > div');
    tabContainersB.hide().filter(':first').show();

    $('div.s-tabsB ul.s-navigation a').click(function ()
    {
        tabContainersB.hide();
        tabContainersB.filter(this.hash).show();
        $('div.s-tabsB ul.s-navigation a').removeClass('selected');
        $(this).addClass('selected');
        return false;
    }).filter(':first').click();
}
//##tabs

//#auto-submit
function open_autosubmit()
{
    $('.submit-box input[type="checkbox"]').change(function(){
        $('.submit-box form').submit();
    });
    $('.submit-box select').change(function(){
        $('.submit-box form').submit();
    });
}
//#auto-submit

function open_options()
{
    //#remove
    $('.remove-a').click(function(){
        var name=null;
        if($('#' + $(this).attr('rel') + ' .flag').length>0)
        {
            name=$('#' + $(this).attr('rel') + ' .flag').html();
        }
        if(name==null)
        {
            name='';
        }
        create_popup('remove',name,$(this).attr('rel'));
    });
}

//#return values
//#engine pre akcne tlacidla ako napr remove

//##menu tree
function open_menu_treeview()
{
    $('.s-treeview').treeview({
         collapsed:     true,
         animated:      'medium',
         prerendered:   false,
         persist:       'location',
         unique:        true,
         urlshort:      true
    });
}
//##menu tree

//##menu vertical
function open_menu_vertical()
{
    $('.s-vertical').superfish({
        hoverClass:     'sfHover',
        pathClass:      'noselect',
        pathLevels:     1,
        delay:          600,
        animation:      {height: 'show'},
        speed:          400,
        autoArrows:     false,
        dropShadows:    false,
        disableHI:      false,
        onInit:        function(){},
        onBeforeShow: function(){},
        onShow:        function(){},
        onHide:        function(){}
    });
}
//##menu vertical

//##menu horizontal
function open_menu_horizontal()
{
    $('.s-horizontal').superfish({
        hoverClass:     'sfHover',
        pathClass:      'noselect',
        pathLevels:     1,
        delay:          600,
        animation:      {height: 'show'},
        speed:          400,
        autoArrows:     false,
        dropShadows:    false,
        disableHI:      false,
        onInit:        function(){},
        onBeforeShow: function(){},
        onShow:        function(){},
        onHide:        function(){}
    });
}
//##menu horizontal

//##menu navbar
function open_menu_navbar()
{
    $('.s-navbar').superfish({
        hoverClass:     'sfHover',
        pathClass:      'selected',
        pathLevels:     1,
        delay:          2000,
        animation:      {height: 'show'},
        speed:          400,
        autoArrows:     false,
        dropShadows:    false,
        disableHI:      false,
        onInit:        function(){},
        onBeforeShow: function(){},
        onShow:        function(){},
        onHide:        function(){}
    });
}
//##menu navbar

function open_print()
{
     $('.printPage').click(function(){
         window.print();

         //#$('html').printElement({
         //#    //printMode:         'popup',
         //#    pageTitle:         '',
         //#    overrideElementCSS:null,
         //#    leaveOpen:         false
         //#});
     });
}

function open_colorbox()
{
    //##colorbox
    $('.showColors').click(function(){
        if($('#boxcolor-' + $(this).attr('id')).length==0)
        {
            var div=document.createElement('div');
            div.innerHTML=get_p_ColorBox($(this).attr('id'));
            div.id='boxcolor-' + $(this).attr('id');
            div.className='box-color';
            $($(this).parent().find('span')).append(div);
        }
    });
    //##colorbox
}
//##########
//##########

//#nacitanie funkcii pri starte
$(function()
{
    if($('.s-treeview').length!=0)
    {
        //##nastavenie menu typu treeview
        open_menu_treeview();
    }
    if($('.s-horizontal').length!=0)
    {
        //##nastavenie menu typu horizontal
        open_menu_horizontal();
    }
    if($('.s-vertical').length!=0)
    {
        //##nastavenie menu typu vertical
        open_menu_vertical();
    }
    if($('.s-navbar').length!=0)
    {
        //##nastavenie menu typu navbar
        open_menu_navbar();
    }
    if($('#add_image').length>0)
    {
        //##nastavenie iframov od cuteeditora
        row_click('',$('#add_image').val());
    }
    $('.smilles-a').click(function(){
        var request='';
        request+='action=main';
        request+='&request=get-smilles';
        sendRequest(request);
    });
    $('.place-box').each(function() {
        var tpl='';
        tpl+=$(this).html();
        tpl+='<br />';
        tpl+=$(this).width() + 14;
        tpl+='x';
        tpl+=$(this).height() + 14;
        $(this).html(tpl);
    });
    
    $(document).ready(function()
    {
        //##nastavenie aktivneho inputs
        $('#inputFirstPoint, .inputFirstPoint').focus();
        
        //##load dalsich funkcii
        if(window.open_colorbox){open_colorbox();}
        if(window.open_print){open_print();}
        if(window.open_autosubmit){open_autosubmit();}
        if(window.open_options){open_options();}
        if(window.open_disappear){open_disappear();}
        if(window.open_wrapper){open_wrapper();}
        if(window.open_tabs){open_tabs();}
        if(window.open_autocomplete){open_autocomplete();}
        if(window.open_datepicker){open_datepicker();}
        if(window.open_calendar){open_calendar();}
        if(window.open_sortable){open_sortable();}
        if(window.open_uploadify){open_uploadify();}

        //##load socialnych funkcii
        if(window.check_glass){check_glass();}
        if(window.check_panel){check_panel();}
        if(window.check_resize)
        {
            check_resize();
            resizeTimer=setTimeout("check_resize();",resizeTimerLimit);
        }
        if(window.check_online && !window.check_glass)
        {
            check_online();
        }
    });
});
//#nacitanie funkcii pri starte;




