
    function changeTabTodayNews($node) {
        $('#tab-today ul li').removeClass('active'); // Remove active class from all links
        $($node).parent().addClass('active'); //Set clicked link class to active
        var currentTab = $($node).attr('href'); // Set variable currentTab to value of href attribute of clicked link
        $('#tab-today div.item').hide(); // Hide all divs
        $(currentTab).show(); // Show div with id equal to variable currentTab
        
        return false;
    }
    
    function rotateNews() {
        var nextLi = $('#tab-today ul li.active').next();
        if(nextLi.length == 0) {
            nextLi = $('#tab-today ul li:first');
        }
        
        var nextA = $(nextLi).find('a');
        changeTabTodayNews(nextA);
    }
      
    $(document).ready(function() {

        $('#tab-cinema').tabs();

        $('#tab-today div.item').hide(); // Hide all divs
        $('#tab-today div:first').show(); // Show the first div
        $('#tab-today ul li:first').addClass('active'); // Set the class of the first link to active
        $('#tab-today ul li a').click(function(){ //When any link is clicked
            return changeTabTodayNews(this);
        });
        
        $('#browserPicture .item').hover(
                function() {
                    $(this).addClass('bpActive');
                    $(this).find('.operation:hidden').show();
                },
                function() {
                    $(this).removeClass('bpActive');
                    $(this).find('.operation:visible').hide()
                }
            );
        
        $('.gPic .minPic img').each(function(){
            var big=$('.gPic .big img');
            var src= $(this).attr('src'); 
            var newSrc = src.replace('/m/', '/'); 
            $(this).click(function(){
                $(big).attr('src', newSrc); 
            });
        });
        
        $('#noticeBtn').click(function() {
            $('#noticeForm').toggle('slow');
        });
        
        if ($('#tab-today ul li.active').length != 0) {
            setInterval('rotateNews()', 10000);
        }
        
        $('#partyTabs').tabs();
        $('#partyTabs').tabs('select', 1);
        
//        var uploader = new qq.FileUploader({
//            // pass the dom node (ex. $(selector)[0] for jQuery users)
//            element: document.getElementById('file-uploader'),
//            // path to server-side upload script
//            action: '/halo/ogloszenia/upload',
//            
//            onComplete: function(id, fileName, responseJSON){
//                alert('aaa'+responseJSON.file_name)
//                },
//            
//            debug: true
//        });        
        
        var uploader2 = new qq.FileUploaderBasic({
            // pass the dom node (ex. $(selector)[0] for jQuery users)
            button: document.getElementById('file-uploader2'),
            // path to server-side upload script
            action: '/halo/ogloszenia/upload',
            
            onSubmit: function(id, fileName) {
                $('div.previewBox').append('<div id="img_'+id+'" class="preview loading"></div>');
            },
            
            onComplete: function(id, fileName, responseJSON){
                var fileName = responseJSON.file_name;
                var fileMin = fileName.substr(0, fileName.lastIndexOf('.')) +'.jpg';
                $('#img_'+id).removeClass('loading');
                $('#img_'+id).html(
                        '<input type="hidden" value="'+responseJSON.file_name+'" name="files[]" />'
                        +'<div style="position: relative;">'
                        +'<img src="/halo/uploads/m/'+fileMin+'" alt="" />'
                        +'<a onclick="$(\'#img_'+id+'\').html(\'\');" style="display: block; position: absolute; top: 0px; right: 0px;" href="javascript:void(0)">XXXXX</a>'
                        +'</div>');
                
                
                },
            
            debug: true
        });        

        
        
    });
    
function validate(form, isMCE) {
    if (isMCE)
        tinyMCE.triggerSave();
    for (i=0; i<form.elements.length; i++) {
        if (form.elements[i].className == 'r' && form.elements[i].value == '') {
            alert('Uzupełnij wszystkie wymagane pola.');
            return false;
        }
    }
    
    return true;
}    

function showPhoto(src) {
    width = 600;
    height = 610;

    xx = 12;
    yy = 60;
    
    x = width + xx;
    y = height + yy;
    
    if (x > screen.availWidth) x = screen.availWidth;
    if (y > screen.availHeight) y = screen.availHeight;

    left= Math.round((screen.width - x) / 2);
    top = Math.round((screen.height - y)  / 2); 
    
    window.open("/file.php?f=photo_window&p="+src,'','width='+width+', height='+height+', top='+top+', left='+left+', resizable=yes, scrollbars=no, toolbars=no, status=no');
}
    
function show(id) {
    var block = document.getElementById(id);
    
    if (block.style.display == "none") {
        block.style.display = "block";
    } else {
        block.style.display = "none"; 
    }
}

function show2(show, hide) {
    var bHide = document.getElementById(hide);
    var bShow = document.getElementById(show);
    
    bHide.style.display = "none";
    bShow.style.display = "block";
}

/**
 * Zaznacza wiersz i jego dzieci (WL - WithLevel)
 * startId - id wiersza z ktorego wolana jest metoda, 
 *   nie jest to id rekordu z bazy, 
 *   tylko numer wiersza na browserze
 * startLevel - ktory level z podelementami ma byc zaznaczony,
      jezeli wartosc jest rowna 0, to wszystkie elementy sa zaznaczane
 */
function confirmDeleteWL(browserName, startId, startLevel) {
    var id = startId;
    var level = startLevel;
    var loop = true;
    var firstLoop = true;
    var oldColors = new Array();
    var index = 0;
    var message;
    var row;
    
    while (loop) {
        row = null;
        if (document.getElementById(browserName+'_'+id+'_'+level) != null) {
            row = document.getElementById(browserName+'_'+id+'_'+level);
        } else if (document.getElementById(browserName+'_'+id+'_'+(level+1)) != null) {
            row = document.getElementById(browserName+'_'+id+'_'+(level+1));
            level++;
        } else if (document.getElementById(browserName+'_'+id+'_'+(level-1)) != null) {
            row = document.getElementById(browserName+'_'+id+'_'+(level-1));
            level--;
        }
        
        if (row != null && (startLevel == 0 || ((firstLoop && level == startLevel)  || (!firstLoop && level > startLevel)))) {
            oldColors[index] = new Array();
            oldColors[index][0] = browserName+'_'+id+'_'+level;
            oldColors[index][1] = row.style.background;
            row.style.background = '#FF9966';
            index++;
        } else
            loop = false;
            
        firstLoop = false;
        id++;
    }
    
    if (oldColors.length > 1)
        message = 'Czy napewno chcesz usunąć zaznaczone pozycje?';
    else
        message = 'Czy napewno chcesz usunąć zaznaczoną pozycję?';
    
    if (confirm(message)) 
        return true;
    else {
        for (var i=0; i<oldColors.length; i++) {
            document.getElementById(oldColors[i][0]).style.background = oldColors[i][1];
        }
        return false;
    }
}



/* --------------- BROWSER --------------- */


function checkAll(obj) {
    var select = document.getElementsByName('select[]');
    for (var i=0; i < select.length; i++) {
        var row = document.getElementById('node_'+select[i].value);
        
        if (obj.checked) {
            if (select[i].checked == false)
                row.className += ' browserRowSelect';
        } else {
            row.className = row.className.replace(' browserRowSelect', '');
        }
        select[i].checked = obj.checked;
    }
}

/**
 *  podswietla aktualny wiersz i odznacza checkboxa glownego (selectAll) 
 * */
function check(obj) {
    var row = document.getElementById('node_'+obj.value);
    if (obj.checked) {
        row.className += ' browserRowSelect';
    } else {
        row.className = row.className.replace(' browserRowSelect', '');
    }
    var checkbox = document.getElementById('selectAll');
    checkbox.checked = false;
}

function isAnyChecked() {
    var select = document.getElementsByName('select[]');
    for (var i=0; i < select.length; i++) {
        if (select[i].checked) 
            return true;
    }
    return false;
}


/**
 * confirm multi selected action
 * */
function confirmMSAction(action, comment) {
    if (!isAnyChecked()) {
        alert('Najpierw musisz wybrać pozycje z listy.');
        return;
    }
    
    if (confirm(comment))
        submitForm(action);
    
    return false;
}

function confirmAction(action, value, comment) {
    if (confirm(comment))
        submitForm(action, value);
    
    return false;
}

function confirmDelAction(value, comment) {
    var row = document.getElementById('node_'+value);
    row.className += ' rowDel';
    
    if (confirm(comment)) {
        submitForm('del', value);
    } else {
        row.className = row.className.replace(' rowDel', '');
    }
    
    return false;
}

function submitForm(action, value) {
    document.form_browser.action_name.value = action;
    if (value != null)
        document.form_browser.action_value.value = value;
        
    document.form_browser.submit();
}

/* --------------- KONIEC BROWSER --------------- */

/**
 * ustawia akcję dla formularza potwierdzajacego, ustawia wartosc i go submituje
 */
function submitConfirmForm(idForm, formAction, value) {
    var form = document.getElementById(idForm);
    form.action = formAction;
    form.confirm.value = value;
    form.submit();
}

/* NODES */

/* NODES - more options*/
function showMO(owner, id) {
    var block = document.getElementById(id);
    
    if (block.style.display == 'none') {
        block.style.display = 'block';
        owner.innerHTML = '-';    
    } else {
        block.style.display = 'none'; 
        owner.innerHTML = '+';
    }
}



/* ---------------- OPTIONS --------------------- */

function selectOption(selectedOption, showOptionId) {
    var panelId = 'optionsPanel';
    var columnId = 'optionsColumn';
    var panel = document.getElementById(panelId);
    var tabOption = panel.childNodes;
       
    for (var i=0; i<tabOption.length; i++) {
        if (tabOption[i].style)
            tabOption[i].style.display = 'none';
    }
    document.getElementById(showOptionId).style.display = 'block';
    
    var column = document.getElementById(columnId);
    var tabOptionLabel = column.getElementsByTagName('A');
    for (var i=0; i<tabOptionLabel.length; i++) {
        tabOptionLabel[i].className = null;
    }
    selectedOption.className = 'active';
}

function picDel(idPic) {
    var picPanel = document.getElementById('pic_'+idPic);
    var picAdd = document.getElementById('add_'+idPic);
    picPanel.style.display = 'none';
    picAdd.style.display = 'inline';
}

function picAdd(idPic) {
    var picPanel = document.getElementById('pic_'+idPic);
    var picAdd = document.getElementById('add_'+idPic);
    picPanel.style.display = 'block';
    picAdd.style.display = 'none';
}

function picEdit(idPic) {
    var picPanel = document.getElementById('pic_'+idPic);
    var picImg = document.getElementById('img_'+idPic);
    var picDel = document.getElementById('del_'+idPic);
    var picEdit = document.getElementById('edit_'+idPic);
    
    picPanel.style.display = 'block';
    picDel.style.display = 'inline';
    picEdit.style.display = 'none';
    picImg.style.display = 'none';
}

//TODO: 
function fileAction(comp) {
    if (comp != '') {
        
    }
    //alert('');
}

function fileAction2() {
    //alert('');
}

function clearFileInput( id )
{
    var elem = document.getElementById( id );
    elem.parentNode.innerHTML = elem.parentNode.innerHTML;
}

function addPoint(id_news, addOp) {
    var op = addOp ? 'Add' : 'Sub';
    $.get(
        global_path+'/ajax/news_add_point?id_news='+id_news+'&add='+addOp, 
        function(result) {
            if (result == 1) {
                point = $('#idPkt').html();
                if (addOp)
                    point++;
                else 
                    point--;
                
                $('#idPkt').html(point);
                /*
                $('#pointAddBtn').attr('src', global_path+'/public/images/user/buttons/point_add_off.gif');
                $('#pointSubBtn').attr('src', global_path+'/public/images/user/buttons/point_sub_off.gif');
                */
                $('#pointAdd').show();
                $('#pointAdd').fadeOut(2000);
            } else if (result == 2) {
                $('#point'+op+'Before').show();
                $('#point'+op+'Before').fadeOut(2000);
            }
      }
    );
}

function addRankPoint(id_rank_item, addOp) {
    var op = addOp ? 'Add' : 'Sub';
    $.get(
        global_path+'/ajax/rank_add_point?id_rank_item='+id_rank_item+'&add='+addOp, 
        function(result) {
            if (result == 1) {
                point = $('#idPkt_'+id_rank_item).html();
                if (addOp)
                    point++;
                else 
                    point--;
                
                $('#idPkt_'+id_rank_item).html(point);
                $('#pointAddBtn_'+id_rank_item).attr('src', global_path+'/public/images/user/buttons/point_add_off.gif');
                $('#pointSubBtn_'+id_rank_item).attr('src', global_path+'/public/images/user/buttons/point_sub_off.gif');
                /*
                $('#point'+op+'_'+id_rank_item).show();
                $('#point'+op+'_'+id_rank_item).fadeOut(2000);
                */
            } else if (result == 2) {
                $('#point'+op+'Before_'+id_rank_item).show();
                $('#point'+op+'Before_'+id_rank_item).fadeOut(2000);
            }
      }
    );
}

function gallery_change(id_gallery, next) {
    var what = '0';
    if (next)
        what = '1';
        
    $('#galleryRWrap').load(global_path+'/ajax/gallery_change/'+id_gallery+'/'+what);
}

function setV(id, val) {
    $('#'+id).val(val);
}

