<?php
/**
* @version $Id: mod_ads_ticker.php v1.12
* @package Joomla 1.0.12
* @created by Cuong Kieu Nguyen
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
*/

/** ensure this file is being included by a parent file */
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

$id = $params->get( 'ads_ticker_id' );
$ads_ticker_delay_time = intval( $params->get( 'ads_ticker_delay_time', 5000 ) );
$ads_ticker_width = intval( $params->get( 'ads_ticker_width', 468 ) );
$ads_ticker_height = intval( $params->get( 'ads_ticker_height', 60 ) );
$ads_ticker_align = intval( $params->get( 'ads_ticker_align' ) );
$ads_ticker_bgc = $params->get( 'ads_ticker_bgc' );
$ads_ticker_randctrl = $params->get( 'ads_ticker_randctrl', 1 );

for ($i=1;$i<=10;$i++) {
  ${$id}[$i] = '';
}

if ($ads_ticker_align == 0) {
  $ads_ticker_align = 'left';
}
elseif ($ads_ticker_align == 2) {
  $ads_ticker_align = 'right';
}
else {
  $ads_ticker_align = 'center';
}

for ($i=1;$i<=10;$i++) {
  $html[$i] = $params->get( 'ads_list'.$i );
  $htmlelement[$i] = explode("<br />",$html[$i]);
  if ( $htmlelement[$i] ) {
    for ($j=0;$j<count($htmlelement[$i]);$j++){
      ${$id}[$i] = ${$id}[$i].$htmlelement[$i][$j];
    }
  }
}

?>
<style type="text/css">

#<?php echo 'ads_ticker_elementsubject' . $id; ?>{
  overflow		: hidden;
  width			: <?php echo $ads_ticker_width; ?>px;
  font-weight		: bold;
}

.<?php echo 'ads_ticker_main' . $id; ?>{
  overflow		: hidden;
  width			: <?php echo $ads_ticker_width; ?>px;
  height		: <?php echo $ads_ticker_height; ?>px;
  border		: 0px solid black;
  background-color	: <?php echo $ads_ticker_bgc; ?>;
  padding		: 0px;
  display		: block;
  text-align		: <?php echo $ads_ticker_align; ?>;
  margin-right		: <?php echo $ads_ticker_align == 'right' ? '0px' : 'auto'; ?>;
  margin-left		: <?php echo $ads_ticker_align == 'left' ? '0px' : 'auto'; ?>;
}

</style>

<script type="text/javascript">

var pos = 100;

function <?php echo 'slideIn' . $id; ?>(<?php echo 'selectedDiv' . $id; ?>Obj){
pos = Math.max (0, pos - 10);
<?php echo 'selectedDiv' . $id; ?>Obj.style.paddingTop = pos + "px";
if (pos != 0) setTimeout(function () {<?php echo 'slideIn' . $id; ?>(<?php echo 'selectedDiv' . $id; ?>Obj);}, 100);
}

/***********************************************
* ProHTML Ticker script- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

var <?php echo 'tickspeed' . $id; ?>=<?php echo $ads_ticker_delay_time; ?> //ticker speed in miliseconds (2000=2 seconds)
var enablesubject=0 //enable scroller subject? Set to 0 to hide

if (document.getElementById){
document.write('<style type="text/css">\n')
document.write('.<?php echo 'ads_ticker_elementclass' . $id; ?>{display:none;}\n')
document.write('</style>\n')
}

var <?php echo 'selectedDiv' . $id; ?>=0
var <?php echo 'totalDivs' . $id; ?>=0

function <?php echo 'contractall' . $id; ?>(){
var inc=0
while (document.getElementById("<?php echo 'ads_ticker_elementid' . $id; ?>"+inc)){
document.getElementById("<?php echo 'ads_ticker_elementid' . $id; ?>"+inc).style.display="none"
inc++
}
}

function <?php echo 'expandone' . $id; ?>(){
var <?php echo 'selectedDiv' . $id; ?>Obj=document.getElementById("<?php echo 'ads_ticker_elementid' . $id; ?>"+<?php echo 'selectedDiv' . $id; ?>)
<?php echo 'contractall' . $id; ?>()
document.getElementById("<?php echo 'ads_ticker_elementsubject' . $id; ?>").innerHTML=<?php echo 'selectedDiv' . $id; ?>Obj.getAttribute("subject")
<?php echo 'selectedDiv' . $id; ?>Obj.style.display="block"
<?php echo 'selectedDiv' . $id; ?>=(<?php echo 'selectedDiv' . $id; ?><<?php echo 'totalDivs' . $id; ?>-1)? <?php echo 'selectedDiv' . $id; ?>+1 : 0;
setTimeout("<?php echo 'expandone' . $id; ?>()",<?php echo 'tickspeed' . $id; ?>)
}

function <?php echo 'startscroller' . $id; ?>(){
while (document.getElementById("<?php echo 'ads_ticker_elementid' . $id; ?>"+<?php echo 'totalDivs' . $id; ?>)!=null)
<?php echo 'totalDivs' . $id; ?>++
<?php echo 'expandone' . $id; ?>()
if (!enablesubject)
document.getElementById("<?php echo 'ads_ticker_elementsubject' . $id; ?>").style.display="none"
}

if (window.addEventListener)
window.addEventListener("load", <?php echo 'startscroller' . $id; ?>, false)
else if (window.attachEvent)
window.attachEvent("onload", <?php echo 'startscroller' . $id; ?>)

</script>
<div id="<?php echo 'ads_ticker_elementsubject' . $id; ?>"></div>

<div class="<?php echo 'ads_ticker_main' . $id; ?>">

<?php

if ($ads_ticker_randctrl==1) {
  shuffle(${$id});
}

$k = 0;
foreach ( ${$id} as $adsel ) {
  if ( !empty($adsel) ) {
    echo '<div class="ads_ticker_elementclass' . $id . '" id="ads_ticker_elementid' . $id . $k . '">' . "\n" . $adsel . "\n" . '</div>' . "\n";
    $k++;
  }
}
echo '</div>';

?>
