/**
 *  swfobject 2.2 einbinden
 *  aber bitte nicht mehr als nötig, 1x reicht.
 */

check = document.getElementById('esgnvideoscript');

if(check == null) {
  (function() {
    var esgnvideo    = document.createElement('script'); 
    esgnvideo.type   = 'text/javascript';
    esgnvideo.id     = 'esgnvideoscript';
    esgnvideo.src    = 'http://stream.esgn.eu/scripts/swfobject.js';
    var scriptinsert = document.getElementsByTagName('script')[0]; 
    scriptinsert.parentNode.insertBefore(esgnvideo, scriptinsert);
  })();
};



/**
 * ESGN Video v2
 *
 * (C) 2010 by Patrick Tiedchen
 *
 * THIS IS NOT FREE SOFTWARE!
 * IT IS NOT ALLOWED TO USE THIS 
 * PROGRAMM WITHOUT ANY PERMISSION!
 */

function esgnvideo_v2(name,params)
{ 

  if(params == null) {
	width   = 640;
        height  = 391;
        type    = 'flv';
        img     = null;
  } else {
	width 	= (params.width  == null) ? width = 640 : params.width;
        height 	= (params.height == null) ? 392 	: params.height+19;
        type 	= (params.type   == null) ? 'flv'	: params.type;
        img 	= (params.img == null) 	  ? null 	: params.img; 
  }

  // Youtube failover function
  if(name.match(/youtube.com/)) {
	type = 'youtube';
        name = name.replace(/gl=DE&hl=de&/, '');
  }

  date = new Date();
  time = date.getTime();

  setup = {
		'host': 	'http://stream.esgn.eu',
                'scriptfolder': 'scripts',
                'previewfolder':'previews',
                'streamfile':   'stream.php',
      		'skin': 	'modieus',
		'logo': 	'esgnlogo.png',
                'buffer':       '5',
                'margin':       '0px 0px 20px 0px',
                'textalign':    'center',
                'message':      'Um dieses Video sehen zu können, muss minimum Flash 9 installiert und Javascript aktiviert sein.'
	      };
  video = {
                'name':         name+'_'+time,
		'file':		name+'.'+type,
                'type':         type,
                'image':	(img == null) ? name+'.jpg' : img+'.jpg',
                'yimg': 	(type=='youtube') ? escape('yt.php?url='+name+'&type=.jpg') : null,
                'target':       (type=='youtube') ? 'youtube_'+time : name,
                'width':	width,
      		'height':	height,
                'youtubeurl':   name,
                'youtubename':  'emb_youtube_'+time,
	      };

  // write dom element
  document.write('<div id="'+video.target+'" style="margin:'+setup.margin+';text-align:'+setup.textalign+'">'+setup.message+'</div>');



  // local or youtube switch
  switch(type) {
    case "youtube":
        var so = new SWFObject(setup.host+'/'+setup.scriptfolder+'/player.swf',video.youtubename,video.width,video.height,'9','#000000');
	so.addVariable('file', video.youtubeurl); 
  	if(img != null && video.yimg == null) so.addVariable('image', setup.host+'/'+setup.previewfolder+'/'+video.image);
  	if(video.yimg != null) so.addVariable('image', setup.host+'/'+video.yimg);
	break;
    case "flv":
        var so = new SWFObject(setup.host+'/'+setup.scriptfolder+'/player.swf',video.name,video.width,video.height,'9','#000000');
        so.addVariable('file',  setup.host+'/'+setup.streamfile+'?filename='+video.file);
        so.addVariable('image', setup.host+'/'+setup.previewfolder+'/'+video.image);
        break;
    case "mp4":
        var so = new SWFObject(setup.host+'/'+setup.scriptfolder+'/player.swf',video.name,video.width,video.height,'9','#000000');
        so.addVariable('file',  setup.host+'/'+setup.streamfile+'?filename='+video.file);
  	so.addVariable('image', setup.host+'/'+setup.previewfolder+'/'+video.image);
        break;
    default:
        var so = new SWFObject(setup.host+'/'+setup.scriptfolder+'/player.swf',video.name,video.width,video.height,'9','#000000');
        so.addVariable('file',  setup.host+'/'+setup.streamfile+'?filename='+video.file);
  	so.addVariable('image', setup.host+'/'+setup.previewfolder+'/'+video.image);
        break;
  }  

  // more params
  so.addParam('allowfullscreen',	'true');
  so.addParam('allowscriptaccess',	'always');
  so.addVariable('logo.hide', 	'false');
  so.addVariable('logo.position', 	'top-right');
  so.addVariable('skin', 		setup.host+'/'+setup.scriptfolder+'/'+setup.skin+'.zip');
  so.addVariable('logo.file', 	setup.host+'/'+setup.scriptfolder+'/'+setup.logo);
  so.addVariable('bufferlength', 	setup.buffer);


  // insert video into dom
  so.write(video.target);
}



/*
---------------------------------------------------------------------------------

       ALTLASTEN

---------------------------------------------------------------------------------
*/



/**
 *  ESGN Video v1 
 */
function esgnvideo(file,type,previewimg,width,height,target)
{

  host = 'http://stream.esgn.eu';
  document.write('<div id="'+target+'" style="margin-bottom:20px;text-align:center">Um dieses Video sehen zu können, muss minimum Flash 9 installiert und Javascript aktiviert sein.</div>');
  height = height+19;

 
  var so = new SWFObject(host+'/scripts/player.swf',''+type+'',''+width+'',''+height+'','9','#000000');
  so.addParam('allowfullscreen','true');
  so.addParam('allowscriptaccess','always');
  so.addVariable('skin', host+'/scripts/modieus.zip');
  so.addVariable('logo.file', host+'/scripts/esgnlogo.png');
  so.addVariable('logo.hide', 'false');
  so.addVariable('bufferlength', '5');
  so.addVariable('image', host+'/previews/'+previewimg+'');
  so.addVariable('logo.position', 'top-right');
  so.addVariable('file', ''+host+'/stream.php?filename='+file+'');
  so.write(''+target+'');
}

