$(document).ready(function(){
	  var mdcurrent =1;
    var mdtotal		=2;
    $("#mdleft").click(function(){
    		
    		var md = mdcurrent-1;
    		if(md < 1)
    			md = mdtotal;
    		
    		$("#insidemd"+md).show();
    		$("#insidemd"+mdcurrent).hide();
				mdcurrent = md;    			    		
    	});
    $("#mdright").click(function(){
    		var md = mdcurrent+1;
    		if(md > mdtotal)
    			md = 1;
    		$("#insidemd"+md).show();
    		$("#insidemd"+mdcurrent).hide();
				mdcurrent = md;    			
    	});
	
	$("#copyright a").attr("target","_blank");	
	
	$(".ic-textsize").click(function(){
			
			var namestr = $(this).attr('id');
			var namearr = namestr.split('-');
			
			$(".story_flow p").css('font-size',namearr[1]+'px');
			
		});

	$("#NewsletterSubmit").click(function(){
		
		$.post("/services/newsletteremail.php",$("#formNewsletter").serialize(),function(data){
			var arr = data.split('|');
			if(arr[0] == 1){
				$("#nlerror").html();
				$("#nlmsg").html(arr[1]);

				$("#nlform").css("display","none");
			}else{
				$("#nlerror").html(arr[1]);
				$("#nlmsg").html();

			}
		});	
	});
	

	var ap_current = 0;
	$(".exsh .Full").click(function(){
		if(ap_current == 1){
						$("#artphoto1").animate({
					opacity: 0
				},400,function(){
					$("#artphoto1").css('display','none');
					});
					
					ap_current = 0;
		}else{
				$("#artphoto1").css('display','block');
				
				$("#artphoto1").css('opacity','0');
				
				$("#artphoto1").animate({
					opacity: 1
					},400);
					ap_current = 1;
		}
	});


var _top = $(window).scrollTop();
    var _direction;
    //var hide=getCookie('recommend_hidden');
var hide=0;
var sl_show=false;
var re_loading=false;    
var order_num = 1;

    $(window).scroll(function(){
        if(!hide){
            var _cur_top = $(window).scrollTop();
            
            if(_top<_cur_top){
                _direction = "down";
            }else{
                _direction = "up";
            }
            
            //$('#sl_height').html(_cur_top);
            scroll_action(_direction,_cur_top);
            _top = _cur_top;
        }
    });
    
    $("#md_bt_wrap .close").click(function() {
        $("#md_bt_wrap").hide();
        //setCookie('recommend_hidden','true',1);
    });
    
    $("#md_bt_wrap .rightbtn").click(function(){
        if(re_loading==false){
            order_num       = order_num+1; 
            var id_array    = $("#md_bt_wrap .recommand1").attr('id').split('-');
            $("#md_bt_wrap .recommand1").html('');
            
            //$(".bk_recommend .title_art").html(htmstr);
            //$(".bk_recommend #re_load").show();
            
            $.get("/main/ajax/recommand.php",{ordernum: order_num,maincat:id_array[2],id: id_array[1]}, function(data){
                re_loading=true;   
                if(data){
                    
                    $("#md_bt_wrap .recommand1").html(data);
                    re_loading=false;
                }    
            },"html");
        }
    });
    /**/
    

    



function scroll_action(direction,cur_top){
    var position=$('#copyright').position();
    var point=position.top;
    //alert("Position: "+point+"px \r\n Current: "+cur_top+"px");
    if(direction=="down"&&point<(cur_top+590)&&sl_show==false){
        sl_show=true;
        $('#md_bt_wrap').stop().animate({'marginRight':'377px'},200);
    }else if(direction=="up"&&point>cur_top&&sl_show==true){
        sl_show=false;
        $('#md_bt_wrap').stop().animate({'marginRight':'-30px'},800);
    }
}



	
});
