var _winscrolling = false,
	_winPosition = [0,0,0,0],
	_bodyPosition = [0,0,0,0],
	viewplugin = {
	load:function(editable){
		$.ajax({
			url:'tabs.php?action=getpluginlist',
			dataType:'json',
			success:function(data){
				if(editable){
					viewplugin._editableLoad(data);
				}else{
					viewplugin._load(data);
				}
			}
		});		
	},
	_load: function(files){
		for (var i = 0; i < files.length; i++) {
			var file = files[i],
				pos = file.pos.split(','),
				opposite = false;
				if(pos[3]<0||pos[1]==0){
					opposite = true;
				}

			this.init(file.id,file.name,pos,opposite).init(true);
		}
	},
	_editableLoad : function(files){
		for (var i = 0; i < files.length; i++) {
			var file = files[i],
				pos = file.pos.split(','),
				opposite = false;	
				if(pos[3]<0||pos[1]==0){
					opposite = true;
					pos[3] -= 20;
				}
				if(pos[1]<0){
					pos[1] -= 20;
				}
			this.editableInit(file.id,file.name,pos,opposite);
		}
	},
	_newObject:function(name){
		var	proto = this[name];
			if(!proto.prototype){
			    this[name] = new Function();
				this[name].prototype = proto;					
			}
		return new this[name]();		
	},
	init:function(id,name,pos,opposite){
		var newplugin = this._newObject(name);
		newplugin.id = id;
		newplugin.position = pos;
		newplugin.opposite = opposite;
		return newplugin;		
	},
	editableInit:function(id,name,pos,opposite){
		var newplugin = this.init(id,name,pos,opposite);
		return newplugin.init().viewPlugin({context:newplugin});
	},
	_tips:$('<div class="ui-viewplugin-dragtip"/>'),
	showTips:function(){
		return this._tips.css({width:arguments[0],height:arguments[1],left:arguments[2],top:arguments[3],right:arguments[4]}).show();	
	},
	getContentBody:function(){
		return bodyContent = $('#bodycontentContainer');
	},
	globalPosition:function(){
		var bodyContent = this.getContentBody();
			bodyTop = bodyContent.offset().top,
			bodyLeft = bodyContent.offset().left,
			bodyRight = bodyContent.width()+bodyLeft,
			bodyBottom = bodyContent.height()+bodyTop,
			winRight = $(window).width(),
			winBottom = $(window).height();
			
		_bodyPosition = [bodyTop,bodyRight,bodyBottom,bodyLeft];
		_winPosition = [0,winRight,winBottom,0];		
	}
}

