var uri;

function hover_star(star, active, baseurl) 
{
  	if (active) 
    	  src = baseurl+"images/watchme/ratingAct.png";
  	else 
  	{
    	  star = 5;
    	  src = baseurl+"images/watchme/ratingDeact.png";
  	}

  	switch(star) 
  	{
    	  case (5):
      		document["star5"].src=src;
    	  case (4):
      		document["star4"].src=src;
    	  case (3):
      		document["star3"].src=src;
    	  case (2):
      		document["star2"].src=src;
    	  case (1):
      		document["star1"].src=src;
  	}
}

function showdata(event) {
        if (event) uri = event.data.uri;
          else uri = $F("uri");
        
	if (!uri) return;

        getMetaData(uri);
        window.location ='#show';
}

function getMetaData()
{
  	xmlHttpMeta=GetXmlHttpObject()
  	if (xmlHttpMeta==null)
  	{
    		alert ("Your browser does not support AJAX!");
    		return;
  	}

  	var url="http://www.mysandbox.com/jscalls/watchme/kyte-show.php";
      	    url=url+"?method=get_metadata";
            url=url+"&uri="+uri;

  	xmlHttpMeta.onreadystatechange=stateChangedMeta;
  	xmlHttpMeta.open("GET",url,true);
  	xmlHttpMeta.send(null);
}

function stateChangedMeta()
{
  	if (xmlHttpMeta.readyState==4)
  	{
    		var ret = xmlHttpMeta.responseText;
    		var rs = ret.split("|", 4);

    		document.getElementById('image').innerHTML="";
    		document.getElementById('title').innerHTML=rs[0];
    		document.getElementById('owner').innerHTML=rs[1];
    		document.getElementById('numviews').innerHTML=rs[2];
    		document.getElementById('numcomments').innerHTML=rs[3];
  	}
  	else
  	{
    		document.getElementById('image').innerHTML="<img src='http://www.mysandbox.com/images/watchme/progress.gif'></img>";
  	}
}

function rateShow(prate)
{
	if(uri)
	{
		if(confirm("Are you sure you want to rate this video as "+prate+"?")){
  			xmlHttpShow=GetXmlHttpObject()
  			if (xmlHttpShow==null)
  			{
    		  	  alert ("Your browser does not support AJAX!");
    		  	  return;
  			}

  			var url="http://www.mysandbox.com/jscalls/watchme/kyte-show.php";
            	    	    url=url+"?method=rate_show";
            	            url=url+"&rate="+prate;
            	            url=url+"&uri="+uri;

  			xmlHttpShow.onreadystatechange=stateChangedShow;
  			xmlHttpShow.open("GET",url,true);
  			xmlHttpShow.send(null);
		}
	}else{
		alert("Show not yet available! Please wait and try again later.");
	}

}

function stateChangedShow()
{
  	if (xmlHttpShow.readyState==4)
  	{
    		var ret = xmlHttpShow.responseText;
    		if (!ret) ret = "  Show successfully rated.";

    		alert(ret);
    		getMetaData(uri);
		window.location ='#show';
  	}
}

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;
}




