
jQuery(document).ready ( function ()
{
	jQuery('body').addClass ('js-enabled');
})

jQuery(document).ready ( function ()
{
	jQuery('a.new_window').click ( function ()
	{
		window.open (this.href);
		return false;
	});
})

jQuery(document).ready ( function ()
{
	jQuery('.enhanced-form').each ( function ()
	{
		jQuery(this).find ('.text').each ( function ()
		{
			jQuery(this).focus ( function () { this.selectionStart = 0; this.selectionEnd = this.value.length; jQuery(this).addClass ('selected'); if ( this.value == this.title ) this.value = '' });
			jQuery(this).blur ( function () { jQuery(this).removeClass ('selected'); if ( this.value == '' ) this.value = this.title; });
			if ( this.value == '' ) this.value = this.title;
		})
	})
})

function build_frames ()
{
	jQuery('.enhanced-frame').each ( function ()
	{
		if ( ! this.frame_built )
		{
			jQuery('body').append ('<table cellpadding="0" cellspacing="0">' +
				'<tr><td class="_lt"></td><td class="_t"></td><td class="_rt"></td></tr>' +
				'<tr><td class="_l"></td><td class="_c"></td><td class="_r"></td></tr>' +
				'<tr><td class="_lb"></td><td class="_b"></td><td class="_rb"></td></tr>' +
				'</table>');

                  var helper = jQuery('body')[0].lastChild;
			var bgc = jQuery(this).css('background-color');
			var bg = jQuery(this).css('background-image');

			// TODO: automaticky zjistit velikost bg obrazku
			var w = h = '5';

			jQuery(helper).find ('._t').css ('background-color', bgc);
			jQuery(helper).find ('._b').css ('background-color', bgc);
			jQuery(helper).find ('._l').css ('background-color', bgc);
			jQuery(helper).find ('._r').css ('background-color', bgc);

     			jQuery(helper).find ('._lt').css ('background-image', bg);
			jQuery(helper).find ('._rt').css ('background-image', bg);
			jQuery(helper).find ('._lb').css ('background-image', bg);
			jQuery(helper).find ('._rb').css ('background-image', bg);

     			jQuery(helper).find ('._lt').css ('background-position', '0px 0px');
			jQuery(helper).find ('._rt').css ('background-position', w + 'px 0px');
			jQuery(helper).find ('._lb').css ('background-position', '0px ' + h + 'px');
			jQuery(helper).find ('._rb').css ('background-position', w + 'px ' + h + 'px');

			jQuery(helper).find ('._lt').css	('height', h + 'px');
			jQuery(helper).find ('._lb').css	('height', h + 'px');

			jQuery(helper).find ('._lt').css	('width', w + 'px');
			jQuery(helper).find ('._rt').css	('width', w + 'px');

			var cont = jQuery(helper).find ('._c')[0];

			while (this.childNodes.length > 0)
			{
				cont.appendChild (this.childNodes[0]);
			}

			helper.className = this.className;
			jQuery(helper).removeClass ('enhanced-frame');
			cont.className = helper.className;
			jQuery(helper).addClass ('enhanced-frame-tbl');

			jQuery(cont).css ('background', bgc);
			jQuery(helper).css ('background', 'transparent');

			this.frame_built = true;
			this.parentNode.replaceChild (helper, this);
		}
	})
}

jQuery(document).ready ( build_frames )

