var to = null;
var msg = null;
var msg_pos = null;

function clearMsg()
{
	msg.hide('normal', function(){
		$(msg).empty();
	});
}
function showMsg(m_text, m_time)
{
	if (msg==null || msg.length==0) 
	{
		$('#site_content').prepend('<div id="message"></div>');
		msg = $('#message');
	}
	msg.append('<p>'+m_text+'</p>').hide().show('normal', setMsgPos);
	hideMsg(m_time);
	
}
function hideMsg(m_time)
{
	if (to!=null)
	{
		clearTimeout(to); 
		to = null;
	}
	if (m_time==undefined) m_time = 30000;
	to = setTimeout(clearMsg, m_time);
}
function setMsgPos()
{
	if (msg!=null && msg.length > 0) 
	{
		if (msg_pos==null || msg.length == 0)
		{
			msg.prepend('<div id="msg_pos"></div>');
			msg_pos = $('#msg_pos');
		}
		var messages_height = 0;
		$('p', msg).each(function(){messages_height += $(this).height();});
		var prep_height = (msg.height() - messages_height) / 2;
		if (prep_height>0) msg_pos.height(prep_height);
		else msg_pos.height(0);
	}
}


function wbbClose(){
    $('#wellbeback, #wbbbg').remove();
}
function wbbReady($this){
    var wbbbg, html, css, w, h, view_w, view_h, body;
    $this = $this.target ? $(this) : $this;
    
    html = $('<div id="wellbeback"></div>');
    html.append($this);
    html.click(wbbClose);

    body = $('body');
    body.append(html);
    
    w = $this.width();
    h = $this.height();

    view_h = window.innerHeight ? window.innerHeight : $(window).height();
    view_w = $(window).width();
    html.css({
            position: 'absolute',
            left: ((view_w-w)/2)+'px',
            top: ((view_h-h)/2)+'px',
            zIndex: 20001,
            width: w+'px',
            height: h+'px',
            cursor: 'pointer'
        }).hide().fadeIn('slow');

    wbbbg = $('<div id="wbbbg"></div>').css({
            position: 'absolute',
            left: '0',
            top: '0',
            zIndex: 20000,
            width: $(document).width()+'px',
            height: $(document).height()+'px',
            backgroundColor: '#000',
            filter: 'alpha(opacity=50)',
            '-moz-opacity': 0.5,
            '-khtml-opacity': 0.5,
            opacity: 0.5

    }).hide().fadeIn('slow');
    body.append(wbbbg);

    $.cookie('wbb', true);
}

$(document).ready(function(){
	$('span.embed').each(function(){
		var val = $(this).attr('title').split('|');
		if (val.length>0) {
			$(this).parent().parent().flashembed({
					src: val[0], 
					width: parseInt(val[1]),
					height: parseInt(val[2]),
                    wmode: "opaque"
				}, {
					'clickTAG': '/ad/redirect/' + val[3], 
					'clickTARGET': '_blank'
				});
		}
	});
	if (ie==false || parseInt(ie)>=7)
	{
		$('.rounded5').corners('5px');
		$('.rounded').corners('15px');
		$('.rounded10').corners('10px');
	}
	$('a.newWindow').click(function(e){
		e.preventDefault();
		var hj_popup = window.open(this.href, 'hj_popup', 'toolbar=no,scrollbars=yes,location=no,statusbar=no,menubar=no,resizable=yes,width=600,height=500,left=200,top=120');
	});
	
	msg = $('#message');
	if (msg.length > 0) 
	{
		setMsgPos();
		hideMsg();
	}

    /*if ( ! $.cookie('wbb') || document.location=='http://www.hojelentes.hu/') {
        var wbb_img = $('<img src="'+assets+'images/wellbeback.png" />');
        wbb_img.load(wbbReady);
    }*/
});
