$(function(){

	$('#s_bg li').each(function(){
 	
		$(this).mouseover(function(){
  		
			outSearch();
  		
			$(this).addClass('s_bg_on');
			$('#s_type').val($(this).attr('tar'));
 		});


	});
	
	$('#search').click(function(){

 		if($(this).val()=='搜索 白马商城 商品')$(this).val('');

	});
	
	$('#search').blur(function(){
 	
		if($(this).val()==''){
  			
			$(this).val('搜索 白马商城 商品');
 		}
	});
	
	$('#search_bn').click(function(){
 	
		if($('#search').val()==''||$('#search').val()=='搜索 白马商城 商品'){
  			alert('请填写关键字');
 		}else if($('#s_type').val()==1){
			document.getElementById('search_frm').action='/category.php';
			document.getElementById('search_frm').submit();
		}else if($('#s_type').val()==2){
			document.getElementById('search_frm').action='/category.php';
			document.getElementById('search_frm').submit();
		}
		
	});
	
	if(document.getElementById('top_bg_menu')){
		
		$('#top_bg_menu li').mouseover(function(){
			var $an=$(this).children('.an_l');
			$an.attr('class','an_l2');
			$an.find("a").addClass('aa');
			$(this).children('.an_r').attr('class','an_r2');
		
		});
		$('#top_bg_menu li').mouseout(function(){
			if($(this).attr('tar')==1)return;
			var $an=$(this).children('.an_l2');
			$an.attr('class','an_l');
			$an.find('a').removeClass();
			$(this).children('.an_r2').attr('class','an_r');
		
		});
		
	}

	if(typeof(QQ_MASK)!='undefined'){
		var qqlist='';
		for(var i=0;i<QQ_MASK.length;i++){
			if(QQ_MASK[i]!='')qqlist+='<a title="给客服 '+QQ_MASK[i]+' 发消息" target=blank href=http://wpa.qq.com/msgrd?V=1&Uin='+QQ_MASK[i]+'&Exe=QQ&Site=www.baimaec.com&Menu=No><img border="0" src=http://wpa.qq.com/pa?p=1:304224:6 alt="给客服 '+QQ_MASK[i]+' 发消息"></a>';
		}
		if(typeof(WW_MASK)!='undefined'){
			
			for(var i=0;i<WW_MASK.length;i++){
				if(WW_MASK[i]!='')qqlist+='<a target="_blank" href="http://amos1.taobao.com/msg.ww?v=2&uid='+WW_MASK[i]+'&s=1" ><img border="0" src="http://amos1.taobao.com/online.ww?v=2&uid='+WW_MASK[i]+'&s=1" alt="点击这里给'+WW_MASK[i]+'发消息" /></a>';
			}
			
		}
		$('<div id="qq_mask">'+qqlist+'</div>').appendTo('body');
		roll();
		/*window.onscroll=function(){
			roll();
		}*/
		$(window).bind('scroll',roll).bind('resize',roll);
	}
	
	if(typeof(MOVE_BOTTOM)!='undefined'){
		
		
		$('<div id="move_bottom">&nbsp;</div>').appendTo('body');

		$('#move_bottom').click(function(){
			window.scrollTo(0,0);
		}).mouseover(function(){
			$(this).addClass('move_bottom_focus');	
		}).mouseout(function(){
			$(this).removeClass('move_bottom_focus');	
		});
		
		sc5();
		
		$(window).bind('scroll',sc5).bind('resize',sc5);
		
	}
	
	if(document.getElementById('loadImg')){
		
		$('#loadImg').find('img').addClass('scrollLoading');
		
	}
	
	e();
	$(window).bind('scroll',e);

});
function sc5(){
	//alert(document.documentElement.scrollTop+document.documentElement.clientHeight-$('#move_bottom').height());
	var top=(document.documentElement.clientHeight-$('#move_bottom').height())+"px";
	
	var left=(document.documentElement.clientWidth-$('#move_bottom').width())+"px";
	
	$('#move_bottom').css({left:left,top:top});
	
}

function e(){

			$('.scrollLoading').each(function(){
			
				var f=$(window).scrollTop(),g=f+$(window).height();
			

				if($(this).attr('load')!=1){
				
					post=$(this).position().top;
					
					posb=post+$(this).height();
					
					if((post>f&&post<g)||(posb>f&&posb<g)){
						
		
							$(this).attr("src",$(this).attr('data-url'));

							
						$(this).attr('load',1);
						
					}
				}
				
			});
}
function roll(){
$('#qq_mask').css({left:(document.documentElement.clientWidth-$('#qq_mask').width()-30)+'px',top:(document.documentElement.scrollTop+(parseInt(window.screen.height/2)-parseInt($('#qq_mask').height())-60))+'px'});
}
//------------
function outSearch(){
	$('#s_bg li').each(function(){
  		$(this).attr({'class':''});
	});
}
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 addFavorite(){
    var aUrls = document.URL.split("/");
    var vDomainName = "http://" + aUrls[2] + "/";
    var description = document.title;
    try {//IE
        window.external.AddFavorite(vDomainName, description);
    } catch(e) {//FF
        window.sidebar.addPanel(description, vDomainName, "");
    }
}
function formatFloat(src, pos)
{
    return Math.round(src*Math.pow(10, pos))/Math.pow(10, pos);
}



