/**
 * POKE.scaling namespace
 * This class holds methods responsible for scaleing various sections of the app
 * Auth: Chris Reeves, POKE, 2010/02/03
 */
POKE.scaling = {}

/**
 * Article posterwall image scaler
 * Resizes images within their containers to 16:9 aspect ratio
 */
POKE.scaling.homePosterwall = function(elmn) {
	var elmn = (elmn == undefined ? '.posterwall' : elmn );
	$(elmn).posterwall({vertical_center:1, ratio:[16,9], min_size:[820, 462], container:$('.wrapper:first')});
}

/**
 * Scaler
 * Performs scaling operations on window resize
 * @object options to override
 */
POKE.scaling.scaler = function(ops) {
	
	// default options
	var defaultOps = {
		// callback function
		callback: 				null, 
		// elements
		elmn: 						'.wrapper',
		container: 				$(window),
		// width
		width: 						true,
		widthNavOffset: 	true,
		widthLimit: 			820,
		// height		
		height: 					true,
		heightBotOffset: 	true,
		heightLimit: 			462,
		// ratio
		ratio: 						9 / 16
	}
	
	// merge user ops with default
	ops = $.extend({}, defaultOps, ops);
	
	var conW = ops.container.width();
	var conH = $(window).height();
	
	// Width scaling
    	if(ops.width) {
    		var width = (ops.widthNavOffset ? conW - 160 : conW);
    		width = ( ops.widthLimit ? ( width > ops.widthLimit ? width : ops.widthLimit ) : width );
    		$(ops.elmn).width(width);
    }
    	
    // Height scaling
	if(ops.height) {
		var height = (ops.heightBotOffset ? (conW * ops.ratio) - 90 : (conW * ops.ratio));
		height = ( ops.heightLimit ? ( height > ops.heightLimit ? height : ops.heightLimit ) : height );
		$(ops.elmn).height(height);
	}
  
	// apply callback when done
	if(ops.callback) {
		ops.callback.apply(this);
	}
	
	/**
	 * Because IE6 is so poo, we have to tell it to refix the pattern png fix once the dom has loaded
	 */
	$(document).ready(function() {
  	if($.browser.msie && $.browser.version == '6.0') {
      $('.pattern').each(function() {
        DD_belatedPNG.vmlOffsets(this);
      });
      $('a.btn .btn-bg').each(function() {
        DD_belatedPNG.vmlOffsets(this);
      });
    }  
	});
	
}