var twYouTube = {
	dados : [],
	config : {
		player : {
			scrolling : null,
			htmlSource : '<object width="[width]" height="[height]"><param name="movie" value="http://www.youtube.com/v/[videoID]&hl=pt-br&fs=1&rel=0&color1=0x3a3a3a&color2=0x999999"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/[videoID]&hl=pt-br&fs=1&rel=0&color1=0x3a3a3a&color2=0x999999" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="[width]" height="[height]"></embed></object>[label]',
			divID : 'divYouTubePlayer',
			width : 480,
			height : 385
		},
		thumbs : {
			htmlSource : '<div style="background-color:white; border: 1px black solid; float:left; margin: 5px;"><a href="javascript:twYouTube.player.show(\'[videoID]\');"><div style="position:relative; display:block; padding:3px"><img src="http://img.youtube.com/vi/[videoID]/0.jpg" width="128" height="96" border="0"/><img src="/Prs/Img/Ft/youtube.png" width="128" height="96" style="position: absolute; top: 3px; left: 3px;" border="0" alt="Clique para ver o video" title="Clique para ver o video" /></div></a>[label]</div>',
			divID : 'divYouTubeThumbs'
		},
		redirect : null
	},
	player : {
		show : function(videoID){
			if(twYouTube.config.redirect!=null){
				document.location = twYouTube.config.redirect+'&q='+videoID;
			} else {
				var label = '';
				for(var x = 0; x < twYouTube.dados.length; x++){
					if(twYouTube.dados[x].videoID==videoID){
						label = twYouTube.dados[x].label;
						if(label.length > 0){ label = '<br />' + label }
						break;
					}
				}
				var htm = twYouTube.config.player.htmlSource;
				while(htm.indexOf('[width]')>=0){ htm = htm.replace('[width]', twYouTube.config.player.width); }
				while(htm.indexOf('[height]')>=0){ htm = htm.replace('[height]', twYouTube.config.player.height); }
				while(htm.indexOf('[videoID]')>=0){ htm = htm.replace('[videoID]', videoID); }
				while(htm.indexOf('[label]')>=0){ htm = htm.replace('[label]', label); }
				document.getElementById(twYouTube.config.player.divID).innerHTML = htm;
				if(twYouTube.config.player.scrolling!=null){
					window.scroll(0, twYouTube.config.player.scrolling);
				}
			}
		}
	},
	thumbs : {
		bind : function(){
			var htmFull = '';
			for(var x = 0; x < twYouTube.dados.length; x++){
				var htm = twYouTube.config.thumbs.htmlSource;
				while(htm.indexOf('[videoID]')>=0){ htm = htm.replace('[videoID]', twYouTube.dados[x].videoID); }
				while(htm.indexOf('[label]')>=0){ htm = htm.replace('[label]', twYouTube.dados[x].label); }
				htmFull += htm;
			}
			document.getElementById(twYouTube.config.thumbs.divID).innerHTML = htmFull;
		}
	},
	bind : function(options){
		if(typeof(options)!='undefined'){
			if(typeof(options.playerID)=='string'){ twYouTube.config.player.divID = options.playerID; }
			if(typeof(options.thumbsID)=='string'){ twYouTube.config.thumbs.divID = options.thumbsID; }
		}
		twYouTube.thumbs.bind();
	},
	adicionar : function(videoID, label){
		if(typeof(label)!='string'){ label = ''; }
		twYouTube.dados[twYouTube.dados.length] = {
			'videoID' : videoID,
			'label' : label
		};
	}
}
