
$.fn.CreateLayer = function(c,oType,oText,aIn){
	var oID = aIn.objArgs.id;
	nL = document.createElement(oType);	
	nL.style.position = (aIn && aIn.styleArgs && aIn.styleArgs.position)?aIn.styleArgs.position:"absolute";
	if(aIn && aIn.objArgs)
		for (a in aIn.objArgs)
			nL.setAttribute(a,aIn.objArgs[a]);
	if(aIn && aIn.styleArgs)
		for (a in aIn.styleArgs)
			nL.style[a]=aIn.styleArgs[a];
	this.append(nL);
	$("#"+oID).html(oText);
	$("#"+oID).attr("oType",oType.toLowerCase());
//	$("#"+oID).attr("zoomvar",(($.browser.firefox)?"MozTransform":"zoom"));

//	if(aIn && aIn.eventArgs)
//		for (a in aIn.eventArgs)
//			$("#"+oID).layer[a] = aIn.eventArgs[a];
//	if(aIn && aIn.objHandlers)
//		for (a in aIn.objHandlers)
//			$("#"+oID)[a]=aIn.objHandlers[a];
	$("#"+oID).MoveToLoc(c.l,c.t);
	$("#"+oID).ResizeTo(c.w,c.h);
}

$.fn.window = function(){
	if($("#"+oID).is("iframe"))
		return window.frames[this.attr.id];
	return false;
}

$.fn.layer = function(){
	return document.getElementById(this.attr("id"));
}

$.fn.MoveToLoc = function(l,t,abs){
	this.css({left:l+"px",top:t+"px"});
}

$.fn.MoveBy = function(l,t){
	var o = this.GetObjectData(true);
	this.css({left:(o.l+l)+"px",top:(o.t+t)+"px"});
}

$.fn.ResizeTo = function(w,h){
	this.css({width:w+"px",height:h+"px"});
}


$.fn.SetClip = function(t,r,b,l){
	this.css({clip:"rect("+t+"px "+r+"px "+b+"px "+l+"px)"});
}

$.fn.ResizeBy = function(w,h){
	this.css({width:(w+this.width())+"px",height:(h+this.height())+"px"});
}

$.fn.GetZoom = function(){
	if(this.css('MozTransform') > ""){
		var z = parseFloat((this.css('MozTransform')=="none")?1:this.css('MozTransform').match(/scale\(([0-9\.]+)\)/m)[1]);
	}else{
		var z = parseFloat((this.css("zoom")=="normal")?1:this.css("zoom"));
	}
	return z;
}

$.fn.GetObjectData = function(rel){
	var mt = this;
	if(!this.layer)return false;
	var op = (rel)?mt.position():mt.offset();
	var m = (false)?this.GetZoom():1;
	return {l:Math.round(op.left*m),t:Math.round(op.top*m),w:mt.width(),h:mt.height(),z:mt.css("zoom")};
}
$.fn.RelPosObject = function(rO,hJ,hI,vJ,vI){
	var addW,addH;
	var rOD = $(rO).GetObjectData();
	var tODr = this.GetObjectData(true);
	var tODa = this.GetObjectData();
	var tOD = {l:tODr.l-tODa.l,t:tODr.t-tODa.t,w:tODr.w,h:tODr.h};
	var h = (hI == "w")?tOD.w:hI;
	var v = (vI == "h")?tOD.h:vI;
		
	if (hJ==0)addW=h;
	if (hJ==1)addW=((rOD.w-tOD.w)/2)+h;
	if (hJ==2)addW=rOD.w-tOD.w+h;
	if (vJ==0)addH=v;
	if (vJ==1)addH=((rOD.h-tOD.h)/2)+v;
	if (vJ==2)addH=rOD.h-tOD.h+v;
	this.MoveToLoc(rOD.l+tOD.l+addW,rOD.t+tOD.t+addH);
}

$.fn.ZoomTo = function(zoomTo,time){
// Scale in FF
// $("#div2").css('MozTransform',"scale(.1)")
//	var z = parseFloat((this.css("zoom")=="normal")?1:(($(this).css("zoom") == undefined)?$(this).attr("zoom"):$(this).css("zoom")));
	var zoomLevel = this.GetZoom();
	var eP = (zoomTo)?zoomTo:this.attr("zL");
	var eT = (time)?time:this.attr("tL");
	var tOD = this.GetObjectData();
	if(zoomLevel<=eP)
	    return false;
	var zoomAmount = Math.round((-(zoomLevel-eP)/(eT/100))*1000)/1000;
//	this.MoveBy(Math.round(-(zoomAmount*tOD.l/2)),Math.round(-(zoomAmount*tOD.t/2)));
	this.MoveBy(1,1);
	this.attr("zL",eP);
	this.attr("tL",eT-100);
	this.attr("zoomAmount",zoomAmount);
	this.attr("zoom",zoomLevel+zoomAmount);
	if($.browser.firefox){
		this.css("MozTransform","scale("+this.attr("zoom")+")");
	}else{
		this.css("zoom",this.attr("zoom"));
	}
//	alert("running");
	setTimeout("$('#"+this.attr("id")+"').ZoomTo()",500);
}

$.fn.makeAbsolute = function(rebase) {
    return this.each(function() {
        var el = $(this);
        var pos = el.position();
        el.css({ position: "absolute",
            marginLeft: 0, marginTop: 0,
            top: pos.top, left: pos.left });
        if (rebase)
            el.remove().appendTo("body");
    });
}