// -------------- Video Statistics --------------
var userClick=false;
var WMP=new Object();
window.onload=function(){
	initStats();
}
function initStats() {	
	if(navigator.appName=="Microsoft Internet Explorer" && document.getElementById("MPlayer")){
		WMP=document.getElementById("MPlayer");
		WMP.attachEvent("playStateChange",stateChange);
		WMP.attachEvent("MouseDown",clickEvent);
	}
}
function clickEvent(){
	userClick=true;
}					
function stateChange(){    				
	// Do not count the firstplay in statistics
	if(userClick && WMP.playstate==3) {						
		var fn=WMP.url;
		if(fn.indexOf("playlist.asx?")>0){
			ajaxStats(fn.substr(fn.indexOf("=")+1,fn.length-fn.indexOf("=")));
			userClick=false;
		}
	}
}
function ajaxStats(id)
{		
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 	
	if (id>'') {
		var url="/stats/vidstats.asp?gid="+id;
		url+="&sid="+Math.random();		
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);	
	}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();  
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("MSXML2.XMLHTTP");	
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");	
    }
  }
return xmlHttp;
}
// -------------- Video Statistics --------------

function toggleBox(szDivID,css_class)
{      
   document.getElementById(szDivID).className = 
   	(document.getElementById(szDivID).className == css_class+'_off') ? css_class+'_on' : css_class+'_off';   	
}

function playVideo(filepath,gal_id)
{	
	var loc
	
	var gidPos = location.href.indexOf('&gid');
	if (gidPos==-1) 
		loc = location.href+'&gid='+gal_id;
	else
		loc = String(location.href).substring(0,gidPos)+'&gid='+gal_id;
		
	// Get rid of the #top
	loc = loc.replace("#top","");
	
	if (document.getElementById('video_title')) {		
		document.getElementById('video_title').innerHTML=document.getElementById('t'+gal_id).innerHTML;
		document.getElementById('video_desc').innerHTML=document.getElementById('d'+gal_id).innerHTML+'<br><br><strong>URL (Copy this link and send to friends and family):</strong><br><input type="text" value="'+loc+'" class="video_url" onClick="javascript:this.focus();this.select();" readonly="true" style="width:95%;font-size:9px;">';
	}
    if (navigator.appName == "Microsoft Internet Explorer")
    {
	  document.getElementById('MPlayer').url=filepath;			
	  document.getElementById('MPlayer').controls.play();
    }
    else
    {  	
	  document.location=loc;					
    }	
    //document.location=loc;	
    document.location = "#top";	  
}

function vote(gal_id)
{
	var loc
	
	var gidPos = location.href.indexOf('&gid');
	if (gidPos==-1) 
		loc = location.href+'&gid='+gal_id;
	else
		loc = String(location.href).substring(0,gidPos)+'&gid='+gal_id;
	
	if (document.getElementById('video_title')) {
		document.getElementById('video_title').innerHTML=document.getElementById('t'+gal_id).innerHTML;
		document.getElementById('video_desc').innerHTML=document.getElementById('d'+gal_id).innerHTML+'<strong>URL</strong><input type="text" value="'+loc+'" class="video_url" onClick="javascript:this.focus();this.select();" readonly="true" />'+
					'<br><br><iframe name="I2" src="/portals/yst/vote.asp?gid='+gal_id+'" width="200" scrolling="no" border="0" frameborder="0"></iframe>';
	}
	document.location = "#top";	  
}

function pausecomp(millis) 
{
var date = new Date();
var curDate = null;

do { curDate = new Date(); } 
while(curDate-date < millis);
} 

function showPic (whichpic,img_id) { 	
 	if (document.getElementById) {
	  var fname=whichpic.href.split("/");	  
	  	  
	  // Remove the border around the thumbnail
	  document.getElementById('b'+document.getElementById('r2r_image_id').innerHTML).className = 'r2r_thumbnail_off';
	  
	  var id_len = whichpic.id.length;
	  document.getElementById('r2r_image_id').innerHTML = whichpic.id.substring(id_len, 1);
	  
	  //document.getElementById('fname').innerHTML = fname[fname.length-1];
	  document.getElementById('fname').innerHTML = document.getElementById('p'+img_id).innerHTML;
	  
	  // Put a border around the thumbnail
	  document.getElementById('b'+img_id).className = 'r2r_thumbnail_on';
	  
	  if (document.getElementById('placeholder').filters) 
	  	document.getElementById('placeholder').filters[0].apply();	  
	  document.getElementById('placeholder').src = whichpic.href;
	  if (document.getElementById('placeholder').filters)
	  	document.getElementById('placeholder').filters[0].play();	  	  
	  if (whichpic.title) {
		   document.getElementById('desc').childNodes[0].nodeValue = whichpic.title;
		} else {
		   document.getElementById('desc').childNodes[0].nodeValue = whichpic.childNodes[0].nodeValue;
		}		
	  return false;
	} else {
	  return true;
 	}
}
function nextImage (curpage,maxpage) { 	
 	var curIndex; 		
 	
 	var img_id = document.getElementById('r2r_image_id').innerHTML;
 	if (img_id.length>0)
 		curIndex = ArraySearch(img_id,jsArray);
 	else
 		curIndex = 0;
 				
	if (curIndex<jsArray.length-2)
 		showPic (document.getElementById('n'+jsArray[curIndex+1]),jsArray[curIndex+1]); 	 	 	 	 		 		
 	else
 		if (curpage<maxpage) {
 			if (location.href.indexOf('&pag=')>0) 
 				location.href=location.href.replace('&pag='+curpage,'&pag='+(curpage+1));
 			else	
 				location.href=location.href+'&pag='+(curpage+1);
 		}
}
function previousImage (curpage,maxpage) { 	
 	var curIndex; 	
 	
 	var img_id = document.getElementById('r2r_image_id').innerHTML;
 	if (img_id.length>0)
 		curIndex = ArraySearch(img_id,jsArray);
 	else
 		curIndex = 0;
 	
 	if (curIndex>0)
 		showPic (document.getElementById('n'+jsArray[curIndex-1]),jsArray[curIndex-1]); 	 	
 	else
 		if (curpage>1) {
 			if (location.href.indexOf('&pag=')>0) 
 				location.href=location.href.replace('&pag='+curpage,'&pag='+(curpage-1));
 			else	
 				location.href=location.href+'&pag='+(curpage-1);
 		}
}
function ArraySearch( searchS, arraySA ) {
 var I = 0;
 var minI = 0;
 var maxI = arraySA.length - 1;
 //
 var s = "";
 //
 var foundB = false;
 //
 I = minI - 1;
 while ( ( I <= maxI ) && ( !( foundB ) ) ) {
  I = I + 1;
  s = arraySA[ I ];
  foundB = ( searchS == s );
  }
 if ( foundB ) {
  return( I );
 }
 else {
  return(-1); 
 }
}
function hostInfo(i) {
	document.getElementById('about_show').className='r2r_about_off';
	if (i==841) {
		document.getElementById('about_host1').className='r2r_about_on';	
		document.getElementById('about_host2').className='r2r_about_off';	
	} else {
		document.getElementById('about_host1').className='r2r_about_off';	
		document.getElementById('about_host2').className='r2r_about_on';	
	}
}

function Querystring(qs) { // optionally pass a querystring to parse
	this.params = new Object()
	this.get=Querystring_get
	
	if (qs == null)
		qs=location.search.substring(1,location.search.length)

	if (qs.length == 0) return

// Turn <plus> back to <space>
// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ')
	var args = qs.split('&') // parse out name/value pairs separated via &
	
// split out each name=value pair
	for (var i=0;i<args.length;i++) {
		var value;
		var pair = args[i].split('=')
		var name = unescape(pair[0])

		if (pair.length == 2)
			value = unescape(pair[1])
		else
			value = name
		
		this.params[name] = value
	}
}

function Querystring_get(key, default_) {
	// This silly looking line changes UNDEFINED to NULL
	if (default_ == null) default_ = null;
	
	var value=this.params[key]
	if (value==null) value=default_;
	
	return value
}
