$(function(){
    analogselect (".selectBotton",".selectOther",".selectShow");
    serachText ();
    sidebarHover ();
    sidebarClick ();
    close();
    selectHover ();
	checkPwdStste();
	linkDelOper();
	placeholders();
	tdSpace();
});
// 搜索框选项 
function analogselect (botton,other,show) {
    $selectBotton = $(botton);
    $selectOther = $(other);
    $selectOtherLi = $selectOther.children("ul").children("li");
    $selectShow = $(show);
    $selectBotton.click(function(){
        if($selectOther.is(":visible")){
            $selectOther.hide();
        }else {
            $selectOther.show();
        }
    });
    $selectOtherLi.click(function(){
        $showSpan = $selectShow.children("span");
        var showSpan=$showSpan.html();
        var hideSpan=$(this).html();
        $showSpan.remove();
        $selectShow.append("<span>"+hideSpan+"</span>");
        $selectOther.hide();
    })
}
function selectHover () {
    $(".selectOther li").mouseover(function(){
        $(this).css('background','#d1e9fb');
        $(this).siblings("li").css('background','#fff');
    })
}
//搜索框文本
function serachText () {
    $serachInput = $(".serachText input");
    $serachInputP = $serachInput.siblings("p");
    $Text = $(".serachText input").val();
    if( $Text == ""){
        $serachInputP.show();
    }else {
        $serachInputP.hide();
    }
    $serachInput.focus(function(){
        $serachInputP.hide();
    }).blur(function(){
        $Text = $serachInput.val();
        if( $Text == ""){
            $serachInputP.show();
        }
    });
}
//侧栏hover
function sidebarHover () {
    $(".sidebarContent ul li a").not($(".sidebarActive").eq(0)).hover(function(){
        $(this).addClass("sidebarHover");
    },function(){
        $(this).removeClass("sidebarHover");
    })
}
//侧栏打开收起切换
function sidebarClick () {
    $sidH3 = $(".sidebarContent h3");
    $sidH3.toggle(function(){
        $(this).children("span").children("img").attr('src','skin/default/images/show/sidebarHide0.jpg')
        $(this).siblings("ul").hide();
        $(this).css("border-bottom","none");
    },function(){
        $(this).children("span").children("img").attr('src','skin/default/images/show/sidebarHide.png')
        $(this).siblings("ul").show();
        $(this).css("border-bottom","1px solid #c5ddf6");
    })
}
/* 关闭提醒 */
function close() {
    $(".close").click(function(){
        $(".remind").hide();
    })
}
//检测变量类型
function getType(o) {
  var _t; return ((_t = typeof(o)) == "object" ? Object.prototype.toString.call(o).slice(8,-1):_t).toLowerCase();
}

//弹出框
function popBox(id){
	var $box=$("#"+id);
	if($box.size()<=0) return false;
	
	var width=$box.outerWidth(),
		height=$box.outerHeight(),
		$shade=$("#shade");
		
	if($shade.size()<=0){
		$shade=$("<div></div>",{
			id:"shade"
		}).appendTo("body");	
	}
	
	var bodyHeight=Math.max(document.documentElement.scrollHeight,document.documentElement.clientHeight),
		top=parseInt($(window).height()/2);
		
	if($.browser.msie && $.browser.version==6) top+=parseInt($(window).scrollTop());
	
	$shade.height(bodyHeight).show();
	$("select:not(#"+id+" select)").css("visibility", "hidden");
	
	$box.css({
		left:"50%",
		top:top,
		marginLeft:-parseInt(width/2),
		marginTop:-parseInt(height/2)
	}).show()
	.find(".close").bind("click",function(e){
		e.preventDefault();
		closePop(id);
	});
}

//关闭弹出框
function closePop(id){
	$("#shade").add($("#"+id)).hide();
	$('select').css('visibility', 'visible');
}

//简单验证密码强度
function checkPwdStste(){
	$('.check-ps').keyup(function(){
		var show='.pwdstate';
		var ps=$(this).data('ps');
		var lv=0;
		var val=this.value;
		
		if(ps) show='.'+ps;
		
		if(val.length>=0){
			lv++;
		
			if(val.length>=6){
				if(/\d/.test(val)) lv++;
				if(/[A-Za-z]/.test(val)) lv++;
			}
		}
		
		$(show).attr('class',function(i,c){
			c=c.replace(/(\s?)ps-lv-\d/g,'');
			if(c.length>0) c+=' ';
			
			return c+'ps-lv-'+lv;
		});
	});
}

//删除弹出提示框
function linkDelOper(){
	$('a.js_deloper').click(function(e){
		if(!confirm('是否删除选择的项目')) e.preventDefault();
	});
}

function setDefaultPhoto(obj,way){
	var path;
	if(way==0){
		path="skin/common/image/nopic_80x80.png"
	}else if(way==1){
		path="skin/common/image/nopic_160x160.png"
	}else if(way==2){
		path="skin/common/image/nopic_300x300.png"
	}else{
		path="skin/common/image/nopic_80x80.png"
	}
	obj.src=path;
}

/**
* tab切换
* @author ljl
* @version v0.1
* @argument index{int} 切换到索引为index的tab
* @example $("selector").tabs(); 
*          $("selector").tabs(1);
**/

;;;(function($){
	$.fn.extend({
		tabs:function(index){
			return this.each(function() {
				new $.Tabs(this,index);
			});
		}
	});
	
	$.Tabs=function(el,index){
		setTab(el,index);
		
		var flag=true;
		var events=$.data(el,"events");
		
		if(events &&  events["click"]){
			for(_event in events["click"]){
				if(_event.origType && _event.origType=="click.tabs"){
					flag=false;
					break;
				}
			}
		}
		
		if(flag){
			$(el).delegate(".tab li","click.tabs",function(e){
				e.preventDefault();
				
				var index=$(this).index();
				setTab(el,index);
			});
		}
	};
	
	function setTab(el,index){
		var $el=$(el);
	
		index=index || 0;
		
		$el.find(".tab li").removeClass("current")
				.eq(index).addClass("current");
		$el.find(".tab-content").children().hide()
				.eq(index).show();
	}	
})(jQuery);

//点击文本框提示消失
function placeholders(){
	$('.placeholders').each(function(i,n){
		var id=n.id;
		var label=$('label[for='+id+']');
		
		if(n.value=="") label.show();
		
		$(n).focusin(function(){
			label.hide();
		}).focusout(function(){
			if(this.value=="") label.show();
		});
	});
}

/**
* 图片卷动
* @author ljl
* @version v0.1
* @argument time{int,5000} 卷动的时间
			auto{bool,true} 是否自动滚动
			vertical{bool,false} 是否垂直方向
* @example $("selector").scrollable();
*          $("selector").scrollable({
*				time:3000,
*				auto:false,
*				vertical:true
*		   });
**/
;(function($) {
	$.fn.extend({
		scrollable:function(options){
			options = $.extend({}, $.Scrollable.defaults,options);
		
			return this.each(function() {
				new $.Scrollable(this, options);
			});
		}
	});
	
	$.Scrollable=function(el,options){
		var $el=$(el),
			$ul=$el.find('ul'),
			$li=$ul.children('li'),
			count=$li.size(),
			space=options.vertical?$li.outerHeight():$li.outerWidth(),
			maxLiCount=Math.floor(options.vertical?$el.height()/space:$el.width()/space),
			_index=0,
			_timer=null,
			_auto=true;
			
		move();
		
		$el.children('.prev').click(function(e){
			e.preventDefault();
			
			clearTimeout(_timer);
			if(_index==0) _index=count-maxLiCount+1;
			prev();
		});
		
		$el.children('.next').click(function(e){
			e.preventDefault();
			
			clearTimeout(_timer);
			next();
		});
		

		$ul.mouseenter(function(){
			clearTimeout(_timer);
			_auto=false;
		}).mouseleave(function(){
			_auto=true;
			_timer=setTimeout(next,options.time);
		});
		
		function move(index){
			clearTimeout(_timer);
		
			index==undefined && (index=_index);
			index>(count-maxLiCount) && (index=0);
			_index=index;
			
			var properties={};
			properties[options.vertical?'top':'left']=-_index*space;
			
			$ul.animate(properties,1000);
				
			if(options.auto && _auto){
				_timer=setTimeout(next,options.time)
			}
		}
		
		function prev(){
			move(--_index);
		}
		
		function next(){
			move(++_index);
		}
	};
	
	$.Scrollable.defaults={
		time:5000,
		auto:true,
		vertical:false
	};
})(jQuery);

/**
* 图片切换
* @author ljl
* @version v0.1
* @argument time{int,5000} 切换的时间
			auto{bool,true} 是否自动滚动
* @example $("selector").slider();
*          $("selector").slider({
*				time:3000,
*				auto:false
*		   });
**/
;(function($) {
	$.fn.extend({
		slider:function(options){
			options = $.extend({}, $.Slider.defaults,options);
		
			return this.each(function() {
				new $.Slider(this, options);
			});
		}
	});
	
	$.Slider=function(el,options){
		var $el=$(el),
			$tab_li=$el.find(".s-triggers").children('li'),
			$tab_info=$el.find(".s-content").children(),
			count=$tab_info.size(),
			_index=0,
			_timer=null,
			_mTimer=null,
			_auto=true;
			
		if($tab_li.size()<=0){
			var html='';
			
			for(var i=1;i<=count;i++){
				html+='<li>'+i+'</li>';
			}
			
			var $html=$('<ol class="s-triggers">'+html+'</ol>');
			$el.prepend($html);
				
			$tab_li=$html.children('li');
		}
			
		move();
	
		$tab_li.mouseenter(function(){
			var index=$(this).index();
		
			_mTimer=setTimeout(function(){
				_auto=false;
				move(index);
			},200);
		}).mouseleave(function(){
			clearTimeout(_mTimer);
			_auto=true;
			move();
		});
		
		function move(index){
			clearTimeout(_timer);
		
			index==undefined && (index=_index);
			index>=count && (index=0);
			_index=index;
			
			$tab_li.removeClass("current")
				.eq(_index).addClass("current");
				
			$tab_info.hide()
				.eq(_index).show();
				
			if(options.auto && _auto){
				_timer=setTimeout(next,options.time)
			}
		}
		
		function next(){
			move(++_index);
		}
	};
	
	$.Slider.defaults={
		time:5000,
		auto:true
	};
})(jQuery);

//间隔颜色
function tdSpace(){
	$('div.listcolor:odd').addClass('lc-odd')
	
	$('div.listcolor').hover(function(){
		$(this).addClass('lc-hover');
	},function(){
		$(this).removeClass('lc-hover');
	});
}

