<?php
/* Ninja Ajax Banner
* By Richie Mortimer
* http://www.ninjoomla.com 
* Copyright (C) 2007 Richie Mortimer www.ninjoomla.com - Code so sharp, it hurts.
* email: ravenlife@raven-webdesign.com
* date: January 2008
* Release: 1.0
* License : http://www.gnu.org/copyleft/gpl.html GNU/GPL 
*
* The Ninja Ajax banner is based on mootools and allows you to place upto five banners together, helping you to greater maximise your website real estate.
*
* Features and Changelog:
*
    * Use from 0-5 images
    * Multiple orientation options.
	* CSS and XHTML Valid
*
* 
*/
###################################################################
//Ninja Ajax Banner
//Copyright (C) 2007 Richie Mortimer. Ninjoomla.com. All rights reserved.
//
//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either version 2
//of the License, or (at your option) any later version.
//
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
###################################################################

defined('_JEXEC') or die('Direct Access to this location is not allowed.');


$full_width 	= $params->get( 'full_width' );
$full_width 	= $full_width + 1;
$full_height 	= $params->get( 'full_height' );
$full_width_over= $params->get( 'full_width_over' );
$small_width	= $params->get( 'small_width' );
$normal_width	= $params->get( 'normal_width' );
$duration	 	= $params->get( 'duration' );
$opacity	 	= $params->get( 'opacity' );
$moduleclass_sfx 	= $params->get('moduleclass_sfx');	
  $forceValid = $params->get( 'forceValid' );
  $inc_mootools = $params->get( 'inc_mootools','2' );
  $incCSS = $params->get( 'incCSS' );
  $incJS = $params->get( 'incJS' );

$pic[0]['enabled']		= $params->get( 'pic1_enabled' );
$pic[0]['url']			= $params->get( 'pic1' );
$pic[0]['align']		= $params->get( 'pica1' );
$pic[0]['link']			= $params->get( 'link1' );
$pic[0]['link_type']	= $params->get( 'linkt1' );

$pic[1]['enabled']		= $params->get( 'pic2_enabled' );
$pic[1]['url']			= $params->get( 'pic2' );
$pic[1]['align']		= $params->get( 'pica2' );
$pic[1]['link']			= $params->get( 'link2' );
$pic[1]['link_type']	= $params->get( 'linkt2' );

$pic[2]['enabled']		= $params->get( 'pic3_enabled' );
$pic[2]['url']			= $params->get( 'pic3' );
$pic[2]['align']		= $params->get( 'pica3' );
$pic[2]['link']			= $params->get( 'link3' );
$pic[2]['link_type']	= $params->get( 'linkt3' );

$pic[3]['enabled']		= $params->get( 'pic4_enabled' );
$pic[3]['url']			= $params->get( 'pic4' );
$pic[3]['align']		= $params->get( 'pica4' );
$pic[3]['link']			= $params->get( 'link4' );
$pic[3]['link_type']	= $params->get( 'linkt4' );

$pic[4]['enabled']		= $params->get( 'pic5_enabled' );
$pic[4]['url']			= $params->get( 'pic5' );
$pic[4]['align']		= $params->get( 'pica5' );
$pic[4]['link']			= $params->get( 'link5' );
$pic[4]['link_type']	= $params->get( 'linkt5' );

// first we will set up our header
$headertag = '';

// now check to see if we want the css included
if ($incCSS) {
$headertag .= '<link href="modules/mod_ninja_ajax_banner/mod_ninja_ajax_banner/css/mod_ninja_ajax_banner.css" rel="stylesheet" type="text/css" />'."\n";
  }
// now we have to place some css in the header that we couldnt put in the css file becuase of the php
if ($incCSS) {
$headertag .='<style type="text/css">'."\n";
$headertag .='#ajcms_container { 
	background-color: '.$margin_left.';
	height: '.$full_height.'px;
	width: '.$full_width.'px;
	}
				#ajcms {
	width: '.$full_width.'px;
	}
				#ajcms .jcms {
	height: '.$full_height.'px;
	width: '.$normal_width.'px;
	}
				#ajcms1 {
	background-image:url('.$pic[0]["url"].');
	background-position: '.$pic[0]["align"].';
	}
				#ajcms2 {
	background-image:url('.$pic[1]["url"].');
	background-position: '.$pic[1]["align"].';
	}
				#ajcms3 {
	background-image:url('.$pic[2]["url"].');
	background-position: '.$pic[2]["align"].';
	}
				#ajcms4 {
	background-image:url('.$pic[3]["url"].');
	background-position: '.$pic[3]["align"].';
	}
				#ajcms5 {
	background-image:url('.$pic[4]["url"].');
	background-position:'.$pic[4]["align"].';
	}
	</style>'."\n";
	  }// incCSS
	
	// include mootools only if indicated 
	  if ($inc_mootools == 1 || ($inc_mootools == 2 && (!strpos($buffer, 'mootools.v1.11.js')&& !strpos($buffer, 'mootools.js'))))
      $headertag .= " <script src=\"modules/mod_ninja_ajax_banner/mod_ninja_ajax_banner/js/mootools.v1.1.js\" type=\"text/javascript\" language=\"javascript\"></script>";
  
  

if ($incJS) {

$headertag .= "<script type=\"text/javascript\">
window.addEvent('domready', function(){"."\n";

$headertag .= "var szNormal = $normal_width, szSmall  = $small_width, szFull   = $full_width_over;"."\n";
	
$headertag .= "var ej_pictures = $$(\"#ajcms .jcms\");
	var fx = new Fx.Elements(ej_pictures, {wait: false, duration: $duration, transition: Fx.Transitions.Back.easeOut});
	//var fx = new Fx.Slide(ej_pictures, {mode: false, duration: 300, transition: Fx.Transitions.Back.easeOut});
	ej_pictures.each(function(ej_picture, i) {
		ej_picture.addEvent(\"mouseenter\", function(event) {
			var o = {};
			o[i] = {width: [ej_picture.getStyle(\"width\").toInt(), szFull], opacity: [1,1]}
			ej_pictures.each(function(other, j) {
				if(i != j) {
					var w = other.getStyle(\"width\").toInt();
					if(w != szSmall) o[j] = {width: [w, szSmall], opacity: [1,$opacity]};
				}
			});
			fx.start(o);
		});
	});"."\n";
	
$headertag .= "$(\"ajcms\").addEvent(\"mouseleave\", function(event) {
		var o = {};
		ej_pictures.each(function(ej_picture, i) {
			o[i] = {width: [ej_picture.getStyle(\"width\").toInt(), szNormal],opacity: [1,1]}
		});
		fx.start(o);
	})"."\n";
	

	if ($pic[0]['enabled']) {
	
$headertag .= "$('ajcms1').addEvent(\"click\", function(event) {"."\n";

		if ($pic[0]['link_type']) {
$headertag .= "window.open('".$pic[0]['link']."');"."\n";
		} else {
$headertag .= "window.location='".$pic[0]['link']."';"."\n";
		}
$headertag .="});"."\n";
	}

	if ($pic[1]['enabled']) {
	
$headertag .= "$('ajcms2').addEvent(\"click\", function(event) {"."\n";

		if ($pic[1]['link_type']) {
$headertag .= "window.open('".$pic[1]['link']."');"."\n";
		} else {
$headertag .= "window.location='".$pic[1]['link']."';"."\n";
		}
$headertag .="});"."\n";
	}

	if ($pic[2]['enabled']) {
$headertag .= "$('ajcms3').addEvent(\"click\", function(event) {"."\n";
		if ($pic[2]['link_type']) {
$headertag .= "window.open('".$pic[2]['link']."');"."\n";
		} else {
$headertag .= "window.location='".$pic[2]['link']."';"."\n";
		}
$headertag .="});"."\n";
}

	if ($pic[3]['enabled']) {
$headertag .= "$('ajcms4').addEvent(\"click\", function(event) {"."\n"; 
		if ($pic[3]['link_type']) {
$headertag .= "window.open('".$pic[3]['link']."');"."\n";
		} else {
$headertag .= "window.location='".$pic[3]['link']."';"."\n";
		}

$headertag .="});"."\n";

	}

	if ($pic[4]['enabled']) {
$headertag .= "$('ajcms5').addEvent(\"click\", function(event) {"."\n";
		if ($pic[4]['link_type']) {
$headertag .= "window.open('".$pic[4]['link']."');"."\n";
		} else {
$headertag .= "window.location='".$pic[4]['link']."';"."\n";
		}
		
$headertag .="});"."\n";

	}

$headertag .="});"."\n";
$headertag .="</script>"."\n";
} // incJS 


// Only force valid XHTML if the user requests it
      if ($forceValid){
          //Now lets put our JS and CSS into the header of our page 
          $buffer = ob_get_contents();
          $hdrPos = strpos ($buffer, '</head>');
          $buffer = substr ($buffer, 0, $hdrPos) . "\n$headertag\n". substr($buffer, $hdrPos);
          ob_clean();
          echo $buffer;
      
      } else {
      
          echo $headertag;
      
      }?>

<table border="0" cellspacing="0" cellpadding="0" class="ej_ajax_banner_<?php echo $moduleclass_sfx; ?>">
<tr>
	<td>
        <div id="ajcms_container">
            <ul id="ajcms">
                <?php 
                if ($pic[0]['enabled']) { //echo "pic1";
                ?>
                    <li id="ajcms1" class="jcms">&nbsp;</li>
                <?php
                }
                if ($pic[1]['enabled']) { //echo "pic1";
                ?>
                    <li id="ajcms2" class="jcms">&nbsp;</li>
                <?php
                }
                if ($pic[2]['enabled']) { //echo "pic1";
                ?>
                    <li id="ajcms3" class="jcms">&nbsp;</li>
                <?php
                }
                if ($pic[3]['enabled']) { //echo "pic1";
                ?>
                    <li id="ajcms4" class="jcms">&nbsp;</li>
                <?php
                }
                if ($pic[4]['enabled']) { //echo "pic1";
                ?>
                    <li id="ajcms5" class="jcms">&nbsp;</li>
                <?php
                }
                ?>
            </ul>
            <span class="clr"><!-- spanner --></span>
        </div>
	</td>
</tr>
</table>