	if(!Array.indexOf)
   {
      Array.prototype.indexOf = function(obj)
      {
          for(var i=0; i<this.length; i++)
          {
              if(this[i] == obj)
              {
                  return i;
              }
          }
          return -1;
      }
   }

   var rootTag = document.getElementsByTagName("html")[0];
   var screenHeight = rootTag.scrollHeight > rootTag.clientHeight ? rootTag.scrollHeight : rootTag.clientHeight;


   function show_videoplayer(name, widget, is_preview, autostart, base, player_type, show_thumbs, show_comments) {
	  
	   jQuery('.preview', '#' + name + '_' + widget).each(function (){

         var file = jQuery(this).attr('id').split('_');
         if( -1 != acceptableFiletypes.video.indexOf(file[1]) )
         {
            if (is_preview)
				{
					if ('' != player_type) {
						 player_type_str = '&player_type=' + player_type;
					} else {
						 player_type_str = '';
					}
					jQuery(this).fancybox({
						'modal': false,
						'width':  (show_thumbs || show_comments) ? 808 : 608,
						'height': (show_thumbs || show_comments) ? 381 : 365,
						'scrolling': 'no',
						'type': 'iframe',
						'href': base + 'videoplayer/videopreview/' + file[0] + '?noclose' + player_type_str + '&autostart=' + autostart + (show_thumbs ? '&show_thumbs' : '') + (show_comments ? '&show_comments' : '')
					});
            }
				else
				{
	            jQuery(this).click(function (){
	                  jQuery('#videoplayer_' + widget).html (file[0] + ' autostart:' + autostart); //TODO make start for videoplayer?
	            });
            }	       
         }
      });
	}
   
	/**
	 * Enhanced Video Player
	 */
	function show_enhanced_videoplayer(name, widget, base, player_type, theme_id, autostart, show_thumbs, show_comments, show_transcript, show_download)
	{
		$('.preview', '#'+name+'_'+widget).each(function(){
			
			var file = $(this).attr('id').split('_');
			if (acceptableFiletypes.video.indexOf(file[1]) != -1)
			{
				
				var goto= base+'videoplayer/videopreview/'+file[0]+'?theme='+theme_id+'&noclose'+((player_type != '') ? '&player_type='+player_type : '')+'&autostart='+autostart+(show_thumbs ? '&show_thumbs' : '')+(show_comments ? '&show_comments' : '')+(show_transcript ? '&show_transcript' : '')+(show_download ? '&show_download' : '');
				
				if (file[3]==1){
				var goto= base + 'order/showform/' + file[0]+'/';
				}
				
				$(this).fancybox({
					'height':	 (show_thumbs || show_comments || show_transcript || show_download) ? 381 : 355,
					'href':		 goto,
					'modal':  	 false,
					'scrolling': 'no',
					'type':		 'iframe',
					'width':		 (show_thumbs || show_comments || show_transcript) ? 808 : 585
				}).click(function(event){
					if (file[3]==1){
						//show_form(base + 'order/showform/' + file[0]+'/');	
					}
				});
			}
		});
	}

	/**
	 * Internal Video PLayer
	 */
	function show_internal_videoplayer(name, widget, base, player_type, theme_id, file_id, autostart, show_thumbs, show_comments, show_transcript)
	{
		
	
		$('.preview', '#'+name+'_'+widget).each(function(){
			
			var elid = $(this).attr('id').split('_');
			$('#single_inline_widget_player').remove();
			$(this).click(function(){ 
				
				show_internal_videoplayer(name, widget, base, player_type, theme_id, elid[0], autostart, show_thumbs, show_comments, show_transcript); 
			});
		});
		var iframe = $('<iframe />').attr({
			'frameborder':'0',
			'id':'single_inline_widget_player'
		}).css({
			'background-color':'#FFF',
			'border':	'0px',
			'height':	((show_thumbs || show_comments || show_transcript) ? 530 : 240) +'px',
			'width':		((show_thumbs || show_comments || show_transcript) ? 870 : 730) +'px'
		}).attr({'src':base+'videoplayer/smallplayer/'+file_id+'?theme='+theme_id+'&noclose'+((player_type != '') ? '&player_type='+player_type : '')+'&autostart='+autostart+(show_thumbs ? '&show_thumbs' : '')+(show_comments ? '&show_comments' : '')+(show_transcript ? '&show_transcript' : '')});
		$('#'+name+'_player_container').html(iframe).parent().width(870).height(246);
		iframe.parent().width(iframe.width());
		iframe.parent().height(iframe.height()+iframe.parent().height());
		iframe.parent().css('background-color','#FFF');
	}

	/**
	 * Alt Download
	 * - deprecated
	 */
	function alt_download(name, widget, base)
	{
		 
		$('.preview', '#'+name+'_'+widget).each(function(){
			var file = $(this).attr('id').split('_');
			var id	= file[0];
			var ext	= file[1];
			var type	= file[2];
			if (type != 'video' && type != 'audio' && type != 'image' && acceptableFiletypes[type].indexOf(ext) != -1){
				$(this).click(function(){
					
					top.open(base+'download/index/'+id);
				});
				if (ext == 'pdf'){
					$(this).mouseenter(function(event){
						var src = base+'download/preview/'+id;
						var div = $('<div />').hide()
							.attr({
								'id':'mouseover_preview'
							}).css({
								'background-color':'#FFF',
								'padding':'20px',
								'position':'absolute',
								'left':event.pageX,
								'top':event.pageY,
								'z-index':999999
							}).appendTo('body');
						var img = $('<img />').attr({'src':src}).appendTo('#mouseover_preview');
						img.load(function(){
							$('#mouseover_preview').fadeIn('normal');
						});
						$(this).data('sto',sto);
					}).mouseleave(function(){
						clearTimeout($(this).data('sto'));
						$('#mouseover_preview').fadeOut('normal',function(){
							$(this).remove();	
						});
					});
				}
			}
		});
	}

   function set_download (name, widget, base) {
	   
	   jQuery('.preview', '#' + name + '_' + widget).each(function (){
		
         var file = jQuery(this).attr('id').split('_');

         if( -1 != acceptableFiletypes.document.indexOf(file[1]) ||  -1 != acceptableFiletypes.archive.indexOf(file[1])  ||  -1 != acceptableFiletypes.other.indexOf(file[1]) )
         {
            jQuery(this).click(function (){
               //alert('t1');
               forsale =  file[3] 
               if (forsale==1){
               show_form(base + 'order/showform/' + file[0]+'/');
               }
               else {
               	 top.open (base + 'download/index/' + file[0]);
               }
               //top.open (base + 'download/index/' + file[0]);
            });
         }
         if ('undefined' != file[2] && 'other' == file[2]) {
        	 jQuery(this).click(function (){
        	 	
                 top.open (base + 'download/index/' + file[0]);
              });
         }
      });
	}
   
    function show_form (libid) {
		//location=libid;
		//alert(libid);
		 jQuery.fn.modalBox({ 
            directCall: { 
                source : libid
            }
          
        });


	}


   function show_image (name, widget, base) {
 		
	   jQuery('.preview', '#' + name + '_' + widget).each(function (){

         var file = jQuery(this).attr('id').split('_');

         if( -1 != acceptableFiletypes.image.indexOf(file[1]) )
         {
         	
        	jQuery(this).fancybox({
                'modal': false,
                'width': 608,
                'height': 360,
                'scrolling': 'no',
                'type': 'image',
                'href': base + 'thumb/source/' + file[0] + ''
            });
         }
      });
	}
   
   function play_audio (name, widget, autostart, base) {

	   jQuery('.preview', '#' + name + '_' + widget).each(function (){

         var file = jQuery(this).attr('id').split('_');
         if( -1 != acceptableFiletypes.audio.indexOf(file[1]) )
         {
            jQuery(this).fancybox(
            {
                'modal': false,
                'width': 608,
                'height': 360,
                'scrolling': 'no',
                'type': 'iframe',
                'href': base + 'videoplayer/audiopreview/' + file[0] + '?noclose&autostart=' + autostart
            });
         }
      });
	}

