function $(id) {return document.getElementById(id);}
var last_poster;
function set_active_layer(layer){
  if (layer==1){
    $('layertab_2').className="div-layer-inactive";
    $('layertab_1').className="div-layer-active";
    disappear('layer_2',0,1,100);
    appear('layer_1',1,0,10);
  } else {
    $('layertab_1').className="div-layer-inactive";
    $('layertab_2').className="div-layer-active";
    disappear('layer_1',0,1,100);
    appear('layer_2',1,0,10);
  }
}


function appear(ob,x,y,timer)
{
  if (timer==undefined) timer=5;
  var t;
  var op=y;
  var obj=$(ob);
  obj.style.display="block";
  if(op < x) {
    clearTimeout(t);
    op += timer/100;
    obj.style.opacity = op;
    obj.style.filter='alpha(opacity='+op*100+')';
    t=setTimeout('appear("'+ob+'",'+x+','+op+','+timer+')',5);
  }
}
function disappear(ob,x,y,timer)
{
  if (timer==undefined) timer=5;
  var t;
  var op=y;
  var obj=$(ob);
  if(op > x) {
    clearTimeout(t);
    op -= timer/100;
    obj.style.opacity = op;
    obj.style.filter='alpha(opacity='+op*100+')';
    t=setTimeout('disappear("'+ob+'",'+x+','+op+','+timer+')',5);
  } else {
    obj.style.display="none";
  }
}

function showposter(film_id){
  if (last_poster==null) last_poster=film_id;
  $("poster"+last_poster).style.display="none";
  last_poster=film_id;
  $("poster"+last_poster).style.display="block";

}


function fconfirm(str){
  if (confirm(str)) {
	return true;
	}
  else {
	return false;
  }
}



function getLatin(str){
	  str = str.replace(/\?/g,'');
	  str = str.replace(/\:/g,'');
	  str = str.replace(/\;/g,'');
	  str = str.replace(/\|/g,'');
	  str = str.replace(/\</g,'');
	  str = str.replace(/\>/g,'');
	  str = str.replace(/\}/g,'');
	  str = str.replace(/\{/g,'');
	  str = str.replace(/\[/g,'');
	  str = str.replace(/\]/g,'');
	  str = str.replace(/\//g,'');
	  str = str.replace(/\\/g,'');
	  str = str.replace(/\+/g,'');
	  str = str.replace(/\-/g,'');
	  str = str.replace(/\=/g,'');
	  str = str.replace(/\~/g,'');
	  str = str.replace(/\#/g,'');
	  str = str.replace(/\@/g,'');
	  str = str.replace(/\$/g,'');
	  str = str.replace(/\^/g,'');
	  str = str.replace(/\&/g,'');
	  str = str.replace(/\*/g,'');
	  str = str.replace(/\(/g,'');
	  str = str.replace(/\)/g,'');
	  str = str.replace(/%/g,'');
	  str = str.replace(/\"/g,'');
	  str = str.replace(/\«/g,'');
	  str = str.replace(/\»/g,'');
	  str = str.replace(/\'/g,'');
	  str = str.replace(/,/g,'');
	  str = str.replace(/\./g,'');
	  str = str.replace(/!/g,'');
	  str = str.replace(/ /g,'_');
	  str = str.replace(/а/g,'a');
	  str = str.replace(/б/g,'b');
	  str = str.replace(/в/g,'v');
	  str = str.replace(/г/g,'g');
	  str = str.replace(/д/g,'d');
	  str = str.replace(/е/g,'e');
	  str = str.replace(/ё/g,'e');
	  str = str.replace(/ж/g,'zh');
	  str = str.replace(/з/g,'z');
	  str = str.replace(/и/g,'i');
	  str = str.replace(/й/g,'j');
	  str = str.replace(/к/g,'k');
	  str = str.replace(/л/g,'l');
	  str = str.replace(/м/g,'m');
	  str = str.replace(/н/g,'n');
	  str = str.replace(/о/g,'o');
	  str = str.replace(/п/g,'p');
	  str = str.replace(/р/g,'r');
	  str = str.replace(/с/g,'s');
	  str = str.replace(/т/g,'t');
	  str = str.replace(/у/g,'u');
	  str = str.replace(/ф/g,'f');
	  str = str.replace(/х/g,'h');
	  str = str.replace(/ц/g,'c');
	  str = str.replace(/ч/g,'ch');
	  str = str.replace(/ш/g,'sh');
	  str = str.replace(/щ/g,'sh');
	  str = str.replace(/ъ/g,'');
	  str = str.replace(/ы/g,'y');
	  str = str.replace(/ь/g,'');
	  str = str.replace(/э/g,'e');
	  str = str.replace(/ю/g,'yu');
	  str = str.replace(/я/g,'ya');

	  str = str.replace(/А/g,'a');
	  str = str.replace(/Б/g,'b');
	  str = str.replace(/В/g,'v');
	  str = str.replace(/Г/g,'g');
	  str = str.replace(/Д/g,'d');
	  str = str.replace(/Е/g,'e');
	  str = str.replace(/Ё/g,'e');
	  str = str.replace(/Ж/g,'zh');
	  str = str.replace(/З/g,'z');
	  str = str.replace(/И/g,'i');
	  str = str.replace(/Й/g,'j');
	  str = str.replace(/К/g,'k');
	  str = str.replace(/Л/g,'l');
	  str = str.replace(/М/g,'m');
	  str = str.replace(/Н/g,'n');
	  str = str.replace(/О/g,'o');
	  str = str.replace(/П/g,'p');
	  str = str.replace(/Р/g,'r');
	  str = str.replace(/С/g,'s');
	  str = str.replace(/Т/g,'t');
	  str = str.replace(/У/g,'u');
	  str = str.replace(/Ф/g,'f');
	  str = str.replace(/Х/g,'h');
	  str = str.replace(/Ц/g,'c');
	  str = str.replace(/Ч/g,'ch');
	  str = str.replace(/Ш/g,'sh');
	  str = str.replace(/Щ/g,'sh');
	  str = str.replace(/Ъ/g,'');
	  str = str.replace(/Ы/g,'y');
	  str = str.replace(/Ь/g,'');
	  str = str.replace(/Э/g,'e');
	  str = str.replace(/Ю/g,'yu');
	  str = str.replace(/Я/g,'ya');
      var reg=/^[0-9]+$/i;
      if (reg.test(str)) str='cat'+str;
      return ( str);

}

var clevercrop = { // NAMESPACE
    processImage : function(id) {
        return new this.construct(id);
    }
};

clevercrop.construct = function(id) { // Constructor
    // Vars
    this.id = id;
        // Image data
    this.iWidth = 0;
    this.iHeight = 0;
    this.iMaxWidth = 0;
    this.iMaxHeight = 0;
    this.iMinWidth = 0;
    this.iMinHeight = 0;
    this.iTop = 0;
    this.iLeft = 0;
    this.iRate = 0;
    this.objx = 0;
    this.objy = 0;
        // Crop block data
    this.cropWidth = 220;
    this.cropHeight = 220;
    this.cropTop = false;
    this.cropLeft = false;
    this.cropMinWidth= 220;
    this.cropMinHeight = 220;
    this.cropBackground = false;
        // Move
    this.X0 = 0;
    this.Y0 = 0;
        // Resize div data
    this.resizeWidth = 8;
    this.resizeHeight = 8;
    //this.resizeTop = 0;
    //this.resizeLeft = 0;
        // Resize move
    this.iBuferWidth = 0;
    this.iBuferHeight = 0;
    // Flags
    this.cropMoveState = false;
    this.resizeTRMoveState = false;
    this.resizeBRMoveState = false;
    this.resizeTLMoveState = false;
    this.resizeBLMoveState = false;
    this.saveProportions = true;
    this.stopSelection = true;
    this.debugMode = true;
    // Handlers
    this.onUpdate = null;
    // Nodes
    this.image = null;
    this.crop = null;
    this.resizeTL = null;
    this.resizeBR = null;
    this.resizeBL = null;
    this.resizeTR = null;
}

clevercrop.construct.prototype = {
// Const
    ERRORS : {
        1 : "Ошибка инициализации картинки",
        2 : "Картинка не найдена",
        3 : "Указанный элемент не является картинкой",
        4 : "Не установлена функция onUpdate",
        5 : "Элемент body не найден"
    },
// Methods
    // Default
    addMouseHandler : function(object, event, handler, useCapture) {
        if (object.addEventListener) {
            object.addEventListener(event, handler, useCapture ? useCapture : false);
        } else if (object.attachEvent) {
            object.attachEvent('on' + event, handler);
        } else alert(this.errorArray[9]);
    },
    defPosition : function(event) {
        var x = y = 0;
        if (document.attachEvent != null) {
            x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
            y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
        }
        if (!document.attachEvent && document.addEventListener) { // Gecko
            x = event.clientX + window.scrollX;
            y = event.clientY + window.scrollY;
        }
        if (x<this.iLeft) x=this.iLeft;
        if (y<this.iTop) y=this.iTop;
        if (x>this.iLeft+this.iWidth) x=this.iLeft+this.iWidth;
        if (y>this.iTop+this.iHeight) y=this.iTop+this.iHeight;
        return {x:x, y:y};
    },
    absPosition : function(obj) {
        var x = y = 0;
        while(obj.offsetParent) {
            x += obj.offsetLeft;
            y += obj.offsetTop;
            obj = obj.offsetParent;
        }
        return {x:x, y:y};
    },
    domReady : function(i) { /* Copyright http://ajaxian.com/ */
        var u =navigator.userAgent;
        var e=/*@cc_on!@*/false;
        var st = setTimeout;
        if (/webkit/i.test(u)) {
            st(
                function() {
                    var dr=document.readyState;
                    if(dr=="loaded"||dr=="complete") i();
                    else st(arguments.callee,10);
                },
                10
            );
        } else if ((/mozilla/i.test(u)&&!/(compati)/.test(u)) || (/opera/i.test(u))) {
            document.addEventListener("DOMContentLoaded", i, false);
        } else if (e) {(
            function(){
                var t=document.createElement('doc:rdy');
                try {
                    t.doScroll('left'); i(); t=null;
                } catch(e) {st(arguments.callee,0);}
            })();
        } else window.onload=i;
    },
    imageReady: function(i){
        if ($(this.id).readyState=='loaded'||$(this.id).readyState=='complete') {
          i();
        } else
        $(this.id).onload=i;
    },
    // Common
    debug : function(keys) {
       // if (!this.debugMode) return;
        var mes = "";
        for (var i = 0; i < keys.length; i++) mes += this.ERRORS[keys[i]] + " : ";
        mes = mes.substring(0, mes.length - 3);
        alert(mes);
    },
    init : function(hash, node, imagenode) {
        if (typeof node == "undefined") {
            var _this = this;
            this.domReady(
                function() {_this.init(hash, 1)}
            );
            return;
        }
        if (typeof imagenode == "undefined") {
            var _this = this;
            this.imageReady(
                function() {_this.init(hash, node, 1)}
            );
            return;
        }
        this.image = $(this.id);
        if (this.image == null) {
            this.debug([1,2]);
                return;
        }
        if (this.image.nodeName.toLowerCase() != "img") {
            this.debug([1,3]);
                return;
        }
        try {
            for (var i in hash) this[i] = hash[i];
            if (this.onUpdate == null) {
                this.debug([1,4]);
                    return;
            }
            if (!document.body) {
                this.debug([1,5]);
                    return;
            }
            this.image.ondragstart = function() {return false;} // IE fix
            // Set default
            this.redefine();
            //alert(" top:"+this.iTop+" left:"+this.iLeft+" width:"+this.iWidth+" height:"+this.iHeight);
            this.cropTop = this.iTop +this.cropTop;
            this.cropLeft = this.iLeft +this.cropLeft;
            this.iMaxWidth = this.iWidth;
            this.iMaxHeight = this.iHeight;
            this.iMinWidth = this.cropMinWidth;
            this.iMinHeight = this.cropMinHeight;
            this.iRate = this.cropWidth / this.cropHeight;
            if (this.cropWidth==150&&this.cropHeight==150){
              if (this.iHeight>this.iWidth){
              this.cropWidth=this.iWidth;
              this.cropHeight=this.cropWidth;
              } else {
              this.cropHeight=this.iHeight;
              this.cropWidth=this.cropHeight;
              }
            }
            this.drawCropBlock();
            this.drawResizeBlocks();
            // Add handers
            var _this = this;
            this.addMouseHandler(document, "mousemove", function (evt) {
                _this.cropMoveHandler(evt);
                _this.resizeMoveHandler(evt);

            });
            this.addMouseHandler(document, "mouseup", function () {
                _this.cropMoveState = false;
                _this.resizeTRMoveState = false;
                _this.resizeBRMoveState = false;
                _this.resizeTLMoveState = false;
                _this.resizeBLMoveState = false;
                _this.redefine();
            });
            this.addMouseHandler(_this.crop, "mousedown", function (evt) {
                _this.cropMoveState = true;
                evt = evt || window.event;
                if (evt.preventDefault && _this.stopSelection) evt.preventDefault();
                _this.X0 = _this.defPosition(evt).x;
                _this.Y0 = _this.defPosition(evt).y;
            });
            this.addMouseHandler(_this.resizeBR, "mousedown", function (evt) {
                _this.resizeBRMoveState = true;
                evt = evt || window.event;
                if (evt.preventDefault && _this.stopSelection) evt.preventDefault();
                _this.X0 = _this.defPosition(evt).x;
                _this.Y0 = _this.defPosition(evt).y;
                _this.iBuferWidth = _this.cropWidth;
                _this.iBuferHeight = _this.cropHeight;
            });
            this.addMouseHandler(_this.resizeTL, "mousedown", function (evt) {
                _this.resizeTLMoveState = true;
                evt = evt || window.event;
                if (evt.preventDefault && _this.stopSelection) evt.preventDefault();
                _this.X0 = _this.defPosition(evt).x;
                _this.Y0 = _this.defPosition(evt).y;
                _this.iBuferWidth = _this.cropWidth;
                _this.iBuferHeight = _this.cropHeight;
            });
            this.addMouseHandler(_this.resizeBL, "mousedown", function (evt) {
                _this.resizeBLMoveState = true;
                evt = evt || window.event;
                if (evt.preventDefault && _this.stopSelection) evt.preventDefault();
                _this.X0 = _this.defPosition(evt).x;
                _this.Y0 = _this.defPosition(evt).y;
                _this.iBuferWidth = _this.cropWidth;
                _this.iBuferHeight = _this.cropHeight;
            });
            this.addMouseHandler(_this.resizeTR, "mousedown", function (evt) {
                _this.resizeTRMoveState = true;
                evt = evt || window.event;
                if (evt.preventDefault && _this.stopSelection) evt.preventDefault();
                _this.X0 = _this.defPosition(evt).x;
                _this.Y0 = _this.defPosition(evt).y;
                _this.iBuferWidth = _this.cropWidth;
                _this.iBuferHeight = _this.cropHeight;
            });
        } catch(e) {this.debug([1]);}
    },
    redefine : function() {
        this.iTop = this.absPosition(this.image).y;
        this.iLeft = this.absPosition(this.image).x;
		this.iWidth = this.image.width ? parseInt(this.image.width) : this.image.offsetWidth;
		this.iHeight = this.image.height ? parseInt(this.image.height) : this.image.offsetHeight;
        if (this.crop) {
              this.cropLeft = parseInt(this.crop.style.left);
              this.cropTop = parseInt(this.crop.style.top);
        }
        this.objx=this.cropLeft-this.iLeft;
        this.objy=this.cropTop-this.iTop;
        this.onUpdate();
    },
    // Crop
    drawCropBlock : function() {
        if (!$("cropDivId_" + this.id)) {
            this.crop = document.createElement("div");
            this.crop.id = "cropDivId_" + this.id;
            this.crop.style.width = this.cropWidth + "px";
            this.crop.style.height = this.cropHeight + "px";
            this.crop.className = "cropDiv";
            //this.crop.style.display = "none";
            document.body.appendChild(this.crop);
        }
        this.crop = $("cropDivId_" + this.id);
        this.crop.style.top = parseInt(this.cropTop) + "px";
        this.crop.style.left = parseInt(this.cropLeft) + "px";
        if (this.cropBackground) this.crop.style.background = this.cropBackground;
        this.crop.style.display = "";
    },
    cropMoveHandler : function(evt) {
        if (!this.cropMoveState) return;

        evt = evt || window.event;
        //alert(this.defPosition(evt).x+" "+this.X0+" "+this.cropLeft);
        var newX = this.defPosition(evt).x - this.X0 + this.cropLeft;
        var newY = this.defPosition(evt).y - this.Y0 + this.cropTop;
        if (newX < this.iLeft) newX = this.iLeft;
        if (newX + this.cropWidth > this.iLeft + this.iWidth) newX = this.iLeft + this.iWidth - this.cropWidth;
        if (newY < this.iTop) newY = this.iTop;
        if (newY + this.cropHeight > this.iTop + this.iHeight) newY = this.iTop + this.iHeight - this.cropHeight;
        this.crop.style.top = parseInt(newY) + "px";
        this.crop.style.left = parseInt(newX) + "px";
        this.resizeBR.style.top = (parseInt(this.crop.style.top)+parseInt(this.crop.style.height) - 5) + "px"; //resizeTop
        this.resizeBR.style.left = (parseInt(this.crop.style.left)+parseInt(this.crop.style.width) - 5) + "px"; //resizeLeft
        this.resizeTL.style.top = (parseInt(this.crop.style.top)-4) + "px"; //resizeTop
        this.resizeTL.style.left = (parseInt(this.crop.style.left)-4) + "px"; //resizeLeft
        this.resizeBL.style.top = (parseInt(this.crop.style.top)+parseInt(this.crop.style.height)-4) + "px"; //resizeTop
        this.resizeBL.style.left = (parseInt(this.crop.style.left)-4) + "px"; //resizeLeft
        this.resizeTR.style.top = (parseInt(this.crop.style.top)-4) + "px"; //resizeTop
        this.resizeTR.style.left = (parseInt(this.crop.style.left)+parseInt(this.crop.style.width)-5) + "px"; //resizeLeft
        this.objx=newX-this.iLeft;
        this.objy=newY-this.iTop;
        this.onUpdate();
    },
    // Resize
    drawResizeBlocks : function() {
        if (!$("resizeBRDivId_" + this.id)) {
            this.resizeBR = document.createElement("div");
            this.resizeBR.id = "resizeBRDivId_" + this.id;
            this.resizeBR.className = "resizeDivnw";
            this.resizeBR.innerHTML = "";
            this.resizeBR.style.width = this.resizeWidth + "px";
            this.resizeBR.style.height = this.resizeHeight + "px";
            this.resizeBR.style.display = "none";
            document.body.appendChild(this.resizeBR);
        }
        this.resizeBR = $("resizeBRDivId_" + this.id);
        this.resizeBR.style.display = "";
        if (!$("resizeTLDivId_" + this.id)) {
            this.resizeTL = document.createElement("div");
            this.resizeTL.id = "resizeTLDivId_" + this.id;
            this.resizeTL.className = "resizeDivnw";
            this.resizeTL.innerHTML = "";
            this.resizeTL.style.width = this.resizeWidth + "px";
            this.resizeTL.style.height = this.resizeHeight + "px";
            this.resizeTL.style.display = "none";
            document.body.appendChild(this.resizeTL);
        }
        this.resizeTL = $("resizeTLDivId_" + this.id);
        this.resizeTL.style.display = "";
        if (!$("resizeBLDivId_" + this.id)) {
            this.resizeBL = document.createElement("div");
            this.resizeBL.id = "resizeBLDivId_" + this.id;
            this.resizeBL.className = "resizeDives";
            this.resizeBL.innerHTML = "";
            this.resizeBL.style.width = this.resizeWidth + "px";
            this.resizeBL.style.height = this.resizeHeight + "px";
            this.resizeBL.style.display = "none";
            document.body.appendChild(this.resizeBL);
        }
        this.resizeBL = $("resizeBLDivId_" + this.id);
        this.resizeBL.style.display = "";
        if (!$("resizeTRDivId_" + this.id)) {
            this.resizeTR = document.createElement("div");
            this.resizeTR.id = "resizeTRDivId_" + this.id;
            this.resizeTR.className = "resizeDives";
            this.resizeTR.innerHTML = "";
            this.resizeTR.style.width = this.resizeWidth + "px";
            this.resizeTR.style.height = this.resizeHeight + "px";
            this.resizeTR.style.display = "none";
            document.body.appendChild(this.resizeTR);
        }
        this.resizeTR = $("resizeTRDivId_" + this.id);
        this.resizeTR.style.display = "";
        this.setResizeVars();
    },
    setResizeVars : function() {
          this.redefine();
          this.resizeBR.style.top = (parseInt(this.crop.style.top)+parseInt(this.crop.style.height) - 5) + "px"; //resizeTop
          this.resizeBR.style.left = (parseInt(this.crop.style.left)+parseInt(this.crop.style.width) - 5) + "px"; //resizeLeft
          this.resizeTL.style.top = (parseInt(this.crop.style.top)-4) + "px"; //resizeTop
          this.resizeTL.style.left = (parseInt(this.crop.style.left)-4) + "px"; //resizeLeft
          this.resizeBL.style.top = (parseInt(this.crop.style.top)-4+parseInt(this.crop.style.height)) + "px"; //resizeTop
          this.resizeBL.style.left = (parseInt(this.crop.style.left)-4) + "px"; //resizeLeft
          this.resizeTR.style.top = (parseInt(this.crop.style.top)-4) + "px"; //resizeTop
          this.resizeTR.style.left = (parseInt(this.crop.style.left)+parseInt(this.crop.style.width) - 5) + "px"; //resizeLeft
    },
    resizeMoveHandler : function(evt) {
        evt = evt || window.event;
        var hW, hH,hLeft,hTop;
        if (!this.resizeBRMoveState&&!this.resizeTLMoveState&&!this.resizeBLMoveState&&!this.resizeTRMoveState) return;
        var defX=this.defPosition(evt).x;
        var defY=this.defPosition(evt).y;

        if (this.resizeTRMoveState){
            hW = this.iBuferWidth + defX - this.X0;
            hH = this.iBuferHeight + defY - this.Y0;
            this.cropWidth=hW;
            this.cropHeight=(this.saveProportions ? hW / this.iRate : hH);
        } else if (this.resizeBRMoveState){
            hW = this.iBuferWidth + defX - this.X0;
            hH = this.iBuferHeight + defY - this.Y0;
            this.cropWidth=hW;
            this.cropHeight=(this.saveProportions ? hW / this.iRate : hH);
        } else if (this.resizeTLMoveState){
            hW = this.iBuferWidth - defX + this.X0;
            hH = this.iBuferHeight - defY + this.Y0;
            this.cropWidth=hW;
            this.cropHeight=(this.saveProportions ? hW / this.iRate : hH);
        } else if (this.resizeBLMoveState){
            hW = this.iBuferWidth - defX + this.X0;
            hH = this.iBuferHeight + defY - this.Y0;
            this.cropWidth=hW;
            this.cropHeight=(this.saveProportions ? hW / this.iRate : hH);
        }
        if (this.cropWidth<this.cropMinWidth||this.cropHeight<this.cropMinHeight) {
          this.cropWidth=this.cropMinWidth;
          this.cropHeight=this.cropWidth;
        }
        if (this.cropWidth>this.iMaxWidth||this.cropHeight>this.iMaxHeight) {
          this.cropWidth=this.iMaxWidth;
          this.cropHeight=this.cropWidth;
        }


        if (hW <= this.iMinWidth) hW = this.iMinWidth;
        if (hW >= this.iMaxWidth) hW = this.iMaxWidth;
        if (hH <= this.iMinHeight) hH = this.iMinHeight;
        if (hH >= this.iMaxHeight) hH = this.iMaxHeight;

        if (this.resizeTLMoveState){
           if (this.iTop<=this.cropTop&&this.cropLeft>=this.iLeft){
              this.cropTop = this.cropTop-this.cropHeight+parseInt(this.crop.style.height);
           }
           if (this.iTop>this.cropTop){
              this.cropTop = this.iTop;
           }
           if (this.cropLeft>=this.iLeft&&this.iTop<this.cropTop)
              this.cropLeft=this.cropLeft-this.cropWidth+parseInt(this.crop.style.width);

           if (this.cropLeft<this.iLeft||this.iTop>=this.cropTop){
              this.cropWidth=parseInt(this.crop.style.width);
              this.cropHeight=(this.saveProportions ? this.cropWidth / this.iRate : this.cropWidth);
              if (this.cropLeft<this.iLeft)
                this.cropLeft=this.iLeft;
              if (this.cropTop<this.iTop)
                this.cropTop = this.iTop;
           }
        }

        if (this.resizeTRMoveState){
           if (this.iTop<=this.cropTop&&this.cropLeft+this.cropWidth<=this.iLeft+this.iWidth){
              this.cropTop = this.cropTop-this.cropHeight+parseInt(this.crop.style.height);
           }
           if (this.iTop>=this.cropTop){
              this.cropTop = this.iTop;
              this.cropWidth=parseInt(this.crop.style.width);
              this.cropHeight=(this.saveProportions ? this.cropWidth / this.iRate : this.cropWidth);
           }

           if (this.cropLeft<this.iLeft||this.iTop>=this.cropTop){
              this.cropWidth=parseInt(this.crop.style.width);
              this.cropHeight=(this.saveProportions ? this.cropWidth / this.iRate : this.cropWidth);
              if (this.cropLeft<this.iLeft)
                this.cropLeft=this.iLeft;
              if (this.cropTop<this.iTop)
                this.cropTop = this.iTop;
           }
           if (this.iLeft+this.iWidth<this.cropLeft+this.cropWidth){
              this.cropWidth=parseInt(this.crop.style.width);
              this.cropHeight=(this.saveProportions ? this.cropWidth / this.iRate : this.cropWidth);
           }
        }

        if (this.resizeBLMoveState){
           if (this.iTop+this.iHeight<this.cropTop+this.cropHeight){
              this.cropHeight=parseInt(this.crop.style.height);
              this.cropWidth=(this.saveProportions ? this.cropHeight / this.iRate : this.cropHeight);
           }
           if (this.cropLeft>=this.iLeft)
           this.cropLeft=this.cropLeft-this.cropWidth+parseInt(this.crop.style.width);
           if (this.cropLeft<this.iLeft){
              this.cropWidth=parseInt(this.crop.style.width);
              this.cropHeight=(this.saveProportions ? this.cropWidth / this.iRate : this.cropWidth);
              this.cropLeft=this.iLeft;
           }
        }

        if (this.resizeBRMoveState){
           if (this.iTop+this.iHeight<this.cropTop+this.cropHeight){
              this.cropHeight=parseInt(this.crop.style.height);
              this.cropWidth=(this.saveProportions ? this.cropHeight / this.iRate : this.cropHeight);
           }
           if (this.iLeft+this.iWidth<this.cropLeft+this.cropWidth){
              this.cropWidth=parseInt(this.crop.style.width);
              this.cropHeight=(this.saveProportions ? this.cropWidth / this.iRate : this.cropWidth);
           }
        }


		this.crop.style.width = this.cropWidth + "px";
		this.crop.style.height = this.cropHeight + "px";
        this.crop.style.left = parseInt(this.cropLeft) +"px";
        this.crop.style.top = parseInt(this.cropTop) +"px";

        this.setResizeVars();
    }
}
