var gsm_gemius_identifier;

Application.adSlots=
{
	boxnavi : 1,
	halfpage : 1,
	top : 1,
	bottom : 1,
	sky : 1
}

Application.adLocalExclusiveConditions=
{
	tags : [],
	items : []
}

Application.Manager.Local=
{
	init : function()
	{
		Application.SwitchesManager.Local.init();
		Application.HeadManager.refreshHead();
		Application.Manager.Local.recursiveBoxes();
	},
	
	recursiveBoxes : function()
	{
		try
		{
			if (window.bxad_change_colors)
				bxad_change_colors(document.cookie.match(/css=black/i) ? 'onet_tv_1' : 'onet_tv_2');
			else
				setTimeout(function() { Application.Manager.Local.recursiveBoxes(); }, 200);
		}
		catch (err)
		{
			setTimeout(function() { Application.Manager.Local.recursiveBoxes(); }, 200);
		}
	}
}

Application.SwitchesManager.Local=
{
	init : function()
	{
		if ($('#no_log').get(0) && $('#no_log').attr('class') && $('#no_log').attr('class').indexOf('switch') !== false)
		{
			$('#no_log').bind('click',function ()
				{
					$('#no_log').attr('href',String(window.location));
					Application.WindowsManager.showWindow('login',null);
					return false;
				}
			);
		}
	    
		if($('#sw_pomoc'))
		{
			$('#sw_pomoc').bind('click',function ()
				{
					$('#sw_pomoc').attr('href',String(window.location));
					Application.WindowsManager.showWindow('help',null);
					return false;
				}
			);
		}
		
		if($('#sw_light'))
		{
			$('#sw_light').bind('click',function ()
				{
					$('#sw_light').attr('href',String(window.location));
					Application.SkinManager.switchCSS();
					bxad_change_colors(document.cookie.match(/css=black/i) ? 'onet_tv_1' : 'onet_tv_2');
					return false;
				}
			);
		}

		if($('#sw_wyslij_uwage'))
		{
			$('#sw_wyslij_uwage').bind('click',function ()
				{
					$('#sw_wyslij_uwage').attr('href',String(window.location));
					Application.WindowsManager.showWindow('send',null);
			       return false;
				}
			);
		}
		
		if($('#sw_regulamin'))
		{
			$('#sw_regulamin').bind('click',function ()
				{
					$('#sw_regulamin').attr('href',String(window.location));
					Application.WindowsManager.showWindow('regulations',null);
					return false;
				}
			);
		}
	}
}

Application.HeadManager=
{
	loginHead : function(identity)
	{
		$('#log').hide();
		$('#no_log').show();
		
		$('#m_moje').bind('click',function(){ Application.WindowsManager.showWindow('login',null);return false; });
	},
	
	loggedHead : function(identity)
	{
		$('#user').html(identity);
		$('#no_log').hide();
		$('#log').show();

		$('#m_moje').bind('click',function(){ window.location.href='/mojetv.html';return false; });
	},
	
	updateHeadTimed : function()
	{
		i=this;
		window.setTimeout(function(){ i.refreshHead() },3000);
	},
	
	refreshHead : function()
	{
		i=this;
		Application.UserManager.getUserInfo(i.loggedHead,i.loginHead);
	}
}

Application.MediaPlayerManager=
{
	Watcher : null,
	Media : '',
	Image : '',
	PlayerId : '',
	MaterialId : '',
	UserTimer : 0,
	PlayEventInterval : null,
	PlayEventId : null,
	
	initialEvent : function()
	{
	   i=this;
	   
	   if(typeof(Application.KropkaManager.kropkaFrameLoaded)!='undefined' && Application.KropkaManager.kropkaFrameLoaded==true)
	   {
		   Application.KropkaManager.setEvent('systemplay',0,0,'MediaPlayer','Stream',0);
		   window.clearInterval(i.Watcher);
	   }
	},
	
	init : function(Media,Image)
	{
		this.Browser=this.DetectBrowser();
		this.MPlayerSupport=this.DetectPlayer();
		//fix for MAC - needs MMS for WMV
		//check if Flip4Mac plugin installed
		if(Application.Tools.isMacOS()) {
			Application.MacOSManager.checkMacPlugin();
			this.Media=Media[1];
		} else {
			this.Media=Media[0];
		}
		//this.Media=Media;
		this.Image=Image;
		gSmConfig.setEncoding('iso-8895-2');
		
		var hitcolector = 'http://spl.hit.gemius.pl';
		var gsId = '0sg1lOd5Xbb_4vj6LTp1D.V471wpf_duHdMY.dJDO4H.O7';
		var gsm_gemius_identifier = '0sg1lOd5Xbb_4vj6LTp1D.V471wpf_duHdMY.dJDO4H.O7';
		var totalTime = -1;
		Application.MediaPlayerManager.PlayerId = 'plive_' + Math.round(Math.random() * 1000000);
		Application.MediaPlayerManager.MaterialId = String(Application.Tools.Url.getId());
		var criteria = new Array({name:'CHANNEL', value:'LIVE'});
		
		gemiusStream.newStream(Application.MediaPlayerManager.PlayerId, Application.MediaPlayerManager.MaterialId, totalTime, criteria, null, gsId, hitcolector);
		
		this.DrawControls();
		this.DrawPlayer();
		this.RunTimer();
		
		this.PlayEvent();
				
		var i=this;

		$('#FullPlayer').bind('mouseover',function(){ i.ShowControls() });
		$('#FullPlayer').bind('mouseout',function(){ i.HideControls() });
		
		if($('#Mute'))
		{
			$('#Mute').bind('click',function(){ i.Mute() });
		}
		if($('#FullScreen'))
		{
			$('#FullScreen').bind('click',function(){ i.FullScreen() });
		}
		
		i.Watcher=window.setInterval(function(){ i.initialEvent() },1000);
	},
	
	playStateManage : function(playState)
	{
		var playStateId=null;
		
		switch (playState)
		{
			case 0:
				//Undefined
				playStateId='stopped';
			break;
			case 1:
				//Stopped
				playStateId='stopped';
				this.DrawPicture();
			break;
			case 2:
				//Paused
				playStateId='paused';
			break;
			case 3:
				//Playing
				playStateId='playing';
			break;
			case 4:
				//Scan Forward
				playStateId='seekingStarted';
			break;
			case 5:
				//Scan Reverse
				playStateId='seekingStarted';
			break;
			case 6:
				//Buffering
				playStateId='buffering';
			break;
			case 7:
				//Waiting
				playStateId='buffering';
			break;
			case 8:
				//Media Ended
				playStateId='stopped';
				this.DrawPicture();
			break;
			case 9:
				//Transitioning
				playStateId='buffering';
			break;
			case 10:
				//Ready
				playStateId='stopped';
			break;
			case 11:
				//Reconnecting
				playStateId='stopped';
			break;
		
		}
		
		return playStateId;
	},
	
	PlayEvent : function()
	{
		if(Application.MediaPlayerManager.MPlayerSupport)
		{
			this.PlayEventInterval=window.setInterval
			(
				function()
				{
					var playerObject=$('#MediaPlayerObject').get(0);
					
					if(playerObject)
					{
						if(Application.MediaPlayerManager.PlayEventId != Application.MediaPlayerManager.playStateManage(playerObject.playState))
						{
							gemiusStream.event(Application.MediaPlayerManager.PlayerId, Application.MediaPlayerManager.MaterialId, Application.MediaPlayerManager.GetTimer(), Application.MediaPlayerManager.playStateManage(playerObject.playState));
							Application.MediaPlayerManager.PlayEventId = Application.MediaPlayerManager.playStateManage(playerObject.playState);
						}
					}
				},500
			);
		}
		else
		{
			gemiusStream.event(Application.MediaPlayerManager.PlayerId, Application.MediaPlayerManager.MaterialId, Application.MediaPlayerManager.GetTimer(), 'playing');
		}
	},
	
	StopEvent : function()
	{
		gemiusStream.event(Application.MediaPlayerManager.PlayerId, Application.MediaPlayerManager.MaterialId, Application.MediaPlayerManager.GetTimer(), 'stopped');
	},
	
	RunTimer : function()
	{
		Application.MediaPlayerManager.Timer=0;
		
		window.setInterval
		(
			function()
			{
				Application.MediaPlayerManager.Timer=Application.MediaPlayerManager.Timer+1;
			}
			,1000
		);
	},
	
	GetTimer : function()
	{
		return Application.MediaPlayerManager.Timer;
	},

	DetectBrowser : function()
	{
		var Return=new Object();

		if(navigator.userAgent.indexOf('MSIE')!=-1)
		{
			Return.Browser='MSIE';

			if(/MSIE[\s](\d+\.\d+)/.test(navigator.userAgent))
			{
				Return.Version=new Number(RegExp.$1)
			}
		}
		else if(navigator.userAgent.indexOf("Firefox")!=-1)
		{
			Return.Browser='Firefox';

			if(/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent))
			{
				Return.Version=new Number(RegExp.$1)
			}
		}
		else if(navigator.userAgent.indexOf("Opera")!=-1)
		{
			Return.Browser='Opera';

			if(/Opera[\/\s](\d+\.\d+)/.test(navigator.userAgent))
			{
				Return.Version=new Number(RegExp.$1)
			}
		}
		else if(navigator.userAgent.indexOf("Chrome")!=-1)
		{
			Return.Browser='Chrome';

			if(/Opera[\/\s](\d+\.\d+)/.test(navigator.userAgent))
			{
				Return.Version=new Number(RegExp.$1)
			}
		}
		else if(navigator.userAgent.indexOf("AppleWebKit")!=-1)
		{
			Return.Browser='Safari';

			if(/AppleWebKit[\/\s](\d+\.\d+)/.test(navigator.userAgent))
			{
				Return.Version=new Number(RegExp.$1)
			}
		}

		return Return;
	},

	DetectPlayer : function()
	{
		if(this.Browser.Browser=='MSIE')
		{
			return true;
		}

		if(Application.Tools.isMacOS()) {
			codecFile = 'Flip4Mac';
		} else {
			codecFile = 'np-mswmp.dll';
		}

		for(var i=0;i<navigator.plugins.length;i++)
		{
			if(navigator.plugins[i].filename.indexOf(codecFile)!=-1)
			{
				return true;
			}
		}

		return false;
	},

	createElementParam : function(name, value, parent)
	{
		var elementParam = document.createElement("param");
		elementParam.setAttribute("name", name);
		elementParam.setAttribute("value", value);
		parent.appendChild(elementParam);
	},

	CleanContent : function()
	{
		$('#MediaPlayer').children().remove();
	},

	DrawPicture : function()
	{
		var ImageElement=$('<img>');
		ImageElement.attr('src',this.Image);
		ImageElement.attr('vspace','55');

		this.Stop();
		this.CleanContent();

		$('#MediaPlayer').append(ImageElement);
		$('#Play').attr('class','Play');
		$('#Play').unbind('click');
		$('#Play').bind('click',function(){ 
			Application.MediaPlayerManager.DrawPlayer();
			Application.KropkaManager.setEvent('userplay',0,0,'MediaPlayer','Stream',0);
			Application.MediaPlayerManager.PlayEvent();
		});
	},
	
	DrawPlayer : function()
	{
		if(this.Browser.Browser=='MSIE')
		{
			var PlayerElement = document.createElement('object');

			this.createElementParam('url', this.Media, PlayerElement);
			this.createElementParam('autostart', 'true', PlayerElement);
			this.createElementParam('uimode', 'none', PlayerElement);
			this.createElementParam('volume', '100', PlayerElement);

			PlayerElement.setAttribute('id', 'MediaPlayerObject');
			PlayerElement.setAttribute('classid','clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6');
			PlayerElement.setAttribute('type', 'application/x-oleobject');

		}
		else if(this.Browser.Browser=='Firefox' && this.MPlayerSupport)
		{
			var PlayerElement = document.createElement('embed');

			PlayerElement.setAttribute('id','MediaPlayerObject');
			PlayerElement.setAttribute('type','application/x-ms-wmp');
			PlayerElement.setAttribute('pluginspage','http://www.microsoft.com/Windows/MediaPlayer/');
			PlayerElement.setAttribute('url', this.Media);
			PlayerElement.setAttribute('autostart','true');
			PlayerElement.setAttribute('volume','100');
			PlayerElement.setAttribute('uimode','none');
			PlayerElement.setAttribute('showcontrols','0');
		}
		else if(this.Browser.Browser=='Chrome' || this.Browser.Browser=='Safari' || this.Browser.Browser=='Opera')
		{
			var PlayerElement = document.createElement('object');

			this.createElementParam('url', this.Media, PlayerElement);
			this.createElementParam('autostart', 'true', PlayerElement);
			this.createElementParam('uimode', 'none', PlayerElement);
			this.createElementParam('volume', '100', PlayerElement);

			PlayerElement.setAttribute('id', 'MediaPlayerObject');
			PlayerElement.setAttribute('type', 'application/x-ms-wmp');
			
		}
		else
		{
			var PlayerElement = document.createElement('embed');

			PlayerElement.setAttribute('id','MediaPlayerObject');
			PlayerElement.setAttribute('type','application/x-mplayer2');
			PlayerElement.setAttribute('pluginspage','http://www.microsoft.com/Windows/MediaPlayer/');
			PlayerElement.setAttribute('src', this.Media);
			PlayerElement.setAttribute('autostart','1');
			PlayerElement.setAttribute('volume','100');
			PlayerElement.setAttribute('uiMode','none');
			PlayerElement.setAttribute('showcontrols','0');
		}

		this.CleanContent();
		
		$('#MediaPlayer').get(0).appendChild(PlayerElement);
		$('#Play').attr('class','Stop');
		$('#Play').unbind('click');
		$('#Play').bind('click',function(){ 
			Application.MediaPlayerManager.DrawPicture();
			Application.KropkaManager.setEvent('userstop',0,0,'MediaPlayer','Stream',0);
			Application.MediaPlayerManager.StopEvent();
		});
	},

	DrawControls : function()
	{
		var Element;
		Element=$('<div>');
		Element.attr('class','Play');
		Element.attr('id','Play');
		$('#Controls').append(Element);

		Element=$('<div>');
		Element.attr('class','ProgressBar');
		$('#Controls').append(Element);

		if(this.MPlayerSupport)
		{
			Element=$('<div>');
			Element.attr('class','Mute');
			Element.attr('id','Mute');
			$('#Controls').append(Element);

			Element=$('<div>');
			Element.attr('class','FullScreen');
			Element.attr('id','FullScreen');
			$('#Controls').append(Element);
		}
	},

	HidePlayer : function()
	{
		if($('#MediaPlayerObject'))
		{
			$('#MediaPlayerObject').css('visibility','hidden');
		}
	},
	
	ShowPlayer : function()
	{
		if($('#MediaPlayerObject'))
		{
			$('#MediaPlayerObject').css('visibility','visible');
		}
	},
	
	HideControls : function()
	{
		if($('#Controls'))
		{
			$('#Controls').css('visibility','hidden');
		}
	},

	ShowControls : function()
	{
		if($('#Controls'))
		{
			$('#Controls').css('visibility','visible');
		}
	},

	Mute : function()
	{
		if(this.MPlayerSupport && $('#MediaPlayerObject').get(0))
		{
			if($('#MediaPlayerObject').get(0).settings.mute)
			{
				$('#MediaPlayerObject').get(0).settings.mute=false;
			}
			else
			{
				$('#MediaPlayerObject').get(0).settings.mute=true;
			}
		}
	},

	FullScreen : function()
	{
		if(this.MPlayerSupport && $('#MediaPlayerObject').get(0))
		{
			$('#MediaPlayerObject').get(0).fullScreen=true;
		}
	},

	Stop : function()
	{
		if($('#MediaPlayerObject').get(0))
		{
			if(this.MPlayerSupport)
			{
				$('#MediaPlayerObject').get(0).controls.stop();
			}
			else
			{
				$('#MediaPlayerObject').get(0).src='';
			}

			$('#MediaPlayerObject').css('visibility','hidden');
		}
	}
}

Application.CategoriesManager=
{
	CategoryTime : '',
	CategoriesTime : '',

	Scroller : 
	{
		init : function()
		{
			this.Box=$('#scrollbox');
			this.Total=0;
			this.Refresh=100000;
			this.Next=0;
			this.Progress=1;
			this.Jump=15;
			this.Speed=50;
			this.Stop=2000;
			this.Interval;
			this.Timeout;
		},

		LoadNewsBoxContent : function()
		{
			var i=this;
			i.GetNewsBoxContent();
			window.setInterval(function(){ i.GetNewsBoxContent(); },i.Refresh);
		},

		GetNewsBoxContent : function()
		{
			var i = this;

			$.ajax
	  		(
				{
					dataType	:	'text',
					type		:	'get',
					url			:	Application.urlService+'/messageslist.json',
					success		:	function(text){ i.DrawNewsBoxContent(eval(text)); }
				}
			);
		},

		DrawNewsBoxContent : function(Messages)
		{
			var Item='';
			var First='';

			this.Total=Messages.length;
			
			if(this.Box)
			{
				for(var i=0;i<this.Total;i++)
				{
					var Item;
					
					if(Messages[i].Priority)
					{
						Item=$('<a>');
						Item.attr('class','Priority');
						Item.attr('href',Messages[i].Url);
						Item.html(Messages[i].Title);
					}
					else
					{
						Item=$('<a>');
						Item.attr('class','Normal');
						Item.attr('href',Messages[i].Url);
						Item.html(Messages[i].Title);
					}
		
					if(!i)
					{
						First=Item;
						this.Box.children().remove();
						this.Box.append(Item);
					}
					else
					{
						this.Box.append(Item);
					}
				}
		
				this.Box.scrollTop(0);
				this.Next=0;
				this.Box.append(First);
			}
		},

		StartScroller : function()
		{
			var i = this;

			this.Interval=window.setInterval( function(){ i.ScrollNewsBox(); },i.Speed );
		},

		StopScroller : function()
		{
			window.clearInterval(this.Interval);
		},

		TimeOutScroller : function()
		{
	      var i = this;
	      this.Timeout=window.setTimeout( function(){ i.StartScroller(); },i.Stop );
		},

		ScrollNewsBox : function()
		{
			if(this.Box)
			{
				var Position=this.Box.get(0).scrollTop;
				var Max=this.Box.get(0).scrollHeight;
				if(Position<Max && Position<this.Next*this.Jump)
				{
					this.Box.get(0).scrollTop=Position+this.Progress;
				}
				else if(Position==this.Next*this.Jump)
				{
					this.Next<this.Total ? this.Next++ : this.Next=0;
					if(this.Next!=0)
					{
						this.StopScroller();
						this.TimeOutScroller();
					}
				}
				else
				{
					this.Box.get(0).scrollTop=0;
				}
			}
		}
	},

	SetTimeCategories : function(id)
	{
		i=this;
		this.CategoriesTime=window.setTimeout(function(){ i.ShowHideCategory(id); },1000);
	},

	ClearTimeCategories : function()
	{
		i=this;
		window.clearTimeout(i.CategoriesTime);
	},

	SetTimeCategory : function(id)
	{
		i=this;
		this.CategoryTime=window.setTimeout(function(){ i.ShowHideCategory(id); },1000);
	},

	ClearTimeCategory : function()
	{
		i=this;
		window.clearTimeout(i.CategoryTime);
	},

	SetPlace : function(id)
	{
		var Position=parseInt($('#cat_'+id).offset().left/100);

		if(id==1)
		{
			$('#cat_detail_'+id).css('top','35px');
		}

		if(Position==1)
		{
			$('#cat_detail_'+id).css('left','7px');
		}
		else if(Position==4)
		{
			$('#cat_detail_'+id).css('left','67px');
		}
		else
		{
			$('#cat_detail_'+id).css('left','126px');
		}
	},
	
	ShowHideCategory : function(id)
	{
		for(var i=0;i<Categories.length;i++)
		{
			if(Categories[i]==id)
			{
				this.SetPlace(Categories[i]);
				this.ShowCategory(Categories[i]);
			}
			else
			{
				this.HideCategory(Categories[i]);
			}
		}
	},

	ShowCategory : function(id)
	{
		if($('#cat_detail_'+id))
		{
			$('#cat_detail_'+id).show();
		}
	},

	HideCategory : function(id)
	{
		if($('#cat_detail_'+id))
		{
			$('#cat_detail_'+id).hide();
		}
	}
}

Application.Misc.showDescription=function()
{
	$('#streamtop1').hide();
	$('#streamtop2').show();

	window.setTimeout(function(){ Application.Misc.showTitle() },10000)
}

Application.Misc.showTitle=function()
{
	$('#streamtop1').show();
	$('#streamtop2').hide();
}

Application.WindowsManager.HelpItems = null;
Application.WindowsManager.RegItems = null;

Application.WindowsManager.Items.send=
{
	content : '<div class="mdHCnt"><h2><a href="#" title="onet.tv - strona główna">onet.pl</a></h2><h3 class="send">WYŚLIJ WIADOMOŚĆ</h3></div><div class="line"></div><form action="" method="post" id="sendform"><p class="senddescription">Tytuł</p><input class="sendtitle" id="sendtitle" name="sendtitle" type="text" /><p class="senddescription">Treść</p><textarea class="sendcontent" id="sendcontent" name="sendcontent"></textarea></form>',
	buttons : '<div class="mdBBar"><a class="btn btn_a" id="anuluj" href="#">Anuluj</a> <a class="btn btn_b" id="wyslij" href="#">Wyślij</a></div>',
		
	properties :
	{
		modal : true,
		width : 635,
		dialogClass : 'send',
		close : function()
		{
			Application.WindowsManager.closeWindow();
		}
	},
	
	init : function(obj)
	{
		$('#anuluj').bind
		(
			'click', function()
			{
				Application.WindowsManager.closeWindow();
			}
		);
		
		$('#wyslij').bind
		(
			'click', function()
			{
				Application.MailManager.sendMail();
				
				return false;
			}
		);
	}
}

Application.WindowsManager.Items.regulations=
{
	content : '<div class="mdHCnt"><h2><a href="#" title="onet.tv - strona główna">onet.pl</a></h2><h3>REGULAMIN</h3></div><div class="mdCCnt"><div class="mdCReg" id="reg_content"></div><div id="regloader"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="64" height="64"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="_s/flash/preloader.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><param name="wmode" value="transparent" /><embed src="_s/flash/preloader.swf" quality="high" bgcolor="#000000" width="64" height="64" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" wmode="transparent" /></object></div></div>',
	buttons : '<div class="mdBBar"><a class="btn btn_a" id="anuluj" href="#">Zamknij</a></div>',
	
	properties :
	{
		modal : true,
		width : 635,
		dialogClass : 'regulations',
		close : function()
		{
			Application.WindowsManager.closeWindow();
		}
	},

	init : function()
	{
		Application.WindowsManager.Regulations.getRegArticle();
		
		$('#anuluj').bind
		(
			'click', function()
			{
				Application.WindowsManager.closeWindow();
			}
		);
	}
}

Application.WindowsManager.Items.help=
{
	content : '<div class="mdHCnt"><h2><a href="#" title="onet.tv - strona główna">onet.pl</a></h2><h3 class="hlp">POMOC</h3><div id="help_content"></div><div id="helploader"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="64" height="64"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="_s/flash/preloader.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><param name="wmode" value="transparent" /><embed src="_s/flash/preloader.swf" quality="high" bgcolor="#000000" width="64" height="64" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" wmode="transparent" /></object></div></div>',
	
	buttons : '<div class="mdBBar"><a class="btn btn_a" id="anuluj" href="#">Zamknij</a></div>',
		
	properties :
	{
		modal : true,
		width : 635,
		dialogClass : 'help',
		close : function()
		{
			Application.WindowsManager.closeWindow();
		}
	},
	
	init : function()
	{
		Application.WindowsManager.Help.getHelpArticle();
		$('#anuluj').bind
		(
			'click', function()
			{
				Application.WindowsManager.closeWindow();
			}
		);
	}
}

Application.WindowsManager.Help=
{
	getHelpArticle : function(oid)
	{
		$.ajax
		(
			{
				dataType	:	'text',
				url			:	Application.urlService+'/pomoc.json',
				type		:	'get',
				success		:	function(text) { HelpItems=eval('('+text+')');$('#helploader').hide();$('#help_content').show();Application.WindowsManager.Help.showTitles();Application.WindowsManager.Help.showChapter(0); }
			}
		);
	},
	
	showTitles : function()
	{
		var html='';

		html+='<div class="mdCCnt">';
		html+='<div class="mdCHlpLst">';
		html+='<ul>';
		for (var i = 0; i < HelpItems.length; i++)
		{
			html+='<li><a id="link_'+i+'" href="javascript:Application.WindowsManager.Help.showChapter('+i+')">'+HelpItems[i].title+'</a></li>';
		}
		html+='</ul>';
		html+='</div>';
		html+='<div class="mdCHlp" id="help_chapter"></div>';
		html+='</div>';

		$('#help_content').html(html);
	},

	showChapter : function(id)
	{
		for (var i = 0; i < HelpItems.length; i++)
		{
			if(i==id)
			{
				$('#link_'+i).attr('class','sel');
			}
			else
			{
				$('#link_'+i).attr('class','');
			}
		}

		if(HelpItems[id])
		{
			$('#help_chapter').html(HelpItems[id].content);
			$("#help_chapter").scrollTop=0;
		}
	}
}

Application.WindowsManager.Regulations=
{
	getRegArticle : function()
	{
		$.ajax
		(
			{
				dataType	:	'text',
				type		:	'get',
				url			:	Application.urlService+'/regulations.json',
				success		:	function(text) { $('#regloader').hide();$('#reg_content').show();RegItems=eval('('+text+')');$('#reg_content').html(RegItems[0].content); }
			}
		);
	}
}

Application.MailManager=
{
	sentMail : function(status)
	{
		if(status==1)
		{
			$('#sendform').html('<p class="sent">Twoja wiadomość została wysłana.</p>');
		}
		else
		{
			$('#sendform').html('<p class="senderror">Wystąpił problem przy wysyłaniu wiadomości.<br />Spróbuj ponownie.</p>');
		}

		$('#wyslij').hide();
		$('#anuluj').html('OK');
	},

	setMail : function()
	{
		Mail=this.getMail();
		if (Mail)
		{
			$('#user').html(Mail); 
			$('#log').show();
			$('#no_log').hide();
		}
	},
	
	getMail : function()
	{
		var Result='';
		
		if (Application.Tools.Cookie.readCookie("onet_uid"))
		{
			var EmailRegEx = /^([a-zA-Z0-9])([a-zA-Z0-9\._-])*@(([a-zA-Z0-9])+(\.))+([a-zA-Z]{2,4})+$/ ;
			var Mail = Application.Tools.Cookie.readCookie("onet_uid");
			if(Mail.search(EmailRegEx)==-1)
			{
				Result=Mail.replace(/%40/,"@");;
			}
		}
		
		return Result;
	},

	sendMail : function()
	{
		Mail=this.getMail();
		
		if(!Mail)
		{
			Mail='user@onet.tv';
		}
		
		$.ajax
		(
			{
				dataType	:	'text',
				method      :	'post',
				url			:	Application.urlService+'/send.json',
				data		:
				{
					subject	:	$('#sendtitle').attr('value'),
					body	:	$('#sendcontent').attr('value'),
					from	:	Mail,
					to		:	'redakcja_tv@portal.onet.pl'
				},
				success		:	function(text){ Application.MailManager.sentMail(text); },
				fail		:	function(text){ Application.MailManager.sentMail(0); }
			}
		);
	}
}
