var baseUrl = "/";

function init_NavSide(source)
{
  var content = document.getElementById(source);
  var nav_side = document.getElementById("nav_side");
  nav_side.style.height = content.offsetHeight + "px";
}

function openMating()
{
    var mareName;
    var stallionName;
    var generations;
    var hypoURL;

    mareName = document.getElementById("txtMare");
    stallionName = document.getElementById("ddlStallion");
    generations = document.getElementById("ddlGeneration");

    if(mareName.value != "") {   
        
        hypoURL = "http://www.pedigreequery.com/cgi-bin/new/hypo.cgi?t=parkstud&hypo_sire="+stallionName.options[stallionName.selectedIndex].value+"&hypo_dam="+mareName.value+"&g="+generations.options[generations.selectedIndex].value;
        OpenWindow(hypoURL, 1024, 768, 'yes');
    }
}

function OpenWindow(url, w, h, sb, r, mb, tb, s, loc, dir)
{
  var screenWidth = window.screen.availWidth;
  var screenHeight = window.screen.availHeight;

  var offsetXWinXP = 5;
  var offsetYWinXP = 18;

  var halfScreenWidth = Number(window.screen.availWidth / 2);
  var halfScreenHeight = Number(window.screen.availHeight / 2);

  var halfWindowWidth = Number(w / 2);
  var halfWindowHeight = Number(h / 2);

  var diffWidth = Number(halfScreenWidth-halfWindowWidth);
  var diffHeight = Number(halfScreenHeight-halfWindowHeight);

  diffWidth -= offsetXWinXP;
  diffHeight -= offsetYWinXP;
  
  //The windowName is a zero-based integer corresponding to the number of milliseconds
  //since January 1, 1970, to the date specified by the instance of the Date object;
  //therefore, the windowName will almost always be unique.
  var dtm = new Date();
  var windowName = dtm.getTime();
  
  //if (url == null) { url = "" };
  if (w == null) { w = 640 };
  if (h == null) { h = 480 };
  if (sb == null) { sb = "no" };
  if (r == null) { r = "no" };
  if (mb == null) { mb = "no" };
  if (tb == null) { tb = "no" };
  if (s == null) { s = "no" };
  if (loc == null) { loc = "no" };
  if (dir == null) { dir = "no" };

  var features = new StringBuilder();
  features.Append("directories=" + dir + ",");
  features.Append("location=" + loc + ",");
  features.Append("menubar=" + mb + ",");
  features.Append("resizable=" + r + ",");
  features.Append("scrollbars=" + sb + ",");
  features.Append("status=" + s + ",");
  features.Append("toolbar=" + tb +",");
  features.Append("width=" + w + ",");
  features.Append("height=" + h + ",");
  features.Append("top=" + diffHeight + ",");
  features.Append("left=" + diffWidth);
  
  return window.open(url, windowName, features.ToString());
}

// Initializes a new instance of the StringBuilder class
// and appends the given value if supplied
function StringBuilder(value)
{
  this.strings = new Array("");
  this.Append(value);
}

// Appends the given value to the end of this instance.
StringBuilder.prototype.Append = function (value)
{
  if (value)
  {
    this.strings.push(value);
  }
}

// Appends the given value to the end of this instance with a line break.
StringBuilder.prototype.AppendLine = function (value)
{
  if (value)
  {
    this.strings.push(value + "\n");
  }
}

// Clears the string buffer
StringBuilder.prototype.Clear = function ()
{
  this.strings.length = 1;
}

// Converts this instance to a String.
StringBuilder.prototype.ToString = function ()
{
  return this.strings.join("");
}


function PopupPic(url)
{
  var helpText = new StringBuilder();
  helpText.AppendLine("<html>");
  helpText.AppendLine("<head>");
  helpText.AppendLine("  <title>View Photo</title>");
  helpText.AppendLine("<script src=\"/Scripts/scripts.js\" type=\"text/javascript\"></script>");
  helpText.AppendLine("</head>");
  helpText.AppendLine("<body onload='fitPic();' topmargin=\"0\" marginheight=\"0\" leftmargin=\"0\" marginwidth=\"0\">");
  
  helpText.AppendLine("    <img src=\"/" + url + "\" />");

  helpText.AppendLine("</body>");
  helpText.AppendLine("</html>");
  
  var pic = OpenWindow("", 100, 100, "no", "no");
  pic.document.write(helpText.ToString());
  pic.document.close();		


}

function fitPic() {			
var NS = (navigator.appName=="Netscape")?true:false;
iWidth = (NS)?window.innerWidth:document.body.clientWidth;
iHeight = (NS)?window.innerHeight:document.body.clientHeight;
iWidth = document.images[0].width - iWidth;
iHeight = document.images[0].height - iHeight;
window.resizeBy(iWidth, iHeight-1);
self.focus();				
}


function PlayVideo(file, description, litTitle){


var so = new SWFObject("Flash/VideoPlayer.swf", "movie", "400", "300", "8", "#000");
so.addParam("wmode", "transparent");
so.addParam("scale", "noscale");
so.addParam("FlashVars", "VideoPath=/media/videos/"+file);
        
var div = window.document.getElementById('movie');
so.write(div);     

    document.getElementById(litTitle).innerHTML = description;

}