/* Suppress al JS errors */
function silentErrorHandler() {return true;}
window.onerror=silentErrorHandler;


/* Hide categories if JS is enabled */
document.write('<style type="text/css">.services { display:none; } #messaging { display:none; }</style>');

/* Initialise function when the DOM is ready */
$(document).ready(init);


function init() {

    // Animation
    var duartion = 700;
    
    $('#services1').fadeIn(duartion,function() {
        $('#services2').fadeIn(duartion,function() {
            $('#services3').fadeIn(duartion,function() {
                $('#services4').fadeIn(duartion,function() {
                    $('#services5').fadeIn(duartion,function() {
                    });
                });
            });
        });
    });

    // Run header animation
    header();

    // Services CSS & actions
    var pace = 400;
    
    $(".services")
        .css({ cursor: 'pointer' });
    
    $("#services1")
        .mouseover(function(){
            $("#services1 .services_header").stop().animate(
                {backgroundPosition:"(0 -32px)"}, 
                {duration:pace})
            })
        .mouseout(function(){
            $("#services1 .services_header").stop().animate(
                {backgroundPosition:"(0 0)"}, 
                {duration:pace})
            })
        .click(function() {
            window.location.href = 'http://www.finance.pro-science.eu/'+lang
        });
    
    $("#services2")
        .mouseover(function(){
            $("#services2 .services_header").stop().animate(
                {backgroundPosition:"(0 -32px)"}, 
                {duration:pace})
            })
        .mouseout(function(){
            $("#services2 .services_header").stop().animate(
                {backgroundPosition:"(0 0)"}, 
                {duration:pace})
            })
        .click(function() {
            window.location.href = 'http://www.lab.pro-science.eu/'+lang
        });
    
    $("#services3")
        .mouseover(function(){
            $("#services3 .services_header").stop().animate(
                {backgroundPosition:"(0 -32px)"}, 
                {duration:pace})
            })
        .mouseout(function(){
            $("#services3 .services_header").stop().animate(
                {backgroundPosition:"(0 0)"}, 
                {duration:pace})
            })
        .click(function() {
            window.location.href = 'http://www.scholar.pro-science.eu/'+lang
        });
    
    $("#services4")
        .mouseover(function(){
            $("#services4 .services_header").stop().animate(
                {backgroundPosition:"(0 -32px)"}, 
                {duration:pace})
            })
        .mouseout(function(){
            $("#services4 .services_header").stop().animate(
                {backgroundPosition:"(0 0)"}, 
                {duration:pace})
            })
        .click(function() {
            window.location.href = 'http://www.expertise.pro-science.eu/'+lang
        });
    
    $("#services5")
        .mouseover(function(){
            $("#services5 .services_header").stop().animate(
                {backgroundPosition:"(0 -32px)"}, 
                {duration:pace})
            })
        .mouseout(function(){
            $("#services5 .services_header").stop().animate(
                {backgroundPosition:"(0 0)"}, 
                {duration:pace})
            })
        .click(function() {
            window.location.href = 'http://www.it.pro-science.eu/'+lang
        });


    // IE actions
    
    $(".services_header")
        .css( {backgroundPosition: "0 0"} )
        .mouseover(function(){
            $(this).stop().animate(
                {backgroundPosition:"(0 -32px)"},
                {duration:pace})
        })
        .mouseout(function(){
            $(this).stop().animate(
                {backgroundPosition:"(0 0)"},
                {duration:pace})
        });


    // Menu oferta
    function initMenus() {
        $('.hideblock').css("display", "none");
        
        $('dl.menu dl').hide();
        $.each($('dl.menu'), function(){
            $('.showblock').show();
        });
        $('#page_path').append('<span id="page_path_plus"></span>');
        $('dl.menu dd a').click(
            function() {
                var checkElement = $(this).next();
                var parent = this.parentNode.parentNode.id;
                var nodeId = this.parentNode.id;



                if($('#' + parent).hasClass('noaccordion')) {
                    $(this).next().slideToggle('normal');
                    return false;
                }
                if((checkElement.is('dl')) && (checkElement.is(':visible'))) {
                    if($('#' + parent).hasClass('collapsible')) {
                        $('#' + parent + ' dl:visible').slideUp('normal');
                    }
                    return false;
                }
                if((checkElement.is('dl')) && (!checkElement.is(':visible'))) {
                    $('#' + parent + ' dl:visible').slideUp('normal');
                    $('.lev').slideUp('normal');
                    checkElement.slideDown('normal');
                    $('.opis').css("display", "none");
                    $('#'+nodeId+'_opis').css("display", "block");
                    if($('#'+nodeId).hasClass('submenu')) {
                        $('#page_path_plus').replaceWith('<span id="page_path_plus"> &#187; <a class="page_path_plus" href="http://www.'+this.parentNode.parentNode.parentNode.id+'.pro-science.eu/'+lang+'">'+this.parentNode.parentNode.parentNode.id.substring(0, 1).toUpperCase()+this.parentNode.parentNode.parentNode.id.substring(1)+'</a> &#187; <a class="page_path_plus" href="http://www.'+this.parentNode.parentNode.parentNode.id+'.pro-science.eu/index.php?cat='+nodeId+lang+'">'+nodeId.substring(0, 1).toUpperCase()+nodeId.substring(1)+'</a></span>');
                    }
                    else {
                        $('#page_path_plus').replaceWith('<span id="page_path_plus"> &#187; <a class="page_path_plus" href="http://www.'+nodeId+'.pro-science.eu/'+lang+'">'+nodeId.substring(0, 1).toUpperCase()+nodeId.substring(1)+'</a></span>');
                    }
                    return false;
                }
                
            }
            
        );
        
        
        
        
        
        
    }
    $(document).ready(function() {initMenus();});

    function wave() {
        //Detect browser and set wave image
        //opera Netscape 6 Netscape 4x Mozilla 
        if (window.innerWidth || window.innerHeight){ 
            docheight = window.innerHeight + 50; 
        } 
        //IE Mozilla 
        if (document.body.clientWidth || document.body.clientHeight){ 
            docheight = document.body.clientHeight; 
        }
        
        if(navigator.appName=="Netscape") {
            docheight = docheight + 50;
        }
        
        $('#wave').css("height",docheight+'px');
    }
    $(document).ready(function() {wave();});
}


    // Make links
    function makelink( name, domain, desc, pre, post ) {
        if ( pre != null && pre != "" )
            document.write( pre );
        
        document.write( '<a class="a" href="mailto:' );
        document.write( name + '&#64;' );
        document.write( domain + '">' );
        
        if ( desc != null && desc != "" )
            document.write( desc )
        else
            document.write( name + '&#64;' + domain );
        
        document.write( '</a>' );
        
        if ( post != null && post != "" )
            document.write( post );
    }


    // jQuery Background plugin
    (function($) {
        $.extend($.fx.step,{
            backgroundPosition: function(fx) {
                if (fx.state === 0 && typeof fx.end == 'string') {
                    var start = $.curCSS(fx.elem,'backgroundPosition');
                    start = toArray(start);
                    fx.start = [start[0],start[2]];
                    var end = toArray(fx.end);
                    fx.end = [end[0],end[2]];
                    fx.unit = [end[1],end[3]];
                }
                var nowPosX = [];
                nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
                nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
                fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

               function toArray(strg){
                   strg = strg.replace(/left|top/g,'0px');
                   strg = strg.replace(/right|bottom/g,'100%');
                   strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
                   var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
                   return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
               }
            }
        });
    })(jQuery);


    // jQuery pause plugin
    (function($) {
        $.fn.extend({
            pause: function(milli,type) {
                milli = milli || 1000;
                type = type || "fx";
                return this.queue(type,function(){
                    var self = this;
                    setTimeout(function(){
                        $(self).dequeue();
                    },milli);
                });
            },
            clearQueue: function(type) {
                return this.each(function(){
                    type = type || "fx";
                    if(this.queue && this.queue[type]) {
                        this.queue[type].length = 0;
                    }
                });
            },
            unpause: $.fn.clearQueue
        });
    })(jQuery);
