/*******************************************
*
* created by wsl 
* date 2018-1-11 08:12:53
* 注：本文件只适用客服边栏客户端
*
********************************************/


;(function($){

	var $custom = $("#custom-wrap");
	var customWrapWidth = $custom.outerWidth();
	// var delaytime = $custom.attr("data-delaytime") =="" ? 0 : $custom.attr("data-delaytime");

	// 加载延迟
	delayShow();

	$("#custom-wrap .custom-btn").click(function(){
		console.log(customWrapWidth);
		var Cpostion = $custom.hasClass("left");
		if( Cpostion ==true ){
			if( $custom.css("marginLeft") == "0px" ){
				$custom.stop(true,true).animate({
					"marginLeft" : - customWrapWidth,
					"marginRight" : - customWrapWidth
				},300);
			}else {
				$custom.stop(true,true).animate({
					"marginLeft" : 0,
					"marginRight" : 0
				},300);
			}
			
		}else{
			if( $custom.css("marginRight") == "0px" ){
				$custom.stop(true,true).animate({
					"marginLeft" : - customWrapWidth,
					"marginRight" : - customWrapWidth
				},300);
			}else {
				$custom.stop(true,true).animate({
					"marginLeft" : 0,
					"marginRight" : 0
				},300);
			}
		}
	})


})(jQuery)

// 加载设置
function delayShow( delaytime ){
		var $custom = $("#custom-wrap");
		var customWrapWidth = $custom.outerWidth();
		var delaytime = $custom.attr("data-delaytime") =="" ? 0 : $custom.attr("data-delaytime");
		if( delaytime < 0 ){
			$custom.css({
				"marginLeft" : 0,
				"marginRight" : 0
			});
			setTimeout(function(){
				$custom.stop(true,true).animate({
					"marginLeft" : - customWrapWidth,
					"marginRight" : - customWrapWidth
				},300);
			}, Math.abs(delaytime) );
		}else if( delaytime > 0 ){
			$custom.css({
				"marginLeft" : - customWrapWidth,
				"marginRight" : - customWrapWidth
			});
			setTimeout(function(){
				$custom.stop(true,true).animate({
				"marginLeft" : 0,
				"marginRight" : 0
				},300);
			}, Math.abs(delaytime) );
		}else{
			$custom.css({
				"marginLeft" : 0,
				"marginRight" : 0
			});
		}
			
	}