/*************************************
DECLARE GLOBAL VARIABLES
*************************************/

var vdTitle='';var linkDocId='';var pubDate="";var vdDesc="";var e='';var f='';var g='';var h='';
var xml_doc;var str111="st=";
var filename = "ourtripvideosRSSMapCode.xml";
var width="320";var height="260";
 
function VideoInfo(title, linkDocId,vdDesc,pubDate,videoid,attractionlinks,youtubeid,datarecno,videotype){
	this.title = title;
	this.linkDocId = linkDocId;
	this.vdDesc = vdDesc;
	this.pubDate = pubDate;
	this.videoid = videoid;
	this.attractionlinks = attractionlinks;
	this.youtubeid = youtubeid;
	//this.coordinates = coordinates;
	this.datarecno = datarecno;
	this.videotype = videotype;
}

var VideoInfoAry = new Array(3);var oneVideoInfo;

function processTabbedXML() {


   try {
	if (request.readyState == 4) {
    		if ((request.status != 200) && (request.status != 304)) {
    		     alert("file not found: "+filename);
    		     return;
    		}
    		
    		var gmarkers = [];
    		
		// var xmlDoc = request.responseXML;
    		var xmlDoc = GXml.parse(request.responseText);

		// obtain the array of markers and loop through it
    		var markers = xmlDoc.documentElement.getElementsByTagName("item");
    		//alert("processing "+ markers.length +" items");

    		gmarkers = new Array();
    		for (var i = 0; i < markers.length; i++) {
    		//for (var i = 0; i < markers.length && i < 5; i++) {
    		     // obtain the attributes of each marker
         	     
         	     //alert('A1start ' + i);	
         	     
    		     vdTitle = GXml.value(markers[i].getElementsByTagName("title")[0]);
    		     linkDocId = unescape(GXml.value(markers[i].getElementsByTagName("link")[0]));

    		     //alert(' title= ' + vdTitle );
    		     
		     //vdTitle = node_list[i].childNodes[0].childNodes[0].nodeValue;
		     //linkDocId = unescape(node_list[i].childNodes[1].childNodes[0].nodeValue);

		     var pairs = linkDocId.split("&");
		     var docNmPos = pairs[0].indexOf('docid=') + 6;
		     linkDocId = pairs[0].substring(docNmPos,pairs[0].length);
		     //alert("docid = " + linkDocId);

		     //e = node_list[i].childNodes[2].childNodes[0].nodeValue;
		     //pubDate = node_list[i].childNodes[3].childNodes[0].nodeValue;
		     
		     pubDate = GXml.value(markers[i].getElementsByTagName("pubDate")[0]);
		     //alert("pubDate = " + pubDate);
		     videoid = GXml.value(markers[i].getElementsByTagName("videoid")[0]);
		     
		     attractionlinks = GXml.value(markers[i].getElementsByTagName("attractionlinks")[0]);
		     
		     youtubeid = GXml.value(markers[i].getElementsByTagName("youtubeid")[0]);
		     
		     //coordinates = GXml.value(markers[i].getElementsByTagName("coordinates")[0]);
		     datarecno = GXml.value(markers[i].getElementsByTagName("datarecno")[0]);
		     
		     videotype= GXml.value(markers[i].getElementsByTagName("videotype")[0]);
		     
		     //g = unescape(node_list[i].childNodes[4].childNodes[0].nodeValue); // Extract the description
		     g = unescape(GXml.value(markers[i].getElementsByTagName("description")[0])); // Extract the description
		     var descStPos = g.indexOf('<br>') + 4;
		     var descEdPos = g.indexOf('<p/>');
		     vdDesc = g.substring(descStPos,descEdPos);
		     //alert("vdDesc = " + vdDesc);


		     VideoInfoAry[i] = new VideoInfo(vdTitle,linkDocId + "",vdDesc,pubDate,videoid,attractionlinks,
		     	youtubeid,datarecno,videotype);
		     
		     //alert('A1end ' + i);	

    		}
    		//alert('A1');
    		if (document.getElementById('selectX')) { // if the list box element(home page) is available
    							  // We could use same logic for other pages by using the object array
 			addDefEle();
 		}
 		//alert('A2');
	}
    
    } catch (e) {
        	alert("Error(processTabbedXML) - EName: " + e.name + ". EMsg: " + e.message);
    }
}

//alert(VideoInfoAry.length);

function addDefEle(){
try {
	 //alert('adding elements');
	 maxNo = VideoInfoAry.length;paramFndinList = 0;
	 for(i=0;i<VideoInfoAry.length;i++){
		 oneVideoInfo = VideoInfoAry[i];

		 var elOptNew = document.createElement('option');
		 elOptNew.text = oneVideoInfo.title;
		 //elOptNew.value = i+1;
		 elOptNew.value = oneVideoInfo.videoid;
		 if (param == oneVideoInfo.videoid){
		 	paramFndinList = i;
		 }
		 var elSel = document.getElementById('selectX');

		 try {
			 elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
		 }
		 catch(ex) {
			 elSel.add(elOptNew); // IE only
		 }
	 }

	 oneVideoInfo = VideoInfoAry[0];// diplay first record info
	 //document.getElementById('descdiv').innerHTML = oneVideoInfo.vdDesc.replace(/CRLAPINDFRN/,"") + "<br>" + "Published on " + oneVideoInfo.pubDate + '.';
	 //document.getElementById('attractionlinksdiv').innerHTML = oneVideoInfo.attractionlinks;

	//if (param >=1 && param <= maxNo ) {
	if (param >=1 && param <= VideoInfoAry.length ) {
	 //alert('a' + param);
		 document.form1.selectX.selectedIndex= paramFndinList;  //param-1;
		 playgooglevideo();
	} else {
		document.getElementById('selectX').selectedIndex=0;
		playgooglevideo();
	}
} catch (e) {
	alert("Error(addDefEle) - EName: " + e.name + ". EMsg: " + e.message);
}
}


function resizePlayer() {

	//var idx1 = document.form1.sizelist.options[document.form1.sizelist.selectedIndex].value;
	var idx1 = document.getElementById('sizelist').options[document.getElementById('sizelist').selectedIndex].value;
	
	//alert(3);
	 //width="320";height="260";
	 //width="480";height="320";
	if(idx1 == 1) {
		width="180";height="135";
	} else if (idx1 == 2) {
		width="260";height="195";
	} else if (idx1 == 3) {
		width="320";height="260";
	} else if (idx1 == 4) {
		width="480";height="320";
	} else if (idx1 == 5) {
		width="640";height="480";
	}

	 
	//alert("Play google video(resize Player) : resize option : " + idx1);
	if (document.getElementById("movie_player")) {	
		document.getElementById("movie_player").height = height;// Use movie player id but not the div id
		document.getElementById("movie_player").width = width; // just change the player width.
		//return;
	} 
	if (document.getElementById("flashCaptPicard")) {	
		document.getElementById("flashCaptPicard").height = height;// Use movie player id but not the div id
		document.getElementById("flashCaptPicard").width = width; // just change the player width.	
	
	}
}

function playgooglevideo(a1){// here a1 is the selected id
try {
	//var elSel = document.getElementById('selectX');
	//var selIdx = elSel.selectedIndex; //alert('seleidx ' + selIdx);
	var selIdx = a1;
	var prevIdx = selIdx - 1; 
	var nextIdx = selIdx + 1;
	//alert('arylen=' + VideoInfoAry.length);
	
	if (selIdx < 0) {selIdx =0; }
	 //alert('seleidx ' + selIdx);

	var descdiv = document.getElementById('descdiv');
	oneVideoInfo = VideoInfoAry[selIdx];
	//alert(oneVideoInfo.linkDocId);
	//alert(2);
	var desctext = descdiv.innerHTML;
	//oneVideoInfo.vdDesc.replace(/CRLAPINDFRN/,"");
	var desctext1="";
	//var desclines = desctext.split("&lt;br&gt;") //split using CRLF 
	var desclines = desctext.split("<br>") //split using CRLF
	//alert(21);
	//alert(desclines.length);
	for (i=0; i<desclines.length; i++) {
		//alert(desclines[i]) 
		desctext1 = desctext1 + "<span id=otvtextlangspan>" + desclines[i] + "</span><br>";
	}
	
	//descdiv.innerHTML = oneVideoInfo.vdDesc.replace(/CRLAPINDFRN/,"") + "<br>" + "Published on " + oneVideoInfo.pubDate + '</span>.';
	descdiv.innerHTML =  desctext1 + "<br>" ; //+ "<span id=otvtextlangspan>Published on " + oneVideoInfo.pubDate + '.</span>';
	//document.getElementById('attractionlinksdiv').innerHTML = oneVideoInfo.attractionlinks;

	//var idx = document.form1.flashlist.selectedIndex + 1;
	
	var idx = a1; //elSel.options[elSel.selectedIndex].value;
	
	width="480";height="320";var idx1 =psize;
	/*if (document.getElementById('sizelist')) {
		idx1 = document.getElementById('sizelist').options[document.getElementById('sizelist').selectedIndex].value;
	}*/
	

	if(idx1 == 1) {
		width="180";height="135";
	} else if (idx1 == 2) {
		width="260";height="195";
	} else if (idx1 == 3) {
		width="320";height="260";		
	} else if (idx1 == 4) {
		width="480";height="320";
	} else if (idx1 == 5) {
		width="640";height="480";
	}
	//alert(idx1 + " " + width + " " + height);

	
	k1 = linkDocIdSrv; //oneVideoInfo.linkDocId;
	videotype = videoTypeSrv; //oneVideoInfo.videotype;//alert(videotype); 
	
	var pinkgifidele = document.getElementById('pinkgifid'); // set the icon and title for this video - place/event
	if (pinkgifidele) { // if the element is available then only set these values
		if (videotype == "Event") {
			pinkgifidele.src = "/images/icons/green.gif";
			pinkgifidele.title = "Event Video";
		} else {
			pinkgifidele.src = "/images/icons/pink.gif";
			pinkgifidele.title = "Visiting Place Video";
		}
	}
	//alert('youtubeid in abc ' + oneVideoInfo.youtubeid);
	
	//var flashvars = { file:'http://www.ourtripvideos.net/videos/EarthDay-09.flv' }; 

	var playerUrl = "http://video.google.com/googleplayer.swf";
	if (k1.indexOf('.flv') > -1) { // FLV file so use FLV player
		//playerUrl = "/flvplayer.swf";
		//playerUrl = "/videos/player-viral.swf"; // Good working
		//playerUrl = "/videos/flowplayer-3.1.0.swf";
		//playerUrl = "http://www.youtube.com/apiplayer?enablejsapi=1&playerapiid=ytplayer";
		//playerUrl = "/videos/flvplayer.swf"; -  working after copying new file
		//playerUrl = "/videos/jcplayer.swf"; - not working
		
		playerUrl = "/videos/mediaplayer.swf";// JW Player 3.16
		playerUrl = "/videos/playerjw45.swf";// JW Player 4.5
		
		/*if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
			alert('IE');
			playerUrl = "/videos/mediaplayer.swf";
		} else {
			alert('NetScape');
			playerUrl = "/videos/flvplayer.swf"; //-  working after copying new file
		}*/
		
		var userAgent = navigator.userAgent;
		
		
		if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
		   //In IE the larger and small options are not working properly so disabling the size
			//document.form1.sizelist.disabled = true;
			//setClearMsgTimer(msgTypeInf,"Player Size - IE is currently supports only Large option for flash player. But Firefox/Chrome supports all options.<br><br>");
		}
	}


	var fo = new SWFObject(playerUrl,"movie_player",width,	height,7,"#000000");

	if (k1.indexOf('.flv') > -1) { // FLV file so use FLV player
	        // This code is useful to work with PHP Streams, it is working good with FF and Chrome, but not working properly
	        // with IE. In IE, it is playing but half of the screen only displaying
	        
		//movieUrl = "http://www.ourtripvideos.net/videos/" + k1;
		movieUrl = "/videos/" + k1;
		//alert('playerUrl 2 ' + movieUrl)
		//fo.addVariable("movie", movieUrl);
		//streamflv.php?id=10
		if (flvFileExists == 1) {
			fo.addVariable('file', encodeURIComponent(movieUrl)); //- working
		} else {
			fo.addVariable('file', '');
			setClearMsgTimer(msgTypeInf,"Sorry, the documentary file not found. Please contact Administrator.<br><br>");
			
		}		
		
		/* 
		//fo.addVariable('file',           'EarthDay-0911.flv');-  working
		fo.addVariable('file',k1);
          	fo.addVariable('streamscript', 'http://www.ourtripvideos.net/videos/streamflv.php');
          	//fo.addVariable('type',           'flv');
          	//fo.addVariable('type','application/x-shockwave-flash');
          	
          	//streamscript = "flvprovider.php"
          	//fo.addVariable("bufferlength","1.5"); - working
		// for javascript menu
		//fo.addVariable("wmode", "transparent"); -  working - not working for IE, small screen is displaying
		fo.addVariable("wmode", "opaque");

             	//s1.addVariable('autostart',        'false');


		fo.addParam("allowfullscreen","true");
		fo.addParam("usefullscreen","true");		
		fo.addParam('allowscriptaccess','always');
		//s1.addVariable('streamer','lighttpd');
		fo.addVariable('width',width);
		fo.addVariable('height',height);
		fo.addVariable('controlbar','bottom');
		fo.addVariable('bufferlength','9');
		//fo.addVariable('fullscreen','true');
		fo.addVariable('displayclick','play');
		//fo.addVariable('stretching','fill'); 
		*/
		fo.addParam("allowfullscreen","true");
		fo.addParam('allowscriptaccess','always');
		fo.addVariable("start",'5');
		fo.addParam('wmode','opaque');
		//fo.addVariable('image','/images/OTVImageflv.jpg');

		//alert(firstPicInDir);
		if (firstPicInDir != '') {// This value is coming from index.php file, showing first image in the pic directory
			fo.addVariable('image',firstPicInDir);
		} else {
			fo.addVariable('image','/images/OTVImageflv.jpg');
		}		
		
	} else {
		//alert('playerUrl 3 ');
		fo.addVariable("docId", k1);
		
	}
	fo.addVariable("autoPlay", "true");
	fo.addVariable("autostart","true");
	//alert('playerUrl 1 ');
	
	//fo.addVariable('file', encodeURIComponent('http://www.ourtripvideos.net/videos/EarthDay-091.flv'));
	
	
	//fo.addVariable("streamName","/videos/EarthDay-09");
	
	
	//fo.addVariable('width','100'); fo.addVariable('height','50');
	
	if (paramTime != "undefined" && !isNaN(paramTime) && idx < 68) { // Code will not break if you give empty value or -a or -100 or 
		                                                     // more than video length
		                                                     // After 67 the videos are flash, so initial time is not working
		   var answer = confirm ("Would you like to continue viewing the video from around " + (Math.round((paramTime/60)*100)/100) + 
		       "th minute?");
		   if (answer){
		      fo.addVariable("initialTime",paramTime);
		      //fo.addVariable("starttime",paramTime); - not working for flash
		   }
	}
		

	fo.write("swfplayer");

	var youtubeversionlink = document.getElementById("youtubeversionidlink");

	if (youtubeversionlink) {// Change the link details on home page - this is toggle between Google Video and YouTube Video
		youtubeversionlink.innerHTML = "YouTube";
		youtubeversionlink.href = "javascript:playutube();";
		youtubeversionlink.title = "YouTube HQ version video - less than 10min"
	}
	

} catch (e) {
	alert("Error(playgooglevideo) - EName: " + e.name + ". EMsg: " + e.message);
}
}

function playutube(a1){
try {

	var leftspanmenuobj = document.getElementById("midtd3");clearBoxBorder();
	if (leftspanmenuobj) { leftspanmenuobj.style.border = "2px solid #ADB9B7";}
	
	
	//var elSel = document.getElementById('selectX');
	var selIdx = a1; //elSel.selectedIndex; //alert('seleidx ' + selIdx);
	//alert('arylen=' + VideoInfoAry.length);

	if (selIdx < 0) {selIdx =0; }
	//alert('seleidx ' + selIdx);

	var descdiv = document.getElementById('descdiv');
	oneVideoInfo = VideoInfoAry[selIdx];
	//alert(oneVideoInfo.linkDocId);

	k1 = youtubeIdSrv; //oneVideoInfo.youtubeid;

        //alert(k1);	
	
	//var fo = new SWFObject("http://www.youtube.com/apiplayer?enablejsapi=1&playerapiid=ytplayer", "ytapiplayer", width, height, 7,"#000000");
	//ytplayer = document.getElementById("ytapiplayer");
	//alert(ytplayer);
	//fo.addVariable("docId", k1);
	//fo.addVariable("autoPlay", "true");
	//fo.write("swfplayer");
	
	      //var params = { allowScriptAccess: "always", bgcolor: "#cccccc" };
	      // this sets the id of the object or embed tag to 'myytplayer'.
	      // You then use this id to access the swf and make calls to the player's API
	      //var atts = { id: "myytplayer" };
	      //swfobject.embedSWF("http://www.youtube.com/apiplayer?enablejsapi=1&playerapiid=ytplayer", 
              //           "swfplayer", "400", "300", "8", null, null, params, atts);
              //ytplayer = document.getElementById("myytplayer");
	//alert(ytplayer);
	//ytplayer.loadVideoById(k1, 0);
	
	if (k1 == "") {
		alert("Sorry, there is no YouTube version for this video");
	} else {

		var youtubeversionlink = document.getElementById("youtubeversionidlink");
		
		if (youtubeversionlink) {
			youtubeversionlink.innerHTML = "Full Video";
			youtubeversionlink.href = "javascript:playgooglevideo();";
			youtubeversionlink.title = "Full video"
		}
		
		var fo = new SWFObject("http://www.youtube.com/v/" + k1, "flashCaptPicard", width, height, "7");
		//fo.addVariable("autoPlay", "true");
		fo.addVariable("autoplay", 1);
		fo.addVariable("fmt", 18); //- hi definition
		fo.addVariable("iv_load_policy", 3); //- to stop annotations
	        fo.write("swfplayer");
	}



} catch (e) {
	alert("Error(playutube) - EName: " + e.name + ". EMsg: " + e.message);
}
}

var AutoCompSelectedIndex = -1; // - value changed in autocomplete.js

function play(){
	 alert("Selected Index - " + AutoCompSelectedIndex);
}


