// JavaScript Document

//去除 A 虚线
    $(document).ready(function(){							   
        $("a").bind("focus",function(){
            if(this.blur){ 
                this.blur();
             }
        });
    });	
	
	
	
// 更改导航链接
	$(function(){ 
		$(".fly").parent().find("ul").remove();
		$("#footer p a:eq(0)").css({"padding":"0","padding-right":"8px"});
		$("#footer a:last").css({"padding":"0"});
		$("#lm_title_RFGL").parent().find("li:eq(3)").find("a").attr("href","http://www.zgcagi.com/fhqnew/webform.aspx?workcategoryid=1&customformid=28");
		$("#mainNav_1018").parent().find("ul li:eq(2)").find("a").attr("href","http://www.zgcagi.com/fhqnew/webform.aspx?workcategoryid=1&customformid=28");
		
		$("a#mainNav_1021").attr("href","http://www.zgcagi.com/fhqnew/Recruitment/index.aspx")
						  .parent().find("ul").css({"width":"115px"})
						  .parent().find("ul").find("a").css({"width":"115px"});
						  
		$("a#mainNav_1021").parent().find("ul").find("li:eq(0)").find("a").attr("href","http://www.zgcagi.com/fhqnew/Recruitment/index.aspx");
		$("a#mainNav_1021").parent().find("ul").find("li:eq(3)").find("a").attr("href","http://www.zgcagi.com/fhqnew/rcfw/ZbrushPX/GYZbrush/");
		
		$("a#mainNav_1070").css({"border-right":"none","width":"115px"})
						   .attr("target","_blank")
		                   .parent().find("ul").css({"width":"115px"})
						   .parent().find("ul").find("a").css({"width":"115px"})
						   .parent().find("a").attr("target","_blank");
		$("a#mainNav_1019").css({"width":"110px"})
						   .parent().find("ul").css({"width":"140px"})
						   .parent().find("ul").find("a").css({"width":"140px"});
		$("div#Billboard")
			.css({"z-index":"1000000","cursor":"pointer"})
			.click( function () { window.open("http://www.zgcagi.com/fhqnew/YSYXCXFHGL/")}); 
			
//		$("ul#wzdt_rcfw").find("li").css({"float":"left","width":"80px"});
//		$("ul#wzdt_ysyxsys").find("li").css({"float":"left","width":"100px"});
	});

// 主导航下拉菜单
	$(function(){ 
		$('.nav li').hover(
			function(){
				$(this).children('ul').stop(true,true).fadeIn('fast');
			},function(){
				$(this).children('ul').stop(true,true).fadeOut('slow');
			});
	});
	
	$(function(){
//		$("ul#gyzbrush").find("li:eq(0)").find("p").css({"line-height":"22px"})		   
//		$("ul#gyzbrush").find("li:eq(1)").find("p").css({"line-height":"20px"})		   
		$("div#main_left li#lm_title_rcfw").parent().find("li:eq(1)").find("a").addClass("over");
		$("li#lm_title_rcfw").parent().find("li:eq(1)").find("a").attr("href","http://www.zgcagi.com/fhqnew/Recruitment/index.aspx");
		$("li#lm_title_rcfw").parent().find("li:gt(4)").css({"height":"20px","background":"url(http://www.zgcagi.com/fhqnew/_images/icon_5.gif) 80px center no-repeat","display":"none","margin-bottom":"0px","line-height":"20px"})
		$("li#lm_title_rcfw").parent().find("li:gt(4)").find("a").css({"height":"18px","line-height":"18px","width":"88px","background":"none","padding-left":"85px"})
		$("li#lm_title_rcfw").parent().find("li:eq(4)").find("a").removeAttr("href")
													   .toggle(
  function () {
    $("li#lm_title_rcfw").parent().find("li:gt(4)").slideDown("slow");
  },
  function () {
    $("li#lm_title_rcfw").parent().find("li:gt(4)").slideUp("slow");
  }
);
		
	});


//leftMenuNav 当前位置
	window.onload=function()
	{
		load();
	}
 
	function load(){

		var thisHREF = document.location.href.substring(21);

		var $leftListA = $('.leftSide a');

		$leftListA.each(function(index){
			var ahref = $(this).attr("href");
			if (thisHREF == ahref) {
				$(this).addClass("over");	
			}
		});

	}
	
//添加收藏
$(document).ready(function() {
    $("#addcollect").click(function() {
        var ctrl = (navigator.userAgent.toLowerCase()).indexOf('mac') != -1 ? 'Command/Cmd' : 'CTRL'; 
        if (document.all){
          window.external.addFavorite('http://www.zgcagi.com/fhqnew/','中关村动漫游戏孵化器');
          }else if (window.sidebar){
         window.sidebar.addPanel('中关村动漫游戏孵化器', 'http://www.zgcagi.com/fhqnew/', "");
       }else {
               alert('您可以尝试通过快捷键' + ctrl + ' + D 加入到收藏夹~');
       }
    });   
});

//设置首页
function SetHome(obj,vrl){
        try{
                obj.style.behavior='url(#default#homepage)';obj.setHomePage(vrl);
        }
        catch(e){
                if(window.netscape) {
                        try {
                                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
                        }
                        catch (e) {
                                alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将 [signed.applets.codebase_principal_support]的值设置为'true',双击即可。");
                        }
                        var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
                        prefs.setCharPref('browser.startup.homepage',vrl);
                 }
        }
}


//图片向上滚动
//(function($){
//$.fn.extend({
//        Scroll:function(opt,callback){
//                if(!opt) var opt={};
//                var _this=this.eq(0).find("ul:first");
//                var lineH=_this.find("li:first").height(), 
//                    line=opt.line?parseInt(opt.line,10):parseInt(this.height()/lineH,10), 
//                    speed=opt.speed?parseInt(opt.speed,10):500, 
//                    timer=opt.timer?parseInt(opt.timer,10):3000; 
//                if(line==0) line=1;
//                var upHeight=0-line*lineH;
//                scrollUp=function(){
//                        _this.animate({
//                                marginTop:upHeight
//                        },speed,function(){
//                                for(i=1;i<=line;i++){
//                                        _this.find("li:first").appendTo(_this);
//                                }
//                                _this.css({marginTop:0});
//                        });
//                }
//                _this.hover(function(){
//                        clearInterval(timerID);
//                },function(){
//                        timerID=setInterval("scrollUp()",timer);
//                }).mouseout();
//        }        
//})
//})(jQuery);

// 图片向左滚动
(function($){
$.fn.extend({
        Scroll:function(opt,callback){
                if(!opt) var opt={};
                var _this=this.eq(0).find("ul:first");
                var lineW=_this.find("li:first").outerWidth(),
                    line=opt.line?parseInt(opt.line,10):parseInt(this.outerWidth()/lineW,10), 
                    speed=opt.speed?parseInt(opt.speed,10):500, 
                    timer=opt.timer?parseInt(opt.timer,10):3000; 
                if(line==0) line=1;
                var leftWidth=0-line*lineW;
                scrollLeft=function(){
						_this.animate({
                                marginLeft:leftWidth
                        },speed,function(){
                                for(i=1;i<=line;i++){
                                        _this.find("li:first").appendTo(_this);
                                }
                                _this.css({marginLeft:0});
                        });
                }
                _this.hover(function(){
                        clearInterval(timerID);
                },function(){
                        timerID=setInterval("scrollLeft()",timer);
                }).mouseout();
        }        
})
})(jQuery);

$(function(){
	$("#scrollArea").Scroll({line:1,speed:500,timer:3000});
})



/*
 * jQuery Highlight plugin
 *
 * Based on highlight v3 by Johann Burkard
 * http://johannburkard.de/blog/programming/javascript/highlight-javascript-text-higlighting-jquery-plugin.html
 *
 * Code a little bit refactored and cleaned (in my humble opinion).
 * Most important changes:
 *  - has an option to highlight only entire words (wordsOnly - false by default),
 *  - has an option to be case sensitive (caseSensitive - false by default)
 *  - highlight element tag and class names can be specified in options
 *
 * Usage:
 *   // wrap every occurrance of text 'lorem' in content
 *   // with <span class='highlight'> (default options)
 *   $('#content').highlight('lorem');
 *
 *   // search for and highlight more terms at once
 *   // so you can save some time on traversing DOM
 *   $('#content').highlight(['lorem', 'ipsum']);
 *   $('#content').highlight('lorem ipsum');
 *
 *   // search only for entire word 'lorem'
 *   $('#content').highlight('lorem', { wordsOnly: true });
 *
 *   // don't ignore case during search of term 'lorem'
 *   $('#content').highlight('lorem', { caseSensitive: true });
 *
 *   // wrap every occurrance of term 'ipsum' in content
 *   // with <em class='important'>
 *   $('#content').highlight('ipsum', { element: 'em', className: 'important' });
 *
 *   // remove default highlight
 *   $('#content').unhighlight();
 *
 *   // remove custom highlight
 *   $('#content').unhighlight({ element: 'em', className: 'important' });
 *
 *
 * Copyright (c) 2009 Bartek Szopka
 *
 * Licensed under MIT license.
 *
 */

jQuery.extend({
    highlight: function (node, re, nodeName, className) {
        if (node.nodeType === 3) {
            var match = node.data.match(re);
            if (match) {
                var highlight = document.createElement(nodeName || 'span');
                highlight.className = className || 'highlight';
                var wordNode = node.splitText(match.index);
                wordNode.splitText(match[0].length);
                var wordClone = wordNode.cloneNode(true);
                highlight.appendChild(wordClone);
                wordNode.parentNode.replaceChild(highlight, wordNode);
                return 1; //skip added node in parent
            }
        } else if ((node.nodeType === 1 && node.childNodes) && // only element nodes that have children
                !/(script|style)/i.test(node.tagName) && // ignore script and style nodes
                !(node.tagName === nodeName.toUpperCase() && node.className === className)) { // skip if already highlighted
            for (var i = 0; i < node.childNodes.length; i++) {
                i += jQuery.highlight(node.childNodes[i], re, nodeName, className);
            }
        }
        return 0;
    }
});

jQuery.fn.unhighlight = function (options) {
    var settings = { className: 'highlight', element: 'span' };
    jQuery.extend(settings, options);

    return this.find(settings.element + "." + settings.className).each(function () {
        var parent = this.parentNode;
        parent.replaceChild(this.firstChild, this);
        parent.normalize();
    }).end();
};

jQuery.fn.highlight = function (words, options) {
    var settings = { className: 'highlight', element: 'span', caseSensitive: false, wordsOnly: false };
    jQuery.extend(settings, options);
    
    if (words.constructor === String) {
        words = [words];
    }
    words = jQuery.grep(words, function(word, i){
      return word != '';
    });
    if (words.length == 0) { return this; };

    var flag = settings.caseSensitive ? "" : "i";
    var pattern = "(" + words.join("|") + ")";
    if (settings.wordsOnly) {
        pattern = "\\b" + pattern + "\\b";
    }
    var re = new RegExp(pattern, flag);
    
    return this.each(function () {
        jQuery.highlight(this, re, settings.element, settings.className);
    });
};
//$(function(){
//     $("div#indexContent p").highlight("企业", { element: 'a', className: 'rfqyLink'});
//     $("div#indexContent a.rfqyLink").attr({ href: 'http://www.zgcagi.com/fhqnew/fhqgk/rzqy/',title: '入驻企业介绍',target:'_blank' });
//     $("div#indexContent p").highlight("技术平台", { element: 'a', className: 'ggjsptLink'});
//     $("div#indexContent a.ggjsptLink").attr({ href: 'http://www.zgcagi.com/fhqnew/ggjspt/GGGLPT/',title: '公共技术平台介绍',target:'_blank' });
//     $("div#indexContent p").highlight("游戏", { element: 'a', className: 'ysLink'});
//     $("div#indexContent a.ysLink").attr({ href: 'http://www.zgcagi.com/fhqnew/Category_1070/Index.aspx',title: '严肃游戏实验室',target:'_blank' });
//})

$(function(){
    var objLeft = $("div.leftSide").height();
    var objRight = $("div.rightSide").height();
	
	
    if (objLeft > objRight){
        $("div.rightSide").css({"height":objRight});
	}
    else {
        $("div.leftSide").find("ul").css({"height":objRight-150});
	}

})