function embed_attach(to_div, id, caption, embed_code, after) {
  Event.observe($(id), 'click', function(e){
    e.stop();
    $(to_div).innerHTML = embed_code;
    if (after) {
      after(caption);
    }
  });
}

function video_attach(to_div, id, caption, thumb_path, video_path, after) {
  Event.observe($(id), 'click', function(e){
    e.stop();
    var newthumb = thumb_path.replace(/medium/, "large");
		var so = new SWFObject("/flash/ur7Player_f9_300x227_v02.swf", to_div, "300", "227", "9");
			so.addVariable("jsEventHandler", "jsEventHandler");
			so.addVariable("filePath", video_path);	
			so.addVariable("thumb", newthumb);
			so.addVariable("fixLayout", 1);
			so.addVariable("app_id", "UR7s");
			so.addVariable("screenMode", "fit");
			so.addVariable("showBug", 1);	
			so.addVariable("vGab", 0);		
			so.addVariable("hGab", 0);
			so.addVariable("bufferLength", 5);
	    so.addParam("wmode","transparent");
			so.addParam("allowFullScreen", "true");
      so.addVariable("originalSwfWidth", 300);
      so.addVariable("originalSwfHeight", 227);  
      so.addVariable("duration", 3000);
      so.addVariable("logo", "/images/elements/logo_ur7s.png");
      so.addVariable("logoAlign", "right");
      so.addVariable("logoX", 0); 
      so.addVariable("logoY", 0); 
      so.addVariable("logoLink", "/");     
      so.addVariable("controlOnTop", 1);  
			so.write(to_div);
    if (after) {
      after(caption);
    }
  });
}

function image_attach(to_div, id, caption, path, after) {
  Event.observe($(id), 'click', function(e){
    e.stop();
    $(to_div).childElements().each(function(el){el.remove()});
    $(to_div).appendChild(new Element('img', {src:path}));
    if (after) {
      after(caption);
    }
  });
}

