<?php
/// $Id: mod_j16randomflash.php, v2.5.0 June 2011 DART Creations Exp $
/**
* Joomla 2.5 Random Flash 
* @ package Joomla
* @ joomla Open Source is Free Software
* @ Released under GNU/GPL License : http://www.gnu.org/copyleft/gpl.html
* @ Author : DART Creations
**/

defined( '_JEXEC' ) or die( 'Go Away' );

$flashfiles	= intval($params->get( 'flashfiles' ));
$flashbase = $params->get( 'flashbase' );
$quality   = $params->get( 'quality');
$background = $params->get( 'background');
$width 			= $params->get( 'width' );
$height 		= $params->get( 'height' );
$link 		= $params->get( 'link' );

// $top = rand (1,$flashfiles);


//------------
$count = 0;
if ($handle = opendir($flashbase)) {
   $retval = array();
   while (false !== ($file = readdir($handle))) 
   {
       if (($file <> ".") && ($file <>  "..") && (strtolower(substr($file,-4)) == ".swf")) 
       {
	       $retval[$count] = $file;
	       $count = $count + 1;
       }
   }
   closedir($handle);
}
shuffle($retval);
$current_image = $retval[0];
//------------



$content = <<<EOD

<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="$width" height="$height" id="g1">
 <param name="movie" value="$flashbase/$current_image"/>
 <param name="loop" value="true"/>
 <param name="quality" value="$quality"/>
 <param name="bgcolor" value="$background"/>
 <embed type="application/x-shockwave-flash" width="$width" height="$height" src="$flashbase/$current_image"></embed>
</object>
EOD;
if ($link)
	{
		$content .= "<a href=\"http://www.dart-creations.com\" style=\"font-size:1px;display:none;\">Joomla Random Flash Module by DART Creations</a>";
	}
return $content;
?>