// JavaScript Document
var Scrollint = "";

function addEvent(obj, evType, fn)
{ 
	if (obj.addEventListener)
	{obj.addEventListener(evType, fn, false);return true;}
	else if (obj.attachEvent)
	{var r = obj.attachEvent("on"+evType, fn);return r;}
	else {return false;} 
}

function appLoad()
{
	generateList(document.getElementById("frmGallery").value, document.getElementById("frmTopic").value);
	//flashVid(document.getElementById("frmVideo").value);
	
	//events
	addEvent(document.getElementById("searchbutton"),"click",dbsearch);
	//addEvent(document.body, "keypress", keypressed);
	
	var isiPad = navigator.userAgent.match(/iPad/i) != null;
	if(isiPad===true){$f("ipad", "flex/flowplayer-3.2.7.swf").ipad().play();}
}

function generateList(galleryID, topicID)
{
	document.getElementById("topicHeader").innerHTML=ajaxrun("player_ajax.php?Page=topicHeader&topicID="+topicID,"");
	document.getElementById("contentblock").src="player_ajax.php?Page=list&topicID="+topicID+"&galleryID="+galleryID;
}

function keypressed(){if(event.keyCode=="13"){dbsearch();}}

function viewVideo(videoName,galleryid,topicid,fileid,device)
{
	if(device=="ipad")
	{
		document.getElementById("colone").innerHTML="<div id=\"vidgallery\"><a href=\"http://fms.basinelectric.com/vod/"+videoName.replace(/.flv/i,".mp4")+"\" style=\"display:block;width:640px;height:390px;\" id=\"ipad\"></a></div>";		
		
		$f("ipad", "flex/flowplayer-3.2.7.swf").ipad().play();
	}
	else
	{flashVid(videoName,galleryid,topicid,fileid);}
		document.getElementById("headerTitle").innerHTML=ajaxrun("player_ajax.php?Page=getTitle&uploadid="+fileid,"");
		
}

function flashVid(filename,galleryid,topicid,fileid)
{
	document.getElementById("colone").innerHTML="<div id=\"vidgallery\">Viewing the video gallery requires javascript be enabled on your browser and the Adobe Flash Player (version 8 or higher). If you are seeing this message, you either need to upgrade your version of the Flash Player or enable Javascript in your browser. <a href=\"http://www.adobe.com/products/flashplayer/\" target=\"_blank\">Download the Flash Player</a>.</div>";

	var server = location.href.split("/")[2];
	/*var so = new SWFObject("includes/flash/jwplayerV1.swf", "vidgallery", "640", "390","8", "#666666");
	so.addParam('allowfullscreen','true');
	so.addParam('allowscriptaccess','always');
	so.addParam('wmode','opaque');
	so.addVariable('playlistfile',"http://" + server + "/player/jwplaylist.php?videoid="+fileid);
	so.addVariable('author','bepc');
	so.addVariable('backcolor','#eee');
	so.addVariable('frontcolor','#333');
	so.addVariable('lightcolor','#09c');
	so.addVariable('screencolor','#000');
	so.addVariable('plugins','viral-2');
	so.addVariable('autostart','true');*/
	
	var so = new SWFObject("includes/flex/basinplayer.swf", "vidgallery", "640", "390","8", "#666666");
	so.addParam("movie", "includes/flex/basinplayer.swf");
	so.addParam("quality", "high");
	so.addParam("bgcolor", "#000000");
	so.addParam("allowfullscreen", "true");
	so.addParam("scale", "noscale");				
	so.addParam("flashvars", "serverPath=" + server + "&videoid="+fileid);
	
	so.write("vidgallery");
}

/*
function flashVidV1(filename,galleryid,topicid,fileid)
{
	document.getElementById("colone").innerHTML="<div id=\"vidgallery\">Viewing the video gallery requires javascript be enabled on your browser and the Adobe Flash Player (version 8 or higher). If you are seeing this message, you either need to upgrade your version of the Flash Player or enable Javascript in your browser. <a href=\"http://www.adobe.com/products/flashplayer/\" target=\"_blank\">Download the Flash Player</a>.</div>";

	//var videoPath = "rtmp%3A//basin14.basinelectric.com%3A8080/vod/"+filename.replace(".flv","");
	//includes/flash/videoPlayer.swf
	var server = location.href.split("/")[2];
	var videoPath = "rtmp://"+server+":8080/vod/"+filename.replace(".flv","");
	//alert(videoPath);
	var so = new SWFObject("includes/flash/vidGallery_v3.1.swf", "vidgallery", "640", "390", "8", "#666666");
	so.addParam("movie", "includes/flash/vidGallery_v3.1.swf");
	so.addParam("quality", "high");
	so.addParam("bgcolor", "#000000");
	so.addParam("allowfullscreen", "true");
	so.addParam("flashvars", "serverPath="+server+"&rtmppath="+videoPath+"&linkpath=http://"+server+"/player/player.php?gallery="+galleryid+"_amp_topic="+topicid+"_amp_video="+fileid+"");
	//so.addParam("flashvars", "&videoWidth=640&videoHeight=377&dsControl=auto&dsSensitivity=100&serverURL="+videoPath+"&streamType=vod&autoStart=true&DS_Status=true");
	so.write("vidgallery");
}*/

function scrollwindow(speed)
{Scrollint = setInterval("document.getElementById('contentblock').contentWindow.scrollBy(0,"+speed+");",20);}

function stopscrollwindow()
{clearInterval(Scrollint);}

function dbsearch()
{
	text=document.getElementById("searchtext").value
	document.getElementById("topicHeader").innerHTML="Custom Search";
	document.getElementById("contentblock").src="player_ajax.php?Page=search&searchtext="+text+"&galleryID="+document.getElementById("frmGallery").value;
}

//run these last
addEvent(window, 'load', appLoad);
