if(typeof $ == 'undefined') {document.write('<script type="text/javascript" src="http://support.melkermedia.cz/livechat/plugin/jquery.js"></script>');}
var BubbleChat = new Object();
BubbleChat.scrollTimeout = null;
BubbleChat.delay = 3000;
BubbleChat.prependInElement = null;
BubbleChat.bubbleType = 'bubblechat';
BubbleChat.tid = 'def';
BubbleChat.lang = null;
BubbleChat.livechatURL = 'http://support.melkermedia.cz/livechat/?t=%tid%&d=%domain%&w=%website%&lang=%lang%';
BubbleChat.getStatusURL = 'http://support.melkermedia.cz/livechat/status/%tid%';
BubbleChat.cssURL = 'http://support.melkermedia.cz/livechat/plugin/bubblechat.css';
BubbleChat.txt = {'notice':'Operátor je právě <strong>online</strong>','btn':'Vstup'};
BubbleChat.init = function()
{
    BubbleChat.lang = $("html").attr("xml:lang");
    if(BubbleChat.lang != null && BubbleChat.lang != 'cz' && BubbleChat.lang != 'cs' && BubbleChat.lang != 'sk')
        return;

    setTimeout('BubbleChat.getStatus()', BubbleChat.delay);
    
    switch(BubbleChat.bubbleType)
    {
        case 'modern':
            $(BubbleChat.prependInElement).prepend('<div id="bubblechat" class="modern"><div class="close"><a href="javascript:" onmousedown="BubbleChat.close();">&nbsp;</a></div><div class="status">'+BubbleChat.txt.notice+'</div><div class="submit"><a href="'+BubbleChat.getURL()+'" target="_blank">'+BubbleChat.txt.btn+'</a></div></div>');
            $('#bubblechat.modern').css(BubbleChat.bubbleCSS);
        break;
        case 'retro':
            $(BubbleChat.prependInElement).prepend('<div id="bubblechat" class="retro"><div class="close"><a href="javascript:" onmousedown="BubbleChat.close();">&nbsp;</a></div><div class="status">'+BubbleChat.txt.notice+'</div><div class="submit"><a href="'+BubbleChat.getURL()+'" target="_blank">'+BubbleChat.txt.btn+'</a></div></div>');
            $('#bubblechat.retro').css(BubbleChat.bubbleCSS);
        break;
    }
}
BubbleChat.set = function()
{
    $(window).bind('scroll', BubbleChat.scroll);
    $('#bubblechat').css('margin-top', $('html, body').scrollTop());
    $('#bubblechat, #bubblechat_retro').fadeIn("fast");
}
BubbleChat.open = function()
{
    var width = 600;
    var height = 400;
    var url = BubbleChat.livechatURL.replace(/%tid%/g, BubbleChat.tid);
    url = url.replace(/%domain%/g, window.location.host);
    url = url.replace(/%website%/g, window.location.href);
    url = url.replace(/%lang%/g, BubbleChat.lang);
    var objWnd = window.open(url, '', "height="+ height +", width="+ width +", left=300, top=150");
}
BubbleChat.getURL = function()
{
    var url = BubbleChat.livechatURL.replace(/%tid%/g, BubbleChat.tid);
    url = url.replace(/%domain%/g, window.location.host);
    url = url.replace(/%website%/g, window.location.href);
    url = url.replace(/%lang%/g, BubbleChat.lang);
    return url;
}
BubbleChat.close = function()
{
    $('#bubblechat').fadeOut("fast");
    $(window).unbind('scroll', BubbleChat.scroll);
}
BubbleChat.scroll = function()
{
    clearTimeout(BubbleChat.scrollTimeout);
    
    $('#bubblechat').css('margin-top', $(this).scrollTop());
}
BubbleChat.getStatus = function()
{
    var docURL = BubbleChat.getStatusURL.replace(/%tid%/g, BubbleChat.tid);
    $.getScript(BubbleChat.bustURL(docURL), function (){});
}
BubbleChat.bustURL = function(url)
{
    if(url.indexOf('?') == -1)
        url += '?'
    else
        url += '&';
    if(url.indexOf('bust=') >= 0)
        url = url.substring(0, url.indexOf('bust='));
    url += 'bust=';
    for(var i = 0; i < 10; i++)
        url += Math.round(Math.random()*10);
    return url;
}
document.write('<link rel="stylesheet" href="'+BubbleChat.cssURL+'" type="text/css" media="screen">');