function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function showInline (elName) {
	var theElemenet = document.getElementById(elName);
	if (theElemenet) {
		theElemenet.style.display = "";
	}
}

function hideInline (elName) {
	var theElemenet = document.getElementById(elName);
	if (theElemenet) {
		theElemenet.style.display = "none";
	}
}

function setVisible(obj,file) //show element
{
		topPosition = (getWindowHeight()/2) - (275/2)
		placeIt(topPosition)
    obj = document.getElementById(obj);
		player = document.getElementById('playeriframe').src = 'play_video.php?file='+file;
    //obj.style.visibility = 'visible';
		$(obj).grow();
		$('playeriframe').blindDown();
}

function setInvisible(obj)//hide element
{
    obj = document.getElementById(obj);
    //obj.style.visibility =  'hidden';
		$('playeriframe').hide();
		$(obj).shrink();
}
function getWindowHeight() {
  var myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}

function getWindowWidth() {
  var myWidth = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
  return myWidth;
}

(document.getElementById) ? dom = true : dom = false;
function placeIt(topPosition,obj) {
  if (dom && !document.all) {
		document.getElementById(obj).style.top = window.pageYOffset + (window.innerHeight - (window.innerHeight-topPosition)) + "px";
	}
  if (document.all) {
		document.all[obj].style.top = (document.documentElement.scrollTop||document.body.scrollTop) + (document.documentElement.clientHeight - (document.documentElement.clientHeight-topPosition)) + "px";
	}
  //window.setTimeout("placeIt("+top+")", 10); 
}
function createPlayerPopup(){
playerh = 275 //126 height of iframe inside layer pop up
playerw = 415 //178 width of iframe inside layer pop up
windoww = playerw + 15
if(navigator.appName == "Microsoft Internet Explorer"){ //adjustments for IE
	playerh = playerh  //133
	playerw = playerw //174
	windoww = windoww + 5
}
	xpos = screen.width/2 - (playerw/2)
var player = '\n\
<div id="playerdiv" style="width:'+windoww+'px;position:absolute;display:none;z-index:1000;background-color:#8a9397;text-align:center;padding: 3px;left:'+xpos+'px;">\n\
	<div style="background:#242c30; padding:3px;">\n\
		<div style="height:26px; background:url(images/player_title_bg.gif); background-repeat:repeat-x; text-align:left;">\n\
			<table width="100%" border="0" cellspacing="0" cellpadding="0">\n\
  <tr>\n\
    <td id="playertitle" style="padding-left:10px;cursor:move;" class="textWhiteTitle">NOW PLAYING VIDEO</td>\n\
    <td align="right" width="28"><img src="images/close.jpg" style="cursor:pointer" onclick="setInvisible(\'playerdiv\')"></td>\n\
  </tr>\n\
</table>\n\
		</div>\n\
		<div style="line-height:5px;">&nbsp;</div>\n\
		<div style="border:1px solid #5a6164; background-color:#394144; padding: 3px">\n\
			<iframe id="playeriframe" src="play_video.php" height="'+playerh+'" width="'+playerw+'" frameborder="0" scrolling="no" style="padding:0px;margin:0px;vertical-align:middle;" marginheight="0"  marginwidth="0" allowtransparency="true"></iframe>\n\
		</div>\n\
	</div>\n\
</div>';
document.write(player)
}

//search youtube videos
var keyword
var totalResults
var startIndex = 1
function searchYoutube(id,keyword,startIndex,paginationdiv){
	//img = '<div style="height:380px; width:250px; display:table-cell; vertical-align:middle; text-align:center"><img src="images/loading.gif" style="vertical-align:middle; border: 1px solid #02314F" width="32" height="32" /></div>'
	showLoadingContent(id)
	new Ajax.Request('search_youtube.php',
  {
    method:'get',
		parameters: { 'vq' : keyword, 'start-index': startIndex },
    onSuccess: function(transport){
			var response = transport.responseText.split('[[separator]]') || "";
			$(id).innerHTML = response[0]
			totalResults = response[1]
			eval('videoPlaylist = '+response[2])
			//if(player) player.sendEvent('LOAD',eval(response[2]));
			$('pagetxt').innerHTML = 'Showing '+startIndex+' to '+(startIndex+23)+' of '+totalResults;
			if(startIndex==1 && paginationdiv && response[3]=='search') $(paginationdiv).style.visibility='visible';
    },
    onFailure: function(){ response =  ""; $(paginationdiv).style.visibility='hidden' }
  });
}

function searchYoutubeNext(id,paginationdiv){
	if(keyword!='' && startIndex<=totalResults){
		searchYoutube(id,keyword,startIndex+=24,paginationdiv)
	}
}
function searchYoutubePrev(id,paginationdiv){
	if(keyword!='' && startIndex>=25){
		searchYoutube(id,keyword,startIndex-=24,paginationdiv)
	}
}

function loadVideoList(id,url){
	showLoadingContent(id)

	new Ajax.Request(url,
  {
    method:'get',
    onSuccess: function(transport){
      var response = transport.responseText.split('[[separator]]') || "";
			$(id).innerHTML = response[0]
			if(player) player.sendEvent('LOAD',eval(response[1]));
    },
    onFailure: function(){ response =  "";}
  });
}

function createLayerPopup(id,title,contenturl,contentW,contentH,contentScroll){
	windoww = contentW + 15
	if(!contentScroll){
		contentScroll='no'
	}
	if(navigator.appName == "Microsoft Internet Explorer"){ //adjustments for IE
		windoww = windoww + 5
		contentH = contentH + 10
	}
	xpos = ((screen.width -(contentW+6))/2)
	var player = '\n\
	<div id="'+id+'" style="width:'+windoww+'px;position:absolute;display:none;z-index:1000;background-color:#8a9397;text-align:center;padding: 3px;left:'+xpos+'px;">\n\
		<div id="'+id+'inner" style="background:#242c30; padding:3px;">\n\
			<div style="height:26px; background:url(images/player_title_bg.gif); background-repeat:repeat-x; text-align:left;">\n\
				<table width="100%" border="0" cellspacing="0" cellpadding="0">\n\
  				<tr>\n\
    				<td id="'+id+'title" style="padding-left:10px;cursor:move;" class="textWhiteTitle">'+title+'</td>\n\
    				<td align="right" width="28"><img src="images/close.jpg" style="cursor:pointer" onclick="hideLayerPopup(\''+id+'\')"></td>\n\
  				</tr>\n\
				</table>\n\
		</div>\n\
		<div style="line-height:5px;">&nbsp;</div>\n\
			<div style="border:1px solid #5a6164; background-color:#394144; padding: 3px">\n\
				<iframe id="'+id+'iframe"  name="'+id+'iframe" src="'+contenturl+'" height="'+contentH+'" width="'+contentW+'" frameborder="0" scrolling="'+contentScroll+'" style="padding:0px;margin:0px;vertical-align:middle; background-color:#3D4E55; height:'+contentH+'px" marginheight="0"  marginwidth="0"></iframe>\n\
			</div>\n\
		</div>\n\
	</div>';
	document.write(player)
}
function hideLayerPopup(id)//hide element
{
	var iframe = id+'iframe'
		$(iframe).hide();
		$(id).shrink();
}
function showLayerPopup(id,contentHeight){
	if(!contentHeight){
			contentHeight = $(id).getHeight()
		}
	var iframe = id+'iframe'
		topPosition = (getWindowHeight()/2) - (contentHeight/2)
		placeIt(topPosition,id)
		//$(iframe).src = 'add_to_channel.php';
    //obj.style.visibility = 'visible';
		$(id).grow();
		$(iframe).blindDown();
}

function resizeContent(id,newheight){
		$(id).style.height = newheight+'px'
}

	function handleSignInInput(e) { //youtube input box
		var key;
		if (window.event) {
			// Get input key from IE
			key = e.keyCode;
		} else if (e.which) {
			// Get input key from Firefox/Netscape/Opera
			key = e.which;
		}
		// Check to see if key is 'enter'
		if (key == 13) {
			document.getElementById("loginForm").submit();
		}
	}

function showLoadingContent(id){
	img = '<div style="height:380px; width:250px; background:url(images/loading.gif) no-repeat center;"></div>'
	$(id).update(img)
}

function loadComments(id,url){
	//img = '<div style="height:215px; width:100%; background:url(images/loading.gif) no-repeat center;"></div>'
	$(id).style.background = 'url(images/loading.gif) no-repeat center'
	//$(id).blindDown()
	var date = new Date();
	new Ajax.Request('community_comments.php',
  {
    method:'get',
		parameters: { 'video' : url , 'time': date.getTime()},
    onSuccess: function(transport){
      var response = transport.responseText || "";
			$(id).innerHTML = response
			$(id).style.background = ''
    },
    onFailure: function(){ response =  "";}
  });
}

