<?php 
/**
* @id $Id$
* @author  mod_slideshow3.php
* @package  JB Slideshow3
* @copyright Copyright (C) 2006 - 2010 Joomla Bamboo. http://www.joomlabamboo.com  All rights reserved.
* @license  GNU/GPL license: http://www.gnu.org/copyleft/gpl.html
*/
// no direct access
defined('_JEXEC') or die('Restricted access');

// Load css into the body
if(!($mainframe->getCfg('caching')) && !($framework)) { ?>
<link rel="stylesheet" href="<?php echo $modbase ?>slideshow/slideshow.css" type="text/css" />
<?php 
	if ($ticker_transition == "fade") {
		// Load script references into the head ?>
		<script type="text/javascript" src="<?php echo $modbase?>slideshow/jquery.cycle.lite.js"></script>
	<?php } else {
		// Load script references into the head ?>
  	  	<script type="text/javascript" src="<?php echo $modbase?>slideshow/jquery.cycle.js"></script>
	<?php }
	if ($type == "slideshow") {	
		if ($fadeEffect) {?>
		<script type="text/javascript">
			jQuery(document).ready(function(){		
				jQuery.fn.cycle.updateActivePagerLink = function(pager, currSlideIndex) { 
				jQuery(pager).find('li').stop().fadeTo('slow', 0.3) 
				.filter('li:eq('+currSlideIndex+')').stop().fadeTo('fast', 1.0); 
				jQuery(pager).find('a').removeClass('activeSlide') 
				.filter('a:eq('+currSlideIndex+')').addClass('activeSlide');
				};
			});
		</script> 		
		<?php }
	} 
} ?>
<?php if ($type == "slideshow") { ?>
<!-- Start Joomla Bamboo Slideshow -->
<div id="slideShowContainer<?php echo $modID?>" class="slideShowContainer<?php echo $ssTheme?>" style="height:<?php echo $slideshow_height ?>;width:<?php echo $slideshow_width ?>;">

	<div id="slideShowDescription<?php echo $modID?>" class="slideShowDescription <?php echo $descriptionOverlay;?>" style="margin-left:<?php echo $descriptionMarginLeft ?>;margin-top:<?php echo $descriptionMarginTop ?>;height:<?php echo $descriptionHeight ?>;width:<?php echo $descriptionWidth ?>;display:<?php echo $showDescriptionText;?>;"><?php echo $descriptionText;?></div>
	<div id="slideShowNav<?php echo $modID?>" class="slideShowNav <?php echo $display_nav;?>" style="<?php if($scrollNav != 'horizontal') {?>width:<?php echo $ssNavWidth ?>;<?php }?><?php if($scrollNav != 'vertical') {?>height:<?php echo $ssNavHeight ?>;<?php }?>overflow:hidden;	position: absolute; float: left; z-index: 50;margin-top: <?php echo $navTop ?>;	margin-left: <?php echo $navLeft ?>;	display: <?php echo $navStyle ?>;">
	<?php if($scrollNav == 'vertical') {?>
        <?php if($numVis<$count){?>
			<div id="scrollPrevVertical<?php echo $modID?>" class="scrollButtonVertical scrollPrevious"></div>
			<div id="scrollNextVertical<?php echo $modID?>" class="scrollButtonVertical scrollNext"></div>
           <?php }?>
	<?php } elseif($scrollNav == 'horizontal'){?>
        <?php if($numVis<$count){?>
			<div id="scrollPrevHorizontal<?php echo $modID?>" class="scrollButtonHorizontal scrollPrevious"></div>
			<div id="scrollNextHorizontal<?php echo $modID?>" class="scrollButtonHorizontal scrollNext"></div>
        <?php }?>
	<?php }?>
		<?php if(($scrollNav == 'vertical') || ($scrollNav == 'horizontal')) {?>
			<div id="scrollContainer<?php echo $modID?>" class="scrollContainer" style="overflow:hidden">
		<?php }?>
		<div id="ssPager<?php echo $modID?>" class="ssPager<?php if($scrollNav == 'vertical') echo ' vertical';?><?php if($scrollNav == 'horizontal') echo ' horizontal';?> <?php echo $display_nav;?>" style="<?php if($display_nav == 'indexNav'):?>float:left;<?php endif;?>"></div>
		<?php if(($scrollNav == 'vertical') || ($scrollNav == 'horizontal')) {?>
			</div>			
		<?php }?>
		<?php if($navButtons && count($list)>1):?>
		<div class="ssNavButtons"><span id="ssPrev<?php echo $modID?>" class="ssPrev"><?php echo $prevNavText;?></span>  <span id="ssNext<?php echo $modID?>" class="ssNext"><?php echo $nextNavText;?></span></div>
		<?php endif;?>
	</div>
	<span class="tickerLabel" style="margin-top:<?php echo $margin_top ?>;"><?php echo $tickerIntro ?></span>
	<div id="news-ticker<?php echo $modID?>" style="height:<?php echo $slideshow_height ?>;width:100%;z-index:10">
		<?php // Start the loop
			if($list){
			$numItems = sizeof($list);
			foreach ($list as $item) :  

			$imagePath = "";

			if (($content_image == 'content') or ($content_image == 'k2content')) {
				
				$html = "";

				if(isset($item->firstimage)) $html= $item->firstimage;

				$html .= "alt='...' title='...' />";

				$pattern = '/<img[^>]+src[\\s=\'"]';

				$pattern .= '+([^"\'>]+)/is';

				$firstImage = '';

				if(preg_match(

				$pattern,

				$html,

				$match))

				$firstImage = "$match[1]";

				$imagePath = $firstImage;

			}

			if (($contentSource == "k2") and ($content_image == "k2item")){

				if(isset($item->firstimage)) $imagePath = $item->firstimage;

			}

			if(($content_image == 'directory'))

			{

				// remove the spaces in the file name

				$imageName = $item->title; 

				$imageName = str_replace (" ", "", $imageName);

				if ($lowercase) {

				$imageName = jb_utf8_strtolower($imageName);

				}

				$imageName = htmlspecialchars($imageName,ENT_COMPAT,'UTF-8');

				$directory = rtrim(ltrim($directory,DS),DS);

				$imagePath = $directory.DS.$imageName.'.'.$fileType;

			}

			$thumbsTitle = $item->title;

			if($titleLimit > 0)

			{

				if(strlen($thumbsTitle) > $titleLimit)

				{

					$thumbsTitle = substr( $thumbsTitle, 0, strrpos(substr($thumbsTitle, 0, $titleLimit), ' ')).$titleSuffix;

				}

			}

			// Plugin processing code from Joomlaworks.gr
			if ($renderPlugin == 'render'){
				/*
				* Process the prepare content plugins
				*/
				$plgparams 	   =& $mainframe->getParams('com_content');
				$dispatcher	   =& JDispatcher::getInstance();
				JPluginHelper::importPlugin('content');
				$results = $dispatcher->trigger('onPrepareContent', array (& $item, & $plgparams));
			} elseif ($renderPlugin == 'strip') {
				$item->text = preg_replace('/{([a-zA-Z0-9\-_]*)\s*(.*?)}/i','', $item->text);
			}
		 ?>
		<div class="scroller" style="height:<?php echo $slideshow_height?>;width:100%;">
			<?php if ($display_nav == "thumbsNav" or $display_nav == "titleNav" or $display_nav == "thumbsTitleNav" or $display_nav == "titleThumbsNav") : ?>
				<div class="slideThumbs<?php echo $modID?>" style="display:none">
					<?php if ($display_nav == "titleNav") { ?>
						<span class="thumbtitle"><?php echo $thumbsTitle ?></span><?php if(($contentSource == 'k2') and ($showCommentCount)) {?><span class="ssComment"><?php echo $item->numOfComments ?> comments</span><?php }?>
					<?php }else { ?>

						<?php if (!($imagePath == "")) { ?>

							<?php if ($display_nav == "titleThumbsNav") { ?><span class="thumbtitleright"><?php echo $thumbsTitle ?></span><?php if(($contentSource == 'k2') and ($showCommentCount)) {?><span class="ssComment"><?php echo $item->numOfComments ?> comments</span><?php }?><?php }?><img class="navThumb<?php if($imageBorder) echo ' border'?> <?php if($display_nav == "titleThumbsNav") echo 'thumbRight'?>" src="<?php echo resizeImageHelper::getResizedImage($imagePath, $thumb_width, $thumb_height, $thumb_option); ?>" alt="<?php echo $item->title; ?>" /> <?php if ($display_nav == "thumbsTitleNav") { ?><span class="thumbtitle"><?php echo $thumbsTitle ?></span><?php if(($contentSource == 'k2') and ($showCommentCount)) {?><span class="ssComment"><?php echo $item->numOfComments ?> comments</span><?php }?><?php }?>

								<?php }else { ?>
									<?php if ($display_nav == "titleThumbsNav") { ?><span class="thumbtitleright"><?php echo $thumbsTitle ?></span><?php if(($contentSource == 'k2') and ($showCommentCount)) {?><span class="ssComment"><?php echo $item->numOfComments ?> comments</span><?php }?><?php }?><img class="navThumb<?php if($imageBorder) echo ' border'?> <?php if($display_nav == "titleThumbsNav") echo 'thumbRight'?>" src="<?php echo resizeImageHelper::getResizedImage(JURI::base(true).DS.'modules/mod_slideshow3/images/spacer.png', $thumb_width, $thumb_height, $thumb_option); ?>" alt="<?php echo $item->title; ?>" /> <?php if ($display_nav == "thumbsTitleNav") { ?><span class="thumbtitle"><?php echo $thumbsTitle ?><?php if(($contentSource == 'k2') and ($showCommentCount)) {?><span class="ssComment"><?php echo $item->numOfComments ?> comments</span><?php }?></span><?php }?>					
								<?php }?>
					<?php }?>
				</div>
			<?php endif; ?>
			<?php if ($display_slideshow) : ?>
				<div class="slideshowImage" style="z-index:15<?php if ($imageResize) { ?>;width=<?php echo $image_width; ?>px;height=<?php echo $image_height; ?>px<?php }?>">

					<?php if (!($imagePath == "")) { ?> 

						<?php if ($imageLink) :?>
							<a href="<?php echo $item->link; ?>">
						<?php endif;
						 if ($imageResize) { ?>

						<img <?php if($imageBorder) :?>class="border"<?php endif?> src="<?php echo resizeImageHelper::getResizedImage($imagePath, $image_width, $image_height, $option); ?>"  alt="<?php echo $item->title; ?>"  style="margin-top:<?php echo $image_top ?>;margin-left:<?php echo $image_left?>"/>

						<?php }  

						if (!$imageResize) { ?>

						<img <?php if($imageBorder) :?>class="border"<?php endif?> src="<?php echo $imagePath ?>" alt="<?php echo $item->title; ?>"  style="margin-top:<?php echo $image_top ?>;margin-left:<?php echo $image_left?>"/>

						<?php }
						 if ($imageLink) :?>
							</a>
						<?php endif;?>
					<?php }else {?>
						<?php if ($imageLink) :?>
							<a href="<?php echo $item->link; ?>">
						<?php endif;?>
							<img <?php if($imageBorder) :?>class="border"<?php endif?> src="<?php echo resizeImageHelper::getResizedImage(JURI::base(true).DS.'modules/mod_slideshow3/images/spacer.png', $image_width, $image_height, $option); ?>" alt="<?php echo $item->title; ?>" style="margin-top:<?php echo $image_top ?>;margin-left:<?php echo $image_left?>"/>
						<?php if ($imageLink) :?>
							</a>
						<?php endif;?>
					<?php }?>
				</div>
			<?php endif; ?>
			<?php if ($display_ticker) : ?>
			<div class="slideshowContent <?php if($bgOverlay != 'no')echo $bgOverlay;?>" style="margin-top:<?php echo $margin_top ?>;margin-left:<?php echo $margin_left?>;width:<?php echo $ticker_width?>;height:<?php echo $ticker_height?>;z-index:20;">
				<?php if ($item_title) : ?>
				<div class="slideshowTitle"><<?php echo $title_class ?>>
				<?php if ($title_link) : ?>
					<a href="<?php echo $item->link; ?>">
				<?php endif; ?>
			<?php echo $item->title; ?>
			<?php if ($title_link) : ?>
					</a>
			<?php endif; ?>
			</<?php echo $title_class ?>></div>
		<?php endif; ?>
		<?php if ($createdDate) { ?>
		<div class="slideshowDate">
			<?php echo $item->dateCreated; ?>
		</div>
		<?php } ?>
		<?php if ($showCategory) { ?>
		<div class="catname"><span class="catname">
				<?php if($catPrefix !="") echo $catPrefix . ' '?>
				<?php if ($catlink) { ?><a href="<?php echo $item->catlink ?>"><?php }?>
							<?php echo $item->catname; ?>
				<?php if ($catlink) { ?></a><?php }?>
		</span></div>
		<?php }?>
		<?php if ($ticker_text) : ?>
			<div>
			<?php echo string_limit_words( $item->text, $wordCount); ?>
			<?php if($readMoreLink) :?>			
			<a class="slideshowMore" href="<?php echo $item->link; ?>"><span class="readmore"><?php echo $readMoreText; ?></span></a>			
			<?php endif;?>
			</div>
		<?php endif; ?>
			</div>
			<?php endif; ?>
		</div>
<?php endforeach; } ?>
	</div>
		
		<div class="slideshowShadowWrap">
			<div class="slideshowInnerLeft"></div>
			<div class="slideshowInnerRight"></div>
		</div>
</div>
<div class="jbclear"></div>
<!-- Joomla Bamboo  Slideshow 3 ends here -->
<script type="text/javascript">
/* <![CDATA[ */
jQuery.noConflict();
jQuery(function() {
	 jQuery('#slideShowContainer<?php echo $modID?>').show();
	 	 jQuery('.slideshowImage').css({'background':'none'});
		 jQuery('#news-ticker<?php echo $modID?>').cycle({ 
			fx:    '<?php echo $ticker_transition ?>', 
			requeueOnImageNotLoaded: true,
			cleartype:	true,		 
			timeout: <?php echo $sstime ?>,
			speed: <?php echo $ssSpeed ?>,
			pager:  '#ssPager<?php echo $modID?>',
			prev: '#ssPrev<?php echo $modID?>',
			next: '#ssNext<?php echo $modID?>'
			<?php if ($hoverTransition) : ?>,
			pagerEvent: 'mouseover'<?php endif;?>
			<?php if ($display_nav == "thumbsNav" or $display_nav == "titleNav" or $display_nav == "thumbsTitleNav" or $display_nav == "titleThumbsNav") : ?>,
			pagerAnchorBuilder: function(idx, slide) {
				return '<li class="navItem<?php echo $modID?>" style="width: <?php echo $navItemWidth ?>px;	height: <?php echo $navItemHeight ?>px;display:block;overflow:hidden;"><a href="#">'+jQuery('div.slideThumbs<?php echo $modID?>',slide).html()+'</a></li>';
			}
			<?php endif; ?>
		});
	<?php if($scrollNav != 'none') :?>
		var navItemHeight = parseInt(jQuery('li.navItem<?php echo $modID?>').css('marginBottom')) + parseInt(jQuery('li.navItem<?php echo $modID?>').css('marginTop')) + parseInt(jQuery('li.navItem<?php echo $modID?>').height());
		var navItemWidth = parseInt(jQuery('li.navItem<?php echo $modID?>').css('marginLeft')) + parseInt(jQuery('li.navItem<?php echo $modID?>').css('marginRight')) + parseInt(jQuery('li.navItem<?php echo $modID?>').width());
		var scrollOffset = 0;
		var scrollFrame = 1;
		var scrollCount = <?php echo $numItems?>-<?php echo $numVis?>+1;
		<?php if($scrollNav == 'vertical') {?>
			var scrollAreaWidth = navItemWidth;
			var scrollAreaHeight = parseInt(<?php echo $numVis > $numItems ? $numItems:$numVis;?>) * navItemHeight;
			var scrollTotalHeight = parseInt(<?php echo $numItems?>) * navItemHeight;
			var scrollButtonHeight = 20;
			var scrollButtonWidth = navItemWidth;
			var scrollBy = navItemHeight;
			jQuery('div#scrollPrevVertical<?php echo $modID?>, div#scrollNextVertical<?php echo $modID?>').css('height',scrollButtonHeight).css('width',scrollButtonWidth);
			jQuery('div#scrollPrevVertical<?php echo $modID?>').css('top',0);
			jQuery('div#scrollNextVertical<?php echo $modID?>').css('top',scrollAreaHeight+20);
			jQuery('div#slideShowNav<?php echo $modID?>').css('height',scrollAreaHeight+40);
			jQuery('div#scrollContainer<?php echo $modID?>').css('marginTop',scrollButtonHeight);
			jQuery('div#ssPager<?php echo $modID?>').css('height',scrollTotalHeight).css('width',scrollAreaWidth);
			jQuery('div#scrollContainer<?php echo $modID?>').css('width',scrollAreaWidth+2).css('height',scrollAreaHeight);
			jQuery(document).ready(function(){
				jQuery('div#scrollPrevVertical<?php echo $modID?>').click(function(){
					newFrame = (scrollFrame/1)-1;
					newOffset = scrollOffset+scrollBy;
					newOffsetAttr = newOffset + "px";
					if(newFrame > 0){
						jQuery('div#ssPager<?php echo $modID?>').stop().animate({top : newOffsetAttr}, 800);
						scrollFrame = newFrame;
						scrollOffset = newOffset;
					}
				});
				jQuery('div#scrollNextVertical<?php echo $modID?>').click(function(){
					newFrame = (scrollFrame/1)+1;
					newOffset = scrollOffset-scrollBy;
					newOffsetAttr = newOffset + "px";
					if(newFrame <= scrollCount){
						jQuery('div#ssPager<?php echo $modID?>').stop().animate({top : newOffsetAttr}, 800);
						scrollFrame = newFrame;
						scrollOffset = newOffset;
					}
				});
			});
		<?php } elseif($scrollNav == 'horizontal'){?>
			var scrollAreaWidth = parseInt(<?php echo $numVis > $numItems ? $numItems:$numVis;?>) * navItemWidth;
			var scrollAreaHeight = navItemHeight;
			var scrollTotalWidth = parseInt(<?php echo $numItems?>) * navItemWidth;
			var scrollButtonHeight = navItemHeight;
			var scrollButtonWidth = 20;
			var scrollBy = navItemWidth;	
			jQuery('div#scrollPrevHorizontal<?php echo $modID?>, div#scrollNextHorizontal<?php echo $modID?>').css('height',scrollButtonHeight).css('width',scrollButtonWidth);
			jQuery('div#scrollPrevHorizontal<?php echo $modID?>').css('left',0);
			jQuery('div#scrollNextHorizontal<?php echo $modID?>').css('left',scrollAreaWidth+20);
			jQuery('div#slideShowNav<?php echo $modID?>').css('width',scrollAreaWidth+40);
			jQuery('div#scrollContainer<?php echo $modID?>').css('marginLeft',scrollButtonWidth);
			jQuery('div#ssPager<?php echo $modID?>').css('height',scrollAreaHeight).css('width',scrollTotalWidth);
			jQuery('div#scrollContainer<?php echo $modID?>').css('width',scrollAreaWidth).css('height',scrollAreaHeight+2);
			jQuery(document).ready(function(){
				jQuery('div#scrollPrevHorizontal<?php echo $modID?>').click(function(){
					newFrame = (scrollFrame/1)-1;
					newOffset = scrollOffset+scrollBy;
					newOffsetAttr = newOffset + "px";
					if(newFrame > 0){
						jQuery('div#ssPager<?php echo $modID?>').stop().animate({left : newOffsetAttr}, 800);
						scrollFrame = newFrame;
						scrollOffset = newOffset;
					}
				});
				jQuery('div#scrollNextHorizontal<?php echo $modID?>').click(function(){
					newFrame = (scrollFrame/1)+1;
					newOffset = scrollOffset-scrollBy;
					newOffsetAttr = newOffset + "px";
					if(newFrame <= scrollCount){
						jQuery('div#ssPager<?php echo $modID?>').stop().animate({left : newOffsetAttr}, 800);
						scrollFrame = newFrame;
						scrollOffset = newOffset;
					}
				});
			});
		<?php }?>
	<?php endif;?>
});
/* ]]> */
</script> 
<?php } ?>
