<?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' );
require_once( dirname(__FILE__).'/helper.php' ); 
$helper = JPATH_SITE.DS.'media'.DS.'zengridframework'.DS.'helpers'.DS.'image.php';
if (!(JFile::exists($helper))){
	$helper = JPATH_SITE.DS.'media'.DS.'plg_jblibrary'.DS.'helpers'.DS.'image.php';
}
$framework = JPATH_SITE.DS.'plugins'.DS.'system'.DS.'zengridframework'.DS.'zengrid.php';
if (!(JFile::exists($framework))){
	$framework = false;
}

if (file_exists($helper)){ 
	require_once($helper); 
} else {

	echo '<div style="font-size:12px;font-family: helvetica neue, arial, sans serif;width:600px;margin:0 auto;background: #f9f9f9;border:1px solid #ddd ;margin-top:100px;padding:40px"><h3>Ooops. It looks like JbLibrary plugin is not installed!</h3> <br />Please install it and ensure that you have enabled the plugin by navigating to extensions > plugin manager. <br /><br />JB Library is a free Joomla extension that you can download directly from the <a href="http://www.joomlabamboo.com/joomla-extensions/jb-library-plugin-a-free-joomla-jquery-plugin">Joomla Bamboo website</a>.</div>';

}
$contentSource = $params->get('contentSource','article');
$modbase = JURI::base(true).'/modules/mod_slideshow3/';
$library = JURI::base(true).'/media/plg_jblibrary/';
$document =& JFactory::getDocument();
$modID = $module->id;
$count = $params->get('count', 5);
$loadJS = $params->get( 'loadJS', 'None');
$loadCSS = $params->get( 'loadCSS', 'None');
if (file_exists($framework)){ 
$framework = 1;
$loadJS = 0;
$loadCSS = "none";
}

$ssTheme = $params->get( 'ssTheme', 'None');
$type = $params->get( 'type', 'slideshow' );
$display_ticker = $params->get( 'display_ticker', '1' );
$display_slideshow = $params->get( 'display_slideshow', '1' );
$ticker_transition = $params->get( 'ticker_transition', 'scrollDown' );
$ticker_title = $params->get( 'ticker_title', '1' );
$ticker_text = $params->get( 'ticker_text', '1' );
$title_class = $params->get( 'title_class', 'h2' );
$item_title = $params->get( 'item_title', '1' );
$title_link = $params->get( 'title_link', '1' );
$ticker_height = str_replace('px', '', $params->get( 'ticker_height', '100' ));
$ticker_width = str_replace('px', '', $params->get( 'ticker_width', '670' ));
$margin_top = str_replace('px', '', $params->get( 'margin_top', '290' ));
$margin_left = str_replace('px', '', $params->get( 'margin_left', '0' ));
$content_image = $params->get(	'content_image','content');
if ($contentSource == 'article'){
	if (!(($content_image == 'content')or ($content_image == 'directory'))) $content_image = 'content';
}else{
	if (!(($content_image == 'k2content') or ($content_image == 'k2item')or ($content_image == 'directory'))) $content_image = 'k2content';
}
$directory = $params->get( 'directory', 'images/stories' );
$slideshow_height = str_replace('px', '', $params->get( 'slideshow_height', '400' ));
$slideshow_width = $params->get( 'slideshow_width', '' );
$imageBorder = $params->get( 'imgBorder','1');
$image_top = str_replace('px', '', $params->get( 'image_top', '290' ));
$image_left = str_replace('px', '', $params->get( 'image_left', '0' ));
$fileType = $params->get( 'fileType', 'jpg' );
$lowercase = $params->get( 'lowercase', '1' );
$display_nav = $params->get( 'display_nav', 'indexNavButtons' );
$navTop = $params->get( 'navTop', '0' );
$navLeft = $params->get( 'navLeft', '0' );
$navButtons = $params->get(	'navButtons', '0');
$sstime = $params->get( 'sstime', '10000' );
$ssSpeed = $params->get( 'ssSpeed','1500');
$image1_pub = $params->get( 'image1_pub', '1' );
$image1 = $params->get( 'image1', 'key.jpg' );
$title1 = $params->get( 'title1', 'Title1' );
$alt1 = $params->get( 'alt1', 'Alt1' );
$image_number = $params->get( 'image_number', '3' );
$image_name = $params->get( 'image_name', 'header' );
$image_extension = $params->get( 'image_extension', 'jpg' );
$time = $params->get( 'time', '10000' );
$duration = $params->get( 'duration', '400');
$jbIntroText = $params->get( 'jbIntroText', 1 );
$words = $params->get( 'words', '80' );
$ssNavWidth = str_replace('px', '', $params->get( 'navWidth', '200' ));
$ssNavHeight = str_replace('px', '', $params->get( 'navHeight', '400' ));
$prevNavText = $params->get( 'navPrevText', 'Previous' );
$nextNavText = $params->get( 'navNextText', 'Next' );
$bgOverlay = $params->get( 'bgOverlay', '0' );
$readMoreLink = $params->get( 'readMoreLink', '1' );
$readMoreText = $params->get( 'readMoreText', 'Read More ...' );
$imageResize = $params->get( 'imageResize', '1' );
$tickerIntro = $params->get( 'tickerIntro', '' );
$navItemWidth = str_replace('px', '', $params->get('navItemWidth','60'));
$navItemHeight = str_replace('px', '', $params->get('navItemHeight','40'));
$titleLimit = $params->get('titleLimit','0');
$titleSuffix = $params->get('titleSuffix','...');
$scrollNav = $params->get('scrollNav','none');
$numVis = $params->get('numVis','3');
$createdDate = $params->get( 'createdDate', "1" );
$dateFormat = $params->get( 'dateFormat', "D, d M Y H:i" );
if (!($display_nav == "thumbsNav" or $display_nav == "titleNav" or $display_nav == "thumbsTitleNav" or $display_nav == "titleThumbsNav"))
{
	$scrollNav = 'none';
}
$images = $image_number + 1;
// Image Size and container
$option = $params->get('option','crop');
$image_width =  str_replace('px', '', $params->get('image_width','234'));
$image_height =  str_replace('px', '', $params->get('image_height','100'));
$colour = $params->get('colour', 'white');
$rightMargin =  str_replace('px', '', $params->get('rightMargin', '10'));
$bottomMargin =  str_replace('px', '', $params->get('bottomMargin', '10'));
$imageLink = $params->get('imageLink','1');
$hoverTransition = $params->get('hoverTransition','1');
$fadeEffect = $params->get('fadeEffect','1');
$wordCount	= $params->get( 'wordCount', '40' );
$stripTags = $params->get(	'striptags','1');
$allowedTags = $params->get('tags','<a><ul><li><h1><h2><h3><h4><h5><h6><b><em><i><strong><blockquote><dd><dt><small><u><br>');
// Thumbnail size
$thumb_option = $params->get('thumb_option','crop');
$thumb_height = str_replace('px', '', $params->get('thumb_height','40'));
$thumb_width = str_replace('px', '', $params->get('thumb_width','60'));
$renderPlugin	= $params->get('renderPlugin','render');
//K2
$contentSource = $params->get('contentSource','article');
$showCommentCount	= $params->get('showCommentCount','1');
//Category Details 
$showCategory = $params->get('showCategory',0);
$catPrefix = $params->get('catPrefix',0);
$catlink = $params->get('catLink',0);
//Description Text
$showDescriptionText = $params->get('showDescriptionText','1');
$descriptionText = $params->get('descriptionText','');
$descriptionMarginTop = str_replace('px', '', $params->get('descriptionMarginTop','0'));
$descriptionMarginLeft = str_replace('px', '', $params->get('descriptionMarginLeft','0'));
$descriptionHeight = str_replace('px', '', $params->get('descriptionHeight','50'));
$descriptionWidth = str_replace('px', '', $params->get('descriptionWidth','100'));
$descriptionOverlay = $params->get('descriptionOverlay','0');
if(!function_exists('jb_get_dimensions')) {
	function jb_get_dimensions($dimension)
	{
		preg_match ('{(\d+)}',$dimension,$m)			;
		$numDim = $m[1];
		trim(strtolower($dimension));
		if(substr($dimension,-1,1) == "%")
		{
			return $numDim."%";
		}
		else
		{
			return $numDim."px";
		}		
	}
}
if(!function_exists('jb_get_px')) {
	function jb_get_px($dimension)
	{
		preg_match ('{((\+|-)?\d+)}',$dimension,$m);
		$numDim = $m[1];
		return $numDim."px";				
	}
}
if($slideshow_width == ""){
$slideshow_width = "100%";
}else{
$slideshow_width = jb_get_dimensions($slideshow_width);
}
$ticker_height = jb_get_px($ticker_height);
$ticker_width = jb_get_px($ticker_width);
$slideshow_height = jb_get_px($slideshow_height);
$margin_top = jb_get_px($margin_top);
$margin_left = jb_get_px($margin_left);
$image_top = jb_get_px($image_top);
$image_left = jb_get_px($image_left);
$navTop = jb_get_px($navTop);
$navLeft = jb_get_px($navLeft);
$ssNavWidth = jb_get_px($ssNavWidth);
$descriptionMarginTop = jb_get_px($descriptionMarginTop);
$descriptionMarginLeft = jb_get_px($descriptionMarginLeft);
$descriptionHeight = jb_get_px($descriptionHeight);
$descriptionWidth = jb_get_px($descriptionWidth);
if($display_nav == "noNav"){
	$navStyle = 'none';
} else {
	$navStyle = 'inline';
}
if(!function_exists('jb_utf8_strtolower')) {
	function jb_utf8_strtolower($string) 
	{
		return utf8_encode(strtolower(utf8_decode($string)));
	}
}
if(!function_exists('string_limit_words')) {
		 function string_limit_words($introText, $wordCount) {
		     $id = explode(' ', $introText);
		     return implode(' ', array_slice($id, 0, $wordCount));
		   }
		}
	//if styles are added to the head
	if($mainframe->getCfg('caching') && !($framework)) { 
		if ($ticker_transition == "fade") {
			// Load script references into the head
			$document->addStyleSheet($modbase.'slideshow/slideshow.css'); 
		} else {
			// Load script references into the head
			$document->addStyleSheet($modbase.'slideshow/slideshow.css'); 
		}

		//if scripts are added to the head
		if ($ticker_transition == "fade") {
			// Load script references into the head
			$document->addScript($modbase . "slideshow/jquery.cycle.lite.js");
		} else {
			// Load script references into the head
			$document->addScript($modbase . "slideshow/jquery.cycle.js");
		}
	
	if ($type == "slideshow") {	
		if ($fadeEffect)
		{
			$document->addScriptDeclaration("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');
				};
		  });
			");
		}
	}
}
$k2 = JPATH_SITE.DS.'administrator'.DS.'components'.DS.'com_k2'.DS.'admin.k2.php';
if(($contentSource == "k2")&&(file_exists($k2)))
{
	$list = modSSK2ContentHelper::getList($params);
}
elseif($contentSource == "article")
{
	$list = mod_slideshow3Helper::getList($params);
}
else
{
	echo 'K2 is not installed';
}
require(JModuleHelper::getLayoutPath('mod_slideshow3'));
?>
