
function ds(e){
    return false
};
function dk(e){
    return disableCtrlKeyCombination(e)
};
function ra(){
    return true
};
function re(e){
    return true
};

var x88Loaded=false;

String.format = function( text ) {
    //check if there are two arguments in the arguments list

    if ( arguments.length <= 1 )
    {
        //if there are not 2 or more arguments there's nothing to replace
        //just return the original text
        return text;
    }

    //decrement to move to the second argument in the array
    var tokenCount = arguments.length - 2;
    for( var token = 0; token <= tokenCount; token++ )
    {
        //iterate through the tokens and replace their placeholders from the original text in order
        text = text.replace( new RegExp( "\\{" + token + "\\}", "gi" ),
            arguments[ token + 1 ] );
    }
    return text;
};

function disableCtrlKeyCombination(e)
{
    //list all CTRL + key combinations you want to disable
    var forbiddenKeys = new Array("a", "n", "c", "x", "v", "j");
    var key;
    var isCtrl;


    if(window.event)
    {
        key = window.event.keyCode;     //IE
        if(window.event.ctrlKey)
            isCtrl = true;
        else
            isCtrl = false;
    }
    else
    {
        key = e.which;     //firefox
        if(e.ctrlKey)
            isCtrl = true;
        else
            isCtrl = false;
    }

    //if ctrl is pressed check if other key is in forbidenKeys array
    if(isCtrl)
    {
        for(i=0; i<forbiddenKeys .length; i++)
        {
            //case-insensitive comparation
            if(forbiddenKeys[i].toLowerCase() == String.fromCharCode(key).toLowerCase())
            {

                return false;
            }
        }
    }
    return true;
}

(function($) {
    var userAgent = navigator.userAgent.toLowerCase();

    // Figure out what browser is being used
    $.browser = {
        version: (userAgent.match( /.+(?:rv|it|ra|ie|me)[\/: ]([\d.]+)/ ) || [])[1],
        chrome: /chrome/.test( userAgent ),
        safari: /webkit/.test( userAgent ) && !/chrome/.test( userAgent ),
        opera: /opera/.test( userAgent ),
        msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
        mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
    };

    $.fn.fixPng = function(settings) {

        // Settings
        settings = jQuery.extend({
            blankgif: 'blank.gif'
        }, settings);

        var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1);
        var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);

        if (jQuery.browser.msie && (ie55 || ie6)) {

            //fix images with png-source
            jQuery(this).find("img[src$=.png]").each(function() {

                jQuery(this).attr('width',jQuery(this).width());
                jQuery(this).attr('height',jQuery(this).height());

                var prevStyle = '';
                var strNewHTML = '';
                var imgId = (jQuery(this).attr('id')) ? 'id="' + jQuery(this).attr('id') + '" ' : '';
                var imgClass = (jQuery(this).attr('class')) ? 'class="' + jQuery(this).attr('class') + '" ' : '';
                var imgTitle = (jQuery(this).attr('title')) ? 'title="' + jQuery(this).attr('title') + '" ' : '';
                var imgAlt = (jQuery(this).attr('alt')) ? 'alt="' + jQuery(this).attr('alt') + '" ' : '';
                var imgAlign = (jQuery(this).attr('align')) ? 'float:' + jQuery(this).attr('align') + ';' : '';
                var imgHand = (jQuery(this).parent().attr('href')) ? 'cursor:hand;' : '';
                if (this.style.border) {
                    prevStyle += 'border:'+this.style.border+';';
                    this.style.border = '';
                }
                if (this.style.padding) {
                    prevStyle += 'padding:'+this.style.padding+';';
                    this.style.padding = '';
                }
                if (this.style.margin) {
                    prevStyle += 'margin:'+this.style.margin+';';
                    this.style.margin = '';
                }
                var imgStyle = (this.style.cssText);

                strNewHTML += '<span '+imgId+imgClass+imgTitle+imgAlt;
                strNewHTML += 'style="position:relative;white-space:pre-line;display:inline-block;background:transparent;'+imgAlign+imgHand;
                strNewHTML += 'width:' + jQuery(this).width() + 'px;' + 'height:' + jQuery(this).height() + 'px;';
                strNewHTML += 'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader' + '(src=\'' + jQuery(this).attr('src') + '\', sizingMethod=\'scale\');';
                strNewHTML += imgStyle+'"></span>';
                if (prevStyle != ''){
                    strNewHTML = '<span style="position:relative;display:inline-block;'+prevStyle+imgHand+'width:' + jQuery(this).width() + 'px;' + 'height:' + jQuery(this).height() + 'px;'+'">' + strNewHTML + '</span>';
                }

                jQuery(this).hide();
                jQuery(this).after(strNewHTML);

            });

            // fix css background pngs
            jQuery(this).find("*").each(function(){
                var bgIMG = jQuery(this).css('background-image');
                if(bgIMG.indexOf(".png")!=-1){
                    var iebg = bgIMG.split('url("')[1].split('")')[0];
                    jQuery(this).css('background-image', 'none');
                    jQuery(this).get(0).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + iebg + "',sizingMethod='scale')";
                }
            });

            //fix input with png-source
            jQuery(this).find("input[src$=.png]").each(function() {
                var bgIMG = jQuery(this).attr('src');
                jQuery(this).get(0).runtimeStyle.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader' + '(src=\'' + bgIMG + '\', sizingMethod=\'scale\');';
                jQuery(this).attr('src', settings.blankgif)
            });

        }

        return jQuery;

    };

    $.fn.disableSelection = function() {
        return this.each(function() {
            this.onkeydown=dk;
            this.onkeypress=dk;
            this.onmousedown=ds;
            this.onclick=ra;
            this.onselectstart = ds;
            this.selectstart = ds;
            this.ondragstart = ds;
            this.unselectable = "on";
            jQuery(this).css('-moz-user-select', 'none');
        });
    };

    $.fn.animateGallery = function(fadeTime, start, repeatInterval) {
        var items=$('ul li',this);
        var skip=false;

        if(start == -1) {
            start=0;
            skip=true;
        }

        var id=$(this).attr('id');
        var prev=items[start];

        if(!skip) {
            if(++start == items.length) start=0;
            var next=items[start];
            $(prev).show();
            $(prev).customFadeOut(fadeTime,function() {
                $(prev).hide(0,function() {
                    $(next).customFadeIn(fadeTime,function() {
                         $('#'+id).click(function() {
                            window.location=$(next).find('a').attr('href');
                        });
                        if(repeatInterval > 0) {
                            setTimeout("$('#"+id+"').animateGallery("+fadeTime+","+start+","+repeatInterval+")",repeatInterval);
                        }
                    });
                });
            });
            if(!$.support.opacity) {
                $(next).each(function() {
                    $(this).get(0).style.removeAttribute('filter');
                });
            }
        } else if(repeatInterval > 0) {
            $(prev).show();
             $('#'+id).click(function() {
                window.location=$(prev).find('a').attr('href');
            });

            var wait=repeatInterval;
            if(!x88Loaded) {
                start=-1;
                wait=50;
            }
           setTimeout("$('#"+id+"').animateGallery("+fadeTime+","+start+","+repeatInterval+")",wait);
        }
    };

    $.fn.animateLogo = function(className, start, textColor, backgroundColor, fadeTime, repeatTime) {
        var items=$(className);

        var skip=false;

        if(start == -1) {
            start=0;//Math.floor(Math.random()*items.length);
            skip=true;
        }

        var prev=items[start];


        if(!skip) {
            if(++start == items.length) start=0;
            var next=items[start];
            $(prev).show();
            $(prev).customFadeTo(fadeTime,backgroundColor,function() {
                $(prev).hide(0,function() {
                    $(next).show(0,function() {
                        $(next).customFadeTo(fadeTime,textColor,function() {
                            if(repeatTime > 0) {
                                var cmd=String.format('$("{0}").animateLogo("{1}",{2},"{3}","{4}",{5},{6})',
                                    $(this).attr('id'),className,start,textColor,
                                    backgroundColor,fadeTime,repeatTime);
                                setTimeout(cmd,repeatTime);
                            }
                        });
                    });
                    if(!$.support.opacity) {
                        $(next).get(0).style.removeAttribute('filter');
                    }
                });
            });
        } else if(repeatTime > 0) {
            $(prev).show();
            var cmd=String.format('$("{0}").animateLogo("{1}",{2},"{3}","{4}",{5},{6})',
                $(this).attr('id'),className,start,textColor,
                backgroundColor,fadeTime,repeatTime);
            setTimeout(cmd,repeatTime);
        }
    };


    $.fn.smoothTop = function() {
        if(!$.browser.opera) {
            $('html, body').animate({
                scrollTop:0
            }, 'fast');
        }
    };

    $.fn.customFadeIn = function(speed, callback) {
        $(this).fadeIn(speed, function() {
            if(!$.support.opacity)
                $(this).get(0).style.removeAttribute('filter');
            if(callback != undefined)
                callback();
        });
    };

    $.fn.customFadeOut = function(speed, callback) {
        $(this).fadeOut(speed, function() {
            if(!$.support.opacity)
                $(this).get(0).style.removeAttribute('filter');
            if(callback != undefined)
                callback();
        });
    };
    $.fn.customFadeTo = function(speed,to,callback) {
        return this.animate({
            'color': to
        }, speed, function() {
            if (to == 1 && jQuery.browser.msie)
                if(!$.support.opacity) {
                    this.style.removeAttribute('filter');
                }
            if (jQuery.isFunction(callback))
                callback();
        });
    };

    $.fn.customFadeToBg = function(speed,to,callback) {
        return this.animate({
            'backgroundColor': to
        }, speed, function() {
            if (to == 1 && jQuery.browser.msie)
                if(!$.support.opacity) {
                    this.style.removeAttribute('filter');
                }
            if (jQuery.isFunction(callback))
                callback();
        });
    };

    $.fn.extend({
        getPath: function( path ) {
            // The first time this function is called, path won't be defined.
            if ( typeof path == 'undefined' ) path = '';

            // If this element is <html> we've reached the end of the path.
            if ( this.is('html') )
                return 'html' + path;

            // Add the element name.
            var cur = this.get(0).nodeName.toLowerCase();

            // Determine the IDs and path.
            var id    = this.attr('id'),
            cls = this.attr('class');


            // Add the #id if there is one.
            if ( typeof id != 'undefined' )
                cur += '#' + id;

            // Add any classes.
            if ( typeof cls != 'undefined' )
                cur += '.' + cls.split(/[\s\n]+/).join('.');

            // Recurse up the DOM.
            return this.parent().getPath( ' > ' + cur + path );
        }
    });

})(jQuery);
	
$.extend($.tools.overlay.conf, {
    effect: $.browser.msie & $.browser.version < 7 ? 'default' : 'apple',
    fadeInSpeed: $.browser.msie ? $.browser.version <9 ? 0 : 350: 350,
    top:    $.browser.msie
    ? $.browser.version >7  ? '-2'
    : $.browser.version == 7
    ? '-3'
    : '-1'
    : $.browser.opera || $.browser.chrome
    ? '-2'
    : '-2',
    speed: 250,
    expose: {
        loadSpeed: 550,
        color: $.browser.msie && $.browser.version <8 ? '#222' : '#555',
        opacity: $.browser.msie && $.browser.version <8 ? 0.70: 0.8,
        closeSpeed: 250
    },

    closeOnEsc: false,

    onLoad: function() {
        document.onkeydown=dk;
        document.onkeypress=dk;
        document.onmousedown=ds;
        document.onclick=ra;
        document.onselectstart = ds;
        document.selectstart = ds;
        document.ondragstart = ds;
        $("div.apple_overlay h2").show();
        $("div.apple_overlay.white p").show();
    },

    onClose: function() {
        try {
            document.onselectstart = re;
            document.selectstart = re;
            document.ondragstart = re;
            document.onkeydown=re;
            document.onkeypress=re;
            document.onmousedown=re;
            document.onclick=re;
        } catch(err) {

        }

    }

});


$(document).ready(
    function() {
        $('#container').css({
            cursor: 'progress'
        });

        if(!((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)))) {
            var text=$("div.apple_overlay.white p");
            var header=$("div.apple_overlay h2");
            $(header).hide();
            $(text).hide();
            $(".topic a[rel]").overlay({
                onBeforeLoad: function() {
                    var wrap = this.getContent().find("#"+this.getTrigger().attr("wrap"));
                    wrap.load(this.getTrigger().attr("link"));
                }

            });
        }
        

        $('#technologyPanel div h2').click(
            function() {
                window.location=$(this).find('a').attr('href');
                $(this).css({
                    backgroundColor: '#fffffa',
                    cursor: "default"
                }) ;
                $(this).find('a').css({
                    color: '#555',
                    cursor: "default"
                }) ;
            });

        $.fn.handleClickOnPanel = function(background) {
            $(this).click(
            function() {
                window.location=$(this).find('span a').attr('href');
                $(this).css({
                    backgroundColor: background,
                    cursor: "default"
                }) ;
                $(this).find('span a').css({
                    color: '#555',
                    cursor: "default"
                }) ;
                $(this).find('p').css({
                    color: '#e60',
                    cursor: "default"
                });
            }
            )};

        $.fn.handleHoverOnPanel = function(background) {
            $(this).hover(
                function() {
                    $(this).parent().css({
                        backgroundColor: '#fae0bb',
                        cursor: "pointer"
                    }) ;
                    $(this).find('a').css({
                        color: '#f60',
                        cursor: "pointer"
                    }) ;
                    $(this).parent().find('span a').css({
                        color: '#f60'
                    });
                    $(this).parent().find('p').css({
                        color: '#555'
                    });
                },

                function() {
                    $(this).parent().css({
                        backgroundColor: background,
                        cursor: "default"
                    }) ;
                    $(this).find('a').css({
                        color: '#555',
                        cursor: "default"
                    }) ;
                    $(this).parent().find('span a').css({
                        color: '#555'
                    });
                    $(this).parent().find('p').css({
                        color: '#e60'
                    });

                });
        };

        $('#feed div ul li').handleClickOnPanel('#fffffa');
        $('#banner ul li').handleClickOnPanel('#f9f1e3');
        $('#feed div ul li span').handleHoverOnPanel('#fffffa');
        $('#feed div ul li p').handleHoverOnPanel('#fffffa');
        $('#banner ul li').handleHoverOnPanel('#f9f1e3');
        $('#technologyPanel div h2').handleHoverOnPanel('#fffffa');
        $('.unselectable').disableSelection();

        if($.browser.msie & $.browser.version < 9) {
            $('#content,#footer').show();
        } else {
            $('#content,#footer').customFadeIn(300);
        }

        var fadeTime=$.browser.msie ? $.browser.version == 8 ? 150 : $.browser.version == 7 ? 0 : 300 : 300;
        $('#gallery').animateGallery(fadeTime,-1,4000);
        fadeTime=$.browser.msie ? $.browser.version == 8 ? 0 : $.browser.version <= 7 ? 0 : 300 : $.browser.mozilla ? 20 : 300;
        $('#banner').animateGallery(fadeTime,-1,2500);

        try {
            $('#logoText').animateLogo(".logoText",-1,"#80828a","white",500,3000);
        } catch(err) {
        }

        $('#container').css({
            cursor: 'default'
        });

    });

$(window).load(function() {
    if($.browser.mozilla) {
        $('#control_image').fadeOut(1000);
    }

    x88Loaded=true;

});
