function drawFlashSingle(clip_id,width,height,hd) {
	//testing var params = "&hl=en&fs=1&showinfo=0&rel=0&autoplay=1";
	if (hd==true) {
		params += "&hd=1";
	}
	//Modify height to accomodate the youtube 25px high chrome
	if (typeof(height != "number")) {
		height = parseInt(height);	
	}
	height += 25;
	var offset = getOffset(height);
	
	var closeBox = "<img class='closebox' border='0' src='/img/overlay/closebox.png'/>";
	//alert("offset: " + offset);
	var src = "http://www.youtube.com/v/" + clip_id + params;
	var flash = "<div style='position:relative;margin-top:" + offset + "px;'>" + closeBox +
		"<object width=\"" + width + "\" height=\"" + height + "\">" +
		"<param name=\"movie\" value=\"" + src + "\"></param>" +
		"<param name=\"allowFullScreen\" value=\"true\"></param>" +
		"<param name=\"allowscriptaccess\" value=\"always\"></param>" +
		"<embed src=\"" + src + "\" type=\"application/x-shockwave-flash\" " +
		"allowscriptaccess=\"always\" allowfullscreen=\"true\" " +
		"width=\"" + width + "\" height=\"" + height + "\"></embed></object>" +
		"</div>";
		
	//wrap the flash in a div that's the correct height;
	return flash;
		
}

function getOffset(object_height) {
	//Get jquery handle on the overlay div
	var sg = $("#sg_tutorial_single_overlay");
	var maxHeight = screen.availHeight;
	
	var x = $(window).height();
	if( !isNaN(x)  ) {
		//youre good	
		maxHeight = x;
	}
	
	//Create a default offset regardless of how low the screen resolution
	minOffset = 100;
	
	//Adjust the offset based on the centered object related to the screen's height
	calculatedOffset = (maxHeight/2) - (object_height/2) - 25;
	
	if (calculatedOffset >= minOffset) {
		return calculatedOffset;
	}
	else {
		return minOffset;
	}
	
	
}

function drawFlash_youtube_single(clip_id,width,height,hd) {
	//Get jquery handle to the screencast div
	var div = $("#sg_tutorial_single_overlay");
	
	//Create the div if it doesn't exist
	if (!div.length == 1) {
		$("body").prepend("<div id='sg_tutorial_single_overlay'></div>");
		div = $("#sg_tutorial_single_overlay");
	}
	
	//Prepend a div to hold the actual screencast
	div.prepend("<div id='ffffff'></div>");
	
  //var html = drawFlashSingle(clip_id,width,height,hd);
  div.find("#ffffff").prepend("<span style='padding-left:25px;'>You'll need flash player 8 to view this screencast.</span>");
  
  //declare params
	var params = { 
		"allowScriptAccess": "always"
	};
	
	//attributes
	var atts = {
		"id": clip_id
	};

  //offset for the div
  var offset = getOffset(height);
  

  //create NON-modal dialog
  var dialogOptions = {
    title: "",
    autoOpen: false,
		position: "top",
    modal: true,
    overlay: {
      backgroundColor: "#000000",
      opacity: .9
      },
    draggable: false,
    resizable: false,
    "width": width + 25,
    "height": height + offset + 50
  };
		//testing
		
		
    div.dialog(dialogOptions);
    
    //Now subtract 50 from height
    width -= 50;
    height -= 50;

    if (!div.dialog("isOpen")) {
      div.dialog("open");

      
			//Make sure height is a number
			if (typeof(height != "number")) {
				//height = parseInt(height);	
			}
			//Modify height to accomodate the youtube 25px high chrome
			height += 25;		
			
			var closeBox = "<img class='closebox' border='0' src='/img/overlay/closebox.png'/>";
			
			//insert closebox
			div.find("#ffffff").before("<div style='position:relative;margin-top:" +
				offset + "px;'>" + closeBox + "</div>");
      
      //now show the screencast div with the screencast html
      var url = "http://www.youtube.com/v/" + clip_id + "&enablejsapi=1&playerapiid=ffffff";
      url += "&hl=en&fs=1&showinfo=0&rel=0&autoplay=1";
      //hd?
      if (hd==true) {
				url += "&hd=1";
			}
			
			swfobject.embedSWF(url, "ffffff", String(width), String(height), "8", null, null, params, atts);	

      //Replace the existing close link with image
			link = $("a.ui-dialog-titlebar-close");
			link.remove();
			link.parent().css("text-align","left");
				
			//get rid of the border
			link.css("outline","none");
			link.css("position","absolute");
			
			//restyle the closebox image
			var img = $("img.closebox");
			img.bind("mouseover mouseenter mousemove",function(){
			var ths = $(this);
			ths.css("cursor","pointer");
			ths.parent().css("cursor","pointer");
			});

      img.one("click",function() {
        div.html("");
        div.dialog("close");
      });
    }
}

function formatSeconds(sec) {
	mins = Math.floor(sec/60);
	if (sec > 60) {
		secs = sec % 60;
	}
	else if(sec == 60) {
		secs = 0;
	}
	else {
		secs = sec;
	}
	
	
	if (secs < 10) {
		secs = "0" + String(secs);
	}
	else {
		secs = String(secs);
	}
	
	
	if (mins <= 0) {
		mins = "00";
	}
	else if(mins >= 10) {
		String(mins);
	}
	else {
		mins = "0" + String(mins);
	}
	
	return mins + ":" + secs;
}