﻿function img_resize(id, xlimit, skinRatio) {
	id = $(id);
	//alert(id.width/xlimit);
	var ratio = (id.width/xlimit);
	//alert(ratio);
	
	h = id.height;
	//alert("orig height: " + id.height + "\norig width: " + id.width + "\nratio: " + ratio);
	id.width /= ratio;
	
	return ratio;
}

var cropImg = Class.create({
	initialize: function(ratio) {
		this.ratio = ratio;
		this.top = this.left = this.width = this.height = "";
	},

	getSelectedArea: function( coords, dimensions ) {
		this.top = coords.y1;
		this.left = coords.x1;
		this.width = dimensions.width;
		this.height = dimensions.height;

		//alert("scaled dimensions\n\ntop: " + this.top + "\nleft: " + this.left + "\n\nwidth: " + this.width + "\nheight: " + this.height + "\n\nratio: " + this.ratio);

		try {
		    document.getElementById("previewC").src = "../aspx/icon.aspx?f=" + document.getElementById('ctl00_main_hidFileUploaded').value + "&t=" + parseInt(Math.ceil(this.ratio * this.top)) + "&l=" + parseInt(Math.ceil(this.ratio * this.left)) + "&w=" + parseInt(Math.ceil(this.ratio * this.width)) + "&h=" + parseInt(Math.ceil(this.ratio * this.height)) + "&r=" + getrediolistvalue('ctl00_main_rdlRound');
		} catch (e) { }
	},
	crop: function() {
		//alert("scaled dimensions\n\ntop: " + this.top + "\nleft: " + this.left + "\n\nwidth: " + this.width + "\nheight: " + this.height + "\n\nratio: " + this.ratio);
		this.top *= this.ratio;
		this.left *= this.ratio;
		this.width *= this.ratio;
		this.height *= this.ratio;
		
		this.top = Math.ceil(this.top);
		this.left = Math.ceil(this.left);
		this.width = Math.ceil(this.width);
		this.height = Math.ceil(this.height);
		
		//alert("real dimensions\n\ntop: " + this.top + "\nleft: " + this.left + "\n\nwidth: " + this.width + "\nheight: " + this.height + "\n\nratio: " + this.ratio);
		return {y: this.top, x: this.left, w: this.width, h: this.height};
	}

});
