﻿
if (!window._) {
	window._ = {};
	_.iexplorerVersion = -1;
}

//////	
////	Error catcher or reporter
//
var Errors = [];
if (window.bDev === undefined) { window.bDev = false; }

function stopError(Event) {
	Event.cancelBubble = true;
	Event.returnValue = true;
	if (Event.preventDefault) Event.preventDefault();
	if (Event.stopPropagation) Event.stopPropagation();
	return true;
}
function flushErrors() {
	if (window.YAHOO && YAHOO.util && YAHOO.util.Connect && YAHOO.util.Connect.asyncRequest) {
		var item;
		while (Errors.length) {
			item = Errors.shift();
			YAHOO.util.Connect.asyncRequest('GET', '/jsError_receiver.aspx?' + item);
		}
	}
}
function logError(a, b, c) {
	var str = 'message=' + window.escape(a) + '&file=' + window.escape(b) + '&line=' + window.escape(c);
	Errors.push(str);
	if (bDev && window.console && console.log) {
		console.log(str);
	}
	else {
		flushErrors();
		return stopError(Event);
	}
}
window.onerror = logError;
if (!bDev) {
	if (window.addEventListener) {
		window.addEventListener('load', flushErrors, false);
		window.addEventListener('unload', flushErrors, false);
	}
	else if (window.attachEvent) {
		window.attachEvent('onload', flushErrors);
		window.attachEvent('onunload', flushErrors);
	}
}

// console
var $debug = function() { };
var $error = function() { };
if (window.console && console.debug) {
	var $debug = function(input) { console.debug(input); };
}
else if (window.console && console.log) {
	var $debug = function(input) { console.log(input); };
}

function reloadStyles(n) { // optionaly choose index to switch only one stylesheet (starts with 0)
	var links = document.getElementsByTagName('LINK'), href = "";
	if (n) {
		if (links[n] && links[n].type == "text/css") {
			href = links[n].href;
			if (href.indexOf("?") >= 0) href = href.substr(0, href.indexOf("?")) + "?" + Math.random();
			else href = href + "?" + Math.random();
			links[n].href = href;
		}
	}
	else {
		for (var n in links) {
			if (links[n] && links[n].type == "text/css") {
				href = links[n].href;
				if (href.indexOf("?") >= 0) href = href.substr(0, href.indexOf("?")) + "?" + Math.random();
				else href = href + "?" + Math.random();
				links[n].href = href;
			}
		}
	}
	return links;
}
/*
javascript: var links = document.getElementsByTagName('LINK'); var href = ""; for (var n in links) { if (links[n].type == "text/css") { void(href = links[n].href); if (href.indexOf("?") >= 0) void(href = href.substr(0, href.indexOf("?")) + "?" + Math.random()); else void(href = href + "?" + Math.random()); void(links[n].href = href); } };
*/


//////// $horthand functions ////////
function $get(sId, context) {
    if (!context || !context.getElementById ) context = document; 
    return context.getElementById(sId);
}
function $F(sId, context) {
	var obj = $get(sId, context);
	if (obj) return obj.value;
	else {
		if (forms[context]) {
			return forms[context][sID];
		}
	}
}

// cut a node (returns node rather than saving to clipboard)
function $cut(sId, context) {
	if (!context || !context.getElementById) context = document;
	var copy = null, found = context.getElementById(sId);
	//$debug(found)
	if (found) {
		//$debug(found.parentNode)
		found.parentNode.removeChild(found);
		copy = found.cloneNode(true);
	}
	return copy;
}

function $getTags(name, context) {
	if (!context || !context.getElementsByTagName) context = document;
    return context.getElementsByTagName(name);
}

function $hasClass(oElement, sClass) { // retuens true / false
    if (!oElement || !sClass) return undefined;
    var i = oElement.className.indexOf(sClass);
    if (i < 0) i = oElement.className.indexOf(' '+sClass);
    return (i >= 0);
}
function $addClass(oElement, sClass) { //returns  new className
    if ( !$hasClass(oElement, sClass) ) return oElement.className += ' '+sClass;
    // oElement.className += ' '+sClass;
    return oElement.className;
}
function $removeClass(oElement, sClass) { // returns false / new className
    // must use SPACE as the seperator whitespace
    var changed = false, arr = oElement.className.split(" ");
    for (var i in arr) {
        if (arr[i] == sClass) {
            arr[i] = undefined;
            changed = true;
        }
    }
    if (changed) return oElement.className = arr.join(' ');
    else return false;
    
}
function $swapClass(oElement, sClassOld, sClassNew) { //returns  new className
    var old = oElement.className;
    if (sClassOld == sClassNew) return oElement.className;
    // must use SPACE as the seperator whitespace
    var changed = false, arr = oElement.className.split(" ");
    for (var i in arr) {
        if (arr[i] == sClassOld) {
            arr[i] = (!changed) ? sClassNew : undefined;
            changed = true;
        }
    }
    if (changed) return oElement.className = arr.join(' ');
    else return $addClass(oElement, sClassNew);
}




// Event listner functions
var $addEvent, $removeEvent;
    // based on http://dean.edwards.name/weblog/2005/12/js-tip1/
if (document.addEventListener) {
  $addEvent = function(element, type, handler) {
	if (!element) return false;
    return element.addEventListener(type, handler, false);
  };
  $removeEvent = function(element, type, handler) {
    return element.removeEventListener(type, handler, false);
  };
}
else if (document.attachEvent) {
  $addEvent = function(element, type, handler) {
    if (!element) return false;
    return element.attachEvent("on" + type, handler);
  };
  $removeEvent = function(element, type, handler) {
    return element.detachEvent("on" + type, handler);
  };
}
else {
  $addEvent = function(element, type, handler) {
    return 'error';
  };
  $removeEvent = $addEvent;
}
 
function $stopEvent(e) {
    e.cancelBubble = true;
    e.returnValue = false;
    if (e.preventDefault) e.preventDefault();
    if (e.stopPropagation) e.stopPropagation();
    return false;
}

function $getEventTarget(e) {
	// http://www.quirksmode.org/js/events_properties.html
	var targ;
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	if (targ.nodeType == 3) targ = targ.parentNode;	// defeat Safari bug
	return targ;
}

// $horthand for YAHOO AJAX & JSON


if (window.YAHOO && YAHOO.lang && YAHOO.lang.JSON) {
	function $toJSON(obj) {
		var result = "";
		try {
			result = YAHOO.lang.JSON.stringify(obj);
		}
		catch (err) { result = err.message }
		return result;
	}
	function $fromJSON(str) {
		var result = {};
		try {
			result = YAHOO.lang.JSON.parse(str);
		}
		catch (err) { result = "ERROR: " + err.message }
		return result;
	}
}
else {
	window.$toJSON = function() {
		window.status = "$toJSON() {}"
	}
	window.$fromJSON = function() {
		window.status = "$fromJSON() {}"
	}
}

if (window.YAHOO && YAHOO.util && YAHOO.util.Connect) {
    var ajaxRequestsObjects = [];
    if ($addEvent) $addEvent(window, 'unload', function(){
        for (var obj in ajaxRequestsObjects) {
            $abortAJAX(ajaxRequestsObjects[obj]);
        }
    });
    function $getAJAX(url, onComplete) {
        return ajaxRequestsObjects.push(YAHOO.util.Connect.asyncRequest('GET', url, {success: onComplete}) ); 
    }
    function $postAJAX(url, onComplete, body) {
        return ajaxRequestsObjects.push(YAHOO.util.Connect.asyncRequest('POST', url, {success: onComplete}, body));
    }
    function $abortAJAX(obj) {
        return YAHOO.util.Connect.abort(obj);
    }
}
else {
	window.$getAJAX = function() {
		window.status = "$getAJAX() {}"
	}
	window.$postAJAX = function() {
		window.status = "$postAJAX() {}"
	}
	window.$abortAJAX = function() {
		window.status = "$abortAJAX() {}"
	}
}


// validations

function isValidEmail(str) {
	var pattern = new RegExp("^[_0-9a-zA-Z-]+([_0-9a-zA-Z+-]*|\.[_0-9a-zA-Z-]+)*@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$");
	return pattern.test(str)
}

// Do not extend Object.prototype as we need to be able to use for(var x in y) later on!!!

function $isArray(subject) {
	return (subject && subject.constructor && subject.constructor.prototype == [].constructor.prototype)
}
function $isObject(subject) {
	return (subject && subject.constructor && subject.constructor.prototype == {}.constructor.prototype)
}
function $trim(str, c) {
    if (!c || c.length != 1) var c = " ";
    var x = 0, y = str.length-1;
    while (str.charAt(x) == c && x <= y) x++;
    while (str.charAt(y) == c && x <= y) y--;
    return str.substr(x, y+1);
}
String.prototype.trim = $trim;

function $indexOf(arr, value) { // returns index or false (index may be 0, compare result using ==)
	if (!value || !arr || arr.length <= 0) return false;
	for (var i = 0, len = arr.length; i < len; i++) {
		if (arr[i] == value) return i;
	}
	return false;
}

function $inArray(arr, value) { // true / false
	return ($indexOf(arr, value) >= 0) ? true : false;
}

function $allIndexOf(arr, value, prop, partial) { // returns array with indexes of all matching values
	if (!value || !arr || arr.length <= 0) return false;
	var indexes = [];
	if (partial) {
		if (prop) {
			for (var i = 0, len = arr.length; i < len; i++) {
				if (arr[i][pop] && arr[i][prop].indexOf(value) >= 0) indexes[indexes.length] = i;
			}
		}
		else  {
			for (var i = 0, len = arr.length; i < len; i++) {
				if (arr[i].indexOf(value) >= 0) indexes[indexes.length] = i;
			}
		}
	}
	else {
		if (prop) {
			for (var i = 0, len = arr.length; i < len; i++) {
				if (arr[i][pop] && arr[i][pop] == value) indexes[indexes.length] = i;
			}
		}
		else  {
			for (var i = 0, len = arr.length; i < len; i++) {
				if (arr[i] == value) indexes[indexes.length] = i;
			}
		}
	}
	return indexes;
}

function $addItem(arr, value) { // push() if not already in array, returns bool.
	// Warning! will delete old item, and add the value onto the end of the array,
	// effectivly MOVES the value to the back fo the queue.
	// (This should be concidered an error)
	if (!value || !arr) return false;
	$removeItem(arr, value);
	arr.push(value);
	return true;
}
function $removeItem(arr, value) { // removes all item of array with specified value, returns false or number of items removed
    var index, num = 0;
    while (false !== (index = $indexOf(arr, value))) {
        arr.splice(index, 1);
        num++;
    }
    return (num) ? num : false;
}
function $keyOf(obj, value) { // returns key or false
    if (!value) return false;
    for (var i in obj) if (obj[i] == value) return i;
    return false;
}
function $getKeys(obj) { // returns list of keys
    var out = [];
    for (var key in obj) out.push(key);
    return out;
}
function $count(obj) { // returns number of properties
    var out = 0;
    for (var key in obj) out++;
    return out;
}
function $joinObject(obj, delim) { // returns list of values
    var out = [];
    if (!delim) delim = '|';
    for (var key in obj) out.push(obj[key]);
    return out.join(delim);
}
function $createClone(obj) {
    // http://keithdevens.com/weblog/archive/2007/Jun/07/javascript.clone
    if(obj == null || typeof(obj) != 'object') return obj;
    var temp = new obj.constructor();
    for(var key in obj) temp[key] = $createClone(obj[key]);
    return temp;
}

// random / generic


function padLeft(str, len, c) {
	if (!str) return str;
	if (parseInt(len) == NaN) return str;
	if (!c) c = ' ';
	var temp = '' + str;
	while (temp.length < len) temp = c + temp;
	return temp;
}



function $arrayWithoutDuplicates(arr) {
    var out = [];
    for (var x in arr) if ($indexOf(out, arr[x]) === false) out[x] = arr[x];
    return out;
}

function toHash(list) { // returns hash object with keys taken from input values
    var obj = new Object();
    for (var p in list) {
        obj[list[p]] = [];
    }
    return obj;
}
function joinObject(obj, prop, delim) {
	$debug('joinObject', obj, prop, delim)
    var retVal = '';
    if ( ! (delim != undefined) ) delim = '|';
    if (prop != undefined) for (var x in obj) retVal += obj[x][prop]+'|';
    else for (var x in obj) retVal += obj[x][prop]+'|';
    return retVal.substr(0, retVal.length-1);
}
function splitObject(str, delim) {
    var retVal = {};
    if ( ! (delim != undefined) ) delim = '|';
    var arr = str.split(delim);
    for (var x in arr) retVal[x] = arr[x];
    return retVal.substr(0, retVal.length-1);
}


function $getPosition(obj) {
	if (!obj || obj.offsetLeft == undefined) return null;
    //http://www.quirksmode.org/js/findpos.html
	var curleft = curtop = 0;
	do {
		curleft += obj.offsetLeft;
		curtop += obj.offsetTop;
	}
	while (obj = obj.offsetParent);
	return [curleft, curtop];
}

function $getSize(obj, newSize) {
	// get size
	var oldSize = [obj.offsetWidth, obj.offsetHeight];
	if (newSize) {
		// set size
	    if (newSize[0] !=null) obj.style.width = newSize[0];
	    if (newSize[1] !=null) obj.style.height = newSize[1];
	}
	// return original
	return oldSize;
}

function $getViewSize() {
    var out = [-1, -1];
	var mdiv = $get('getViewSizeMdiv');
	if (!mdiv) {
		mdiv = document.createElement('DIV');
		mdiv.id = 'getViewSizeMdiv';
		mdiv.style.height = '100%';
		mdiv.style.width = '100%';
		mdiv.style.padding = '0';
		mdiv.style.margin = '0';
		mdiv.style.display = 'block';
		mdiv.style.visibility = 'hidden';
		//mdiv.style.outline = 'dashed red 1px';
		mdiv.style.zIndex = '9999990';
		if (document.body) {
			document.body.appendChild(mdiv);
			mdiv = $get('getViewSizeMdiv');
		}
		//out[0] = mdiv.offsetWidth;
		//out[1] = mdiv.offsetHeight;
	}
	out[0] = document.documentElement.clientWidth;
	out[1] = document.documentElement.clientHeight;
	/*
	if (document.attachEvent) {
		if (document.compatMode == 'CSS1Compat') {
			if (out[0]==-1) out[0] = document.documentElement.offsetWidth;
			out[1] = document.documentElement.offsetHeight;
		}
		else {
			if (out[0]==-1) out[0] = document.body.clientWidth;
			out[1] = document.body.clientHeight;
		}
	}
	else {
		if (out[0]==-1) out[0] = window.innerWidth;
		out[1] = window.innerHeight;
	}
	*/
	return out;
	return out;
}

////// Image Pre-Loader ///////
// window.onload or after
function preloadImages(images, delay) {
	var div;
	if ( !(div = $get('image-preload-div')) ) {
		div = document.createElement('DIV');
		div.id = 'image-preload-div';
		div.style.display = 'none';
		document.body.appendChild(div);
	}
	var img;
	div = $get('image-preload-div');
	if (delay == undefined) delay = 1;
	setTimeout(function() {
		preloadImages_process(images, div, delay);
		
	}, delay * 1000);
}

function preloadImages_process(images, div, delay) {
	img = document.createElement('IMG');
	img.src = images.pop();
	div.appendChild(img);
	if (images.length > 0) setTimeout(function() {
		preloadImages_process(images, div);

	}, delay * 1000);
}
///////////



////////////////   Delayed Input Handler     /////////////////////

function DelayedInputHandler(fieldsToUse, typeDelay, fCallback) {
	// public
	this.submit = function(id) {
		this.triggerID = id;
		submit();
	}
	this.validate = function() {
		return 'TODO: write validation functions.';
	};
	this.trigger = function(id) {
		this.triggerID = id;
		clearTimer();
		startTimer();
	}
	this.abort = function() {
		clearTimer();
	}
	this.reset = reset;
	this.clear = clear;
	this.toQueryString = getQueryString;
	this.getHash = getHash;
	this.list = getHash;
	this.fields = {}
	// private vars
	var typeDelay = (typeDelay) ? typeDelay : 1000; // Milli-seconds before parsing the input and calling the callback
	var timer = null;
	var fields = this.fields;
	var initial_values = {};
	var f, obj;
	//innit 
	for (var x in fieldsToUse) {
		f = document.getElementById(fieldsToUse[x]);
		if (f && f.tagName == 'INPUT') {
			obj = {};
			obj.obj = f;
			obj.type = (f.type.toUpperCase() == 'RADIO' || f.type.toUpperCase() == 'CHECKBOX') ? 'boolean' : 'text';
			obj.name = (f.name) ? f.name : false;
			obj.value = getFieldValue(fields[fieldsToUse[x]]);
			fields[fieldsToUse[x]] = obj;
			initial_values[fieldsToUse[x]] = '' + obj.value;
		}	
	}
	//$debug(fields);
	// private functions
	function reset(list) {
		if (list) {
			for (var x in list) {
				if (initial_values[list[x]]) {
					fields[list[x]].value = initial_values[list[x]];
					fields[list[x]].changed = null;
					setFieldValue(fields[list[x]]);
				}
			}
		}
		else {
			for (var x in initial_values) {
				fields[x].value = initial_values[x];
				fields[x].changed = null;
				setFieldValue(fields[x]);
			}
		}
	}
	function clear(list) {
		if (list) {
			for (var x in list) {
				if (initial_values[list[x]]) {
					if (fields[list[x]].value) fields[list[x]].value = '';
					if (fields[list[x]].checked) fields[list[x]].checked = '';
					fields[list[x]].changed = null;
					setFieldValue(fields[list[x]]);
				}
			}
		}
		else {
			for (var x in fields) {
				fields[x].value = '';
				fields[x].changed = null;
				setFieldValue(fields[x]);
			}
		}
	}
	function startTimer() {
		this.timer = window.setTimeout(function() { timeComplete(obj) }, typeDelay);
	}
	function clearTimer() {
		if (this.timer) window.clearTimeout(this.timer);
		this.timer = null;
	}
	function timeComplete() {
		clearTimer();
		submit();
	}
	function submit(obj) {
		var result = parseInput();
		if (result.nChanged > 0) fCallback(obj);
	};
	function getHash() {
		var hash = {};
		for (var f in fields) {
			if (fields[f].type == 'boolean') {
				if (fields[f].obj.checked) hash[fields[f].name] = fields[f].obj.value;
			}
			else hash[fields[f].name] = fields[f].value;
		};
		//$debug(hash)
		return hash;
	}
	function getQueryString() {
		var values = [];
		for (var f in fields) {
			if (fields[f].type == 'boolean') {
				if (fields[f].obj.checked) values[values.length] = fields[f].name + '=' + fields[f].obj.value;
			}
			else values[values.length] = fields[f].name + '=' + fields[f].value;
		};
		//$debug(values)
		return values.join('&');
	}
	function getFieldValue(obj) {
		var value = null;
		if (!obj) return;
		if (obj.type == 'boolean') return (obj.obj.checked);
		else return obj.obj.value;
	}
	function setFieldValue(obj) {
		var value = null;
		if (obj.type == 'boolean') obj.obj.checked = obj.value;
		else obj.obj.value = obj.value;
	}
	function parseInput() {
		var value, result = { 'nChanged': 0, fields: [] };
		for (var x in fields) {
			value = getFieldValue(fields[x]);
			if (fields[x].value != value) {
				result.nChanged++;
				result.fields[x] = value;
				fields[x].changed = true;
			}
			else fields[x].changed = false;
			fields[x].value = value;
		}
		return result;
	}
};

////////////////////////////////////////



if (window.YAHOO && YAHOO.util.Dom && YAHOO.util.Dom.getStyle) var $getStyle = YAHOO.util.Dom.getStyle;
else var $getStyle = function $getStyle(oElm, strCssRule) {
	// Get the rendered style of an element
	// http://www.robertnyman.com/2006/04/24/get-the-rendered-style-of-an-element/
	var strValue = "";
	if(document.defaultView && document.defaultView.getComputedStyle){
		strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
	}
	else if(oElm.currentStyle) {
		strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
			return p1.toUpperCase();
		});
		strValue = oElm.currentStyle[strCssRule];
	}
	return strValue;
}


// getElementsByClassName
var $getClassNames = function (className, tag, elm){
    /*  Developed by Robert Nyman, http://www.robertnyman.com
	    Code/licensing: http://code.google.com/p/getelementsbyclassname/ */	
	if (document.getElementsByClassName) {
		getElementsByClassName = function (className, tag, elm) { // FF3
			elm = elm || document;
			var elements = elm.getElementsByClassName(className),
				nodeName = (tag)? new RegExp("\\b" + tag + "\\b", "i") : null,
				returnElements = [],
				current;
			for(var i=0, il=elements.length; i<il; i+=1){
				current = elements[i];
				if(!nodeName || nodeName.test(current.nodeName)) {
					returnElements.push(current);
				}
			}
			return returnElements;
		};
	}
	else if (document.evaluate) {
		getElementsByClassName = function (className, tag, elm) {
			tag = tag || "*";
			elm = elm || document;
			var classes = className.split(" "),
				classesToCheck = "",
				xhtmlNamespace = "http://www.w3.org/1999/xhtml",
				namespaceResolver = (document.documentElement.namespaceURI === xhtmlNamespace) ? xhtmlNamespace : null,
				returnElements = [],
				elements,
				node;
			for(var j=0, jl=classes.length; j<jl; j+=1){
				classesToCheck += "[contains(concat(' ', @class, ' '), ' " + classes[j] + " ')]";
			}
			try	{
				elements = document.evaluate(".//" + tag + classesToCheck, elm, namespaceResolver, 0, null);
			}
			catch (e) {
				elements = document.evaluate(".//" + tag + classesToCheck, elm, null, 0, null);
			}
			while ((node = elements.iterateNext())) {
				returnElements.push(node);
			}
			return returnElements;
		};
	}
	else {
		getElementsByClassName = function (className, tag, elm) {
			tag = tag || "*";
			elm = elm || document;
			var classes = className.split(" "),
				classesToCheck = [],
				elements = (tag === "*" && elm.all)? elm.all : elm.getElementsByTagName(tag),
				current,
				returnElements = [],
				match;
			for(var k=0, kl=classes.length; k<kl; k+=1){
				classesToCheck.push(new RegExp("(^|\\s)" + classes[k] + "(\\s|$)"));
			}
			for(var l=0, ll=elements.length; l<ll; l+=1){
				current = elements[l];
				match = false;
				for(var m=0, ml=classesToCheck.length; m<ml; m+=1){
					match = classesToCheck[m].test(current.className);
					if (!match) {
						break;
					}
				}
				if (match) {
					returnElements.push(current);
				}
			}
			return returnElements;
		};
	}
	return getElementsByClassName(className, tag, elm);
};

function setBgImage(obj, url) {
	if (obj.style) return obj.style.backgroundImage = "url('" + url + "')";
	else return false;
}


//<!-- Cookie script - Scott Andrew -->
//<!-- For more free scripts go to http://www.sivamdesign.com/scripts/ -->

function newCookie(name, value, days) {
	if (value == undefined) value = '';
	var expires = "";
	if (days == undefined) days = 1;
	else if (days) {
		var date = new Date();
		date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
		var expires = "; expires=" + date.toGMTString();
	}
	document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
	var nameSG = name + "=";
	var nuller = '';
	if (document.cookie.indexOf(nameSG) == -1)
		return nuller;

	var ca = document.cookie.split(';');
	for (var i = 0; i < ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0) == ' ') c = c.substring(1, c.length);
		if (c.indexOf(nameSG) == 0) return c.substring(nameSG.length, c.length);
	}
	return null;
}

function eraseCookie(name) { newCookie(name, "", 1); }

///////////////////////////////////////////////


function rectCalcAll(obj, newSize, newPosition, constrain) {
	// size = [w,h] or null
	// position = [l,t] or [[l,t],[r,b]] or [[null,null],[r,b]] or [[l,t],[null,null]]
	// constrain = true or false
    if (obj == null) return;
    if (typeof obj != 'object') return;
	var conSize = $getViewSize();
    var oldPosition = $getPosition(obj);
    var oldSize = $getSize(obj);
    var calcPosition = ($isArray(newPosition[0])) ? [[newPosition[0][0], newPosition[0][1]], [newPosition[1][0] ,newPosition[1][1]]] : [[newPosition[0], newPosition[1]], [null, null]];
    var out = {
		'width': newSize[0],
		'height': newSize[1],
		'left': calcPosition[0][0],
		'top': calcPosition[0][1],
		'right': calcPosition[1][0],
		'bottom': calcPosition[1][1]
	};
    if (out.left == null) out.left = conSize[0] - out.right - out.width;
    if (out.top == null) out.top = conSize[1] - out.bottom - out.height;
    if (out.right == null) out.right = out.left + out.width;
    if (out.bottom == null) out.bottom = out.top + out.height;
    if (constrain) {
		if (out.left < 0) out.left = 0;
		if (out.top < 0) out.top = 0;
		if (out.width > conSize[0]) out.width = conSize[0];
		if (out.height > conSize[1]) out.height = conSize[1];
		if (out.right < 0) out.right = out.width;
		if (out.bottom < 0) out.bottom = out.height;
	}
	/*
	window.RECTANGLE =  {
		'from': {
			'width': oldSize[0],
			'height': oldSize[1],
			'left': oldPosition[0],
			'top': oldPosition[1],
			'right': oldPosition[0] + oldSize[0],
			'bottom': oldPosition[1] + oldSize[1]
		},
		'to': out
	};
	*/
	return {
		'from': {
			'width': oldSize[0],
			'height': oldSize[1],
			'left': oldPosition[0],
			'top': oldPosition[1],
			'right': oldPosition[0] + oldSize[0],
			'bottom': oldPosition[1] + oldSize[1]
		},
		'to': out
	};
}

//
// IE 6 PNG alpha channel fix 
// for <img> using DirectX Filter
//

function pngIE6(trans_src) {
    if (!trans_src) trans_src = '/images/transparent_pixel.gif';
    var list = $getClassNames('pngIE6', 'img'); //
    var pngSrc, pngSize;
    for (var x in list) {
        pngSrc = '' + list[x].src;
        list[x].src = trans_src;
        pngSize = $getSize(list[x]);
        list[x].width = pngSize[0];
        list[x].height = pngSize[1];
        list[x].style.background = 'transparent';
        list[x].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + pngSrc + "', sizingMethod='scale')";
    }
}

