// JavaScript Document
if (!Mould) { var Mould = new Object(); }

Mould ={
	RollTitle:function(opt){
				if(!opt) return;
				var _this = this;
				var _txt  = $('#'+opt.id);
				
				_this.timer = null;
				_this.lineH = _txt.find("li:first").height();
				_this.line=opt.line?parseInt(opt.line,15):parseInt(_txt.height()/_txt.lineH,10);
				_this.speed=opt.speed?parseInt(opt.speed,10):3000;
				_this.timespan=opt.timespan?parseInt(opt.timespan,13):5000;
				
				if(_this.line==0)
				{
					this.line=1;
				}
				
				_this.upHeight=0-_this.line*_this.lineH;
				
				_this.scrollUp=function(){
					_txt.animate({
							marginTop:_this.upHeight
							},_this.speed,function(){
								for(i=1;i<=_this.line;i++){
									_txt.find("li:first").appendTo(_txt);
							}
							_txt.css({marginTop:0});
					});
				}
				
				_txt.hover(function(){
						clearInterval(_this.timer);
					},function(){
						_this.timer=setInterval(function(){_this.scrollUp();},_this.timespan);
				}).mouseout();
			},
	Search :function(){
				$('.search_tab li:even').bind('click',function(){
					var _thisid = $(this).attr('id');
					$('.search_tab li').each(function(i){$(this).removeClass()})
					$(this).addClass('now');
					$('.search_list div').each(function(i){
						if($(this).attr('id')!='S_'+_thisid)
						{
							$(this).hide();	
						}else{
							$(this).show();
						}
					})
				});
				
			},
	Cookie :{
		set: function(name, value, path, domain)
		{
			
			expires = new Date(new Date().getTime() + 18000000);
			document.cookie = name + "=" + escape(value) +
				((expires) ? "; expires=" + expires.toGMTString() : "") +
				((path) ? "; path=" + path : "; path=/") +
				((domain) ? "; domain=" + domain : "");
		},
	
		get: function(name)
		{
			var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
	
			if (arr != null)
			{
				return unescape(arr[2]);
	
			}
	
			return null;
		},
	
		clear: function(name, path, domain)
		{
			if (this.get(name))
			{
				document.cookie = name + "=" +
					((path) ? "; path=" + path : "; path=/") +
					((domain) ? "; domain=" + domain : "") +
					";expires=Fri, 02-Jan-1970 00:00:00 GMT";
			}
		}
	},
	
	Weather :function(id){
		weather_info = this.Cookie.get('weather');

		if(!weather_info)
		{
			var rs = "http://61.4.185.48:81/g/";
			var js = document.createElement("script");
			js.setAttribute("type", "text/javascript");
			js.setAttribute("src", rs);
			document.body.insertBefore(js, null);
		}else{
			$('#weather').html(weather_info);	
		}
	},
	Contact :function(company)
	{
		if(typeof(window.contact)=='undefined')
		{
			$.ajax({
			  type: "GET",
			  async:false,
			  url: '/enterprise/getcontact/'+company,
			  success:function(data){contact= eval('('+data+')');},
			  error:function(){alert('发生错误，请稍后再试');}
			});
		}else{
			contact = window.contact;
		}
		
		$('#linker').html(contact[company].linker);
		$('#addr').html(contact[company].addr);
		$('#phone').html(contact[company].phone);
		$('#fax').html(contact[company].fax);
		
		$('#qq').attr('href',$('#qq').attr('href').replace('{$qq}',contact[company].qq));
		$('#msn').attr('href',$('#msn').attr('href').replace('{$msn}',contact[company].msn));
		$('#wangwang').attr('href',$('#wangwang').attr('href').replace('{$wangwang}',contact[company].wangwang));
		$('#message').attr('href',$('#message').attr('href').replace('{$domain}',company));
		$('#email').html(contact[company].email)
		$('#Contact').css({
			position:'absolute',
			'z-index':999,
			left: ($(window).width() - 450)/2, 
			top: ($(window).height() - 208)/2 + $(document).scrollTop() 
			}).show(); 
	},
	
	Gettechnology:function(box,id,Mid)
	{
		li_id = box+id;
		li_css= 'now_'+box;
		boxcotent=box+'_con'+id;
		boxF  = box+'_box';
		if($('#'+li_id).attr('class') == li_css) return;
		$("#"+box+" li").each(function(){
			if($(this).attr('id')==li_id)
			{
				$(this).addClass(li_css);
			}else{
				$(this).removeClass(li_css);
			}
		});
		$('#'+boxF+' > div').hide();
		$('#'+boxcotent).show();
		
		if($('#'+boxcotent).attr('show')=='none')
		{
			$.ajax({
			  type: "GET",
			  url: '/technology/gettechnology/'+Mid,
			  beforeSend  : function(){$('#'+boxcotent).html('<br><br><br><br><img src="/resources/images/iloading.gif" style="margin-left:250px;" width="100" height="9" />&nbsp;&nbsp;&nbsp;稍后，系统加载中。。。')},
			  success:function(data){$('#'+boxcotent).html(data).attr('show','yes').show();},
			  error:function(){alert('发生错误，请稍后再试');}
			});
		}else{
			$('#'+boxcotent).show();
		}
			
	},
	
	Addfavorite:function(url,title){ 
		url   = url?url:'http://www.91mould.com';
		title = title?title:'91模具网 - 专业的模具企业展示平台';
        try 
        { 
                window.external.addfavorite(url,title); 
        } 
        catch (e) 
        { 
                try 
                { 
                        window.sidebar.addPanel(title, url, ""); 
                } 
                catch (e) 
                { 
                        alert("加入收藏失败，请使用ctrl+d进行添加"); 
                } 
        } 
	},
	Sethome:function(obj,vrl){ 
		if (document.all){   
			document.body.style.behavior = 'url(#default#homepage)';   
			document.body.setHomePage('http://www.91mould.com');   
		}else if (window.sidebar){   
			if (window.netscape){   
				try {   
					netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");   
				}catch (e) {   
					alert("该操作被浏览器拒绝，如果想启用该功能，请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该为true");   
				}   
			}   
			var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);   
			prefs.setCharPref('browser.startup.homepage', 'http://www.caidao8.com');   
		}   
	},
	Searchhelp:{
		show: function()
		{
		    issearch = Mould.Cookie.get('issearch');
			if(!issearch)
			{
				
				$('.search_help').slideDown(1000);
			}
		},
		
		close: function()
		{
			$('.search_help').hide();
			Mould.Cookie.set("issearch",1,null,'.91mould.com');
		}
		
	}
}

function id_callback()
{
	if (typeof(id) == "undefined")
	{
		id = "101010100";
	}
	$.get('/welcome/getweather/'+id+'/'+Math.random(),function(result){
		Mould.Cookie.set("weather",result,null,'.91mould.com');
		$('#weather').html(result);	
	});
}


$(document).ready(function(){
	Mould.RollTitle({id:'RunTopic',line:1,speed:200});
	Mould.Search();
	Mould.Searchhelp.show();
	Mould.Weather();
	
	$(".mymjt span").hover(
		function(){
		   $(".wdmjt").show();
		},
		function(){
		   $(".wdmjt").hide();
		}
	);
	$(".wdmjt").hover(
		function(){
		   $(this).show();
		},
		function(){
		   $(this).hide();
		}
	);

});

