<!--

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_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_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 extLink(url) {  //Open a Popup
    window.open(url); 
	return false;
	}
	
// DISABLE Right Clicking	
document.oncontextmenu = new Function("return false")

FORM_DATA = createRequestObject();
var url_requested_video=FORM_DATA['v'];


function loadGalleryXML(xmlfileIn) {
    loadXMLDoc(xmlfileIn);
    return false;
    };


var req;

function loadXMLDoc(url) { // Load XML Document from a URL (Must be SAME domain)
    
    if (window.XMLHttpRequest) {
      req = new XMLHttpRequest();
      req.onreadystatechange = processReqChange;
      req.open("GET", url, true);
      req.send(null);
      
	  // branch for IE/Windows ActiveX version
      } else if (window.ActiveXObject) {
      isIE = true;
      req = new ActiveXObject("Microsoft.XMLHTTP");
      if (req) {
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        req.send();
        }
      }
    };


function processReqChange() {  // XML onLoad handler
    
    if (req.readyState == 4) {
      if (req.status == 200) {  // only if "OK"
	    //XML is Loaded - Process it
        build_ChannelList();
        } else {
        alert("There was a problem retrieving the XML data:\n" +
        req.statusText);
        }
      }
    };


var curr_channel = 0;
var channelArry = [];
var videos_per_page = 15;
var videoClipArry = [];

var thumb_dir = "";
var image_dir = "";



function build_ChannelList() {
    // grab the some global settings	
	var global_settings = req.responseXML.getElementsByTagName("WINKplaylist");
	
	thumb_dir = global_settings[0].attributes.getNamedItem("thumb_dir").nodeValue;
	image_dir = global_settings[0].attributes.getNamedItem("image_dir").nodeValue;
	
	 // loop through <channels> elements and build a list of channels
    var channels = req.responseXML.getElementsByTagName("channel");
  	var listStr = "";

    for (var i = 0; i < channels.length; i++) {
      var ch_title = getElementTextNS("", "title", channels[i], 0);
	  var ch_desc = getElementTextNS("", "description", channels[i], 0);
	 
	  channelArry[i] = new Array();	  
      var myArray = {"ch_title": ch_title, "ch_desc": ch_desc }; 
	  channelArry[i].push(myArray);
      
	  listStr += "<div class=\"channel_button\" id=\"butt_channel" + i  + "\" ";
	  listStr += "onmouseover=\"ch_navOver('butt_channel"+ i +"');\" onmouseout=\"ch_navOff('butt_channel"+ i+"');\" ";
	  listStr += "onclick=\"loadChannel(" + i + ");\" ";
      listStr += "title=\"" + ch_desc + "\" >";
	  listStr += ch_title;
      listStr += "</div>";
	  	  
	  // Locate the video in the orignal page quesry String....
	  var videosNode = channels[i].getElementsByTagName("video");
	  
	  for (var j = 0; j < videosNode.length; j++) {
        var vnodeid = ""; 
		
		try {
	      vnodeid = videosNode[j].attributes.getNamedItem("id").nodeValue;
	      } catch (e) {
	      vnodeid = "";
	      }
        

        if (url_requested_video == vnodeid && url_requested_video != "") {
		  curr_channel = i;
		  }
		} // end Locate Video
	  
      }
	
    document.getElementById("channel_buttons").innerHTML = "<div id=\"img_gal\">" + listStr + "</div>";
	document.getElementById("video_share").innerHTML =  getShareLinks();
	
	// load up the current channel - if no video was on the querysting this will be the first channel 0	
	loadChannel(curr_channel);
    };


var thumbsMode = "thumbs"
var channel_page = 0;
var channel_page_cnt = 0;

function channel_view(channelNum,styleIn) {
 
    if (styleIn != "list") {
      thumbsMode = "thumbs";
	  document.getElementById("view_thumbs").src = "_images/icons/butt_view_thumbs_m.gif";
	  document.getElementById("view_list").src = "_images/icons/butt_view_list.gif";
      } else {
	  thumbsMode = "list";
	  document.getElementById("view_thumbs").src = "_images/icons/butt_view_thumbs.gif";
	  document.getElementById("view_list").src = "_images/icons/butt_view_list_m.gif";
      }
    channelThumbs(channelNum, channel_page, channel_page_cnt);  
    };


function loadChannel(xmlElementIn) {  // Loads a channel from the XML
    
	var galleryParent = req.responseXML.getElementsByTagName("channel")[xmlElementIn];
	var galleryNode = galleryParent.getElementsByTagName("clips")[0];
	var videosNode = galleryNode.getElementsByTagName("video");
	var channelNum = parseInt(xmlElementIn)	;
    
	var mda = 0;
	var current_arrayindex = 0;
	var current_page = 1;
	
	var ch_title = channelArry[channelNum][0]['ch_title'];
	
	var div_channel_title = document.getElementById("channel_head");
	var chan_thumbhtml = "";
	
	chan_thumbhtml += "<div id=\"ch_head_left\">Channel: " + ch_title + "</div>";
	chan_thumbhtml += "<div id=\"ch_head_right\"><img id=\"view_list\" src=\"_images/icons/butt_view_list.gif\" onclick=\"channel_view("+channelNum+",'list');\"  />";
	
	chan_thumbhtml += "<img id=\"view_thumbs\" src=\"_images/icons/butt_view_thumbs.gif\" onclick=\"channel_view("+channelNum+",'thumbs');\" />";
	chan_thumbhtml += "</div>";
	
	div_channel_title.innerHTML = chan_thumbhtml;
	
	videoClipArry[channelNum] = new Array();
    videoClipArry[channelNum] = [];
	
	// Loop through the Videos and make some thumbnails
    for (var i = 0; i < videosNode.length; i++) {
		
	  // Group the array so we have pages
	  if (i % videos_per_page == 0) {
	    mda ++;
		videoClipArry[channelNum][mda] = new Array();
		}

        var vid_file = "";
        var vid_id = "";
        var vid_length = "";
        var vid_title = "";
        var vid_description = "";
        var vid_thumb_img = "";
        var vid_poster_img = "";
		var vid_views = "";
        var vid_posted = "";
        var vid_votedown = "";
        var vid_voteup = "";


        try {
          vid_file = videosNode[i].attributes.getNamedItem("file").nodeValue;
          } catch (e) {
          vid_file = "";
          }

        try {
          vid_id = videosNode[i].attributes.getNamedItem("id").nodeValue;
          } catch (e) {
          vid_id = "";
          }

        try {
          vid_length = videosNode[i].attributes.getNamedItem("length").nodeValue;
          } catch (e) {
          vid_length = "";
          }

        try {
          vid_thumb_img = videosNode[i].attributes.getNamedItem("thumb").nodeValue;
          } catch (e) {
          vid_thumb_img = "No Image";
          }

        try {
          vid_poster_img = videosNode[i].attributes.getNamedItem("poster").nodeValue;
          } catch (e) {
          vid_poster_img = "No Image";
          }
		  
		try {
          vid_voteup = videosNode[i].attributes.getNamedItem("voteup").nodeValue;
          } catch (e) {
          vid_voteup = "0";
          }
		  
		try {
          vid_votedown = videosNode[i].attributes.getNamedItem("votedown").nodeValue;
          } catch (e) {
          vid_votedown = "0";
          }
		  
		try {
          vid_views = videosNode[i].attributes.getNamedItem("views").nodeValue;
          } catch (e) {
          vid_views = "No Image";
          }
		  
		try {
          vid_posted = videosNode[i].attributes.getNamedItem("posted").nodeValue;
          } catch (e) {
          vid_posted = "--/--/--";
          }
		  
        try {
          vid_title = URLEncode(videosNode[i].getElementsByTagName("title")[0].firstChild.nodeValue);
          } catch (e) {
          vid_title = "No Title";
          }

        try {
          vid_description = URLEncode(videosNode[i].getElementsByTagName("desc")[0].firstChild.nodeValue);
          } catch (e) {
          vid_description = "";
          }
		  
	  var rateup = parseInt(vid_voteup);
	  var ratedown = parseInt(vid_votedown);
	  var vid_rating = 0;
	  
	  if (rateup < 1) {
	    rateup = 0;
	    }
		
	  if (ratedown < 1) {
	    ratedown = 0;
	    }
		
	  vid_rating = (rateup - ratedown);

        // Make sure we dont add any duds
	  if (vid_file != "") {
		  
		var myArray = {"channelNum": channelNum,
					   "vid": vid_id, 
				   	   "vfile": vid_file, 
				       "vlen": vid_length, 
				       "vtitle": vid_title, 
				       "vposter": vid_poster_img, 
				       "vthumb": vid_thumb_img, 
				       "vdesc": vid_description,
					   "views": vid_views,
                       "vposted": vid_posted,
                       "votedown": vid_votedown,
                       "voteup": vid_voteup,
					   "rating": vid_rating}; 

	    videoClipArry[channelNum][mda].push(myArray);
	    }
		
      // If the video is the one in the URL make sure we load it
	  if (url_requested_video == vid_id && url_requested_video != "") {
		current_arrayindex = videoClipArry[channelNum][mda].length - 1;	
		current_page = mda;
		}	  
	  }
	  
      // Load up the current video is there is one
      if (url_requested_video != "") {
        openVideo(channelNum, 0, current_page, current_arrayindex);
		add2playlist(channelNum,current_page,current_arrayindex,vid_title);
		// Clear out the video
		url_requested_video = "";
        }
	
	ch_navClick('butt_channel',channelNum);
	
	// Show the thumbnails open to the right page
	channelThumbs(channelNum, current_page, mda);
	};
	


function channelThumbs(channelNum, page, page_cnt) {  // Draws the video thumbnails and page numbers

    channel_page = page;
	channel_page_cnt = page_cnt;

	var div_videoThumbs_html = "";
	var thumbPageNumbers = "";
	
	if (thumbsMode == "thumbs") {
	  document.getElementById("view_thumbs").src = "_images/icons/butt_view_thumbs_m.gif";
	  document.getElementById("view_list").src = "_images/icons/butt_view_list.gif";
      } else {
	  document.getElementById("view_thumbs").src = "_images/icons/butt_view_thumbs.gif";
	  document.getElementById("view_list").src = "_images/icons/butt_view_list_m.gif";
      }
	  

    if (thumbsMode == "thumbs") {  // SHOW A LIST OF THUMBNAILS WITH PAGE NUMBER
	  div_videoThumbs_html = "<div id=\"video_thumbs\">"
  	 
      for (var i = 0; i < videoClipArry[channelNum][page].length; i++) {
	
        var vid_file = videoClipArry[channelNum][page][i]['vfile'];
        var vid_title = videoClipArry[channelNum][page][i]['vtitle'];
        var vid_description = videoClipArry[channelNum][page][i]['vdesc'];
        var vid_thumb_img = videoClipArry[channelNum][page][i]['vthumb'];
	    var vid_poster_img = videoClipArry[channelNum][page][i]['vposter'];
        var vid_length = videoClipArry[channelNum][page][i]['vlen'];
	    var vid_vdown = videoClipArry[channelNum][page][i]['votedown'];
	    var vid_vup = videoClipArry[channelNum][page][i]['voteup'];
	    var vid_rating = videoClipArry[channelNum][page][i]['rating'];
	  
	    var votestr = "";		  
	  
	    if (vid_rating < 0) {
	      votestr = "<span id=\"thumb_votesdown\">" + vid_rating.toString() + "</span>";
		  } else {
	      votestr = "<span id=\"thumb_votesup\">+" + vid_rating.toString() + "</span>";
		  }
		  
	    if (vid_thumb_img == "") {
	      vid_thumb_img = "no_thumb.jpg";
	      }
		
	    if (vid_poster_img == "") {
	      vid_poster_img = "no_poster.jpg";
	      }
	    
		var clickopen = "";
		var clickplaylist = "";
	    
		clickopen = "onclick=\"openVideo("+ channelNum +",'1'," + page + "," + i + "); add2playlist("+ channelNum +"," + page + "," + i + ",'" + vid_title + "');\" ";
	    clickplaylist = "onclick=\"add2playlist("+ channelNum +"," + page + "," + i + ",'" + vid_title + "');\" ";
	    clickplaylist += "onmouseover=\"this.className = 'thumb_addplaylist_m';\" ";
		clickplaylist += "onmouseout=\"this.className = 'thumb_addplaylist';\" ";
	  
	    // Create the innerHTML for the channel thumbnails
	    div_videoThumbs_html += "<div id=\"thumb\" " + "" + " title=\"" + URLDecode(vid_description) + "\" >";
        div_videoThumbs_html += "<div id=\"thumb_img\" "+ clickopen +"><img id=\"imgGal2" + i + "\" ";
		div_videoThumbs_html += "src=\"" + thumb_dir + vid_thumb_img + "\"  /></div>";
	    div_videoThumbs_html += "<div id=\"thumb_txt\" "+ clickopen +"><span id=\"thumb_title\">" + URLDecode(vid_title) + "</span> ";
	    div_videoThumbs_html += "<span id=\"thumb_length\"> (" + vid_length + ")</span></div>";
	    div_videoThumbs_html += "<div id=\"thumb_bottom\">";
	    div_videoThumbs_html += "<div id=\"thumb_votes\">" + votestr + "</div>";
	    div_videoThumbs_html += "<div id=\"addpl"+i+"\" class=\"thumb_addplaylist\" " + clickplaylist + " ";
		div_videoThumbs_html += "title=\"" + "Add to Playlist" + "\"></div>";
	    div_videoThumbs_html += "</div></div>";
        }
	  
	  div_videoThumbs_html += "</div>";
	  
	  } else {  // SHOW A LIST OF VIDEOS WITH NO PaGE NUMBERS
		
	  div_videoThumbs_html += "<div id=\"video_list\"><table class=\"videolist\" cellpadding=\"0\" cellspacing=\"0\" >"
	  div_videoThumbs_html += "<tr class=\"videolist_header\"><td>Title</td><td>Description</td>";
	  div_videoThumbs_html += "<td>Length</td><td>Rating</td><td>Playlist</td></tr>"
	  	  
	  var modCounter = 0;
	  
	  for (var j = 1; j < videoClipArry[channelNum].length; j++) {
        for (var i = 0; i < videoClipArry[channelNum][j].length; i++) {
	      modCounter ++
          var vid_file = videoClipArry[channelNum][j][i]['vfile'];
          var vid_title = videoClipArry[channelNum][j][i]['vtitle'];
          var vid_description = videoClipArry[channelNum][j][i]['vdesc'];
          var vid_thumb_img = videoClipArry[channelNum][j][i]['vthumb'];
	      var vid_poster_img = videoClipArry[channelNum][j][i]['vposter'];
          var vid_length = videoClipArry[channelNum][j][i]['vlen'];
		  var vid_rating = videoClipArry[channelNum][page][i]['rating'];	
		  
	      if (vid_thumb_img == "") {
	        vid_thumb_img = "no_thumb.jpg";
	        }
		
	      if (vid_poster_img == "") {
	        vid_poster_img = "no_poster.jpg";
	        }
		
		  var cssClass = ""
		  if (modCounter % 2) {
		    cssClass = "videolist_1";
		    } else {
			cssClass = "videolist_2"; 
		    }
			
		  if (vid_rating < 0) {
	        votestr = "<span id=\"thumb_votesdown\">" + vid_rating.toString() + "</span>";
		    } else {
	        votestr = "<span id=\"thumb_votesup\">+" + vid_rating.toString() + "</span>";
		    }
			
		  var clickopen = "";
		  var clickplaylist = "";
	    
		  clickopen = "onclick=\"openVideo("+ channelNum +",'1'," + page + "," + i + ");add2playlist("+ channelNum +"," + page + "," + i + ",'" + vid_title + "');\" ";
	      clickplaylist = "onclick=\"add2playlist("+ channelNum +"," + page + "," + i + ",'" + vid_title + "');\" ";
	      clickplaylist += "onmouseover=\"this.className = 'thumb_addplaylist_m';\" ";
		  clickplaylist += "onmouseout=\"this.className = 'thumb_addplaylist';\" ";
	  
	      // Create the innerHTML for the channel list      
		  div_videoThumbs_html += "<tr class=\"" + cssClass + "\"; "
		  div_videoThumbs_html += "onmouseover=\"this.className = 'videolist_over';\" ";
		  div_videoThumbs_html += "onmouseout=\"this.className = '" + cssClass + "';\" ";
		  div_videoThumbs_html += ">";
	      div_videoThumbs_html += "<td " + clickopen + "><b>" + URLDecode(vid_title) + "</b></td>";
		  div_videoThumbs_html += "<td " + clickopen + ">" + URLDecode(vid_description) + "</td>";
	      div_videoThumbs_html += "<td " + clickopen + ">" + vid_length + "</td>";
		  div_videoThumbs_html += "<td><div id=\"thumb_votes\">" + votestr + "</div></td>";
		  div_videoThumbs_html += "<td><div id=\"addpl"+i+"\" class=\"thumb_addplaylist\" " + clickplaylist + " ";
		  div_videoThumbs_html += "title=\"" + "Add to Playlist" + "\"></div></td>";
		  div_videoThumbs_html += "</tr>";
		  }
	    }
      div_videoThumbs_html += "</table>"
	  }
	
	// Clear Left and Right
    div_videoThumbs_html += "<div class=\"clear\"></div>";
	div_videoThumbs_html += "</div>";
	
		
    // show the page numbers if there is more than one page in the channel
	if (page_cnt > 1 & thumbsMode == "thumbs") {
	  thumbPageNumbers = "<div id=\"video_pagenumbers\">";
	  
	  for (var i = 1; i < page_cnt + 1; i++) {
	    if (i == page) {
	      thumbPageNumbers += "<div class=\"numberlinksOver\" >" +  (i) + "</div>";
	      } else {
	      thumbPageNumbers += "<div class=\"numberlinks\" ";
		  thumbPageNumbers += "onclick=\"channelThumbs(" + channelNum + "," + i + ", " + page_cnt + ");\" >" +  (i) + "</div>";
	      }	
	    }
		thumbPageNumbers += "<div class=\"clear\"></div>";
	    thumbPageNumbers += " </div>";
	  }
	 		
    // Populate the DIVs with the new html
	document.getElementById("video_list").innerHTML =  div_videoThumbs_html;
	document.getElementById("channel_foot").innerHTML = thumbPageNumbers;
    };
	


function openVideo(channelNum, autoplay, page, indx){

	var vid_id = videoClipArry[channelNum][page][indx]['vid'];
	var vid_file = videoClipArry[channelNum][page][indx]['vfile'];
       var vid_title = videoClipArry[channelNum][page][indx]['vtitle'];
       var vid_description = videoClipArry[channelNum][page][indx]['vdesc'];
       var vid_thumb_img = videoClipArry[channelNum][page][indx]['vthumb'];
	var vid_poster_img = videoClipArry[channelNum][page][indx]['vposter'];
       var vid_length = videoClipArry[channelNum][page][indx]['vlen'];
	var vid_views = videoClipArry[channelNum][page][indx]['views'];
	var vid_vposted = videoClipArry[channelNum][page][indx]['vposted'];
	var vid_votedown = videoClipArry[channelNum][page][indx]['votedown'];
	var vid_voteup = videoClipArry[channelNum][page][indx]['voteup'];
	
	
	var metahtml = "";
	metahtml += "Posted: <b>" + cleanDate(vid_vposted) + "</b> ";
	metahtml += "Length: <b>" + URLDecode(vid_length) + "</b> ";
	metahtml += "Views: <b>" + vid_views + "</b>";

	document.getElementById("video_metadata").innerHTML = metahtml;
	document.getElementById("video_title").innerHTML = "<h1>" + URLDecode(vid_title) + "</h1>";
	document.getElementById("video_title").innerHTML += "<h2>" + URLDecode(vid_description) + "</h2>";	
	
	voting(0, vid_voteup, vid_votedown, vid_id);
	mainVideo(autoplay, vid_title, vid_file, image_dir + vid_poster_img, vid_id);
	window.scroll(0,0);	
	
	// Set the URL and title for sharing
	setShareLink(URLEncode(window.location.href.split("?")[0] + "?v=" + vid_id), vid_title, vid_description);
	};


var videoPlaylist = [];
var plistcnter = 0;

function add2playlist(channelNum, page, indx, title) {
		
	var tmpunique = channelNum + "." + page + "." + indx;
	var foundunique = 0;
	
	// Make sure it is not already in the playlist cue
	for (var i = 0; i < videoPlaylist.length; i++) {
	  var findunique = videoPlaylist[i]['channelNum'] + "." + videoPlaylist[i]['page'] + "." + videoPlaylist[i]['index'];
	  if (findunique == tmpunique) {
		foundunique = 1;
	    }
	  }
	
	if (foundunique == 0) {
	  var myArray = { "plid":plistcnter, "channelNum":channelNum, "page": page, "index": indx, "title": title, "watched":0 }; 
      videoPlaylist.push(myArray);
	  plistcnter ++;
      drawplaylist();
	  }
    };
	
function removeplaylist(plid) { // Remove from the Playlist
	for (var i = 0; i < videoPlaylist.length; i++) {	  
	  if (videoPlaylist[i]['plid'] == plid) {
	    videoPlaylist.remove(i);
	    }
	  }
	drawplaylist();
    };
	
Array.prototype.remove = function(from, to) { // Removes an item from the array
    var rest = this.slice((to || from) + 1 || this.length);
    this.length = from < 0 ? this.length + from : from;
    return this.push.apply(this, rest);
    };
	
function nextInPlayList() {  // Find the next video in the playlist that has not been watched
    var nextVideo = -1;

	for (var i = 0; i < videoPlaylist.length; i++) {	
	  var tmpWatched = videoPlaylist[i]['watched'];
		
	  if (tmpWatched == 0) {
	    nextVideo = i;
	    break;
	    }
	  }
		
	if (nextVideo >= 0) {
	  updatePlaylistStatus(videoPlaylist[nextVideo]['plid']); 
	  openVideo(videoPlaylist[nextVideo]['channelNum'],1,videoPlaylist[nextVideo]['page'],videoPlaylist[nextVideo]['index']);
	  }
	};


function updatePlaylistStatus(plid) {  // Marks an item in the Playlist as watched.
	for (var i = 0; i < videoPlaylist.length; i++) {
	  if (videoPlaylist[i]['plid'] == plid) {
	    videoPlaylist[i]['watched'] = 1;
		}
	  }
	};
	

function drawplaylist() { // Draws 
	var playlistHead = "<div id=\"playlist_head\" >Playlist</div>";
	var playlistHtml = "<table width=\"100%\" class=\"playlist_items\" cellpadding=\"0\" cellspacing=\"0\" >";
	var modCounter = 0;
	
	for (var i = 0; i < videoPlaylist.length; i++) {
		
		var tmpchannelNum = videoPlaylist[i]['channelNum'];
		var tmpPage = videoPlaylist[i]['page'];
		var tmpIndex = videoPlaylist[i]['index'];
		var tmpPlid = videoPlaylist[i]['plid'];
		var tmpWatched = videoPlaylist[i]['watched'];
				
		var thumbimg = thumb_dir + videoClipArry[tmpchannelNum][tmpPage][tmpIndex]['vthumb'];
		var thumbClick = "title=\"Play Now\" onclick=\"updatePlaylistStatus("+tmpPlid+"); openVideo(" + tmpchannelNum + ",1," + tmpPage + "," + tmpIndex + ");\"";
		
        modCounter ++
		var cssClass = ""
		if (modCounter % 2) {
		  cssClass = "videolist_1";
		  } else {
		  cssClass = "videolist_2";  
		  }
		
		playlistHtml += "<tr class=\""+ cssClass+"\">"
		playlistHtml += "<td width=\"42px\" "+thumbClick+" >" + "<img class=\"plthumb\" src=\"" + thumbimg + "\"  />" + "</td>";
		playlistHtml += "<td "+thumbClick+">" + URLDecode(videoClipArry[tmpchannelNum][tmpPage][tmpIndex]['vtitle']) + "</td>";
		playlistHtml += "<td width=\"20px\" align=\"right\"><img title=\"Remove from Playlist\" src=\"_images/icons/playlist_remove.gif\" ";
		playlistHtml += "onclick=\"removeplaylist(" + tmpPlid + ");\" width=\"20\" height=\"20\"  />" + "</td>";
		playlistHtml += "</tr>";
		}
		document.getElementById("video_playlist").innerHTML = playlistHead + "<div id=\"playlist_scroll\" >" + playlistHtml + "</div>";	
    }


function voting(staus, voteup, votedown, vid) {
	
	var upvotes = 0;
	var downvotes = 0;
	
	var action_voteup = " onclick=\"voting(1,"+ voteup +","+ votedown +","+ vid +");\" title=\"Votes " + voteup +  "\" ";
	var action_votedown = " onclick=\"voting(2, "+ voteup +","+ votedown +","+ vid +");\" title=\"Votes " + votedown +  "\" ";
	
    switch (staus) {
      case 0:
	    upvotes = voteup;
		downvotes = votedown;
        break
      case 1:  // Vote for
	    upvotes = voteup + 1;
		downvotes = votedown;
        break
      case 2: // vote against
	    upvotes = voteup;
		downvotes = votedown + 1;
        break
	  }
	
	var upvotesStr = upvotes.toString();
	var downvotesStr = downvotes.toString();
	
    if (upvotesStr.length > 3) {
	  upvotesStr = Left(upvotesStr, (upvotesStr.length - 3)) + "K";	  
	  }
	  
	if (downvotesStr.length > 3) {
	  downvotesStr = Left(downvotesStr, (downvotesStr.length - 3)) + "K";
	  }
	  
	if (staus == 0) {
	  action_voteup = " onclick=\"voting(1,"+ voteup +","+ votedown +","+ vid +");\" title=\"Thumbs up: " + voteup +  "\" ";
	  action_votedown = " onclick=\"voting(2, "+ voteup +","+ votedown +","+ vid +");\" title=\"Thumbs down: " + votedown +  "\" ";
	  } else {
	  action_voteup = " title=\"Thumbs up: " + voteup +  "\" ";
	  action_votedown = " title=\"Thumbs down: " + votedown +  "\" ";
	  }
	
	var votehtml = "";
	votehtml += "<div id=\"voteup\" class=\"votenumber\" "+ action_voteup +" >" + upvotesStr + "</div>" 
	votehtml += "<div id=\"votedown\" class=\"votenumber\" "+ action_votedown +" >" + downvotesStr + "</div>";
	votehtml += "<div class=\"clear\" ></div>";
	
       document.getElementById("video_vote").innerHTML = votehtml;
	
       if (staus > 0) {
	  sendvote(votingURL + "?vote=" + staus + "&v=" + vid);
	  }
      };
	


function sendvote(url) { // Sends a vote to the server 1=Liked Video 2=Sucked
    var votereq;
    if (window.XMLHttpRequest) {
      votereq = new XMLHttpRequest();
      //votereq.onreadystatechange = processReqChange;
      votereq.open("GET", url, true);
      votereq.send(null);
      
	  // branch for IE/Windows ActiveX version
      } else if (window.ActiveXObject) {
      isIE = true;
      votereq = new ActiveXObject("Microsoft.XMLHTTP");
      if (votereq) {
        //votereq.onreadystatechange = processReqChange;
        votereq.open("GET", url, true);
        votereq.send();
        }
      }
    };



var channelSelectedImg = "";
var channelSelectedIndex = -1;


function ch_navOff(obj) { //Rollout for Channels Nav 
    if (channelSelectedImg != obj) {
      document.getElementById(obj).className = "channel_button"; 
	  }
    };


function ch_navOver(obj) { //Rollover for Channels Nav  
    var chImg = document.getElementById(obj);
	
	if (channelSelectedImg != obj) {
	  chImg.className = "channel_button_over";
	  }
    };


function ch_navClick(imgGroup, index) {	//Click for Channels Nav
	var newImg = imgGroup + index;
	
    if (channelSelectedImg != "") { //Reset the old Button    
      document.getElementById(channelSelectedImg).className = "channel_button"; 
      }
	
	document.getElementById(newImg).className = "channel_button_active";

	channelSelectedImg = newImg;
	channelSelectedIndex = index;
	};
	

function URLEncode (clearString) {  //URL Encodes a String
    var output = "";
    var x = 0;
	var regex = /(^[a-zA-Z0-9_.]*)/;
    clearString = clearString.toString();
    
    while (x < clearString.length) {
      var match = regex.exec(clearString.substr(x));
      if (match != null && match.length > 1 && match[1] != "") {
        output += match[1];
        x += match[1].length;
        } else {
        if (clearString[x] == " ") {
          output += "+";
		  } else {
          var charCode = clearString.charCodeAt(x);
          var hexVal = charCode.toString(16);
          output += "%" + ( hexVal.length < 2 ? "0" : "" ) + hexVal.toUpperCase();
          }
        x++;
        }
      }
    return output;
    };
	


function URLDecode(clearString) {  //URL Encodes a String
    var output2 = "";
	var f = 0; 

    clearString = unescape(clearString.toString());
		    
    while (f < clearString.length) {
      if (clearString.charAt(f)== "+") {
          output2 += " ";
		  } else {
          output2 += clearString.charAt(f);
          }
		f++;
        }
      
    return output2;
    };
	
	

function createRequestObject() {  //// GET QUERY STRING
    FORM_DATA = new Object();
    separator = ',';
    query = '' + this.location;
    qu = query
  
    query = query.substring((query.indexOf('?')) + 1);
    // Keep everything after the question mark '?'.
    if (query.length < 1) { return false; }  // Perhaps we got some bad data?
      keypairs = new Object();
      numKP = 1;
 
    while (query.indexOf('&') > -1) {
      keypairs[numKP] = query.substring(0,query.indexOf('&'));
      query = query.substring((query.indexOf('&')) + 1);
      numKP++;
      }
	  
    keypairs[numKP] = query;
    // Store what's left in the query string as the final keypairs[] data.<
    for (i in keypairs) {
      keyName = keypairs[i].substring(0,keypairs[i].indexOf('='));
      // Left of '=' is name.
      keyValue = keypairs[i].substring((keypairs[i].indexOf('=')) + 1);
      // Right of '=' is value.
      while (keyValue.indexOf('+') > -1) {
        keyValue = keyValue.substring(0,keyValue.indexOf('+')) + ' ' + keyValue.substring(keyValue.indexOf('+') + 1);
        // Replace each '+' in data string with a space.
        }
      keyValue = unescape(keyValue);
      // Unescape non-alphanumerics
      if (FORM_DATA[keyName]) {
        FORM_DATA[keyName] = FORM_DATA[keyName] + separator + keyValue;
        } else {
        FORM_DATA[keyName] = keyValue;
        }
      }
    return FORM_DATA;
    }; //// END QUERY STRING




function getElementTextNS(prefix, local, parentElem, index) { // retrieve text of an XML document element
    var result = "";
    if (prefix && isIE) {
        // IE-Windows way of handling namespaces
        result = parentElem.getElementsByTagName(prefix + ":" + local)[index];
    	} else {
        result = parentElem.getElementsByTagName(local)[index];
    	}
		
    if (result) {
        if (result.childNodes.length > 1) {
            return result.childNodes[1].nodeValue;
        	} else {
            return result.firstChild.nodeValue;    		
        	}
    	} else {
        return "n/a";
    	}
	};


function changeOpac(opacity, id) {  // Change the opacity of an object 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
    };
	

function Left(str, n){
    if (n <= 0) {
	  return "";
	  } else if (n > String(str).length) {
	  return str;
	  } else {
	  return String(str).substring(0,n);
	  }
    }

function Right(str, n){
    if (n <= 0) {
      return "";
	  } else if (n > String(str).length) {
      return str;
	  } else {
      var iLen = String(str).length;
      return String(str).substring(iLen, iLen - n);
      }
    }



function cleanDate(dateIN) {
    var dateParts = dateIN.split("-");
    
	var month = parseInt(dateParts[1]);
    var day = dateParts[2];
    var year = dateParts[0];
  
    var monthstr = "";
    var monthOut = "";
   
    switch (month) {
      case 1:
	    monthstr = "Jan";
        break
      case 2:
	    monthstr = "Feb";
        break
      case 3:
	    monthstr = "Mar";
        break
      case 4:
	    monthstr = "Apr";
        break
      case 5:
	    monthstr = "May";
        break
      case 6:
	    monthstr = "Jun";
        break
      case 7:
	    monthstr = "Jul";
        break
	  case 8:
	    monthstr = "Aug";
        break
	  case 9:
	    monthstr = "Sep";
        break
	  case 10:
	    monthstr = "Oct";
        break
	  case 11:
	    monthstr = "Nov";
        break
	  case 12:
	    monthstr = "Dec";
        break	 
      }
	
    monthOut = day + " " + monthstr + " " + year;
    return monthOut;
    }





//-->