function api(object, action, params, callback) {
    var url = '';
    url = "/api/" + object + "/" + action;
    $.getJSON(url, params, callback);
}

function specialKey(evt)
{
    var code = evt.keyCode;
    if(code == 9 || code == 16 || code == 17 || code == 18 || code == 144 || code == 20 || code == 145 || code == 27 || code == 19 || code == 91 || code == 92 || code == 93 || code == 116 || code == 37 || code == 38 || code == 39 || code == 40)
    {
        return true;
    }
    return false;
}

function getSelText()
{
    var txt = '';
    if (window.getSelection)
    {
        txt = window.getSelection();
    }
    else if (document.getSelection)
    {
    txt = document.getSelection();
    }
    else if (document.selection)
    {
        txt = document.selection.createRange().text;
    }
    return txt;
}

function checkDiscountCode()
{
    var input = $('#registrace_index #code');
    var code = input.val();
    if(code.length >= 3)
    {
        var loader = $('<span>&nbsp;<img src="/images/loader-small.gif" alt="oběřuji" />... ověřuji kód</span>');
        
        loader.insertAfter(input);
        $.getJSON("/checkCode?code=" + code, function(data)
        {
            var info = $('#kampan-info');
            if(data != false)
            {
                info.html($('<h2 class="italic center"><small class="small">1490 Kč / rok - <span style="color:#0C0;">SLEVA ' + data['sleva'] + ' %</span> =</small><br /> ' + data['cena'] + ' Kč / rok</h2>'));
                if(data['logo'])
                {
                    info.append('<p class="center"><img src="' + data['logo'] + '" /></p>');
                }
                
            }
            else
            {
                info.html('<h2 class="italic center"> 1490  Kč / rok</h2><p><strong>neplatný kód</strong></p>');
            }
            loader.remove();
        });

    }
}

function getLoader(text)
{
    return $('<p class="center" style="color:#1E9CC8;font-weight:bold;">' + text + '<br /><br /><img src="/images/loader.gif" /></p>');
}


function TUIDialog(src, title, params, ident) 
{
    var _this = this;
    if(!ident || ident == undefined)
    {
        ident = 'dialog';
    }
    
    this.src = src;
    this.title = title;
    this.dialog = false;
    this.opts = {draggable: 1, modal: 1, span_width: 20, buttons: {}, onload: false, closeOnEscape: 1, beforeclose: false};
	this.opts = $.extend(this.opts, params);
    this.buttons = $.extend({'Zavřít': function() { _this.dialog.dialog('close'); }}, this.opts.buttons);
    
    this.dialog = $('#tui-' + ident);
    
    if(this.dialog.length)
    {
        this.dialog.dialog('destroy');
        this.dialog.remove();
    }
    else
    {
        this.dialog = $('<div id="kui-' + ident + '" class="container"></div>').css({'margin': '0', 'overflow': 'hidden'});
        $('body').append(this.dialog);
    }
    this.dialog.dialog({beforeclose: this.opts.beforeclose, hide: 'slide', 'closeOnEscape': this.opts.closeOnEscape, 'modal': this.opts.modal, 'draggable': this.opts.draggable, 'title': this.title, 'width': this.opts.span_width * 40 + 30, 'buttons': this.buttons, 'maxHeight': '400'});
    var loader = $('<p style="padding:1em;text-align:center;font-weight:bold;">nahrávám...<br /><br /><img src="/images/loader.gif" /></p>');
    this.dialog.html(loader);
    this.dialog.load(this.src, {}, function(text) 
    {
        _this.dialog.html(text);
        if(_this.opts.onload)
        {
            _this.opts.onload.call(_this, _this.dialog);
        }
        //~ KUIContent(_this.dialog);
    });
	
	this.close = function()
	{
		_this.dialog.dialog('close');
	}
}

(function($)
{
    var source = false;
    var content = false;
    var dlg = false;
    var defaults = {
        'size': 'full'
    };
    
    $.fn.progressBar = function(options)
    {
        return this.each(function()
        {
            var dlg = false;
            var timer = false;
            var opts = {
                
            };
            $.extend(opts, defaults, options);
            create($(this));
            
            function create(el)
            {
                el.css({'width': '110px', 'height': '12px', 'padding': '0', 'margin': '0', 'display': 'block', 'background': 'url(/images/progressbg_green.gif) no-repeat -120px 0', 'border': '1px solid #999', 'border-width': '0 1px'})
                var value = parseInt(el.html());
                el.html('');
                var end = value / 100 * 110;
                
                var div = end / 50;
                timer = setTimeout(function() { run(el, 0, div, end); }, 10);
            }
            
            function run(el, act, div, end)
            {
                if(act + div > end)
                {
                    el.css('background', 'url(/images/progressbg_green.gif) no-repeat -' + (120 - end) + 'px 0');
                }
                else
                {
                    var posx = 120 - parseInt(act) + parseInt(div);
                    el.css('background', 'url(/images/progressbg_green.gif) no-repeat -' + posx + 'px 0');
                    timer = setTimeout(function() { run(el, act + div, div, end); }, 10);
                }
            }
        });
        
    };

})(jQuery);

$(document).ready(function()
{
    $('div.tabs').each(function(i, el) {
        $(el).tabs();
    });
    $('h3.shadow').each(function(i, el) {
        var h = $(el);
        h.css('position', 'relative')
        var text = h.html();
        var color = h.css('color');
        
        var span = $('<span />').html(text).css({'position': 'absolute', 'left': '-1px' - h.css('padding-left'), 'top': '-1px', 'color': color});
        h.css('color', '#999');
        h.prepend(span);
        
    });
    $("span.progressbar").progressBar();
    var lekce_slovicka_list = $('#lekce-slovicka-list');
    if(lekce_slovicka_list.length > 0)
    {
        bindWordlistAdd(lekce_slovicka_list);
    }
    if($('#roztesthidden').length)
    {
        $('#roztesthidden').dialog({ autoOpen: false, width: 500, title: 'Rozřazovací test', modal: true, buttons: {
             "Zavřít": function() {
             $(this).dialog("close");
             },
             "Opakovat rozřazovací test": function() {
             window.location = '/testy/rozrazovaci';
             }
             }
        });
    }
    $('a.wordlisttest').click(function() 
    {
        var ident = $(this).attr('name') ? $(this).attr('name') : false;
        var params = {span_width: 15, onload: bindWordlistTest, 'draggable': 0, 'closeOnEscape': 0, beforeclose: function() {
            $('#lekce-slovicka-list').fadeIn('slow');
            $('#wordlist').css('visibility', 'visible');
        }};
        var dialog = new TUIDialog('/wordlist/test' + $(this).attr('href') + '&start=1', $(this).attr('title'), params, ident);
        $('#lekce-slovicka-list').fadeOut('slow');
        $('#wordlist').css('visibility', 'hidden');
        if(typeof(pageTracker) != 'undefined')
        {
            pageTracker._trackPageview("/wordlist/test");
        }
        return false;
    });
    $('#registrace_index #code').keydown(function(evt) {
        if(evt.keyCode == 13)
        {
            checkDiscountCode();
            return false;
        }
    });
    $('#show_test_invite').click(function() {
        $('#test_invite').show();
        return false;
    });
    $('#registrace_index #checkcode').click(function(evt) 
    {
        checkDiscountCode();
        return false;
    });
    $('a.favoritsadd').click(function() {
        var link = $(this);
        var id = link.attr('id').split('_')[1];
        var loader = $('<span style="color:white;">ukládám... <img src="/images/loader-small-white.gif" /></span>');
        loader.insertAfter(link);
        link.hide();
        api('lessons', 'addFavourite', {id: id}, function(response) {
            if(response['result'])
            {
                link.remove();
            }
            else
            {
                link.show();
                alert(response['data']['msg']);
            }
            loader.remove();
        });
        
        return false;
    });
    
    function loadSlovnik(content, q)
    {
        content.load('/slovnik/modal', {q: q}, function() {
            bindPlayer(content);
            bindWordlistAdd(content);
            $('#slovnik-q', content).keydown(function(evt) {
                if(evt.keyCode == 13 && $(this).val() != '')
                {
                    $('#slovnik-results', content).html(getLoader('vyhledávám...'));
                    loadSlovnik(content, $(this).val());
                }
            }).focus();
        });
    }
    
    function showSlovnik(q)
    {
        if(typeof(pageTracker) != 'undefined')
        {
            pageTracker._trackPageview("/slovnik/popup");
        }
        if(!q)
        {
            q = '';
        }
        var dlgcontent = $('#dlgcontent');
        if(dlgcontent.length == 0)
        {
            dlgcontent = $('<div id="dlgcontent" class="container"></div>');
            $('body').append(dlgcontent);
        }
        else
        {
            dlgcontent.dialog('destroy');
        }
        dlgcontent.html(getLoader('nahrávám slovník...'));
        loadSlovnik(dlgcontent, q);
        dlgcontent.dialog({title: 'Slovník', modal:false, draggable:true, width:444, buttons: { "Zavřít": function() { $(this).dialog("close"); }, "Vyhledat": function() { 
            var q = $('#slovnik-q').val();
            if(q != '')
            {
                $('#slovnik-results', dlgcontent).html(getLoader('vyhledávám...'));
                loadSlovnik(dlgcontent, q);
            }
            else
            {
                alert('Zadejte hledané slovo');
            }
            return false;
        }}});
    }
    
    $('#slovnikmodal').click(function() 
    {
        showSlovnik();
        return false;
    });
    $('div.mceContentBody').dblclick(function() 
    {
        showSlovnik(getSelText());
    });
    
    $('input.lqar').click(function() {
        var input = $(this);
        
        $('div.lqahint', input.parent().parent()).slideUp('fast');
        $('div.lqahint', input.parent()).slideDown('fast');
    });
    
    
    $('#searchmodal').click(function() 
    {
        var link = $(this);
        var dlgcontent = $('#dlgcontent');
        if(dlgcontent.length == 0)
        {
            dlgcontent = $('<div id="dlgcontent" class="container"></div>');
            $('body').append(dlgcontent);
        }
        else
        {
            dlgcontent.dialog('destroy');
        }
        dlgcontent.load(link.attr('href'), {}, function() 
        {
            dlgcontent.dialog({title: link.attr('title'), modal:true, width:500, buttons: { "Zavřít": function() { $(this).dialog("close"); }, "Vyhledat": function() { 
                var q = $('#slovnik-q');
                dlgcontent.load('/vyuka/search_modal', {q: q.val()}, function() {
                });
                return false;
            }}});
        });
        return false;
    });
    $('#favmodal').click(function() 
    {
        var link = $(this);
        var dlgcontent = $('#dlgcontent');
        if(dlgcontent.length == 0)
        {
            dlgcontent = $('<div id="dlgcontent" class="container"></div>');
            $('body').append(dlgcontent);
        }
        else
        {
            dlgcontent.dialog('destroy');
        }
        dlgcontent.load(link.attr('href'), {}, function() 
        {
            dlgcontent.dialog({title: link.attr('title'), modal:true, width:500, buttons: { "Zavřít": function() { $(this).dialog("close"); }}});
        });
        return false;
    });
    if($('#objednavka-form').lenght != 0 && $('#show-form').val() != '1')
    {
        $('#objednavka-form').hide();
    }
    if($('#show-objednavka-form').length != 0 && $('#show-form').val() != '1')
    {
        $('#show-objednavka-form').show();
    }
    $('#show-objednavka-form').click(function() {
        $(this).hide();
        $('#objednavka-form').show();
        $(this).blur();
        return false;
    });
    bindPlayer(false);
    $('#slovnik #q').keydown(function(e) {
        if(e.keyCode == 13)
        {
            slovnik();
            return false;
        }
    });
    $('#ajax-slovnik').click(function() 
    {   
        slovnik();
        return false;
    });
    $('#wordlist a.wordlist-remove').click(function() {
        var a = $(this);
        var slovo_id = a.attr('id').split('_')[1];
        var loader = $('<img src="/images/loader-small.gif" />');
        loader.insertAfter(a);
        a.hide();
        api('wordlist', 'remove', {'word_id': slovo_id}, function(response) {
            if(response['result'])
            {
                var ul = a.parent().parent();
                a.parent().remove();
                if($('li', ul).length == 0)
                {
                    ul.prev('h2:first').remove();
                    ul.remove();
                }
            }
            else
            {
                alert(response['data']['msg']);
                a.show();
            }
            loader.remove();
            
        });
        return false;
    });
});

function slovnik()
{
    var q = $('#q').val();
    var results = $('#slovnik-results');
    if(q == '')
    {
        results.html('<p class="white center bold">Zadejte slovo pro přeložení</p>');
    }
    else
    {
        results.html('<p class="center"><br /><img src="/images/slovnik-progress.gif" /></p>');
        $.ajax({type: "GET", url: '/slovnik/ajax/', data: 'q=' + $('#q').val(), complete: function(request) {
            text = request.responseText;
            results.html(text);
            bindPlayer($('#slovnik-results'));
            $('#slovnik-clear', results).click(function() {
                results.html('');
                return false;
            })
        }});
    }
}

function bindWordlistTest(content)
{
    function checkWordlistTest(content)
    {
        var link = $('#wordlisttestcheck', content);
        var result = $('#wordlisttestresult', content);
        var loader = $('<p class="center"><img src="/images/loader.gif" alt="testuji" /><br />hned to bude...<br /></p>');
        result.append(loader);
        link.hide();
        var input = $('input[name=answer]', content);
        input.attr('disabled', 'disabled');
        var answer = input.val();
        var answer_div = $('div.answer', content);
        answer_div.removeClass('ui-state-error');
        answer_div.removeClass('ui-state-active');
        $('h2', answer_div).remove();
        
        $.getJSON('/wordlist/test', {answer: answer}, function(response)
        {
            if(response.result)
            {
                answer_div.addClass('ui-state-active');
                answer_div.append('<h2 class="center"><span>SPRÁVNĚ</span><br />' + answer + '</h2>');
            }
            else
            {
                answer_div.addClass('ui-state-error');
                answer_div.append('<h2 class="center"><span>ŠPATNĚ</span><br /><span class="strike">' + answer + '</span><br />' + response.correction + '</h2>');
            }
            loader.remove();
            $('#wordlisttestnext', content).show();
        });
    }
    $('#wordlisttestcheck', content).click(function() 
    {
        checkWordlistTest(content);
        return false;
    });
    $('input[name=answer]', content).keyup(function(e) 
    {
        if(e.keyCode == 13)
        {
            checkWordlistTest(content);
            return false;
        }
    });
    $('#wordlisttestnext', content).click(function() 
    {
        content.load('/wordlist/test', {}, function() 
        {
            bindWordlistTest(content);
        });
        return false;
    });
}

function bindWordlistAdd(content)
{
    $('a.wordlist-add', content).click(function() {
        var a = $(this);
        var slovo_id = a.attr('id').split('_')[1];
        var loader = $('<span class="quiet">ukládám ... </span><img src="/images/loader-small.gif" />');
        
        loader.insertAfter(a);
        a.hide();
        api('wordlist', 'add', {word_id: slovo_id}, function(response) {
            if(response['result'])
            {
                var saved = $('<span class="quiet">uloženo</span>');
                saved.insertAfter(a);
                setTimeout(function() { saved.html('<img src="/images/icons/favorits.png" alt="oblíbené" title="slovíčko mám uloženo v mých slovíčkách" />'); } , 5000);
            }
            else
            {
                alert(response['data']['msg']);
                a.show();
            }
            loader.remove();
        });
        return false;
    });
}

function bindPlayer(content)
{
    if(!content)
    {
        content = $('body');
    }
    $('a.player', content).click(function() {
        var a = $(this);
        if($('#player').length == 0)
        {
            $('body').append('<div id="player"></div>');
        }
        $('#player').flash(
            { src: '/flash/singlemp3player.swf', height: 1, width: 1 },
            { version: 7 },
            function(htmlOptions) {
                $this = $(this);
                htmlOptions.flashvars.file = a.attr('href');
                htmlOptions.flashvars.autoStart = "true";
                $this.html('');
                $this.append($.fn.flash.transform(htmlOptions));
           }
        );
        a.blur();
        return false;
    });
}

/**
 * Flash (http://jquery.lukelutman.com/plugins/flash)
 * A jQuery plugin for embedding Flash movies.
 * 
 * Version 1.0
 * November 9th, 2006
 *
 * Copyright (c) 2006 Luke Lutman (http://www.lukelutman.com)
 * Dual licensed under the MIT and GPL licenses.
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.opensource.org/licenses/gpl-license.php
 * 
 * Inspired by:
 * SWFObject (http://blog.deconcept.com/swfobject/)
 * UFO (http://www.bobbyvandersluis.com/ufo/)
 * sIFR (http://www.mikeindustries.com/sifr/)
 * 
 * IMPORTANT: 
 * The packed version of jQuery breaks ActiveX control
 * activation in Internet Explorer. Use JSMin to minifiy
 * jQuery (see: http://jquery.lukelutman.com/plugins/flash#activex).
 *
 **/ 
;(function(){
	
var $$;

/**
 * 
 * @desc Replace matching elements with a flash movie.
 * @author Luke Lutman
 * @version 1.0.1
 *
 * @name flash
 * @param Hash htmlOptions Options for the embed/object tag.
 * @param Hash pluginOptions Options for detecting/updating the Flash plugin (optional).
 * @param Function replace Custom block called for each matched element if flash is installed (optional).
 * @param Function update Custom block called for each matched if flash isn't installed (optional).
 * @type jQuery
 *
 * @cat plugins/flash
 * 
 * @example $('#hello').flash({ src: 'hello.swf' });
 * @desc Embed a Flash movie.
 *
 * @example $('#hello').flash({ src: 'hello.swf' }, { version: 8 });
 * @desc Embed a Flash 8 movie.
 *
 * @example $('#hello').flash({ src: 'hello.swf' }, { expressInstall: true });
 * @desc Embed a Flash movie using Express Install if flash isn't installed.
 *
 * @example $('#hello').flash({ src: 'hello.swf' }, { update: false });
 * @desc Embed a Flash movie, don't show an update message if Flash isn't installed.
 *
**/
$$ = jQuery.fn.flash = function(htmlOptions, pluginOptions, replace, update) {
	
	// Set the default block.
	var block = replace || $$.replace;
	
	// Merge the default and passed plugin options.
	pluginOptions = $$.copy($$.pluginOptions, pluginOptions);
	
	// Detect Flash.
	if(!$$.hasFlash(pluginOptions.version)) {
		// Use Express Install (if specified and Flash plugin 6,0,65 or higher is installed).
		if(pluginOptions.expressInstall && $$.hasFlash(6,0,65)) {
			// Add the necessary flashvars (merged later).
			var expressInstallOptions = {
				flashvars: {  	
					MMredirectURL: location,
					MMplayerType: 'PlugIn',
					MMdoctitle: jQuery('title').text() 
				}					
			};
		// Ask the user to update (if specified).
		} else if (pluginOptions.update) {
			// Change the block to insert the update message instead of the flash movie.
			block = update || $$.update;
		// Fail
		} else {
			// The required version of flash isn't installed.
			// Express Install is turned off, or flash 6,0,65 isn't installed.
			// Update is turned off.
			// Return without doing anything.
			return this;
		}
	}
	
	// Merge the default, express install and passed html options.
	htmlOptions = $$.copy($$.htmlOptions, expressInstallOptions, htmlOptions);
	
	// Invoke $block (with a copy of the merged html options) for each element.
	return this.each(function(){
		block.call(this, $$.copy(htmlOptions));
	});
	
};
/**
 *
 * @name flash.copy
 * @desc Copy an arbitrary number of objects into a new object.
 * @type Object
 * 
 * @example $$.copy({ foo: 1 }, { bar: 2 });
 * @result { foo: 1, bar: 2 };
 *
**/
$$.copy = function() {
	var options = {}, flashvars = {};
	for(var i = 0; i < arguments.length; i++) {
		var arg = arguments[i];
		if(arg == undefined) continue;
		jQuery.extend(options, arg);
		// don't clobber one flash vars object with another
		// merge them instead
		if(arg.flashvars == undefined) continue;
		jQuery.extend(flashvars, arg.flashvars);
	}
	options.flashvars = flashvars;
	return options;
};
/*
 * @name flash.hasFlash
 * @desc Check if a specific version of the Flash plugin is installed
 * @type Boolean
 *
**/
$$.hasFlash = function() {
	// look for a flag in the query string to bypass flash detection
	if(/hasFlash\=true/.test(location)) return true;
	if(/hasFlash\=false/.test(location)) return false;
	var pv = $$.hasFlash.playerVersion().match(/\d+/g);
	var rv = String([arguments[0], arguments[1], arguments[2]]).match(/\d+/g) || String($$.pluginOptions.version).match(/\d+/g);
	for(var i = 0; i < 3; i++) {
		pv[i] = parseInt(pv[i] || 0);
		rv[i] = parseInt(rv[i] || 0);
		// player is less than required
		if(pv[i] < rv[i]) return false;
		// player is greater than required
		if(pv[i] > rv[i]) return true;
	}
	// major version, minor version and revision match exactly
	return true;
};
/**
 *
 * @name flash.hasFlash.playerVersion
 * @desc Get the version of the installed Flash plugin.
 * @type String
 *
**/
$$.hasFlash.playerVersion = function() {
	// ie
	try {
		try {
			// avoid fp6 minor version lookup issues
			// see: http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
			var axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6');
			try { axo.AllowScriptAccess = 'always';	} 
			catch(e) { return '6,0,0'; }				
		} catch(e) {}
		return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1];
	// other browsers
	} catch(e) {
		try {
			if(navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){
				return (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1];
			}
		} catch(e) {}		
	}
	return '0,0,0';
};
/**
 *
 * @name flash.htmlOptions
 * @desc The default set of options for the object or embed tag.
 *
**/
$$.htmlOptions = {
	height: 240,
	flashvars: {},
	pluginspage: 'http://www.adobe.com/go/getflashplayer',
	src: '#',
	type: 'application/x-shockwave-flash',
	width: 320		
};
/**
 *
 * @name flash.pluginOptions
 * @desc The default set of options for checking/updating the flash Plugin.
 *
**/
$$.pluginOptions = {
	expressInstall: false,
	update: true,
	version: '6.0.65'
};
/**
 *
 * @name flash.replace
 * @desc The default method for replacing an element with a Flash movie.
 *
**/
$$.replace = function(htmlOptions) {
	this.innerHTML = '<div class="alt">'+this.innerHTML+'</div>';
	jQuery(this)
		.addClass('flash-replaced')
		.prepend($$.transform(htmlOptions));
};
/**
 *
 * @name flash.update
 * @desc The default method for replacing an element with an update message.
 *
**/
$$.update = function(htmlOptions) {
	var url = String(location).split('?');
	url.splice(1,0,'?hasFlash=true&');
	url = url.join('');
	var msg = '<p>This content requires the Flash Player. <a href="http://www.adobe.com/go/getflashplayer">Download Flash Player</a>. Already have Flash Player? <a href="'+url+'">Click here.</a></p>';
	this.innerHTML = '<span class="alt">'+this.innerHTML+'</span>';
	jQuery(this)
		.addClass('flash-update')
		.prepend(msg);
};
/**
 *
 * @desc Convert a hash of html options to a string of attributes, using Function.apply(). 
 * @example toAttributeString.apply(htmlOptions)
 * @result foo="bar" foo="bar"
 *
**/
function toAttributeString() {
	var s = '';
	for(var key in this)
		if(typeof this[key] != 'function')
			s += key+'="'+this[key]+'" ';
	return s;		
};
/**
 *
 * @desc Convert a hash of flashvars to a url-encoded string, using Function.apply(). 
 * @example toFlashvarsString.apply(flashvarsObject)
 * @result foo=bar&foo=bar
 *
**/
function toFlashvarsString() {
	var s = '';
	for(var key in this)
		if(typeof this[key] != 'function')
			s += key+'='+escape(this[key])+'&';
	return s.replace(/&$/, '');		
};
/**
 *
 * @name flash.transform
 * @desc Transform a set of html options into an embed tag.
 * @type String 
 *
 * @example $$.transform(htmlOptions)
 * @result <embed src="foo.swf" ... />
 *
 * Note: The embed tag is NOT standards-compliant, but it 
 * works in all current browsers. flash.transform can be
 * overwritten with a custom function to generate more 
 * standards-compliant markup.
 *
**/
$$.transform = function(htmlOptions) {
	htmlOptions.toString = toAttributeString;
	if(htmlOptions.flashvars) htmlOptions.flashvars.toString = toFlashvarsString;
	return '<embed ' + String(htmlOptions) + '/>';		
};

/**
 *
 * Flash Player 9 Fix (http://blog.deconcept.com/2006/07/28/swfobject-143-released/)
 *
**/
if (window.attachEvent) {
	window.attachEvent("onbeforeunload", function(){
		__flash_unloadHandler = function() {};
		__flash_savedUnloadHandler = function() {};
	});
}
	
})();