/**
 *  增加缓动函数
 */
jQuery.easing['jswing'] = jQuery.easing['swing'];
jQuery.extend( jQuery.easing, {
    def: 'easeOutQuad',
    swing: function (x, t, b, c, d) {
        return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
    },
    easeOutQuad: function (x, t, b, c, d) {
        return -c *(t/=d)*(t-2) + b;
    },
    easeOutExpo: function (x, t, b, c, d) {
        return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
    },
    easeOutElastic: function (x, t, b, c, d) {
        var s=1.70158;var p=0;var a=c;
        if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
        if (a < Math.abs(c)) {
            a=c; var s=p/4;
        }
        else var s = p/(2*Math.PI) * Math.asin (c/a);
        return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
    },
    easeInBack: function (x, t, b, c, d, s) {
        if (s == undefined) s = 1.70158;
        return c*(t/=d)*t*((s+1)*t - s) + b;
    },
    easeOutBack: function (x, t, b, c, d, s) {
        if (s == undefined) s = 1.70158;
        return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
    },
    easeInOutBack: function (x, t, b, c, d, s) {
        if (s == undefined) s = 1.70158;
        if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
        return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
    },
    easeOutBounce: function (x, t, b, c, d) {
        if ((t/=d) < (1/2.75)) {
            return c*(7.5625*t*t) + b;
        } else if (t < (2/2.75)) {
            return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
        } else if (t < (2.5/2.75)) {
            return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
        } else {
            return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
        }
    }
});


/**
 * 导航光标跟踪效果
 */
$(document).ready(function() {
    var $nav = $('#header .nav');
    var $li  = $nav.find('li');
    var $current = $li.filter('.current');

    //初始化
    $current.css('border', 'none');
    var $elf = $('<div class="nav-elf"></div>').appendTo('#header');
    elf($current, false);

    function elf($target, isAnimate) {
        if (isAnimate == undefined) isAnimate = true;

        var width = $target.width() + parseInt($target.css('padding-left'), 10)*2 - 20; //为了减少padding带来的宽度 减去20
        var left = $nav.position().left + $target.position().left + 10; //左边只减去20/2
        var cleft = $elf.position().left + 10;
        var extraPixel = 5;
        var forward = cleft < left? 1 : cleft > left? -1 : 0;

        if (isAnimate) {
            $elf.stop().animate({
                'width': width,
                'left': left + forward*extraPixel
            }, 300, function() {
                $elf.animate({
                    'left': (forward==1?'-=':'+=') +extraPixel*Math.abs(forward)
                },100);
            });
        } else {
            $elf.css({
                'width': width,
                'left': left
            });
        }
        return false;
    }
    $li.hover(function() {
        this.className.indexOf('current') == -1 && elf($(this));
    }, function() {
        this.className.indexOf('current') == -1 && elf($current);
    });

});


/**
 * 人才招聘滑动
 */
$(document).ready(function() {
    var $list = $('.job #content .list .item');
    $list.find('h3').click(function() {
        var $this = $(this);
        var $ul = $this.next('.con');
        var bpl = parseInt($this.css('background-position'))+ 'px';
        if ($ul.css('display') == 'none') {
            $list.find('.con').stop().hide();
            if ($.browser.msie) {
                $list.find('h3').css('background-position-y', '0');
                $this.css('background-position-y', '100%');
            } else {
                $list.find('h3').css('background-position', bpl+' 0');
                $this.css('background-position', bpl+' 100%');
            }
            $ul.slideDown('600', 'easeOutElastic');
        }
    });
});

/*
 * 添加收藏
 */
function addBookmark(title,url) {
    if (window.sidebar) {
        window.sidebar.addPanel(title, window.location.href,"");
    } else if( document.all ) {
        window.external.AddFavorite( window.location.href, title);
    } else if( window.opera && window.print ) {
        return;
    }
}

/**
 * 加载css
 */
function loadCSS(content, type) {
    if (typeof type == "undefined") type = "file";

    var fileRef
    if (type == 'content') {
        fileRef = document.createElement("style");
        try {
            var cssContent = document.createTextNode(content);
            fileRef.appendChild(cssContent);
        } catch (e) {
            alert(e.toString());
            fileRef.innerHTML = content;
        }


    } else if (type == 'file') {
        fileRef = document.createElement("link");
        fileRef.setAttribute('href', content);
    }

    fileRef.setAttribute('rel', 'stylesheet');
    fileRef.setAttribute('type', 'text/css');
    document.getElementsByTagName('head')[0].appendChild(fileRef);
}