(function($) {

	  $.fn.extend({

	  	overlay: function(ops,id){
	  		var ops = $.extend({
	  				position: 'fixed', top: 0, left: 0,
	  				width: '100%',height: '100%',
	  				opacity: 0.2, background: 'black', zIndex: 99
	  			}, ops),
	  		id = id || 'overlay';
	  		if( $.fn.ie6 ) ops = $.extend(ops, {
	  			position: 'absolute',
	  			width: Math.max($(window).width(),$(document.body).width()),
	  			height: Math.max($(window).height(),$(document.body).height()) });

	  		return $('<div class="overlay" id="'+id+'"/>').appendTo(document.body).css(ops);
	  	},

	  	position: function(ops){
	  		var ops = $.extend({
	  				fixx: 0,
	  				fixy: 0
	  			}, ops),
	  			mod = (this.css("position")=="fixed") ? 0 : 1,
	  			t = $(document).scrollTop()*mod,
	  			l = $(document).scrollLeft()*mod,
	  			mt = t;

	  		l += ($(window).width() - this.width()) / 2;
	  		t += ($(window).height() - this.height()) / 2;
	  		
	  		l += ops.fixx;
	  		t = Math.max(t, mt)+ops.fixy;
	  		
	  		if(t<0) t = 0;
	  		if(l<0) l = 0;
	  		
	  		return this.css({top: t, left: l});
	  	},

	  	dragdrop:function(ops,callback) {
	          if(typeof(ops)=='function')callback=ops;
	  		this.css('position','absolute');
	          var ops = $.extend({
	              }, ops),handle=ops.handle ? $(ops.handle, this) : this,
	              flag =false,_o={left:0,top:0},self=this;
	           
	          function pos(e){
	              if (flag) {self.css( {left : e.pageX - _o.left + 'px',top : e.pageY - _o.top + 'px'});}
	          }
	          handle.mousedown(function(e){
	              flag = true;
	              self.css('z-index',parseInt(new Date().getTime()/1000));
	              var offset = self.offset();
	              _o = { left: e.pageX - offset.left, top: e.pageY - offset.top };
	              $(document).mousemove(pos);
	          }).mouseup(function(e){
	              pos(e);
	              flag = false;
	              $(document).unbind('mousemove');
	              if(callback)callback.apply(this,[self]);
	          }).css('cursor','move');
	          return self;
	      },
	  	
	  	popup: function(ops,callback){
	  		var ops = $.extend({
	                  buttons:{},esc: true, id: 'popup', iframe: false,scrolling:'no',
	  				overlay: { opacity: 0.4, background: 'black' },
	  				text: '', 
	  				title: 'Information', 
	  				type: 1, 
	  				width: 240, height: 0, 
	  				zIndex:1
	  			}, ops),
	  			self = this;
	  		
	  		function close(){
	  			$('#_overlay').add([document, window]).unbind('._overlay');
	  			$('#'+ops.id).add([document, window]).unbind('._darg');
	  			$('#_overlay').remove();
	  			if(select)select.ie6fix(false);
	  			$('#'+ops.id).fadeOut('fast',function(){$(this).remove()});
	  		}

	  		var o = $('#'+ops.id);

	  		switch(ops.action){
	  			case -1://resize
	  				$('.content', o).animate(callback,function(){o.ie6fix(false);}).find('iframe').css(callback);
	  				return;
	  			case 0://retitle
	  				$('.title', o).text(ops.text);
	  				return;
	  			case 1://first btn
	  				$('.btnpane', o).children('a:nth-child(1)').trigger('click');
	  				return;
	  			case 2://second btn
	  				$('.btnpane', o).children('a:nth-child(2)').trigger('click');
	  				return;
	  			case 9://close
	  				$('.close', o).trigger('click',callback);
	  				return;
	  			case 8:
	                  callback.apply(this, arguments);
	                  return;
	  			default:
	  				(o.length==1) && close(); 
	  		}
	  		
	  		var pHtm;
	  		if(ops.iframe){
	  			pHtm = $('<iframe src="'+ops.url+'" marginwidth="0" id="popup_iframe" marginheight="0" frameborder="0" hspace="0" vspace="0" scrolling="'+ops.scrolling+'" />')
	  			.css({ width: ops.width-16, height: ops.height==0 ? 'auto' : ops.height-74 });
	  		}else{
	  			pHtm = $('<div>'+ops.text+'</div>');
	  		}

	  		var pContent = $('<div class="content content_'+ops.type+'"/>').append(pHtm)
	  			.wrap('<div class="popup p'+ops.type+'"/>')
	  			.wrap('<div class="container container_'+ops.type+'"/>'),

	  		pContainer = pContent.parent(),
	  		
	  		pClose = $('<div class="titleclose"/>')
	  			.append('<span class="title">' + ops.title + '</span>')
	  			.append('<a href="javascript:;" class="close"><span>X</span></a>')
	  			.prependTo(pContainer),
	  			
	  		_p = ($.fn.ie6) ? 'absolute' : 'fixed';	
	  		popup = pContainer.parent()
	  			.css({
	  				position: _p, zIndex: 99+ops.zIndex,
	  				top: ops.iframe?($(window).height()-ops.height) / 2-60:($(window).height()-ops.height) / 2, left:($(window).width()-ops.width)/ 2, width: ops.width, height: ops.height==0 ? 'auto' : ops.height, outline: 0
	  			})
	  			.attr({ id: ops.id, tabIndex: '-1' }).appendTo(document.body).hide()
	  			.keydown(function(ev) {
	  				if (ops.esc) {
	  					(ev.keyCode && ev.keyCode == 27 && close());
	  				}
	  			})
	  			.dragdrop({handle:'.titleclose'}),
	  		
	  		btnPane = $('<div class="btnpane"/>').appendTo(pContainer);
	  		
	  		$('.close', pClose)
	  			.mousedown(function(ev) {
	  				ev.stopPropagation();
	  			})
	  			.click(function(event, callback) {
	  				if(callback) callback.apply(this, arguments);
	  				close();
	  				return false;
	  			});
	  		
	  		var hasBtns = false, genBtns = [];
	  		function newBtns(btns) {
	  			btnPane.empty().hide();	
	  			$.each(btns, function() { return !(hasBtns = true); });
	  			if (hasBtns) {
	  				btnPane.show();
	  				$.each(btns, function(name, fn) {
	  					genBtns.push($('<a href="javascript:;"/>')
	  						.text(name)
	  						.appendTo(btnPane)
	  						.bind('click', function() { fn.apply(this, arguments);return false;}));
	  				});
	  			}
	  		}
	  		newBtns(ops.buttons);
	  		
	  		if(ops.overlay){
	  			var _overlay = $().overlay( $.extend(ops.overlay, { position: _p }),'_overlay' );
	  			if (ops.esc) {
	  				$(document).bind('keydown._overlay', function(e) {
	  					(e.keyCode && e.keyCode == 27 && close()); 
	  				});
	  			}
	  		}
	  		popup.position( ops.iframe ? { fixy: -60 } : {} ).show();		
	  		var select = $('select').ie6fix(true);
	  		if(window.event){event.returnValue = false;}
	  	},

	  	ie6fix: function(flag){
	  		return ($.fn.ie6)?this.css('visibility',flag?'hidden':'visible'):this;
	  	}
	  });

  })(jQuery);
$(document).ready(function(){
	//----begin of paging function on newscenter part on home page ------
    $('#newsPages>.pageNum').click(function() {
        var pageNum = $(this).attr('pagenum') / 1;
        switch2Page(pageNum);
    });
    $('#newsPrev').click(function() {
        switch2Page('prev');
    });
    $('#newsNext').click(function() {
        switch2Page('next');
    });
    function switch2Page(pageNum) {
        var currentPage = $('#newsPages>.current').attr('pagenum') / 1;
        var totalPage = $('#newsPages>.pageNum').size();
        if (pageNum == 'next') {
            currentPage++;
        } else if (pageNum == 'prev') {
            currentPage--;
        } else {
            currentPage = pageNum / 1;
        }
        currentPage = currentPage < 1 ? 1 : currentPage > totalPage ? totalPage : currentPage;
        $('#newsPages>.pageNum').removeClass('current');
        $('#newsPages>.pageNum[pagenum="' + currentPage + '"]').addClass('current');
        $('#newsContents>.pageItems').hide();
        $('#newsContents>.pageItems:eq(' + (currentPage - 1) + ')').show();
    }
    //----end of paging function on newscenter part on home page ------
	//---begin of the contact us map pop up function
	  	var node_30_url = 'http://ditu.google.cn/maps?f=q&amp;source=s_q&amp;hl=zh-CN&amp;geocode=&amp;q=%E4%B8%8A%E6%B5%B7%E5%B8%82%E9%95%BF%E5%AE%81%E5%8C%BA%E9%87%91%E9%92%9F%E8%B7%AF658%E5%BC%848%E5%8F%B7%E6%A5%BC&amp;sll=31.230708,121.472916&amp;sspn=1.524157,2.469177&amp;brcurrent=3,0x35b2669ca7c199bb:0xab19fabd296e96ee,0,0x35b265b90ce06dbf:0xe54ce122d0b98ab2%3B5,0,0&amp;ie=UTF8&amp;hq=&amp;hnear=%E4%B8%8A%E6%B5%B7%E5%B8%82%E9%95%BF%E5%AE%81%E5%8C%BA%E9%87%91%E9%92%9F%E8%B7%AF658%E5%8F%B7&amp;z=14&amp;ll=31.220548,121.359042&amp;output=embed';
	  	var node_31_url = 'http://ditu.google.cn/maps?q=%E5%8C%97%E4%BA%AC%E5%B8%82%E6%B5%B7%E6%B7%80%E5%8C%BA%E5%AD%A6%E9%99%A2%E5%8D%97%E8%B7%AF15%E5%8F%B7%E5%8C%97%E5%8F%91%E5%A4%A7%E5%8E%A6B%E5%BA%A7%E4%BA%8C%E5%B1%82&hl=zh-CN&ie=UTF8&ll=39.960889,116.352897&spn=0.008848,0.021136&view=map&cid=6096626372565171741&brcurrent=3,0x35f053b3692cde39:0x53e8f120c1db0e54,0,0x35f0525303f10153:0x6b772a2a053ba4a0%3B5,0,0&t=m&z=16&vpsrc=0&iwloc=A&amp;output=embed';
	  	var node_35_url = 'http://ditu.google.cn/maps?f=q&amp;source=s_q&amp;hl=zh-CN&amp;geocode=&amp;q=1600+Old+Country+Rd+Plainview,+New+York+11803&amp;sll=31.220821,121.36131&amp;sspn=0.011762,0.019119&amp;brcurrent=3,0x0:0x0,0%3B5,0,0&amp;ie=UTF8&amp;hq=&amp;hnear=1600+%E6%97%A7%E5%BA%B7%E7%89%B9%E5%88%A9%E8%B7%AF,+%E6%99%AE%E8%8E%B1%E6%81%A9%E7%BB%B4%E5%B0%A4,+%E6%8B%BF%E9%AA%9A,+%E7%BA%BD%E7%BA%A6+11803,+%E7%BE%8E%E5%9B%BD&amp;ll=40.781895,-73.449887&amp;spn=0.010415,0.019119&amp;z=14&amp;output=embed';
	  	var node_36_url = 'http://ditu.google.cn/maps?f=q&amp;source=s_q&amp;hl=zh-CN&amp;geocode=&amp;q=463+King+Street+West++Toronto,+Ontario,+M5V+1K4&amp;sll=40.782101,-73.449891&amp;sspn=0.010009,0.019119&amp;brcurrent=3,0x0:0x0,0%3B5,0,0&amp;ie=UTF8&amp;hq=&amp;hnear=463+%E9%87%91%E8%A1%97%E8%A5%BF,+%E5%A4%9A%E4%BC%A6%E5%A4%9A,+%E5%A4%9A%E4%BC%A6%E5%A4%9A%E8%BF%AA%E7%BB%B4%E7%94%B3,+%E5%AE%89%E5%A4%A7%E7%95%A5+M5V+1K4,+%E5%8A%A0%E6%8B%BF%E5%A4%A7&amp;ll=43.645188,-79.396268&amp;spn=0.009953,0.019119&amp;z=14&amp;output=embed';
	  	var node_37_url = "http://ditu.google.cn/maps?f=q&amp;source=s_q&amp;hl=zh-CN&amp;geocode=&amp;q=5595+Roy+Street+Suite+201+Burnaby,+BC,+V5B+3A5&amp;sll=43.644989,-79.396262&amp;sspn=0.009953,0.019119&amp;brcurrent=3,0x0:0x0,0%3B5,0,0&amp;ie=UTF8&amp;hq=&amp;hnear=5595+%E7%BD%97%E4%BC%8A%E8%A1%97+%23201,+%E4%BC%AF%E7%BA%B3%E6%AF%94,+%E5%A4%A7%E6%B8%A9%E5%93%A5%E5%8D%8E%E9%87%8C%E7%9C%9F%E7%BA%B3%E5%B0%94%E8%BF%AA%E6%96%AF%E7%89%B9%E9%87%8C%E5%85%8B%E7%89%B9,+%E8%8B%B1%E5%B1%9E%E5%93%A5%E4%BC%A6%E6%AF%94%E4%BA%9A+V5B+3A5,+%E5%8A%A0%E6%8B%BF%E5%A4%A7&amp;z=14&amp;ll=49.261973,-122.982726&amp;output=embed";
	  	var node_42_url = "http://ditu.google.cn/maps?f=q&amp;source=s_q&amp;hl=zh-CN&amp;geocode=&amp;q=45+East+34th+St+New+York,+New+York+10016&amp;sll=49.26198,-122.982717&amp;sspn=0.008976,0.019119&amp;brcurrent=3,0x0:0x0,0%3B5,0,0&amp;ie=UTF8&amp;hq=&amp;hnear=45+%E4%B8%9C%E4%B8%89%E5%8D%81%E5%9B%9B%E8%A1%97,+%E7%BA%BD%E7%BA%A6,+10016,+%E7%BE%8E%E5%9B%BD&amp;z=14&amp;ll=40.747775,-73.982239&amp;output=embed";
	  	var node_43_url = "http://ditu.google.cn/maps?f=q&amp;source=s_q&amp;hl=zh-CN&amp;geocode=&amp;q=800+Central+Park+Drive+Sanford,+Florida+32771&amp;sll=40.747777,-73.982234&amp;sspn=0.01042,0.019119&amp;brcurrent=3,0x0:0x0,0%3B5,0,0&amp;ie=UTF8&amp;hq=&amp;hnear=800+%E4%B8%AD%E5%A4%AE%E5%B8%95%E5%B0%94%E5%85%8B%E8%BD%A6%E9%81%93,+%E6%A1%91%E7%A6%8F%E5%BE%B7,+%E5%A1%9E%E7%B1%B3%E8%AF%BA%E5%B0%94,+%E4%BD%9B%E7%BD%97%E9%87%8C%E8%BE%BE+32771,+%E7%BE%8E%E5%9B%BD&amp;z=14&amp;ll=28.804632,-81.316102&amp;output=embed";
	  	var node_44_url = "http://ditu.google.cn/maps?f=q&amp;source=s_q&amp;hl=zh-CN&amp;geocode=&amp;q=West+Point,++33-34+Warple+Way+London+W3+0RG+UK&amp;sll=28.804876,-81.316102&amp;sspn=0.011582,0.019119&amp;brcurrent=3,0x0:0x0,0%3B5,0,0&amp;ie=UTF8&amp;hq=West+Point,+33-34+Warple+Way&amp;hnear=%E4%BC%A6%E6%95%A6+W3+0RG,+%E8%8B%B1%E5%9B%BD&amp;ll=51.504359,-0.2555&amp;spn=0.006295,0.006295&amp;output=embed";

	  	//define  function
	  	jQuery.fn.contract_map= function(obj){
	  		nid = $(obj).attr('href').substr(6);		
	  		$.fn.popup({
	  			iframe:true,
	  			url:eval('node_'+nid+'_url'),
	  			title:"地图",width:610,height:450,type:9})
	  	}

	    //$.fn.contract_map(30);

	  //initialize 
	  	$('div.listhalf').find('a').each(function(){
	  		
	  			//id = $(this).attr('href').substr(6);			
	  			//this doesn't work on IE
	  			//$(this).attr('onclick','$.fn.contract_map('+id+');return false;');
	  			$(this).unbind('click').removeAttr('onclick').click(function(){
	  				$.fn.contract_map(this);
	  				return false;
	  			})

	  	});
	// -------End of the map pop up function-----------
    $('#home_left_image .focusImgTitle').mouseenter(function() {
        if (!$(this).hasClass('current')) {
            var obj = $(this).parent().find('img.current');
            var originalSrc = obj.attr('src');
            obj.attr('src', originalSrc.replace('_s.jpg', '.jpg'));
            $(this).parent().find('img').removeClass('current');
            $(this).addClass('current');
            var src = $(this).attr('src');
            src = src.replace('.jpg', '_s.jpg');
            $(this).attr('src', src);

            var id = $(this).attr('id').substring(5);
            $('#home_left_image .focusImg').hide();
            $('#homePageImage' + id).show();
        }
    });
    
});
