// (c) SZOK.PL 2009 - Krzysztof Frankiewicz
// Narzedzia

var swfu;

var hotkeys = {
	buttons : {
		'Zapisz': 'Ctrl+S',
		'Odśwież': 'Ctrl+R',
		'Anuluj': 'Ctrl+Z',
		'Dodaj': 'Ctrl+N'
	},
	shortcutButton : function (text)
	{
		if ($('.right .container a:contains('+text+')').size() > 0)
			$.jGrowl('<center>'+text+'</center>',{
						 header: hotkeys.buttons[text] ,
						 background: colors.yellow,
						 speedIn: 0, 
						 speedOut: 0, 
						 life: 100,
						 close: function () {
								if ($('.right .container a[href]:contains('+text+'):first').size() > 0)
									location.hash = $('.right .container a[href]:contains('+text+'):first').attr('href');
								else
									$('.right .container a:contains('+text+'):first').click();
								$(window).focus();
							}
					});
	},
	init : function ()
	{
		$.each(hotkeys.buttons, function (i,el) {
			$(window).bind('keydown',el,function (e) { e.preventDefault(); hotkeys.shortcutButton(i); });
		});
	}
}

$.fn.movieResize = function (w) {
	var _w = parseInt($(this).attr('width'));
	var _h = parseInt($(this).attr('height'));
	
	var h = Math.round(w * (_h / _w));
	$(this).attr({width: w, height: h, wmode: 'opaque'}).find('embed').attr({width: w, height: h});
	$(this).append('<param value="opaque" name="wmode" />');
	var o = $(this).wrap('<div style="width: '+w+'px; height: '+h+'px;" class="embed" />').parent();
	
	return o;
}


// nasluchuje zmian w hashu adresu strony, wywolywany co 1ms
var hashListener = {
	hash : location.hash,
	stack : [],
	interval : 10,
	add : function (fn) {
		if (!$.isFunction(fn)) fn = function () {};
		this.stack.push(fn);
	},
	check : function () {
		if (this.hash != location.hash)
		{
			this.hash = location.hash;
			for (i in this.stack)
				this.stack[i]();
		}
	},
	begin : function () {
		setInterval('hashListener.check()',this.interval);
	}
};

var loading = {
	show : function () {
		$('.container .left').addClass('loading');
	},
	hide : function () {
		$('.container .left').removeClass('loading');
	}
};
