function removePromo1() {
	stopvideo();
}

function showPromo1() {
	playvideo('zIiOupEBHUM');
}

function showBg() {
	$('#popup-bg').show();
}

function hideBg() {
	$('#popup-bg').hide();
}

$(function() {
	
	$('body').append('<div id="popup-bg"></div>');
	$('body').append('<div id="popup-center"><div id="popup"><div class="content"></div></div></div>');
	$('body').append('<div id="popup-all"></div>');
	$('body').append("<div id='popup-center2'><div id='popup-login'></div></div>");
	$.ajax({
		url: login_form_url,
		success: function(html) {
			$('#popup-login').html(html);
		}
	});
	$('#open-login-popup').click(function() {
		showBg();
		$('#popup-center2').show();
		return false;
	});
	
});

function close_login_popup() {
	hideBg();
	$('#popup-center2').hide();
}


function getFlashMovie(div) {
	div = div || "player" ;
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? window[div] : document[div];
}


function toas_load(file, sbool) {
	getFlashMovie().toas_load(file,sbool);
}

function toas_stop() {
	getFlashMovie().toas_stop();
}

function toas_play(file, abool) {
	getFlashMovie().toas_play();
}


function playvideo(id) {
	var c = '<div style="padding-top:100px;" class="center"><div class="center video"><a href="javascript:stopvideo()" id="close-popup">&nbsp;</a><div id="ytapiplayer" style="margin-left: 15px;"></div></div></div>';
	showBg();
	$('#popup-all').html(c).show();
	var params = { allowScriptAccess: "always", bgcolor: "#cccccc", allowFullScreen: "true" };
    swfobject.embedSWF("http://www.youtube.com/v/"+id+"&enablejsapi=1&playerapiid=ytplayer&hl=pl&fs=1&rel=0", 
            "ytapiplayer", "425", "344", "8", null, null, params, {id: "myytplayer"});
    $('#myytplayer').css('margin-left', '20px').css('margin-top', '20px');
}
var ytplayer;
function onYouTubePlayerReady(playerId) {
	ytplayer = document.getElementById('myytplayer');
	ytplayer.playVideo();
}

function stopvideo() {
	ytplayer.stopVideo();
	hideBg();
	$('#myytubeplayer').remove();
	$('#popup-all').hide();
}



$(function() {
	$('#top-links a').click(function() {
		playvideo($(this).attr("rel"));
		return false;
	});
	$('body').append('<div id="thumb-win" style="display: none"><img src="" alt="zdjęcie" /></div>');
	$('.tooltip').tooltip({
		track: true,
		delay: 0,
		showURL: false,
		showBody: " - "
	});
	setTimeout(function() { if (meetUsers()) { setInterval("meetUsers()", 6000); } }, 3000);
});

function last_actions() {
	

	$.ajax({
		url: last_actions_url,
		success: function(s) {
			$(s).each(function(k, v) {
				try {
					
					var nId = $(v).attr("id");
					if (nId != undefined ) {
						var obj = $('#last-actions-window #' + nId);
						
						if (obj.attr("id") == undefined) {
							
							$('#last-actions-window').prepend(v);
							$('#' + nId).css({
								opacity: "0",
								marginTop: "-20px"
							});
							$('#' + nId).animate({
								opacity: 1,
								marginTop: "0px"
							}, 1000, function() { $('#last-actions-window .portal-log-item:last-child').fadeOut();try { document.getElementById(nId).style.removeAttribute('filter');}catch(err) {}; });
						}
					} 
				} catch (err) {alert(err); };
			} );
			//$('#last-actions-window').html(s);
		}
		
	});
}

function meetUsers() {
	try {
		if (! meet_users_url) {
			return false;
		}
	} catch (err) { return false; }
	$('.meet-users .round-center').css({overflow: 'hidden', height: $('.meet-users .round-center').height() + 'px'});
	$.ajax({ 
		url: meet_users_url,
		success: function(html) {
			var d = $('.meet-users .round-center .users-in:first-child');
			$('.meet-users .round-center .slider').append(html);
			d.animate({
				opacity: '0.0',
				marginLeft: '-340px'
			}, 1000, function() { d.remove(); });
			$('.tooltip').tooltip({
				track: true,
				delay: 0,
				showURL: false,
				showBody: " - "
			});
		}
	});
	return true;
}

function showThumb(el, file) {
	$('#thumb-win img').attr("src", file);
	$('#thumb-win').css({
		top: ($(el).position().top + 20)+ 'px', 
		left: $(el).position().left + 'px'
	}).show();
}

function hideThumb() {
	$('#thumb-win').hide();
}

function externallinks()
{
    var c=document.getElementById('all-page');
    if(c)
    {
        var ls=c.getElementsByTagName('a');
        for(var i=0;i<ls.length;i++){
            if(ls[i].getAttribute('rel')=='external' || ls[i].getAttribute('href').match(/^\:\/\/(.*)/i))
            {
	            ls[i].className+=ls[i].className?' extlink':'extlink';
	            ls[i].onclick=function(){window.open(this.href);return false;}
        	}
   		}
	}
}
$(document).ready(function(){
   // if(!document.getElementById && !document.createTextNode){return;}
    externallinks();
});
