$(function(){
	var top_menu_html = '<ul class="hide_menu">'+
							'<div class="popup"><span></span></div>'+
							'<li><a href="wap.php"><i class="hm_01"></i><span>首页</span></a></li>'+
							'<li><a href="wap.php?a=cats"><i class="hm_02"></i><span>分类</span></a></li>'+
							'<li><a href="wap.php?m=cart"><i class="hm_03"></i><span>购物车</span></a></li>'+
							'<li><a href="wap.php?m=member"><i class="hm_04"></i><span>会员中心</span></a></li>'+
						'</ul>';
	$(".cnav a.thome").after(top_menu_html); 
	$(".cnav a.thome").click(function(){ 
		if($(".hide_menu").css("display")=="none"){
			$(".hide_menu").show(); 
		}else{
			$(".hide_menu").hide(); 
		}
	});
	// 后退
	$(".cnav a.back").click(function(){ 
		window.history.back();
	});
	$(document).click(function(){
    	$(".hide_menu").hide();
	});
	$(".hide_menu,.cnav a.thome").click(function(event){
		event.stopPropagation();
	});  
	
});

function hideOverlay() {
    $("#overlay").fadeOut(200);
} 
function showOverlay() {
    $(".mdg_bgcolor").height(document.body.scrollHeight);
    $(".mdg_bgcolor").width(document.body.scrollWidth); 
    $(".mdg_bgcolor").fadeTo(200, 0.5);
} 
function ajax_close(){
	//弹窗
	$(".mdg_box").addClass('rch');
	$(".mdg_box_bar").animate({marginTop:'-10',opacity:'0'},300).delay(200).queue(function(){ $(this).remove(); }); 
	$(".mdg_bgcolor").animate({opacity:'0'},300).delay(300).queue(function(){ $(this).remove(); }); 
} 
function mdialog(name, url, width, height){
	var dialog_con = '<div class="mdg_bgcolor"></div><div class="mdg_box_bar"></div>'; 
	$("body").after(dialog_con);
	showOverlay();
	$.get(url,function(data){ 
		 var dialog_con_box = '<div class="mdg_box">'+
		 			'<div class="name"><span>'+name+'</span></div>'+
					'<div class="con" >'+data+'</div>'+
					'<div class="foot"><a class="fsave" href="javascript:;" onclick="ajax_submit();">确定</a>'+
					'<a class="fcancel" href="javascript:;" onclick="ajax_close();">取消</a></div>'+
				'</div>';  
			$(".mdg_box_bar").html(dialog_con_box).css({opacity:'0',marginTop:'-10px'}).animate({opacity:'1',marginTop:'0'},200);
	});
} 
function sys_login(){ 
	var width = '380'; 
	var height = 'auto'; 
	var dialog_con = '<div class="txt_bgcolor"></div><div class="txt_box_bar"></div>'; 
	$("body").after(dialog_con);
	showOverlay();
	$.ajaxSetup({cache:false});
	$.get('member.php?a=login_ajax&callback=?',function(data){ 
		 var dialog_con_box = '<div class="dg3_box">'+
		 			'<div class="name"><span>用户登陆</span><em onclick="ajax_close();">×</em></div>'+
					'<div class="con" >'+data+'</div>'+ 
				'</div>';  
			$(".dg3_box_bar").html(dialog_con_box).css({opacity:'0',marginTop:'-10px'}).animate({opacity:'1',marginTop:'0'},200); 
			$(".dg3_box").css({"width":width,"height":height}).addClass('ch');
	});
} 
$.extend({
	alert:function(str, callback){
		var timeout;
		var com_con = '<div class="com_bg"></div><div class="com_box"><span>'+str+'</span></div>';
		$("body").append(com_con);
		width = $(".com_box").width();
		$(".com_box").css({"margin-right":"-"+width/2+"px"});
	  	timeout = setTimeout(function(){
			$(".com_bg").remove(); 
			$(".com_box").hide(1000).remove(); 
			callback();
		},1500); 
		$(document).on('click', '.com_box', function(){
			$(".com_bg").remove(); 
			$(".com_box").hide(1000).remove(); 
			clearTimeout(timeout);
			callback();
		});
	},
	load:function(){
			
	} 
});

// 图片懒加载
function lazyload(){
	jQuery.getScript(PUBLIC_PATH+'js/jquery.lazyload.js', function(){
		$("img.lazy").show().lazyload({effect: "fadeIn", threshold:100, skip_invisible : false}); 							  
	});	
}

function scrollLoad(scrollcontent, scrollbox){
	$.getScript('public/js/jquery.infinitescroll.js', function(){
		$(scrollcontent).infinitescroll({ 
			navSelector: "#more", 
			nextSelector: "#more a",  
			itemSelector: scrollbox,
			bufferPx: 20,
			loading: {
				msgText: "加载中...",   
				finishedMsg: '已经到了最后了...', 
				img: "public/images/loading.gif",
			},
			state:{ 
				currPage:$("#curr_page").val() 
			},
			pathParse: [$("#path_parse").val(), ""], 
		}, function(e,d,u){
			$("img.lazy", e).lazyload({effect: "fadeIn", threshold:200});
		});	 
	});
}








