
//NOTE: get/set height/width should always be pixel values

var crop = {
	// properties
	swf: null,
	div: null,
	width: 0,
	height: 0,
	
	// public
	setWidth: function(value){
		crop.width = value;
		crop._refresh();
	},
	
	getWidth: function(){
		var value = crop.div.style.width;
		if(value == "100%") value = swfIN.detect.getBrowserSize().w;
		return String(value).split("px")[0];
	},
	
	setHeight: function(value){
		crop.height = value;
		crop._refresh();
	},
	
	getHeight: function(){
		var value = crop.div.style.height;
		if(value == "100%") value = swfIN.detect.getBrowserSize().h;
		return String(value).split("px")[0];
	},
	
	getDimensions: function(){
		return {w:crop.getWidth(), h:crop.getHeight()};
	},
	
	// private
	_getDimension: function(type, min){
		value = String( crop.div.style[type] );
		var inner = swfIN.detect.getBrowserSize()[ type.substr(0,1) ];
		
		if ( value.indexOf("%") > -1 ){
			var pixelVal = Math.round( inner * ( value.split("%")[0] / 100 ) );
			value = ( pixelVal < min ) ? min : "100%";
		} else {
			value = value.split("px")[0];
			value = ( inner >= min ) ? "100%" : min;
		}
		
		return ( String(value).indexOf("%") > -1 ) ? value : value + "px";
	},
	
	_refresh: function(){
		crop._refreshDiv();
		
		setTimeout('crop._delayedCallback()', 20);
	},
	
	_delayedCallback: function(){
		//resize bugs.. wait a bit for callback
		crop.swf.callback("stageResizeHandler", crop.getWidth(), crop.getHeight());
	},
	
	_refreshDiv: function(){
		crop.div.style.width = crop._getDimension("width", crop.width);
		crop.div.style.height = crop._getDimension("height", crop.height);
	},
	
	//constructor
	construct: function(swf, width, height){
		crop.swf = swf;
		crop.div = document.getElementById("crop");
		
		crop.width = width;
		crop.height = height;
		
		//important! cannot use stageResizeHandler yet
		crop._refreshDiv();
		
		swfIN.utils.addEventListener(window, "resize", crop._refresh);
	}

}

