// -----------------------------------------------------------
// this function accepts a media id and gets the data for this
// video from the database and populates the update form
// -----------------------------------------------------------
function GetGridForGenre(genre_id,limit,start,page)
{

if (limit == '')
{
	limit = 20;
}

if (start == '')
{
	start = 0;
} 

if (genre_id.length==0)
  {
  	return;
  }
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
var url = '/cgi-bin/yourphotos.pl';
url=url+"?id="+genre_id+'&limit='+limit+'&start='+start+'&page='+page;

xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
window.location.hash="green_nav_grid";
//setTimeout('LoadFirstImage();',3000);
}

// -----------------------------------------------------------
function LoadFirstImage()
{
// this function loads the first image in the bottom grid.
var media_id = $('#grid ul li:first').attr('id');
var url = document.getElementById(media_id + '_image_url').innerHTML;
var prev = document.getElementById(media_id + '_prev').innerHTML;
var next = document.getElementById(media_id + '_next').innerHTML;
var genre_id = document.getElementById('current_genre').innerHTML;

loadUserImage(media_id,url,next,prev,genre_id);

}

// ------------------------------------

function stateChanged() 
{ 
if (xmlHttp.readyState==4)
{ 

if (xmlHttp.responseText != '')
{
	mydata = xmlHttp.responseText;
  	document.getElementById("grid").innerHTML=mydata;
	return false;
} else {
	alert('there was an error');
  	document.getElementById("grid").innerHTML="<b>There was an error loading the data.";
} // if
} // if
} 

// -----------------------------------------------------------

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");
    }
  }
if (!xmlHttp)
{ alert('Error initializing XMLHttpRequest'); }
return xmlHttp;
}

// ------------------------------------------------------

function LoadUserImage(media_id,genre_id,token,title,author,description){

if (author != '')
{ author = 'By ' + author; }

var str2 = GetEmbedCode(token,media_id,description,genre_id,title,author)

	$('#vid_clip').html(str2);
}
// -----------------------------------------------------------
function GetEmbedCode(token,media_id,description,genre_id,title,author)
{

var newdesc = description.replace(/%27/g,"'");
var newtitle  = title.replace(/%27/g,"'");

var str2;
	str2='';
	str2+='<div class="videoinfo"><h1>' + newtitle + '<\/h1><\/br><p>' + author + '<\/p></div>';
	str2+='<div class="box"><div class="box2"><div id="embed_player">';
	str2+='<embed id="player_swf" src="http:\/\/media.miamiherald.com\/static\/multimedia\/channels\/VideoPlayer-SectionFront.swf" quality="high" width="640" height="392" name="UnifiedVideoPlayer" align="middle" play="true" loop="false" quality="high" allowScriptAccess="always" allowFullScreen="true" wmode="transparent" type="application\/x-shockwave-flash" flashvars="player_id=401b7ca7fd61e67bcb94ebabbacd1847&token=' + token + '&media_id=' + media_id + '" pluginspage="http:\/\/www.adobe.com\/go\/getflashplayer"><\/embed><\/div>';
	str2+='<\/div><\/div>';
	str2+='<div class="videoinfo" style="padding-bottom:10px;"><p>' + newdesc + '<\/p><br></div>';

return str2;
}
// -----------------------------------------------------------
/*
GetGridForGenre('00004675'); 
$(function() {
        $('li#00004675 a').trigger('click');        
});			
*/

// ------------------------------------------------------
