
$(function(){ 
	$("a.thome,a.thome").click(function(){
		$this = $(this); 
		top_menu_html = '<ul class="hide_menu">'+
							'<div class="popup"><span></span></div>'+
							'<li><a href="'+WAP+'index"><i class="hm_01"></i><span>首页</span></a></li>'+
							'<li><a href="'+WAP+'index/cats"><i class="hm_02"></i><span>分类</span></a></li>'+
							'<li><a href="'+WAP+'cart/index"><i class="hm_03"></i><span>购物车</span></a></li>'+
							'<li><a href="'+WAP+'member/index"><i class="hm_04"></i><span>会员中心</span></a></li>'+
						'</ul>'; 
		$this.after(top_menu_html);
		if($(".hide_menu").css("display")=="none"){
			$(".hide_menu").show(); 
		}else{
			$(".hide_menu").hide(); 
		}
	});
	
	// 搜索
	$('input.sch_input').click(function(){
		$(".schAll").show();
		str = $("input.sch_input2").val(); 
		$("input.sch_input2").val("").focus().val(str); 
		$("html").css('overflow','hidden');
	});
	$(".schAll em.close").click(function(){
		$(".schAll").hide();
		$("html").css('overflow','auto');
	});
	
	// 后退
	$(".cnav a.back").click(function(){ 
		window.history.back();
	});
	$(document).click(function(){
    	$(".hide_menu").hide();
	});
	$(".hide_menu,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><a class="fcancel" href="javascript:;" onclick="ajax_close();">×</a></div>'+
					'<div class="con" >'+data+'</div>'+
					'<div class="foot"><a class="fclose" href="javascript:;" onclick="ajax_close();">取消</a><a class="fsave" href="javascript:;" onclick="ajax_submit();">确定</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(URI+'member/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+'plug/jquery.lazyload.js', function(){
		$("img.lazy").show().lazyload({effect: "fadeIn", threshold:100, skip_invisible : false}); 							  
	});	
}

function scrollLoad(scrollcontent, scrollbox, masonry){ 
	$.getScript(PUBLIC+'plug/jquery.masonry.min.js'),
	$.getScript(PUBLIC+'plug/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(newElements){
			if(masonry == '1'){
				var $newElems = $(newElements);  
				$(scrollcontent).masonry('appended', $newElems, false);
				$newElems.fadeIn();
				$(scrollcontent).masonry({ 
					itemSelector: scrollbox
				});	
			}
			$("img.lazy", newElements).lazyload({effect: "fadeIn", threshold:200});
		});	
	});
}

 