﻿var Url = {
 
	// public method for url encoding
	encode : function (string) {
		return escape(this._utf8_encode(string));
	},
 
	// public method for url decoding
	decode : function (string) {
		return this._utf8_decode(unescape(string));
	},
 
	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
 
}

var $j = jQuery.noConflict();   

function show_search(){
var ttl=5;
var q=$j("#extra_vars11").val();
if(q=='undefined' || q=='') $j("#searching_msg").html("&nbsp;&nbsp;Type search word!");
else {
	$j("#searching_msg").html("<img src='/_json/manga/images/spinner.gif'>&nbsp;&nbsp;Searching videos ...");
	$j("#player").empty();
	$j("#relatedset").empty();
	related_search(q,ttl);
	
}
}

function close_video(){
$j("#player").empty();
$j("#video_main1").css("display","none");
}


function gqbox(gq){
var url="/gq.php?q="+gq;
var links=$j('a[rel^=2lightbox]');
var overlay2=$j(jQuery('<div id="overlay2" style="display: none"></div>'));
var container2=$j(jQuery('<div id="lightbox2" style="display: none"></div>'));
var target2=$j(jQuery('<div class="target2" id="target2" style="display: none"><iframe width="1px" height="1px" src="'+url+'" frameborder="0" scrolling="no" marginheight="0" marginwidth="0"></iframe></div>'));
$j('#relatedset').append(overlay2).append(container2).append(target2);


//$j('#2target iframe').attr("src",url);
//alert(url);
}


function related_search(q,ttl){
		var q=q;
		i=0;
		$j.getJSON("/addons/video_relation/get_search2.php?q="+q,
        function(data){
		$j.each(data.items, function(i,item){
		if(i==0){
		$j("#video_main1").css("display","block");
		$j("#video_title1").css("display","block");
 		}

		
		i++;
		if(i<5){
		title = item.title;
		ntitle = title.replace("'", "");
		$j("#relatedset").append('<div class="cell" style="width: 130px; height: 135px;float:left;"><a href="#" onclick="updateplayer(\''+item.video_id+'\',\''+item.thumbnail+'\');return false;" title="'+ntitle+'"><img src="'+item.thumbnail+'" alt="'+ntitle+'" class="thumb" border="0" width="100" height="60"></a><div class="title2"><span><a href="#" onclick="updateplayer(\''+item.video_id+'\',\''+item.thumbnail+'\');return false;" title="'+ntitle+'">'+ntitle+'</a></span></div></div>');
        }
		$j("#searching_msg").empty();
        });
		});
gqbox(q);
}

function updateplayer (vid,thumbnail) {
var curl=window.location.href;
var curl1=curl.replace("&","%26");
var link='%26link%3D'+curl1+'%26displayclick%3Dlink';
//var link='';
//var embed='%3Cobject height%3D%22375%22 width%3D%22600%22%3E%3Cparam name%3D%22movie%22 value%3D%22http://fooyoh.com/player/player.swf%22 /%3E%3Cparam name%3D%22allowfullscreen%22 value%3D%22true%22 /%3E%3Cparam name%3D%22allowscriptaccess%22 value%3D%22always%22 /%3E%3Cparam name%3D%22flashvars%22 value%3D%22file%3Dhttp://fooyoh.com/_get_video/get.php?v%3D'+vid+'%26type%3Dvideo%26skin%3Dhttp://fooyoh.com/player/snel.swf%26autostart%3Dtrue%26stretching%3Dexactfit%26abouttext%3DFOOYOH.COM%26aboutlink%3Dhttp://FOOYOH.COM%26image%3D'+thumbnail+link+'%22 /%3E%3C/param%3E%3Cembed src%3D%22http://fooyoh.com/player/player.swf%22 type%3D%22application/x-shockwave-flash%22 flashvars%3D%22file%3Dhttp://fooyoh.com/_get_video/get.php?v%3D'+vid+'%26type%3Dvideo%26skin%3Dhttp://fooyoh.com/player/snel.swf%26autostart%3Dtrue%26stretching%3Dexactfit%26abouttext%3DFOOYOH.COM%26aboutlink%3Dhttp://FOOYOH.COM%26image%3D'+thumbnail+link+'%22 allowscriptaccess%3D%22always%22 allowfullscreen%3D%22true%22 width%3D%22600%22 height%3D%22375%22%3E%3C/embed%3E%3C/object%3E';

//var embed2='&plugins=viral-2&viral.functions=embed,link&viral.link='+curl1+'&viral.embed='+embed;
var embed2='';
//if ($j.browser.mozilla) {
$j("#player").html('<object height="375" width="600"><param name="movie" value="/player/player.swf" /><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="flashvars" value="file=http://www.youtube.com/watch?v='+vid+'&skin=/player/snel.swf&autostart=true&stretching=exactfit&abouttext=FOOYOH.COM&aboutlink=http://FOOYOH.COM&image='+thumbnail+embed2+'" /></param><embed src="/player/player.swf" type="application/x-shockwave-flash" flashvars="file=http://www.youtube.com/watch?v='+vid+'&skin=/player/snel.swf&autostart=true&stretching=exactfit&abouttext=FOOYOH.COM&aboutlink=http://FOOYOH.COM&image='+thumbnail+embed2+'" allowscriptaccess="always" allowfullscreen="true" width="600" height="375"></embed></object>');
 
/** }else{

$j.ajax({
  url: 'http://www.youtube.com/get_video_info?&video_id='+vid,
  type:'get',
  success: function(data) {
  
	var svr=data.split('fmt_stream_map',2);
    var svr=svr[1].split('http', 3);
	var svr2=svr[1].split('%');
	var svr_count=svr2.length-2;
	var splitkey='%'+svr2[svr_count]+'%'+svr2[svr_count+1];
	var svr=svr[1].split(splitkey,2);
	
	var svr='http'+Url.encode(svr[0]);

	$j("#player").html('<object height="375" width="600"><param name="movie" value="/player/player.swf" /><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="flashvars" value="file='+svr+'&type=video&skin=/player/snel.swf&autostart=true&stretching=exactfit&abouttext=FOOYOH.COM&aboutlink=http://FOOYOH.COM&image='+thumbnail+embed2+'" /></param><embed src="/player/player.swf" type="application/x-shockwave-flash" flashvars="file='+svr+'&type=video&skin=/player/snel.swf&autostart=true&stretching=exactfit&abouttext=FOOYOH.COM&aboutlink=http://FOOYOH.COM&image='+thumbnail+embed2+'" allowscriptaccess="always" allowfullscreen="true" width="600" height="375"></embed></object>');

  }
});

}
**/

}
				


