(function(){
	function Education(settings){
		this.opt=$.extend({
			con:null,//dom
			data:[{type:'本科及以上',value:3078}],
			color:'#1786C6',
			label:{
				fontSize:'14px',
				color:'#FFFFFF'
			},
			imgsrc:"images/book.png",
			animateTime:2250
		},settings);
		this.init.apply(this,arguments);
	}
	Education.prototype={
		init:function(){
			this.render();
			this.numIncrease(this.opt.con.find("[data-percent]"));
			this.modifyImgSize(46,36);
		},
		render:function(){
			var obj=this.opt;
			var html="";
			var li="";
			var uh=(obj.con.height()-55)/obj.data.length; //unit height
			var uw=obj.con.width()/obj.data.length; //unit width
			for(var i=0 in obj.data){
				li="<li style='display:inline-block;width:"+uw+"px;vertical-align:bottom;'>"
						+"<span style='vertical-align:bottom;position:relative;top:-8px;'>"
							+"<p data-percent='"+i+"' style='margin-bottom:5px;'>0%</p>"
							+"<div style='height:32px;'><img src='"+obj.imgsrc+"' data-book='"+i+"' style='width:0px;height:0px;vertical-align:middle;'/></div>"
						+"</span>"
						+"<div style='line-height:"+(uh*0.8)+"px;height:"+(uh*(parseInt(i,10)+1))+"px;background-color:"+obj.color+";color:"+obj.label.color+";font-size:"+obj.label.fontSize+";'>"+obj.data[i].type+"</div>"
					+"</li>";
				html+=li;
			}
			obj.con.html("<ul style='font-size:12px;color:"+obj.color+";text-align:center;'>"+html+"</ul>");
		},
		getPercent:function(t){
			var total=0;
			for(var i=0 in this.opt.data){
				total+=this.opt.data[i].value;
				
			}
			return Math.round(this.opt.data[t].value/total*10000)/100;
		},
		numIncrease:function(collection){
			var self=this;
			collection.each(function(){
				$(this).animateNumber({
					number:self.getPercent($(this).data('percent')),
				    numberStep: function(now, tween) {
				       	var floored_number = Math.floor(now*100)/100;
				            target = $(tween.elem);
				    	target.text(floored_number+"%");
				    }
				},self.opt.animateTime);
			});
		},
		modifyImgSize:function(imgW,imgH){
			var self=this;
			var popuArray= new Array();
			for(var i=0 in this.opt.data){
				popuArray.push(this.opt.data[i].value);
			}
			var max=Math.max.apply(null,popuArray);
			
			var baseH=imgH*0.75/max;
			var baseW=imgW*0.75/max;

			this.opt.con.find("[data-book]").each(function(){
				$(this).animate({
					width:baseW*self.opt.data[$(this).data("book")].value+0.25*imgW,
					height:baseH*self.opt.data[$(this).data("book")].value+0.25*imgH
				},self.opt.animateTime);
			});
		}
	}
	Education.prototype.constructor=Education;
	window.jClass_Education=Education;
})()