/**
 * Klasa do obslugi Video
 */
var	Video = {

	youtubevideo: "",
	ytplayer: "",
	currentTab: false,
	playerOptions: {
		videoName: "",
		videoDiv: "you_tube_player",
		boxWidth: 480,
		boxHeight: 385,
		hl: "pl",
		play: 0,
		rel: 0,
		color1: "0x888888",
		color2: "0xDDDDDD",
		disablekb: 1,
  		egm: 0,
  		fs: 1,
  		hd: 1,
  		showsearch: 0,
  		showinfo: 1
	},

	onYouTubePlayerReady: function(playerId) 
	{
		ytplayer = $('ytapiplayer');
	},

	playVideo: function(params) 
	{
		var iloscWyswietlen = params.iloscWyswietlen;
		var video = params.video;
		var videoDiv = params.videoDiv;
		Common.Loader.open();
		var ajaxObj = new Ajax.Request('/video,ajax-data',
				{
					method: 'post',
					parameters : { id: params.inwestycjaId },
					onSuccess: function(transport){
						Common.Loader.destroy();
						var resTable = transport.responseText.evalJSON();
						$('video_opis_inw').innerHTML = resTable[0].opisTekst;
						$('video_title').innerHTML = '<h1>' + resTable[0].inwestycjaNazwa + '</h1>';
						$('video_link').href = resTable[0].link + '?clear';
						if (Object.isElement($('video_ilosc_wyswietlen'))) {
							$('video_ilosc_wyswietlen').innerHTML = iloscWyswietlen;
						}
						Video.displayMultimedia({videoName: video, videoDiv: videoDiv, play: 1});
					},
					onFailure: function(){
						Common.Loader.destroy();;
						alert('Something went wrong...')
						}
					
				}
			);
		
	},

	playerStart: function(ytplayer) 
	{
		if (ytplayer) {
			ytplayer.playVideo();
		}
	},

	playerPause: function(ytplayer) 
	{
		if (ytplayer) {
			ytplayer.pauseVideo();
		}
	},
	
	displayMultimedia: function(curOptions)
	{
		Object.extend(this.playerOptions, curOptions);
		if ( typeof youtubevideo == "undefined") {
	
			var flashvars = {
		  		enablejsapi: 1,
		  		playerapiid: "ytplayer",
		  		hl: this.playerOptions.hl,
		  		autoplay: this.playerOptions.play,
		  		rel: this.playerOptions.rel,
		  		color1: this.playerOptions.color1,
		  		color2: this.playerOptions.color2,
		  		disablekb: this.playerOptions.disablekb,
		  		egm: this.playerOptions.egm,
		  		fs: this.playerOptions.fs,
		  		hd: this.playerOptions.hd,
		  		showsearch: this.playerOptions.showsearch,
		  		showinfo: this.playerOptions.showinfo
			};
			var params = {
		  		allowScriptAccess: "always",
		  		wmode: "opaque"
			};
			if ( typeof youtubevideo == "undefined") {
				swfobject.embedSWF("http://www.youtube.com/v/" + this.playerOptions.videoName, this.playerOptions.videoDiv, this.playerOptions.boxWidth, this.playerOptions.boxHeight, "9.0.0","false", flashvars, params);
			} else {
				var youtubevideo = "";
				swfobject.embedSWF("http://www.youtube.com/v/" + this.playerOptions.videoName, this.playerOptions.videoDiv, this.playerOptions.boxWidth, this.playerOptions.boxHeight, "9.0.0","false", flashvars, params);
			}					
		}
	},
	
	fillMiejscowosci: function(params)
	{
		
		var ajaxObj = new Ajax.Request('/video,ajax-lista-miejscowosci',
			{
			method: 'post',
			parameters : params,
			onSuccess: function(transport){
				var resTable = transport.responseText.evalJSON();
				Common.Form.clearSelect($('videoMiejscowsci'), true);
				Common.Form.fillSelect($('videoMiejscowsci'), resTable);
			},
			onFailure: function(){
				alert('Something went wrong...')
				}
			
		});
		
	},
	
	addTabsObservers: function()
	{
		if (Object.isElement($('videoTabMieszkania'))) {
			Event.observe($('videoTabMieszkania'), 'click', function(event) {
				if (Object.isElement($('videoTabDomy')))
					$('videoTabDomy').className = 'msz_video2';
				if (Object.isElement($('videoTabApartamenty')))
					$('videoTabApartamenty').className = 'msz_video3';
				$('videoTabMieszkania').className = 'msz_video1 msz_sel';
				Video.fillData({typ: 'mieszkanie', klasa: '_apartament.loft.penthouse.mieszkanie_wysoki_standard'});
				Video.fillMiejscowosci({typ: 'mieszkanie', klasa: '_apartament.loft.penthouse.mieszkanie_wysoki_standard'});
				Video.currentTab = 'mieszkanie';
			});
		}
		if (Object.isElement($('videoTabDomy'))) {
			Event.observe($('videoTabDomy'), 'click', function(event) {
				if (Object.isElement($('videoTabApartamenty')))
					$('videoTabApartamenty').className = 'msz_video3';
				if (Object.isElement($('videoTabMieszkania')))
					$('videoTabMieszkania').className = 'msz_video1';
				$('videoTabDomy').className = 'msz_video2 msz_sel';
				Video.fillData({typ: 'dom', klasa: '_apartament.loft.penthouse.mieszkanie_wysoki_standard'});
				Video.fillMiejscowosci({typ: 'dom', klasa: '_apartament.loft.penthouse.mieszkanie_wysoki_standard'});
				Video.currentTab = 'dom';
			});
		}
		if (Object.isElement($('videoTabApartamenty'))) {
			Event.observe($('videoTabApartamenty'), 'click', function(event) {
				if (Object.isElement($('videoTabDomy')))
					$('videoTabDomy').className = 'msz_video2';
				if (Object.isElement($('videoTabMieszkania')))
					$('videoTabMieszkania').className = 'msz_video1';
				$('videoTabApartamenty').className = 'msz_video3 msz_sel';
				Video.fillData({typ: 'apartament.loft.penthouse.mieszkanie_wysoki_standard'});
				Video.fillMiejscowosci({typ: 'apartament.loft.penthouse.mieszkanie_wysoki_standard'});
				Video.currentTab = 'apartament.loft.penthouse.mieszkanie_wysoki_standard';
			});
		}
		
	},
	
	fillData: function(params)
	{
		Common.Loader.open();
		var ajaxObj = new Ajax.Request('/video,ajax-lista',
				{
				method: 'post',
				parameters : params,
				onSuccess: function(transport){
					//var resTable = transport.responseText.evalJSON();
					Common.Loader.destroy();
					$('videoLista').innerHTML = transport.responseText;
					//alert(transport.responseText);
				},
				onFailure: function(){
					Common.Loader.destroy();
					alert('Something went wrong...')
				}
				
			});
	},
	
	addMiejscowosciObservers: function()
	{
		
		Event.observe($('videoMiejscowsci'), 'change', function(event) {
			var optionClicked = Event.element(event);
			Video.fillData({ typ: Video.currentTab, miejscowosc: optionClicked.value });
		});
		
	}
	
}