/**
 *
 * Slider Widget
 * based on bcw_homepage
 * Stefan Ostermann <ostermann (at ) dimast.de>
 *
**/

/* check for bc array */

if(typeof bc_id != 'array') {
	var bc_id = new Array();
}

function bc_make_slider(arg){
  var id = bc_id.length;
	bc_id.push(new bc_slider(arg,id));
	bc_id[id].generate();
} 

function bc_slider(arg,id){
  this.id = id;
	this.playlistId = arg.playlistId;
	this.token = arg.token;
	this.playerId = arg.playerId;
	this.videos = new Array();
	this.ie = (document.all) ? true: false;

	this.generate = function(){
	  var code;
		var content;
	
/* if first widget include API */
	
	  if(this.id < 1){
			code = document.createElement("script");
			code.setAttribute('src', 'http://admin.brightcove.com/js/BrightcoveExperiences.js');
			code.setAttribute('charset', 'UTF-8');
			code.setAttribute('type', 'text/javascript');
			document.getElementsByTagName('head')[0].appendChild(code);
			code = document.createElement("script");
			code.setAttribute('src', 'http://admin.brightcove.com/js/APIModules_all.js');
			code.setAttribute('charset', 'UTF-8');
			code.setAttribute('type', 'text/javascript');
			document.getElementsByTagName('head')[0].appendChild(code);

	  }	

	if(this.ie) {
		document.write('<style type="text/css">');
		document.write('div.bc_carousel div.slide_video_overlay { background: none; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src="/fileadmin/img/video-slider-overlay.png",sizingMethod="image"); }');
		document.write('</style>');
	}

          document.write('<div class="bc_carousel"><div id="' + this.id + 'BC_slider" class="jcarousel-skin-tango" /></div></div>');
          document.write('<script type="text/javascript">');
          document.write(' jQuery(document).ready(function() { jQuery("#'+this.id+'BC_sliderlist").jcarousel({visible:4, scroll:4, itemLoadCallback: { onBeforeAnimation:  function(carousel,state){ jcarousel_itemcallback(bc_id['+this.id+'].videos,carousel,state); } } }); }); ');
          document.write('</script>');

	
	

/* Code for getting Content */	
	
		code = document.createElement('script');
		code.setAttribute('src', 'http://api.brightcove.com/services/library?command=find_playlist_by_id&playlist_id=' + this.playlistId + '&token=' + this.token + '&callback=bc_id[' + this.id + '].autoReturn');
		code.setAttribute('charset', 'UTF-8');
		code.setAttribute('type', 'text/javascript');
		document.getElementsByTagName('head')[0].appendChild(code);



		
	}
	
	this.autoReturn = function(bc_data){	
		var content = '<ul id="'+this.id+'BC_sliderlist"></ul>';
    var videos = bc_data['videos'];
var link = '';
var count = 15;
if(count > videos.length){ count = videos.length; };
		for(i=0;i<count;i++){
         link = 'video.html?bcpid='+this.playerId+'&bclid='+this.playlistId+'&bctid='+videos[i]['id'];
      this.videos.push('<div class="slide_video"><div class="slide_video_content"><a href="'+link+'"><img src="'+ videos[i]['thumbnailURL'] +'" width="120" height="90" alt=""><div class="slide_video_overlay"> </div></a><a href="'+link+'">'+videos[i]['name']+'</a></div></div>');
		}




	  document.getElementById(this.id + 'BC_slider').innerHTML = '<ul id="'+this.id+'BC_sliderlist"></ul>';


	}	
		
}		
