/**
 * Moonbase
 *
 * LICENSE
 *
 * This source file is subject to the Closed Source license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opcom.pl/blacms/license/closed_source
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@opcom.pl so we can send you a copy immediately.
 *
 * @copyright  Copyright (c) 2007 Opcom Grupa Eskadra (http://www.opcom.pl)
 * @license    http://opcom.pl/blacms/license/cs Closed Source License
 * @version    $Id: Controller.php 181 2008-06-24 13:46:11Z m..balus $
 */

$(document).ready( function() {
    // Num checked
    function countChecked() {
        var n = $(".ctsa:checked").length;
        $(".selectors_sum span").text(n);
    }

    // Select all
    $("a[href='#select_all']").click( function() {
        $(".ctsa").attr('checked', true);
        $(".listData tr").addClass('activeTr');
        countChecked();
        return false;
    });

    $(".ctsa").live('click', function(){
        var n = $(".ctsa:checked").length;
        $(".selectors_sum span").text(n);
    });

    // Select none
    $("body A[href='#select_none']").click( function() {
        $(".ctsa").attr('checked', false);
        $(".listData tr").removeClass('activeTr');
        countChecked();
        return false;
     });

    // Invert selection
    $("body A[href='#invert_selection']").click( function() {
        $(".ctsa").each( function() {
            $(this).attr('checked', !$(this).attr('checked'));
        });
        return false;
    });
});



/* Start modrewrite letter switch */
function modRewrite(strToConvert) {
var snew = "";
    snew = strToConvert.toLowerCase();
    snew = snew.replace(/_{2,}/g, '_');
    snew = snew.replace(/-_/g, '_');
    snew = snew.replace(/-{2,}/g, '');
    snew = snew.replace(/ - /g, '-');
    snew = snew.replace(/ą/g, 'a');
    snew = snew.replace(/ś/g, 's');
    snew = snew.replace(/ę/g, 'e');
    snew = snew.replace(/ż/g, 'z');
    snew = snew.replace(/ź/g, 'z');
    snew = snew.replace(/ć/g, 'c');
    snew = snew.replace(/ń/g, 'n');
    snew = snew.replace(/ó/g, 'o');
    snew = snew.replace(/ł/g, 'l');
    snew = snew.replace(/ /g, '_');
    snew = snew.replace(/,/g, '');
    snew = snew.replace(/\{/g, '');
    snew = snew.replace(/\}/g, '');
    snew = snew.replace(/\+/g, '');
    snew = snew.replace(/\~/g, '');
    snew = snew.replace(/\`/g, '');
    snew = snew.replace(/\!/g, '');
    snew = snew.replace(/\@/g, '');
    snew = snew.replace(/\#/g, '');
    snew = snew.replace(/\$/g, '');
    snew = snew.replace(/\%/g, '');
    snew = snew.replace(/\^/g, '');
    snew = snew.replace(/\&/g, '');
    snew = snew.replace(/\*/g, '');
    snew = snew.replace(/\(/g, '');
    snew = snew.replace(/\)/g, '');
    snew = snew.replace(/\=/g, '');
    snew = snew.replace(/\[/g, '');
    snew = snew.replace(/\]/g, '');
    snew = snew.replace(/\:/g, '');
    snew = snew.replace(/\;/g, '');
    snew = snew.replace(/\./g, '');
    snew = snew.replace(/\?/g, '');
    snew = snew.replace(/\</g, '');
    snew = snew.replace(/\>/g, '');
    snew = snew.replace(/\\/g, '');
    snew = snew.replace(/\//g, '');
    snew = snew.replace(/\"/g, '');
    snew = snew.replace(/\'/g, '');
    snew = snew.replace(/\|/g, '');
    snew = snew.replace(/_{2,}/g, '_');
    snew = snew.replace(/-_/g, '_');
    snew = snew.replace(/-{2,}/g, '');
    snew = snew.replace(/ - /g, '-');
    return snew;
}
/* End modrewrite letter switch */

/* Horizontal Menu*/
var menuids=["horizontalMenu"];
function buildsubmenus_horizontal(){
    for (var i=0; i<menuids.length; i++){
      var ultags=document.getElementById(menuids[i]).getElementsByTagName("ul")
        for (var t=0; t<ultags.length; t++){

            if (ultags[t].parentNode.parentNode.id==menuids[i]){
                ultags[t].style.marginLeft=ultags[t].parentNode.offsetLeft+"px";
                ultags[t].style.top=ultags[t].parentNode.offsetTop+ultags[t].parentNode.offsetHeight+"px";
            }
            else{
              ultags[t].style.left=ultags[t-1].getElementsByTagName("a")[0].offsetWidth+"px"
              ultags[t].parentNode.getElementsByTagName("a")[0].className="setMoreIco"
            }

            ultags[t].parentNode.onmouseout=function(){
                //alert(this.id);
                //alert(this.getElementsByTagName("ul")[0].id);
                this.getElementsByTagName("ul")[0].style.visibility="hidden";
            }

            ultags[t].parentNode.onmouseover = ultags[t].parentNode.onmousemove=function(){
                this.getElementsByTagName("ul")[0].style.visibility="visible";
            }

            ultags[t].onmouseover=function(){
                var children = this.getElementsByTagName("ul");
                for (var i = 0; i < children.length; i++){
                    children[i].style.top = (children[i].parentNode.offsetTop+9)+"px";
                }
            }
        }
    }

}

if (window.addEventListener){
    window.addEventListener("load", buildsubmenus_horizontal, false)
} else if(window.attachEvent){
    window.attachEvent("onload", buildsubmenus_horizontal)
}

function loadBoxFadeOut() {
    setTimeout ( "$('#loadStatusContainer').fadeOut('slow',function(){$(this).hide().find('span').removeClass('greenStatus')})", 2000 );
}