<?php

/*------------------------------------------------------------------------
# "Hot Joomla Carousel Pro" Joomla module
# Copyright (C) 2010 ArhiNet d.o.o. All Rights Reserved.
# License: http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 only
# Author: HotJoomlaTemplates.com
# Website: http://www.hotjoomlatemplates.com
-------------------------------------------------------------------------*/

defined('_JEXEC') or die('Restricted access'); // no direct access

// get the document object
$doc =& JFactory::getDocument();

// add your stylesheet
$doc->addStyleSheet( 'modules/mod_hot_joomla_carousel_pro/tmpl/hot_joomla_carousel_pro.css' );

if($buttonRadius) {
	$buttonRadiusHTML = '-moz-border-radius:'.$buttonRadius.'px; ';
	$buttonRadiusHTML .= '-webkit-border-radius:'.$buttonRadius.'px; ';
	$buttonRadiusHTML .= 'border-radius:'.$buttonRadius.'px;';
}

// style declaration
$doc->addStyleDeclaration( '

.hotcarousel li.carouselimage img {
	border:'.$objectBorderWidth.'px solid '.$objectBorderColor.';
	margin:'.$objectMarginReal.'px;
	padding:'.$objectPadding.'px;
}

.hotcarousel li .carouselarticle {
	border:'.$objectBorderWidth.'px solid '.$objectBorderColor.';
	margin:'.$objectMarginReal.'px;
	padding:'.$objectPadding.'px;
	width:'.$objectWidth.'px;
	height:'.$objectHeight.'px;
	overflow:hidden;
}

.hotcarousel .js {
	overflow:hidden;
	height:'.$moduleHeight.'px;
}

.hotcarousel .carousel-next {
	background: url('.$mosConfig_live_site.'/modules/mod_hot_joomla_carousel_pro/images/icon'.$arrowStyle.'_right.png) 0 '.$controlPositon.'px no-repeat; float:left;
}

.hotcarousel .carousel-previous {
	background: url('.$mosConfig_live_site.'/modules/mod_hot_joomla_carousel_pro/images/icon'.$arrowStyle.'_left.png) 0 '.$controlPositon.'px no-repeat; float:left;
}

.hotcarousel .carousel-control {
	height:'.$moduleHeightControl.'px;
	'.$arrowDisplayHTML.'
}

div.carousel-pagination a span {
	border:'.$buttonBorderSize.'px solid '.$buttonBorderColor.';
	padding:'.$buttonVertPadding.'px '.$buttonHorizPadding.'px;
	margin:1px;
	line-height:20px;
	background:'.$buttonBgColor.';
	'.$buttonRadiusHTML.'	
	cursor:pointer;
}

div.carousel-pagination span:hover, div.carousel-pagination a.active span {
	background:'.$buttonBgColorActive.';
	cursor:pointer;
	border:'.$buttonBorderSizeActive.'px solid '.$buttonBorderColorActive.';
}

.carousel-wrap {
	width:'.$moduleWidth.'px;
	height:'.$moduleHeightControl.'px !important;
	float:left;
}

.carouselarticle {
	/* background:'.$articleBgColor.'; */
}

.hidecarousel {
	display:none;
}

' );

?>

<?php if ($enablejQuery!=0) { ?>
<script type="text/javascript" src="<?php echo $mosConfig_live_site; ?>/modules/mod_hot_joomla_carousel_pro/js/jquery.min.js"></script>
<?php } ?>
<?php if ($noConflict!=0) { ?>
<script type="text/javascript">
     jQuery.noConflict();
</script>
<?php } ?>

<script type="text/javascript">
jQuery(document).ready(function() {				   
		jQuery('#hotcarouselmodule').removeClass('hidecarousel');	
});
</script>

<script type="text/javascript" src="<?php echo $mosConfig_live_site; ?>/modules/mod_hot_joomla_carousel_pro/js/jquery.carousel.min.js"></script>
<script type="text/javascript">
    jQuery(function(){
        jQuery("div.foo").carousel({
			direction: "<?php echo $carouselDirection; ?>",
			loop: <?php if ($carouselLoop) { echo "true"; }else{ echo "false"; } ?>,
			dispItems: <?php echo $articleNumber; ?>,
			pagination: <?php if ($carouselPagination) { echo "true"; }else{ echo "false"; } ?>,
			paginationPosition: "inside",
			autoSlide: <?php if ($carouselAutoSlide) { echo "true"; }else{ echo "false"; } ?>,
			autoSlideInterval: <?php echo $carouselAutoSlideInterval; ?>,
			delayAutoSlide: false,
			combinedClasses: false,
			effect: "<?php echo $carouselEffect; ?>",
			slideEasing: "swing",
			animSpeed: "<?php echo $carouselAnimSpeed; ?>",
			equalWidths: "true"
		});
    });
</script>
<div id="hotcarouselmodule" class="hotcarousel hidecarousel">
    <div class="foo">
         <ul style="margin:0; padding:0">
    
			<?php
			
			if ($where == 'category' || $where == 'content') {
				// source is content category/item
				foreach ($html2out as $key => $value) {
					echo '<li class="carouselcontent"><div class="carouselarticle">'.$value.'<div class="clr"></div></div></li>';
				}
				
			}else{
				
				$linksList = explode("\n", $imageLinks);
				
				$carouselPath = $_SERVER['SCRIPT_FILENAME'];
				$carouselRealPath = substr_replace($carouselPath ,"",-9);
				$carouselFullPath = $carouselRealPath.$carouselImagesPath;
				if ($handle = opendir($carouselFullPath)) {
					while (false !== ($file = readdir($handle))) {
						if ($file != "." && $file != "..") {
							$infinite_list = $infinite_list."$file"."||";
						}
					}
					closedir($handle);
					// edited may 2011
					$infinite_pic = explode("||", $infinite_list);
					$infinite_pics_number = count($infinite_pic);
					sort($infinite_pic);
					for ($loop = 0; $loop < $infinite_pics_number ; $loop += 1) {
						if(!isset($infinite_pic[$loop])) continue;
        				if($infinite_pic[$loop] === '') continue;
        				if($linksList[$loop] && $linksList[$loop]!='$$') {
							$currentLink = '<a href="'.$linksList[$loop].'"'.$linkTargetHTML.'>';
					// end	
							$currentLinkClose = '</a>';
						}else{
							$currentLink = '';
							$currentLinkClose = '';
						}
						$pic_type = explode(".", $infinite_pic[$loop]);
						if ((($pic_type[1]=="jpg")or($pic_type[1]=="gif"))or(($pic_type[1]=="jpeg")or($pic_type[1]=="png"))) {
							echo '<li class="carouselimage">'.$currentLink.'<img src="'.$carouselImagesPath.'/'.$infinite_pic[$loop].'" alt="" width="'.$objectWidth.'" height="'.$objectHeight.'" />'.$currentLinkClose.'</li>';
							echo "\n";
						} elseif ((($pic_type[1]=="JPG")or($pic_type[1]=="GIF"))or(($pic_type[1]=="JPEG")or($pic_type[1]=="PNG"))) {
							echo '<li class="carouselimage">'.$currentLink.'<img src="'.$carouselImagesPath.'/'.$infinite_pic[$loop].'" alt="" width="'.$objectWidth.'" height="'.$objectHeight.'" />'.$currentLinkClose.'</li>';
							echo "\n";						
						}
					}
				}
				
			}
            ?>
    
        </ul>

    </div>
</div>
<div class="clr"></div>