function createLBdiv (id,vidWidth) {
  var lightboxDiv = $("<div></div>").attr({id: "lbVideo", style: "display: none;"}).addClass("videoHolder");

  var closeLink = $("<a></a>").attr("href", "#").addClass("video_close");
  lightboxDiv.append(closeLink);
  
  // Create div for video
  var videoDiv = $("<div></div>").attr({id: id, style: "padding-top:32px; height:100%;"})
  if (vidWidth == "640") {videoDiv.addClass("wide_video");} //Is it wideformat?
  lightboxDiv.append(videoDiv);
  

  //create noflash div and insert
  var noflashDiv = $("<div></div>").attr("id","noflash").addClass("no-flash");
  var noflashP1 = $("<p></p>").text("To view this area of the site, you must have the latest version of Flash.").attr("style","padding-top:30px");
  var noflashP2 = $("<p></p>").text(" to go to the flash download center.");
  noflashP2link = $("<a></a>").attr({href: "http://www.adobe.com/go/getflashplayer", target: "_blank"}).text("Click here");
  noflashP2.prepend(noflashP2link);
  noflashDiv.append(noflashP1).append(noflashP2);
  videoDiv.append(noflashDiv);

  //Insert lightboxDiv
  $("#container").append(lightboxDiv);
  return lightboxDiv;
}

function playVideo (videoURL, vidDuration, vidWidth, vidHeight, lbid, playerURL, optionalParamStr) {
  // test function variable
  if (videoURL == "") {return false;}
  if (vidDuration == "") {vidDuration = "9999";}
  if (vidWidth == "") {vidWidth = "532";}
  if (vidHeight == "") {vidHeight = "400";}
  if (lbid == "") {lbid = "product_detail_flash_lbVideo";}
  if (playerURL == null || playerURL == "") {
    if (vidWidth == "532") {playerURL = "/usa/flash/FlashVideoPlayer.swf";}
    else {playerURL = "/usa/flash/FlashVideoPlayer_16x9.swf";}
  }
  if (optionalParamStr == null || optionalParamStr == "") {
    optionalParamStr = "";
  }


  // get div if exists, create if it doesn't
  var lightboxDiv = $("#" + lbid);
  if(lightboxDiv.length == 0) {
    lightboxDiv = createLBdiv(lbid,vidWidth);
  }


  var swfWidth = "532";
  var swfHeight = "423";
  if (vidWidth == "640") {
    swfWidth = "640";
    swfHeight = "383";
  }
  // setup SWFObject
  var mifso = new SWFObject(playerURL,"videoPlayer",swfWidth,swfHeight,"9.0.115","#FFFFFF");
  mifso.addParam("align", "middle");
  mifso.addParam("menu", "false");
  mifso.addParam("wmode", "transparent");
  if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){
    mifso.addParam("allowscriptaccess", "sameDomain");
  }
  mifso.addParam("pluginspage", "http://www.macromedia.com/go/getflashplayer");
  mifso.addParam("type", "application/x-shockwave-flash");
  mifso.addParam("quality", "high");
  mifso.addVariable("videoUrl", videoURL);
  mifso.addVariable("videoWidth", vidWidth);
  mifso.addVariable("videoHeight", vidHeight);
  mifso.addVariable("videoDuration", vidDuration);

  // write the video object
  mifso.write(lbid);
  
  // open thickbox to display
  var tb_width = "587";
  var tb_height = "562";
  if (vidWidth == "640") {
    tb_width = "700";
    tb_height = "435";
  }
  tb_show("","#TB_inline?height=" + tb_height + "&width=" + tb_width + "&inlineId=lbVideo" + optionalParamStr,"");
}
