// JavaScript Document

function playerControl(){
	this.zeit = 0; //aktuelle position
	this.duration = 0; //innerhalb die Dauer
	this.pduration = 0;  
	this.pinterval = null;
	this.percent = 0;
	this.bytesloaded = 0;
	this.bytestotal = 0;
	this.bytesstart = 0;
	this.bytes_loaded = -1;
	this.ptime = 0;
	this.pressed = false;
	this.addtolisten = true;
	this.noinfo = false;
	this.pcurrent = 0;
	this.hd = 0;
	this.repeatone = false;
	this.repeat = false;
	this.shuffle = false;
	this.size = new Object();
	this.size.x = 425;
	this.size.y = 344;
	this.rel = 425 / 344;
	this.listen = listen;
	this.video_visible = false;
	this.videos_searched = false;
	this.full_screen = false;
	this.down = 0;
	this.stille = false;
	this.silencing = {
		"active" : false,
		"mute": 0,
		"marker": $("#silencer"),
		"btn": $("#silenceBtn"),
		"m": $("#silence-m"),
		"cont": $("#silence-2"),
		"cancel": $(".silence-cancel"),
		"none" : $("#silence-none"),
		"ok" : $("#silence-ok"),
		"can" : true
	}
	this.silencing.marker.mousedown(function(event){
		pc.pressed = false;
		event.stopImmediatePropagation();
		event.stopPropagation();
		$(this).toggleClass("silencer-deactivate");
		pc.silencing.can = !$(this).hasClass("silencer-deactivate");
	});
	this.setSilence = function(){
			pc.silencing.cont.show();
			pc.silencing.active = true;
			var pos = player.getCurrentTime();
			pc.silencing.mute = pos;
			pc.silencing.m.html(__("silenceat", pc.secsToString(pos)));
			pc.silencing.btn.html(__("abort"));
			pc.silencing.btn.parent(':first').width(pc.silencing.btn.width());
			pc.silencing.btn.addClass("silence-cancel");
			pc.silencing.cont.css("visibility", "visible");
			pc.silencing.none.one("click", function(){ 
				pc.silencing.mute = 0; 
				pc.silencing.cancel.unbind();
				pc.silencing.ok.unbind();
				pc.silencing.none.unbind();
				pc.silencing.btn.unbind();				
				pc.silencing.active = false;
				pc.silencing.cont.css("visibility", "hidden");
				pc.silencing.btn.html(__("silence"));
				pc.silencing.btn.parent(':first').width(pc.silencing.btn.width());
				pc.silencing.btn.one("click", function(){ pc.setSilence(); })
				if(pc.stille != false)
				requestP({"a" : "silence", "m" : "video", "video": pc.getVideoID(), "mute" : 0});
				pc.setStille(0, pc.duration);
			});
			$("#silence-ok,.silence-cancel").one("click", function(){
				pc.silencing.cancel.unbind();
				pc.silencing.ok.unbind();
				pc.silencing.none.unbind();
				pc.silencing.btn.unbind();
				pc.silencing.active = false;
				pc.silencing.cont.css("visibility", "hidden");
				pc.silencing.btn.html(__("silence"));
				pc.silencing.btn.parent(':first').width(pc.silencing.btn.width());				
				pc.silencing.btn.one("click", function(){ pc.setSilence(); })
				if($(this).hasClass("silence-cancel")) return pc.silencing.btn.removeClass("silence-cancel");
				pc.silencing.btn.removeClass("silence-cancel");
				pc.silencing.btn.parent(':first').width(pc.silencing.btn.width());
				requestP({"a" : "silence", "m" : "video", "video": pc.getVideoID(), "mute" : Math.round(pc.silencing.mute) });
				pc.setStille(Math.round(pc.silencing.mute), pc.duration);
			});
	}
	
	this.setStille = function(stille, dauer){
		this.stille = stille;
		if(!stille || stille == 0) pc.silencing.marker.hide(); else {
			pc.silencing.marker.show();
			var pos = Math.round((stille / dauer) * pc.bwidth) - pc.bytesstart;
			pc.silencing.marker.css("margin-left", pos);
		}
	}
	
	this.getVideoID = function(){
		if(!player) return "";
		var id = player.getVideoUrl().match(/v\=([^\&]*)/);
		return id[1];
	}
	this.getVideoName = function(){
		return $(".echovid[v='"+this.getVideoID()+"']").text();
	}
	
	this.bar = $("#bar");
	this.vbar = $("#vbar");
	this.vbar_vol = $("#vbar_vol");
	this.silencer = $("#silencer");
	this.bwidth = this.bar.width();
	this.bar.mousedown(function(event){bdown(event, this)});
	this.bar.mouseup(function(event){bup(event, this)});
	this.bar.mousemove(function(event){bmove(event, this)});
	
	this.vbar.mousedown(function(event){bdown(event, this)});
	this.vbar.mouseup(function(event){vup(event, this)});
	this.vbar.mousemove(function(event){vmove(event, this)});

	this.slider = $("#slider");
	this.bloaded = $("#bloaded");
	this.bplayed = $("#bplayed");
	this.timelabel = $("#timelabel");
	
	this.setUpdate = function(value){
		if(!value) window.clearInterval(this.pinterval); else
		this.pinterval = window.setInterval(this.updatePlayer, 200);
	}
	//test = true;
	this.updatePlayer = function(){
		if(player == null) return;
		if(!lta.loaded.listen && pc.duration > 0 && lta.loaded.infos && player_is("playing")) pc.listen(-1);
		
		pc.bytestotal = player.getVideoBytesTotal();
		pc.bytes_loaded = player.getVideoBytesLoaded();
		if(pc.bytes_loaded < 0) pc.bytesloaded = 0; else
		pc.bytesloaded = Math.round((pc.bytes_loaded / pc.bytestotal) * pc.bwidth);
		pc.bytesstart = Math.round((player.getVideoStartBytes() / pc.bytestotal) * pc.bwidth);
		pc.percent = player.getVideoStartBytes() / pc.bytestotal * 100;
		pc.pduration = player.getDuration();
		if(pc.pduration > 0) pc.duration = pc.pduration;
		pc.current = player.getCurrentTime();
		if(pc.current > 0) pc.zeit = pc.current;
		
		pc.ptime = Math.round((pc.current / pc.pduration) * pc.bwidth);
		/*if(test) {
			alert(pc.ptime + " : " + pc.duration + " : " + pc.pduration + " : " + player.getPlayerState() + " : " + player.getVideoBytesLoaded());
			test = false;
			window.setTimeout(function(){test = true;}, 2000);
		}*/
		pc.bplayed.css("width", pc.ptime - pc.bytesstart);
		pc.slider.css("margin-left", pc.ptime);
		pc.bloaded.css("width", pc.bytesloaded);
		pc.bloaded.css("margin-left", pc.bytesstart);
		
		pc.timelabel.html(pc.secsToString(pc.current) + "/" + pc.secsToString(pc.pduration));
		if(pc.silencing.active) pc.silencing.m.html(__("silenceat", pc.secsToString(pc.current)));
		
		if(pc.stille > 0 && pc.silencing.can) {
			if(pc.current - 5 >= pc.stille) pls.playI("next"); 
		}
		var newState = player.getPlayerState();
		if(newState == 1 || newState == 3) $(".playbtn").addClass("set");
		else $(".playbtn").removeClass("set");
		if(newState == 3 || newState == 5 || newState == -1 || pc.bytes_loaded < 0){
			pc.bar.addClass("bloading");
		} else pc.bar.removeClass("bloading");
	}
	
	this.secsToString = function(d){
		var cm = Math.floor(d / 60); 
		var cs = Math.floor(d % 60);
		if(cm < 0) cm = 0; 
		if(cs < 0) cs = 0;
		if(cs < 10) cs = "0"+cs;
		return cm+":"+cs;
	}

	this.setRepeat = function(val){
		this.repeat = val;
		if(val) $(".repeat").addClass("set"); else $(".repeat").removeClass("set");
	}
	this.setRepeatOne = function(val){
		this.repeatone = val;
		if(val) $(".repeatone").addClass("set"); else $(".repeatone").removeClass("set");
	}
	this.setShuffle = function(val){
		this.shuffle = val;
		if(val) $(".shuffle").addClass("set"); else $(".shuffle").removeClass("set");
	}
	
	this.videos = new function(){
		this.v = []; //Videos
		this.searched = false;
		this.play = 0;
		this.entries = []; //Von Youtube
		this.it = false;
		this.first = "";
		this.checking = false;
		this.download = {"url": "", "link": ""};
		
		this.getVids = function(q, it){
			q = q.replace(/\&/, "%26");
			if(!it) return this.novideofound(3);
			this.it = it;
			this.searched = false;
			var url = "http://gdata.youtube.com/feeds/api/videos?q=" + q +"&alt=json-in-script&orderby=relevance&format=5&callback=pc.videos.results";
			var head = document.getElementsByTagName('head')[0];
			script = document.createElement("script");
			script.setAttribute("type", "text/javascript");
			script.setAttribute("src", url);
			head.appendChild(script);
			this.checking = true;
		}

		this.novideofound = function(i, first){
			window.clearTimeout(lta.timer.video);
			if(first && this.it){
				this.it.attr("hasVideos", "no");
				this.it.addClass("no-video");
			}
			if(i >= 2) {
				lta.videopod.html("");
				pls.playI("next"); 
			} else {
				lta.videopod.html("<h3 class='error'>"+__("novideo") + " " + __("continuein", 2 - i)+"</h3>");
				lta.videolist.show();
				lta.tabs.show();
				lta.timer.video = window.setTimeout(function(){pc.videos.novideofound(i + 1)}, 1000);
			}
			this.checking = false;
		}
		
		this.rateRelevance = function(vidTitle, artist, track){
			var vt = trim(vidTitle.replace(/-|\s{2,}|[\(\)\[\]\"\'\+]/g, " ").toLowerCase());
			var s1 = vt.split(" ");
			var s = artist.replace(/-|\s{2,}|[\(\)\[\]\"\'\+]/g) + " " + track.replace(/-|\s{2,}|[\(\)\[\]\"\'\+]/g);
			var score = 0;
			for(var i in s1) {
				if(trim(s1[i]) == "") continue;
				if(s.indexOf(s1[i]) != -1) score++; else {
					if(s1[i].search(/unofficial|instrumental|acoustic|piano|karaoke|unoffiziell|cover|singing|live|festival|instrumental|tutorial|remix|chipmunk|parody|vivo|accapella/) != -1)  	
					score -= 2;
					else if(s1[i].search(/official|musikvideo|hd|hq|offiziell|lyric|high quality/) != -1) score++; 
					else score--;
					//println(i+": "+s1[i]+" - "+score);
				}
				//println(i+": "+s1[i]+" - "+score);
			}
			return score;
		}
		
		this.results = function(data){
			var video_entries = [];
			var found = false;
			if(data.feed) {
				var feed = data.feed;
				video_entries = feed.entry || [];
			} else {
				this.entries = data;
				this.searched = true;
				found = true;
			}
			
			var it = this.it;
			var track = this.it.attr("track").replace(/[\s]*(\([^\)]*\)|\[[^\]]*\])/g, "").toLowerCase();
			var s1 = track.split(" ");
			var artist = this.it.attr("artist").replace(/[\s]*(\([^\)]*\)|\[[^\]]*\])/g, "").toLowerCase();
			var limit = 0.7;
			if(s1.length < 3) limit = 0.5;
			if(!this.searched && it.attr("title").search(/(\[|\()/) != -1) {
					var q = it.attr("title").replace(/[\s]*(\([^\)]*\)|\[[^\]]*\]|\")/g, "");
					this.entries = video_entries;
					this.getVids(q, this.it);
					this.searched = true;
					return;
			} else if(!found) {
				if(!this.entries) this.entries = [];
				this.entries = this.entries.concat(video_entries);
				for(var i = 0; i < this.entries.length; i++) {
					this.entries[i].found = 0;
					for(var k in s1){
						if(this.entries[i].title.$t.toLowerCase().indexOf(s1[k]) != -1) {
							this.entries[i].found++;
						} 
					}
					if(this.entries[i].found / s1.length < limit){
						this.entries.splice(i, 1);
						i--;
					} else {
						this.entries[i].viewCount = 0;
						if(this.entries[i].yt$statistics) this.entries.viewCount = this.entries[i].yt$statistics.viewCount;
						
						this.entries[i].score = this.rateRelevance(this.entries[i].title.$t.toLowerCase(), artist, track);
						for(var j = i + 1; j < this.entries.length; j++) {
							if(this.entries[i].id.$t == this.entries[j].id.$t) {
								this.entries.splice(j, 1);
								j--;
							}
						}
					}
				}
			} else {
				for(var i = 0; i < this.entries.length; i++) 
				this.entries[i].score = this.rateRelevance(this.entries[i].title.$t.toLowerCase(), artist, track);
			}
		
			this.entries.sort(function(a, b) { 
				var dif = b.viewCount - a.viewCount;
				if(dif == 0) dif = b.score - a.score; 
				return dif;
			});
			var aktuell = pls.playitem.attr("video");
			this.v = [];
			this.play = -1;
			var id = 0;
			lta.videopod.html("");
			if(this.entries.length == 0) { 
				if((pls.repeat || pls.play < pls.anzahl() - 1) && this.it.attr("track") != "") 
				this.novideofound(0, true);
				toggleHeight(1);
				lta.playerpod.show();
				return; 
			} else {
				
			}
			
			if(aktuell) this.v = [aktuell]; else { 
				this.play = 0;
				found = true;
				var raus = false;
				do {
					if(this.play == this.entries.length) { found = false; raus = true; }
					id = this.entries[this.play].id.$t.split('/');
					id = id[id.length-1];
					this.play++;
				} while(user.hates.indexOf(id) !== -1 && !raus) 
				if(!found) this.novideofound(0, true);
				else {
					var echoed = id;
					echoVideo(id);
				}
			}
			var html = ['<ul>'];
			var klasse = "";
			var klasse2 = "blockvid";
			var ltitle = __("blockvideo");
			for (var i = 0; i < this.entries.length; i++) { 
				var entry = this.entries[i];
				var title = entry.title.$t;
				id = entry.id.$t.split('/');
				id = id[id.length-1];
				if(id != aktuell) this.v.push(id);
				if(user.hates.indexOf(id) !== -1) {
					klasse = " error"; 
					klasse2 = "unblockvid";
					ltitle = __("unblockvideo");
				} else {
					klasse = "";
					klasse2 = "blockvid";
					ltitle = __("blockvideo");
				}
				html.push('<li><span><a class="echovid'+klasse+'" v="'+id+'">', title, 
						  '</a><a title="'+ltitle+'" class="'+klasse2+'"></a></span></li>');
			}
			html.push('</ul>');
			var h = html.join("");
			lta.videopod.html(h);
			lta.videolist.show();
			var video_id = generateID();
			pls.videos.v[video_id] = copyArray(this.entries);
			this.it.attr("hasVideos", video_id);
			//if(!pc.video_visible) showTooltip($(".showvid"), __("click-for-video"), 4);
			//if(pls.playitem.attr("artist")) showTooltip(lta.videopod, __("select-video"), 4);
			this.checking = false;
			pls.videos.check();
			this.searched = false;
			this.entries = [];
			pc.videos.mark(pc.getVideoID());
		}
		
		this.getIndex = function(video){
			if(!this.v) return 0;
			for(var i = 0; i < this.v.length; i++)
			if(this.v[i] == video) return i;
			return 0;
		}
		
		this.deleteLink = function(video){
			if(this.v.length == 0) return;
			var ind = this.getIndex(video);
			this.v.splice(ind, 1);
			$(".echovid:eq("+ind+")", lta.videopod).remove();
		}
		this.next = function(hate){
			if(hate) $(".echovid[v='"+hate+"']").addClass("error");
			do {
				this.play++;
			} while(user.hates.indexOf(this.v[this.play]) !== -1 && this.play < this.v.length - 1)
			if(this.play >= this.v.length - 1) this.novideofound(0, true); else
			echoVideo(this.v[this.play]);
		}
		this.mark = function(v){
			$("span", "#videopod").removeClass("playing");
			$(".echovid[v='"+v+"']").parents(":first").addClass("playing");
			scroll_dom(lta.videolist, $(".echovid[v='"+v+"']").parents(":first"));
		}
		this.markHate = function(v, type, it){
			var ev = $(".echovid[v='"+v+"']");
			if(type == "not") {
				ev.removeClass("error");
				it.removeClass("unblockvid");
				it.addClass("blockvid");
				it.attr("title", __("blockvideo"));
			} else {
				ev.addClass("error");
				it.removeClass("blockvid");
				it.addClass("unblockvid");
				it.attr("title", __("unblockvideo"));
			}
		}
	}

	this.setUpdate(true);
}

function listen(percent){
	if(percent == -1 && lta.loaded.listen) return; else
	if(percent > 0 && !lta.loaded.listen) return;
	if(!pc.addtolisten) return;
	if(percent == -1) lta.loaded.listen = true;
	var p = {};
	p.a = "listen";
	p.video = pls.playitem.attr("video");
	p.name = pc.getVideoName();
	p.track = pls.playitem.attr("track");
	p.tags = pls.playitem.attr("tags");
	p.artist = pls.playitem.attr("artist");
	p.own = pls.playitem.attr("own");
	p.image = pls.playitem.attr("image");
	p.albums = pls.playitem.attr("albums");
	p.artistid = pls.playitem.attr("artistid");
	p.mbid = pls.playitem.attr("mbid");
	p.shuffle = pc.shuffle;
	p.repeat = pc.repeat;
	p.repeatone = pc.repeatone;
	p.play = pls.play;
	p.duration = pc.duration;
	p.percent = percent;
	requestP(p);
}

function video_changed(v, name){
	var p = {};
	p.shuffle = pc.shuffle;
	p.repeat = pc.repeat;
	p.repeatone = pc.repeatone;
	p.video = v;
	p.name = name;
	p.track = pls.playitem.attr("track");
	p.artist = pls.playitem.attr("artist");
	p.a = "video_changed";
	requestP(p);
}


function barSeek(event, it){
	var x = event.pageX - $(it).position().left - $("#tabs").position().left;
	var pos = Math.round((x / pc.bwidth) * pc.pduration);
	if(pc.silencing.active) {
		pc.silencing.mute = pos;
		pc.silencing.m.html(__("silenceat", pc.secsToString(pos)));
	}
	pc.updatePlayer();
	pc.bplayed.css("width", 0);
	player.seekTo(pos, true);
	pc.setUpdate(true);
	pc.updatePlayer();
	if(pc.stille) pc.setStille(pc.stille, pc.duration);
}

function bdown(e){
	pc.pressed = true;
}

function bup(e, it){
	if(!pc.pressed) return;
	pc.pressed = false;
	barSeek(e, it);
}

function bmove(e, it){
	if(!pc.pressed) return;
	pc.setUpdate(false);
	var x = e.pageX - $(it).position().left;
	pc.bplayed.css("width", x);
	pc.slider.css("margin-left", x);
	pc.bloaded.css("width", 0);
	pc.bloaded.css("margin-left", 0);
}

function setVolume(val, pos){
	if(!player) return;
	if(pos) {
		val = Math.round(pos / pc.vbar.width() * 100);
	}
	if(val == -1) val = player.getVolume();
	if(val > 100) val = 100; else
	if(val < 0) val = 0;
	if(val == 0) player.mute(); else
	if(player.isMuted) player.unMute();
	player.setVolume(val);
	var width = Math.round(pc.vbar.width() * val / 100);
	pc.vbar_vol.css("width", width+"px");
}

function vbarSeek(event, it){
	var x =  event.pageX - $(it).offset().left;
	setVolume(null, x);
}

function vup(e, it){
	pc.pressed = false;
	vbarSeek(e, it);
}

function vmove(e, it){
	if(!pc.pressed) return;
	var x = e.pageX - $(it).position().left;
	vbarSeek(e, it);
}

function togglePlay(){
	var state = player.getPlayerState();
	if(state == -1 || state == 1 || state == 3) { 
		player.pauseVideo(); 
	} else { 
		if(pls.ended) { 
			pls.playI("play");
			return;
		}
		if(state == 0) player.cueVideoById(pls.playitem.attr("video")); 
		player.playVideo(); 
	}
}

function onplayerStateChange(newState){
	//Possible values are unstarted (-1), ended (0), playing (1), paused (2), buffering (3), video cued (5). 
	if(newState == 0){
		$("#video-nav").hide();
		pc.listen(pc.zeit / pc.duration * 100);
		pc.setStille(0);
		/*d = getDuration() - 3;
		if(d > 0 && getCurrentTime() >= d) {*/
		if(pc.repeatone || (pc.repeat && pls.anzahl() == 1)) {  
			player.seekTo(0, true);
			pls.playI("play");
			lta.loaded.listen = false;
			pc.listen(-1);
			newState = 1;
		} else {
			pls.playI("next");
		}
		//} 
	} else 
	if(!pc.full_screen) $("#video-nav").show();

	if(newState == 1 || newState == 3) $(".playbtn").addClass("set");
	else $(".playbtn").removeClass("set");
	if(newState == 3 || newState == 5 || newState == -1 || newState == 0){
		pc.bar.addClass("bloading");
	} else pc.bar.removeClass("bloading");
}

function player_is(s){
	if(player == null) var state = 0; else
	var state = player.getPlayerState();
	switch(s){
			case "playing": return state == 1 || state == 3;
			case "ended": return state == 0;
			case "paused": return state == 2;
	}
}

function onYouTubePlayerReady(playerId) {
	player = document.getElementById("ytplayer");
	player.addEventListener("onStateChange", "onplayerStateChange");
	player.addEventListener("onError", "onplayerError");
	echoVideo(pc.videos.first);
	setVolume(-1);
	toggleHeight(0);
	toggleHeight(1);
	setSizes();
}


function onplayerError(error){
	//100: Nicht gefunden
	if(error == 100) {
		pc.videos.deleteLink(pls.playitem.attr("video"));
		if(pc.videos.play >= pc.videos.v.length - 1)
		lta.timer.video = setTimeout(function(){ pls.playI("next")}, 2000); else{
			echoVideo(pc.videos.v[pc.videos.play]);
		}
		
	} else
	if(error == 2){
		player.clearVideo();
		if(pls.play < pls.anzahl() - 1) lta.timer.video = setTimeout(function(){ pls.playI("next")}, 2000); 
	}
}

function echoVideo(video){
	pls.playitem.attr("video", video);
	//println($(".echovid[v='"+video+"']").length+" "+video);
	$("#ytlink").val("http://youtube.com/watch?v="+video);
	pc.videos.mark(video);
	pc.videos.play = pc.videos.getIndex(video);
	pc.videos.download.url = "";
	if(lta.loaded.video){
		if(pc.silencing.active) $("#silence-cancel").click();
		player.loadVideoById(video); 
		pc.pready = false;
		player.playVideo();
		pc.zeit = 0;
	} else {
		lta.loaded.video = true;
		lta.showBars();
		var hd = pc.hd;
		pc.videos.first = video;
		video = "http://www.youtube.com/apiplayer?v="+video+"&hd="+hd+"&autoplay=1&showsearch=0&enablejsapi=1&playerapiid=123";
		var params = { allowScriptAccess: "always" }; 
		if($("#playerbox").css("display") == "none") $("#playerbox").show();
		//BEISPIEL: 
		//swfobject.embedSWF("dateiname", "DIV-ID", "WIDTH", "HEIGHT", "FLASHVERSION","ALTERNATE FILE", flashvars, params, attributes);
		swfobject.embedSWF(video, "ytplayer", pc.size.x, pc.size.y, "8", null, null, params, null);
		//$(".flashplayer").show();
	}
}


function getPlayInfos(p){
	var q = new Object();
	q.artist = p.artist;
	q.track = p.track;
	q.query = p.track;
	q.image = pls.playitem.attr("image");
	q.v = pls.playitem.attr("video");
	q.m = "track";
	q.a = "playinfo";
	q.pod = "playerbox";
	q.nopod = 1;
	$("#video-message").html("");
	//p.load();
	requestP(q); //POSTEN WEGEN UTF-8! 
}

function stopTimer(){
	window.clearTimeout(lta.timer.video)
	$("#video-list-message").html("");
}

function toggleHeight(d){
		var p = document.getElementById("ytplayer");
		var vb = document.getElementById("videobox");
		if(d != undefined)
		if(d != pc.down) return;
		if(pc.down) {
			pc.video_visible = false;
			pc.down = 0;
			p.style.width = 0;
			p.style.height = 0;
			vb.style.width = 0;
			vb.style.height = 0;
			setSizes();
			lta.playerpod.removeClass("full");
			$(".smallscreen").addClass("fullscreen");
			$(".smallscreen").removeClass("smallscreen");
			$(".showvid").removeClass("set");
		} else {
			pc.down = 1;
			pc.video_visible = true;
			setSizes();
			$(".showvid").addClass("set");
		}
}

function fullscreen(o){
	var p = document.getElementById("ytplayer");
	var vb = document.getElementById("videobox");
	toggleHeight(0);
	if($(o).hasClass("fullscreen") || o == 1) {
		pc.full_screen = true;
		lta.playerpod.addClass("full");
		$("#left").addClass("full");
		var width = lta.playerpod.width();
		var height = lta.tabs.position().top;
		p.style.width = width+"px";
		p.style.height = height+"px";
		vb.style.width = width+"px";
		vb.style.height = height+"px";
		$("#head").hide();
		$("#video-nav").hide();
		$("#content").hide();
		
		lta.tabs.css("width", "100%");
		lta.tabs.css("left", 0);
		lta.videolist.hide();
		lta.playinfo.hide();
		pls.list.hide();
		$(".up-nav").hide();
		$(".fullscreen").addClass("smallscreen");
		$(".fullscreen").removeClass("fullscreen");
		$(".smallscreen", "#down-nav").show();
		displayMessage(__("exit-fullscreen"));
	} else {
		pc.full_screen = false;
		$("#left").removeClass("full");
		lta.playerpod.removeClass("full");
		$("#head").show();
		$(".up-nav").show();
		$("#content").show();
		lta.videolist.show();
		lta.playinfo.show();
		pls.list.show();
		$(".smallscreen", "#down-nav").hide();
		$(".smallscreen").addClass("fullscreen");
		$(".smallscreen").removeClass("smallscreen");
		hideMessage();
		setSizes();
	}
}

function resizePlayer(){
		if(!pc.video_visible) return;
		var p = document.getElementById("ytplayer");
		var vb = document.getElementById("videobox");
		
		if(pc.full_screen){
			var width = lta.playerpod.width();
			var height = lta.tabs.position().top;
			p.style.width = width+"px";
			p.style.height = height+"px";
			vb.style.width = width+"px";
			vb.style.height = height+"px";
			return;
		}

		var podwidth = $("#left").width();
		pc.size.x = podwidth;
		pc.size.y = Math.round(podwidth / pc.rel);
		
		p.style.width = pc.size.x+"px";
		p.style.height = pc.size.y+"px";
		vb.style.width = pc.size.x+"px";
		vb.style.height = pc.size.y+"px";
		pc.bwidth = pc.bar.css("width").replace(/px/, "");
}




