/*
 * ppDrag 0.2 - Extremely Fast Drag&Drop for jQuery
 * http://ppdrag.ppetrov.com/
 * Modified by Michal Stankoviansky, April 2009
 *
 * Copyright (c) 2008 Peter Petrov (ppetrov AT ppetrov.com)
 * Licensed under the LGPL (LGPL-LICENSE.txt) license.
 */

(function($) {
	
	$.fn.ppdrag = function(options) {
		if (typeof options == 'string') {
			if (options == 'destroy') return this.each(function() {
				$.ppdrag.removeEvent(this, 'mousedown', $.ppdrag.start, false);
				$.data(this, 'pp-ppdrag', null);
			});
		}
		return this.each(function() {
			$.data(this, 'pp-ppdrag', { options: $.extend({}, options) });
			$.ppdrag.addEvent(this, 'mousedown', $.ppdrag.start, false);
		});
	};
	
	$.ppdrag = {
		start: function(event) {
			var t = event.target || event.srcElement;
			if ($(t).is($.data(this, "pp-ppdrag").options.not, this)) {
				return;
			}
			
			if (!$.ppdrag.current) {
				$.ppdrag.current = {
					el: this,
					oleft: parseInt(this.style.left) || 0,
					otop: parseInt(this.style.top) || 0,
					ox: event.pageX || event.screenX,
					oy: event.pageY || event.screenY
				};
				var current = $.ppdrag.current;
				var data = $.data(current.el, 'pp-ppdrag');
				if (data.options.zIndex) {
					current.zIndex = current.el.style.zIndex;
					current.el.style.zIndex = data.options.zIndex;
				}
				$.ppdrag.addEvent(document, 'mouseup', $.ppdrag.stop, true);
				$.ppdrag.addEvent(document, 'mousemove', $.ppdrag.drag, true);
			}
			if (event.stopPropagation) event.stopPropagation();
			if (event.preventDefault) event.preventDefault();
			return false;
		},
		
		drag: function(event) {
			if (!event) var event = window.event;
			var current = $.ppdrag.current;
			var left = (current.oleft + (event.pageX || event.screenX) - current.ox);
			var top = (current.otop + (event.pageY || event.screenY) - current.oy);
			current.el.style.left = left + 'px';
			current.el.style.top = top + 'px';
			$("#eurocalcShadow").css({ "left": (left + 4) + "px", "top": (top + 4) + "px" });
			if (typeof document.body.style.filter != "undefined") { // IE
				$("iframe#eurocalcIFrame").css({ "left": left + 'px', "top": top + 'px' });				
			}
			
			if (event.stopPropagation) event.stopPropagation();
			if (event.preventDefault) event.preventDefault();
			return false;
		},
		
		stop: function(event) {
			var current = $.ppdrag.current;
			var data = $.data(current.el, 'pp-ppdrag');
			$.ppdrag.removeEvent(document, 'mousemove', $.ppdrag.drag, true);
			$.ppdrag.removeEvent(document, 'mouseup', $.ppdrag.stop, true);
			if (data.options.zIndex) {
				current.el.style.zIndex = current.zIndex;
			}
			if (data.options.stop) {
				data.options.stop.apply(current.el, [ current.el ]);
			}
			$.ppdrag.current = null;
			if (event.stopPropagation) event.stopPropagation();
			if (event.preventDefault) event.preventDefault();
			return false;
		},
		
		addEvent: function(obj, type, fn, mode) {
			if (obj.addEventListener)
				obj.addEventListener(type, fn, mode);
			else if (obj.attachEvent) {
				obj["e"+type+fn] = fn;
				obj[type+fn] = function() { return obj["e"+type+fn](window.event); }
				obj.attachEvent("on"+type, obj[type+fn]);
			}
		},
		
		removeEvent: function(obj, type, fn, mode) {
			if (obj.removeEventListener)
				obj.removeEventListener(type, fn, mode);
			else if (obj.detachEvent) {
				obj.detachEvent("on"+type, obj[type+fn]);
				obj[type+fn] = null;
				obj["e"+type+fn] = null;
			}
		}
		
	};

})(jQuery);

// end: ppdrag



/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

/**
 * Create a cookie with the given name and value and other optional parameters.
 *
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 * @desc Create a cookie with all available options.
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 * @example $.cookie('the_cookie', null);
 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
 *       used when the cookie was set.
 *
 * @param String name The name of the cookie.
 * @param String value The value of the cookie.
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
 *                             when the the browser exits.
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
 *                        require a secure protocol (like HTTPS).
 * @type undefined
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

// end: jquery cookie










// ---
if (typeof M000 == "undefined") var M000 = {};
if (typeof M000.store == "undefined") M000.store = {};

M000.ECalc = function() {

	this.currentLang = M000.ECalc.languages.SK; // TODO: zistit jazyk pri loade
	/*
	var texts;
	if (this.currentLang === M000.ECalc.languages.SK) {
		texts = M000.ECalc.texts.SK;
	} else if (this.currentLang == M000.ECalc.languages.EN) {
		texts = M000.ECalc.texts.EN;
	}
	
	var htmlCalc = M000.ECalc.tpl
		.replace("{{TEXT_CLOSE}}", texts.TEXT_CLOSE)
		.replace("{{TEXT_CONVERSION_RATE}}", texts.TEXT_CONVERSION_RATE)
		.replace("{{LINK_CALC_INFO}}", texts.LINK_CALC_INFO);
		
	// insert calculator into DOM:
	$("#eurocalc")[0].innerHTML(htmlCalc);
	*/
	
	this.$el = $("#eurocalc");
	var el = this.$el[0]; 
	
	this.$elHeader = $("div.hd", el);
	this.$elShadow = $("#eurocalcShadow");
	
	this.$elClose = $("a.close", el);
	
	this.focusedTextField = null;
	
	this.$displayEur = $("input.displayEur", el).val("0").data("lastValue", "0");
	this.$displaySkk = $("input.displaySkk", el).val("0").data("lastValue", "0");
	
	this.displayEurWatchInterval = null;
	this.displaySkkWatchInterval = null;
	
	this.activateMode(M000.ECalc.modes.EUR_SKK);
	this.mode = M000.ECalc.modes.EUR_SKK;
	
	this.ie6 = false;
	this.$iframe = []; // jQuery obj
	if (navigator.userAgent.indexOf("MSIE 6.0") != -1 && document.all && typeof document.body.style.filter == "string") {
		this.ie6 = true;
		var iframeTpl = '<iframe id="eurocalcIFrame" src="js/blank.txt" frameborder="0" scrolling="no"></iframe>';
		$(document.body).append(iframeTpl);
		this.$iframe = $("iframe#eurocalcIFrame");
	}
	
	// get visibility from cookie or hide by default:
	this.isVisible = false;
	this.restoreState();
	
	this.init();
}

// exchange rate:
M000.ECalc.exchangeRate = 30.126;
// enum:
M000.ECalc.modes = { SKK_EUR:1, EUR_SKK:2 };
// default position:
M000.ECalc.defaultPosition = { top:100, left:100 };
// languages enum:
M000.ECalc.languages = { SK:"SK", EN:"EN" };
// cookies:
M000.ECalc.cookie = {};
M000.ECalc.cookie.name = "eurocalc";
M000.ECalc.cookie.tpl = "lang={{LANG}},visible={{VISIBLE}},top={{TOP}},left={{LEFT}}";
M000.ECalc.cookie.expiration = 365; // in days
M000.ECalc.imgPathAndPrefix = "img/calc_btn_";
M000.ECalc.comma = ",";
M000.ECalc.regExpAllowedInputDisplayValue = /^[0-9]+([\.\,][0-9]{0,2})?$|^$/;

M000.ECalc.tpl = '<!-- <div id="eurocalc"> --><div class="hd"><a href="#close" class="close"><img src="img/calc_btn_close.gif" width="8" height="8" alt="{{TEXT_CLOSE}}"></a></div><div class="bd"><div class="displays"><p><input id="eurocalcDisplayEur" class="display displayEur"><label for="displayEur" class="displayLabel">EUR</label></p><p><input id="eurocalcDisplaySkk" class="display displaySkk"><label for="displayEur" class="displayLabel">SKK</label></p></div><table><tr><td><img src="img/calc_btn_7.gif" alt="7" class="btn btn7"></td><td class="space">&nbsp;</td><td><img src="img/calc_btn_8.gif" alt="8" class="btn btn8"></td><td class="space">&nbsp;</td><td><img src="img/calc_btn_9.gif" alt="9" class="btn btn9"></td><td class="space">&nbsp;</td><td><img src="img/calc_btn_c.gif" alt="C" class="btn btnCancel"></td></tr><tr><td><img src="img/calc_btn_4.gif" alt="4" class="btn btn4"></td><td class="space">&nbsp;</td><td><img src="img/calc_btn_5.gif" alt="5" class="btn btn5"></td><td class="space">&nbsp;</td><td><img src="img/calc_btn_6.gif" alt="6" class="btn btn6"></td><td class="space">&nbsp;</td><td><img src="img/calc_btn_eur_skk.gif" alt="EUR &rarr; SKK" class="btn btnMode btnEurSkk"></td></tr><tr><td><img src="img/calc_btn_1.gif" alt="1" class="btn btn1"></td><td class="space">&nbsp;</td><td><img src="img/calc_btn_2.gif" alt="2" class="btn btn2"></td><td class="space">&nbsp;</td><td><img src="img/calc_btn_3.gif" alt="3" class="btn btn3"></td><td class="space">&nbsp;</td><td><img src="img/calc_btn_skk_eur.gif" alt="SKK &rarr; EUR" class="btn btnMode btnSkkEur"></td></tr><tr class="last-child"><td><img src="img/calc_btn_0.gif" alt="0" class="btn btn0"></td><td class="space">&nbsp;</td><td><img src="img/calc_btn_comma.gif" alt="," class="btn btnComma"></td><td class="space">&nbsp;</td><td><img src="img/calc_btn_equal.gif" alt="=" class="btn btnEquals"></td><td class="space">&nbsp;</td><td></td></tr></table><div><a href="{{LINK_CALC_INFO}}"><img src="img/calc_kk.gif" width="139" height="13" alt="{{TEXT_CONVERSION_RATE}}"></div></div> <!-- </div> -->';

// texts:
M000.ECalc.texts = {
	SK: {
		TEXT_CLOSE: "Zavrieť",
		TEXT_CONVERSION_RATE: "Konverzný kurz: 30,1260 Sk/€",
		LINK_CALC_INFO: "#calc_info"
	},
	EN: {
		TEXT_CLOSE: "Close",
		TEXT_CONVERSION_RATE: "Conversion rate: 30,1260 Sk/€",
		LINK_CALC_INFO: "#calc_info"
	}
};


M000.ECalc.formatNum = function(num) { // return formatted string
	var retVal = ( Math.round(num * 100) / 100 ).toString().replace(".", M000.ECalc.comma); 
	return retVal;
}

M000.ECalc.parseNum = function(numericString) {
	return parseFloat(numericString.replace(",", "."));
}

M000.ECalc.prototype.activateMode = function(mode) {
	var sameAsBefore = (this.mode === mode);
	var el = this.$el[0];
	
	var $img = null;
	var $imgOtherMode = null;
	var $inputDisplay = null;
	if (mode === M000.ECalc.modes.EUR_SKK) {
		$img = $("img.btnEurSkk", el);
		$imgOtherMode = $("img.btnSkkEur", el);
		$inputDisplay = this.$displayEur;
	} else if (mode === M000.ECalc.modes.SKK_EUR) {
		$img = $("img.btnSkkEur", el);
		$imgOtherMode = $("img.btnEurSkk", el);
		$inputDisplay = this.$displaySkk;
	}
	
	if (!sameAsBefore) {
		$imgOtherMode.attr("src", M000.ECalc.getBtnOffImgPath($imgOtherMode.attr("src")));
		$img.attr("src", M000.ECalc.getBtnOnImgPath($img.attr("src")));	
	}
	
	if (this.isVisible) {
		this.focusInputDisplayWithoutFocusEvent($inputDisplay[0]);
		this.focusedTextField = $inputDisplay[0];
	}
	
	this.mode = mode; // save current mode
}

M000.ECalc.getNamesValuesFromCookie = function() {
	var val = $.cookie(M000.ECalc.cookie.name);
	
	// cookie not present - return defaults:
	if (!val) return {
		lang:M000.ECalc.languages.SK,
		visible:false,
		top:M000.ECalc.defaultPosition.top,
		left:M000.ECalc.defaultPosition.left
	};
	
	var tmpArrValues = val.split(",");
	var values = {};
	var tmpArr = [];
	for (var i = 0; i < tmpArrValues.length; i++) {
		tmpArr = tmpArrValues[i].split("=");
		values[tmpArr[0]] = tmpArr[1];
	}
	
	return values;
}

M000.ECalc.prototype.show = function() {
	var cookieValues = M000.ECalc.getNamesValuesFromCookie();
	var top = parseInt(cookieValues.top, 10) || 0;
	var left = parseInt(cookieValues.left, 10) || 0;
	this.moveTo({"top":top, "left":left});
	
	this.$el.show();
	this.startWatchingInputsDisplay();
	
	if (this.ie6) {
		this.$iframe.show();
	}
	
	this.$elShadow.show();
	
	this.isVisible = true;
}

M000.ECalc.prototype.hide = function() {
	this.stopWatchingInputsDisplay();
	this.$el.hide();
	this.$elShadow.hide();
	if (this.ie6) {
		this.$iframe.hide();
	}
	this.isVisible = false;
}

M000.ECalc.prototype.restoreState = function() {
	var cookieValues = M000.ECalc.getNamesValuesFromCookie();
	
	// restore position:
	var top = parseInt(cookieValues.top, 10) || 0;
	var left = parseInt(cookieValues.left, 10) || 0;
	this.moveTo({"top":top, "left":left});
	
	// restore visibility:
	if (cookieValues.visible === "true") {
		this.show();
	} else {
		this.hide();
	}
}

M000.ECalc.prototype.saveState = function(position) {
	var val = M000.ECalc.cookie.tpl;
	// language:
	val = val.replace("{{LANG}}", this.currentLang);
	// visibility:
	if (this.isVisible) {
		val = val.replace("{{VISIBLE}}", "true");
	} else {
		val = val.replace("{{VISIBLE}}", "false");
	}
	// position:
	var pos = {};
	if (typeof position == "object" && typeof position.top == "number" && typeof position.left == "number") {
		pos = position;
	} else {
		pos = this.$el.position();
	}
	
	val = val.replace("{{TOP}}", pos.top).replace("{{LEFT}}", pos.left);
	$.cookie(M000.ECalc.cookie.name, val, { path: '/', expires: M000.ECalc.cookie.expiration });
}

M000.ECalc.prototype.moveTo = function(/* object */ position) {
	if (!position || !position.left || !position.top) return;
	this.$el.css({ left:position.left + "px", top:position.top + "px" });
	this.$elShadow.css({ left:(position.left + 3) + "px", top:(position.top + 3) + "px" });
	if (this.ie6) {
		this.$iframe.css({ left:position.left + "px", top:position.top + "px" });
	}
}

M000.ECalc.getBtnOffImgPath = function(origImgPath) {
	return origImgPath.replace(/\_on\.gif$/, ".gif");
}

M000.ECalc.getBtnOnImgPath = function(origImgPath) {
	return origImgPath.replace(/\.gif$/, "_on.gif");
}

M000.ECalc.doBtnClickedEffect = function($btn) {
	var src = $btn.attr("src");
	if (src.indexOf("_on.gif") != -1) return;
	var temporarySrc = M000.ECalc.getBtnOnImgPath(src);
	$btn.attr("src", temporarySrc);
	window.setTimeout(function() {
		$btn.attr("src", src);
	}, 150);
	
}

M000.ECalc.prototype.doCalc = function(mode) {
	var valSkk, valEur;
	if (mode === M000.ECalc.modes.EUR_SKK) {
		valEur = M000.ECalc.parseNum(this.$displayEur.val());
		valSkk = M000.ECalc.formatNum(valEur * M000.ECalc.exchangeRate);
		this.$displaySkk.val(valSkk).data("lastValue", valSkk);
	} else if (mode === M000.ECalc.modes.SKK_EUR) {
		valSkk = M000.ECalc.parseNum(this.$displaySkk.val());
		valEur = M000.ECalc.formatNum(valSkk / M000.ECalc.exchangeRate);
		this.$displayEur.val(valEur).data("lastValue", valEur);
	}
}

//
// Event handlers:
//
M000.ECalc.handlerCloseClick = function(e) {
	var thisRef = e.data.thisRef;
	
	var pos = thisRef.$el.position(); // save position before setting display:none
	thisRef.hide();
	thisRef.saveState(pos);
	return false;
}

M000.ECalc.handlerShowEuroCalcClick = function(e) {
	var thisRef = e.data.thisRef;
	thisRef.show();
	thisRef.saveState();
	return false;
}

M000.ECalc.handlerBtnClick = function(e) {
	var thisRef = e.data.thisRef;
	
	M000.ECalc.doBtnClickedEffect($(this));
	
	// get input.display to write to:
	var input = null;
	if (thisRef.mode == M000.ECalc.modes.EUR_SKK) {
		input = thisRef.$displayEur[0];
	} else {
		input = thisRef.$displaySkk[0];
	}
	
	if (!input) return;
	
	var btnVal = $(this).attr("alt");
	var parsedNum = parseInt(btnVal, 10);
	if (!isNaN(parsedNum)) {
		if (input.value === "0") {
			$(input).val("").data("lastValue", "");
		}
		var tmpNewVal = input.value + "" + btnVal;
		$(input).val(tmpNewVal);
	} else {
		if (btnVal === "C") {
			thisRef.$displayEur.val("0").data("lastValue", "0");
			thisRef.$displaySkk.val("0").data("lastValue", "0");
		} else if (btnVal === ",") {
			var tmpNewVal = input.value + ",";
			$(input).val(tmpNewVal);
		}
	}
}

M000.ECalc.handlerBtnModeClick = function(e) {
	var thisRef = e.data.thisRef;
	
	if ($(this).hasClass(".btnEurSkk")) {
		thisRef.activateMode(M000.ECalc.modes.EUR_SKK);
	} else if ($(this).hasClass(".btnSkkEur")) {
		thisRef.activateMode(M000.ECalc.modes.SKK_EUR);
	}
}

M000.ECalc.handlerInputDisplayBlurFocus = function(e) {
	var thisRef = e.data.thisRef;
	if (e.type == "blur") {
		this.focusedTextField = null;
		if (this.value == "") {
			$(this).val("0").data("lastValue", "0");
		}
	} else if (e.type == "focus") {
		this.focusedTextField = this;
		if (parseInt(this.value, 10) === 0) {
			$(this).val("").data("lastValue", "");
		}
		
		if ($(this).hasClass("displayEur")) {
			thisRef.activateMode(M000.ECalc.modes.EUR_SKK);
		} else if ($(this).hasClass("displaySkk")) {
			thisRef.activateMode(M000.ECalc.modes.SKK_EUR);
		}
	}
}
//
// End: Event handlers
//

M000.ECalc.prototype.handlerInputDisplayEurWatchInterval = function() {
	M000.ECalc.handlerInputDisplayWatchInterval(M000.store.ec.$displayEur[0], M000.store.ec);
}

M000.ECalc.prototype.handlerInputDisplaySkkWatchInterval = function() {
	M000.ECalc.handlerInputDisplayWatchInterval(M000.store.ec.$displaySkk[0], M000.store.ec);
}

M000.ECalc.handlerInputDisplayWatchInterval = function(input, thisRef) {
	var lastValue = $(input).data("lastValue");
	
	if (input.value !== lastValue) { // field's value changed
		var newValue = "";
		var re = M000.ECalc.regExpAllowedInputDisplayValue; // check and sanitize value:
		if (!re.test(input.value)) { // new value has invalid chars...restore the previous one:
			input.value = lastValue;
			return;
		} else { // new value OK, store it: 
			if (input.value === "") {
				$(input).val("").data("lastValue", "");
			} else {
				newValue = M000.ECalc.formatNum(M000.ECalc.parseNum(input.value));
				if (/([\.\,])/.test(input.value) && !(new RegExp("\\" + M000.ECalc.comma + "")).test(newValue)) {
					var commaAndAfter = input.value.match( (new RegExp("[\\,\\.].*")) )[0];
					newValue = newValue + "" + commaAndAfter.replace(".", M000.ECalc.comma);  
				}
				$(input).val(newValue).data("lastValue", newValue);
				thisRef.doCalc(thisRef.mode);
			}
		}
	}
}

M000.ECalc.prototype.startWatchingInputsDisplay = function() {
	this.displayEurWatchInterval = window.setInterval(this.handlerInputDisplayEurWatchInterval, 100);
	this.displaySkkWatchInterval = window.setInterval(this.handlerInputDisplaySkkWatchInterval, 100);
}

M000.ECalc.prototype.stopWatchingInputsDisplay = function() {
	if (this.displayEurWatchInterval) {
		window.clearInterval(this.displayEurWatchInterval);
	}
	
	if (this.displaySkkWatchInterval) {
		window.clearInterval(this.displaySkkWatchInterval);
	}
}

M000.ECalc.prototype.addEventInputDisplayFocus = function() {
	$("input.display", this.$el[0]).bind("focus", { thisRef: this }, M000.ECalc.handlerInputDisplayBlurFocus);
}

M000.ECalc.prototype.removeEventInputDisplayFocus = function() {
	$("input.display", this.$el[0]).unbind("focus", M000.ECalc.handlerInputDisplayBlurFocus);
}

M000.ECalc.prototype.focusInputDisplayWithoutFocusEvent = function(input) {
	this.removeEventInputDisplayFocus();
	input.value = "";
	input.focus();
	this.focusedTextField = input;
	this.addEventInputDisplayFocus();
}


M000.ECalc.prototype.init = function() {
	var thisRef = this;
	$("#eurocalc").ppdrag({
		stop: function() {
			thisRef.saveState();
		},
		not: "input.display,a.close,img.btn"
	});
	
	// activate all triggers - clicking them will open the calculator:
	$(".showEuroCalc").bind("click", { thisRef: this }, M000.ECalc.handlerShowEuroCalcClick);
	// activate the close button:
	this.$elClose.bind("click", { thisRef: this }, M000.ECalc.handlerCloseClick);
	// text inputs focus: 
	$("input.display", this.$el[0]).bind("blur",  { thisRef: this }, M000.ECalc.handlerInputDisplayBlurFocus);
	this.addEventInputDisplayFocus();
	
	// buttons click:
	$("img.btn:not(.btnMode)", this.$el[0]).bind("click", { thisRef: this }, M000.ECalc.handlerBtnClick);
	// btnMode click:
	$("img.btnMode", this.$el[0]).bind("click", { thisRef: this }, M000.ECalc.handlerBtnModeClick);
	
	
	//
	// preload images:
	//
	var img = null;
	var imgPath = "";
	var pref = M000.ECalc.imgPathAndPrefix;
	// first do the numeric ones:
	for (var i = 0; i <= 9; i++) {
		// "off" version:
		imgPath = pref + i.toString() + ".gif";
		img = new Image();
		img.src = imgPath;
		// "on" version:
		imgPath = pref + i.toString() + "_on.gif";
		img = new Image();
		img.src = imgPath;
	}
	
	// other than numeric images:
	var images = ["c", "comma", "equal", "eur_skk", "skk_eur"];
	for (var index in images) {
		// "off" version:
		imgPath = pref + images[index] + ".gif";
		img = new Image();
		img.src = imgPath;
		// "on" version:
		imgPath = pref + images[index] + "_on.gif";
		img = new Image();
		img.src = imgPath;
	}
	
	img = new Image();
	img.src = "img/calc_bg.gif";

}

// ----------

$().ready(function() {
	M000.store.ec = new M000.ECalc();
});