var pics=new Array();
var stat=new Array();
var pic=new Array();

function changepic(i,code, prefix)
{var loop=0;

	if (stat[code])
	{
		while ((pics[code][i]==0 || i>=16) && loop<100)
		{if (i>=16) {i=0;}
			else
			{i++;
			}
			loop++;
		}

		if (pic[code][i].complete)
		{
			if(prefix != null){
				document.getElementById(prefix).src=pic[code][i].src;
				setTimeout("changepic("+(i+1)+",'"+code+"', '"+prefix+"')",500);
			}else{
				document.getElementById(code).src=pic[code][i].src;
				setTimeout("changepic("+(i+1)+",'"+code+"')",500);
			}
		}
		else
		{
			if(prefix != null)	setTimeout("changepic("+i+",'"+code+"', '"+prefix+"')",20);
			else				setTimeout("changepic("+i+",'"+code+"')",20);
		}
	}


}

function loadpic(url,code,j)
{if (stat[code]) {pic[code][j].src=url;}
}

function startm(code,ta,te,prefix)
{
	stat[code]=1;
	var jj, jjj;
	var first=1;

	for(var j=0;j<16;j++)
	{if (pics[code][j]==1)
		{pic[code][j]=new Image();
			jj=j+1;
			if (jj>=100) {jjj=""+jj;}
			if (jj<100 && jj>=10) {jjj="0"+jj;}
			if (jj<10) {jjj="00"+jj;}
			if (first) {
				first=0;loadpic(ta+jjj+te,code,j);
				if(prefix != null){
					document.getElementById(prefix).title="";
					document.getElementById(prefix).parentNode.title="";
				}else{
					document.getElementById(code).title="";
					document.getElementById(code).parentNode.title="";
				}
			}
			else {setTimeout("loadpic('"+ta+jjj+te+"','"+code+"',"+j+")",j*50);}
		}
	}
	if(prefix != null)	changepic(0,code,prefix);
	else				changepic(0,code);
}

function endm(code)
{stat[code]=0;
}

function thumb_action(id, cmd, priv){
	// priv = 1   -> If video is private - diplays the private tag
	// priv = 2   -> If friend is pending - displays of elements is a bit different

	var opacity = document.getElementById('xop_'+id);
	var confirm = document.getElementById('xconf_'+id);
	var button = document.getElementById('but_'+id);
	var div_button = document.getElementById('xbut_'+id);

	if(priv!=null && priv==1){
		var priv_tag = document.getElementById('xpriv_'+id);
	}else if(priv==2){
		var msg_tag = document.getElementById('xmsg_'+id);
	}

	switch(cmd){
		case 'over':
			div_button.style.display = 'block';
			if(priv!=null && priv==1) priv_tag.style.display = 'block';
			break;
		case 'out':
			div_button.style.display = 'none';
			if(priv!=null && priv==1) priv_tag.style.display = 'none';
			break;
		case 'delete':
			if(priv!=2) opacity.style.display = 'block';
			confirm.style.display = 'block';
			button.style.display = 'none';
			document.getElementById('smf_'+id).style.display="none";
			if(priv==2) msg_tag.style.display = 'none';
			break;
		case 'reject':
			if(priv!=2)	opacity.style.display = 'none';
			confirm.style.display = 'none';
			button.style.display = 'block';
			document.getElementById('smf_'+id).style.display="block";
			if(priv==2) msg_tag.style.display = 'block';
			break;
	}
}
function rotateCatThumb(code,ta,te)
{stat[code]=1;
	var jj, jjj;
	var first=1;

	pic[code][0]		= new Image();
	pic[code][0].src	= "http://img01.redtubefiles.com/_thumbs/categories/s115x85/category_img_01.gif";

	for(var j=1;j<16;j++)
	{if (pics[code][j]==1)
		{pic[code][j]=new Image();
			jj=j+1;
			if (jj>=100) {jjj=""+jj;}
			if (jj<100 && jj>=10) {jjj="0"+jj;}
			if (jj<10) {jjj="0"+jj;}
			if (first) {
				first=0;loadpic(ta+jjj+te,code,j);
				document.getElementById(code).title="";
				document.getElementById(code).parentNode.title="";
			}
			else {setTimeout("loadpic('"+ta+jjj+te+"','"+code+"',"+j+")",j*50);}
		}
	}
	changepic(0,code);
}

function resetCatThumb(id) {
	stat[id]=0;
	var image	= document.getElementById(id);
	if (image) {
		image.src	= 'http://img01.redtubefiles.com/_thumbs/categories/s115x85/category_img_01.gif';
	}
}

function getFlashMovieObject(movieName) {
	if (window.document[movieName]){
		return window.document[movieName];
	}
	if (navigator.appName.indexOf("Microsoft Internet")==-1){
		if (document.embeds && document.embeds[movieName])
			return document.embeds[movieName];
	}
	else{
		return document.getElementById(movieName);
	}
	
	return null;
}

function showFlashContainer() {
	var flash = jQuery( "#flashThumb" );
	var reference = jQuery( "#"+ flash.data( "refImageId" ) );
	
	flash.offset(reference.offset());
}

function videoThumbCreate( url ) {
	var so;
	
	if ( jQuery.browser.msie )
		so = new SWFObject(url +"/flash/overlaystream_ie.swf", "overlaystream", "180", "135", "10.0.0", "#ffffff");
	else
		so = new SWFObject(url +"/flash/overlaystream.swf", "overlaystream", "180", "135", "10.0.0", "#ffffff");
	
	so.addParam("wmode", "transparent");
	so.setAttribute("allowScriptAccess", "always");
	so.write("flashThumb");
	
	jQuery('<div/>', {
		"class": "overlay"
//		"onmouseout": "videoThumbStop()",
//		"onclick": "videoThumbGoto()"
	}).bind("mouseout", function() {
		videoThumbStop();
	}).bind("click", function() {
		videoThumbGoto();
	}).appendTo( "#flashThumb" );
}

function videoThumbStart( image, video ) {
	var flash = jQuery( "#flashThumb" );
	var reference = jQuery( image );
	
	flash.data( "refImageId", image.id );
	if ( jQuery.browser.webkit || jQuery.browser.msie )
		showFlashContainer();
	
	var overlaystream = getFlashMovieObject( "overlaystream" );
	
	if ( jQuery.browser.msie )
		overlaystream.jsActivateStreamer({flashVar: 'http://previews.redtubefiles.com/jap/' + video + '.mp4', targetlink: reference.parent().attr( "href" )});
	else
		overlaystream.start('http://previews.redtubefiles.com/jap/' + video + '.mp4', reference.parent().attr( "href" ));
}

function videoThumbStop() {
	var overlaystream = getFlashMovieObject( "overlaystream" );
	overlaystream.stop();
	jQuery( "#flashThumb" ).offset({top: -200, left: -300});
}

function videoThumbGoto() {
	var reference = jQuery( "#"+ jQuery( "#flashThumb" ).data( "refImageId" ) );
	window.location = reference.parent().attr( "href" );
}


