<?php // no direct access

defined('_JEXEC') or die('Restricted access');

//K2
$showCommentCount	= $params->get('showCommentCount','yes');
$renderPlugin	= $params->get('renderPlugin','render');

if(!($mainframe->getCfg('caching')) && !($framework)) {
	$document->addStyleSheet($modbase.'css/microblog.css');
	
	if($colorBox){
		$document->addStyleSheet($modbase.'css/cbtheme'.$cbTheme.'.css');
		$document->addScript($modbase . "js/jquery.colorbox-min.js");
	}
}

// Triggers for filter option
?>

<div class="mbContainer intro" <?php if ($mbHeight !="") { ?> style="height:<?php echo $mbHeight ?>px" <?php } ?>>


<?php

		if($list)
		{
		$numMB = sizeof($list);	
		foreach ($list as $item) :  

		// Grabs the first image from the intro text
		$firstImage = $item->firstImage;
		$sTitle = $item->title;
		if($titleLimit > 0)
		{
			if(strlen($sTitle) > $titleLimit)
			{
				//$sTitle = substr( $sTitle, 0, strrpos(substr($sTitle, 0, $titleLimit), ' ')).$titleSuffix;
				$sTitle = substr($sTitle, 0, $titleLimit).$titleSuffix;
			}
		}

// Assigns the last image in the row to have 0 margin		
		$imageNumber++;
		if($addMargin){
			$imgRightMargin = ($imageNumber % $imagesPerRow) ? $autoRightMargin : 0;
		}
		else{
			$imgRightMargin = ($imageNumber % $imagesPerRow) ? $rightMargin.'px' : '0px';
		}

		$rowFlag = ($imageNumber % $imagesPerRow) ? 0 : 1;
		// 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');
			$item->text = $item->fulltext;
			$results = $dispatcher->trigger('onPrepareContent', array (& $item, & $plgparams));
			$item->fulltext = $item->text;			
			$item->text = $item->introtext;
			$results = $dispatcher->trigger('onPrepareContent', array (& $item, & $plgparams));
			$item->introtext = $item->text;
			
		} elseif ($renderPlugin == 'strip') {

			$item->introtext = preg_replace('/{([a-zA-Z0-9\-_]*)\s*(.*?)}/i','', $item->introtext);
			$item->fulltext = preg_replace('/{([a-zA-Z0-9\-_]*)\s*(.*?)}/i','', $item->fulltext);
		}


// Logic for link behaviour
if ($colorBox && $popupGallery) {
$linkbehaviour ="id='inline".$item->id.$moduleID."' class='cBox".$moduleID."' rel='mbgallery".$moduleID."' href='#mbpopup".$item->id.$moduleID."' title='".$item->title."'";
$linkbehaviourImage ="id='inlineIMG".$item->id.$moduleID."' class='cBoxi".$moduleID."' rel='mbgalleryi".$moduleID."' href='#mbpopup".$item->id.$moduleID."' title='".$item->title."'";
$linkbehaviourReadon ="id='inlineRO".$item->id.$moduleID."' class='cBoxr".$moduleID." readon' rel='mbgalleryr".$moduleID."' href='#mbpopup".$item->id.$moduleID."' title='".$item->title."'";
} 

if ($colorBox && !($popupGallery)) {
$linkbehaviour ="id='inline".$item->id.$moduleID."' class='cBox".$moduleID."'  href='#mbpopup".$item->id.$moduleID."' title='".$item->title."'";
$linkbehaviourImage ="id='inlineIMG".$item->id.$moduleID."' class='cBoxi".$moduleID."' href='#mbpopup".$item->id.$moduleID."' title='".$item->title."'";
$linkbehaviourReadon ="id='inlineRO".$item->id.$moduleID."' class='cBoxr".$moduleID." readon' rel='mbgalleryr".$moduleID."' href='#mbpopup".$item->id.$moduleID."' title='".$item->title."'";
} 

if (!($colorBox)) {
$linkbehaviour ="href='".$item->link."'";
$linkbehaviourReadon ="href='".$item->link."' class='readon'";
$linkbehaviourImage ="href='".$item->link."'";
} 
?>

<div class="mbWrapIntro">

<?php if ($imageNumber =="1") { ?>

		<div class="mbitemIntro">

				<?php if ($displayImages != "no" ) {

							if (!($firstImage == "")) { ?>



									<a <?php echo $linkbehaviourImage ?>>

										<?php if($resizeImage) {?><img src="<?php echo resizeImageHelper::getResizedImage($firstImage, $image_width, $image_height, $option); ?>" width="<?php echo $image_width;?>px" height="<?php echo $image_height;?>px" alt="<?php echo $item->title; ?>" class="mbImageIntro <?php if ($fadeEffect) { ?>fade<?php } ?>" />

										<?php } else {?><img src="<?php echo $firstImage ?>" alt="<?php echo $item->title; ?>" class="mbImageIntro <?php if ($fadeEffect) { ?>fade<?php } ?>" />

												<?php }?>

									</a>

							<?php } 

				} ?>

				<?php if ($titlelink) {?>

				<<?php echo $titleClass ?>>

						<?php if ($titlelink == '2') { ?><a <?php echo $linkbehaviour ?>><?php }?>

									<?php echo $sTitle; ?>

						<?php if ($titlelink == '2') { ?></a><?php }?>

				</<?php echo $titleClass ?>>

				<?php }?>

				<?php if ($showCategory) { ?>

				<br/><span class="intro 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>

				<?php }?>

				<?php if ($showdate) { ?>

				<div class="mbdatePanel ">

						<?php echo $item->dateCreated; ?>

				</div>

				<?php } ?>

				<?php if ($showintro) { ?>

						<?php echo $item->introtext; ?>

				<?php } ?>

				<?php if ($displayMore) { ?>

				<div class="mbPanelMore">

						<a <?php echo $linkbehaviourReadon ?>><?php echo $readonText ?></a>

				</div>

					<?php } ?>

		</div>

	<?php } 

	if ($imageNumber >"1") { ?>

			<ul class="mbList">

					<li>

							<a <?php echo $linkbehaviour ?>><?php echo $sTitle; ?>

							<?php if ($showdate) { ?>

							<span class='mbIntrolistdate'><?php echo $item->dateCreated; ?>

</span>

							<?php } ?>

							</a>

					</li>

			</ul>

		<?php } ?>

		</div>

<?php if ($colorBox) { ?>

			<!-- Start Joomla Bamboo Microblog Inline Content -->
			<div style="display:none">
				<div id="mbpopup<?php echo $item->id.$moduleID; ?>">
					
					
					<?php // View for displaying k2 Video
					
					if ($justImage == "k2video") { ?>
						<?php echo $item->video;
			
						
						// Fallback to display the item if there is no video available
				 		if ($item->video =="") { ?>
								<h2 class="popupTitle"><?php echo $item->title; ?></<?php echo $titleClass ?>>
								<div class="popupIntroText">
										<?php echo $item->introtext ?>
								</div>
								<div class="mbClear"></div>
								<div class="popupFullText">
										<?php echo $item->fulltext ?>
								</div>
						<?php }
					}
					
					// Displays just the item image
					elseif ($justImage =="1" && !($firstImage == "")) { ?>
						<img src="<?php echo $firstImage; ?>" alt="<?php echo $item->title; ?>" class="mbImageFlat" />
					<?php } 
								
					// Displays just the fulltext
					if ($justImage == "fulltext") { ?>
						<h2 class="popupTitle"><?php echo $item->title; ?></<?php echo $titleClass ?>>
						<div class="popupFullText">
								<?php echo $item->fulltext ?>
						</div>
					<?php }					
					
					// Displays the intro and the fulltext
					elseif(!($justImage)) { ?>
						<h2 class="popupTitle"><?php echo $item->title; ?></<?php echo $titleClass ?>>
						<div class="popupIntroText">
								<?php echo $item->introtext ?>
						</div>
						<div class="mbClear"></div>
						<div class="popupFullText">
								<?php echo $item->fulltext ?>
						</div>
					<?php } ?>

				</div>
			</div>

				<!-- End Joomla Bamboo Microblog Inline Content -->
		<?php }
endforeach; }
?>
</div>

<?php if($mainframe->getCfg('caching') && !($framework)) { ?>
	<!-- Microblog CSS | Move these scripts into the head of th etemplate to make this module xhtml valid  -->
	<link href="modules/mod_microblog/css/microblog.css" rel="stylesheet" type="text/css" media="screen" />


	<?php if ($colorBox) { ?>
	<!-- Colorbox Scripts | Move these scripts into the head of th etemplate to make this module xhtml valid -->
	<link href="modules/mod_microblog/css/cbtheme<?php echo $cbTheme?>.css" rel="stylesheet" type="text/css" media="screen" />
	<script type="text/JavaScript" src="modules/mod_microblog/js/jquery.colorbox-min.js"></script>
	<?php }
} ?>


<?php 
	// Code for any of the effects like image fades, filter effects or colorbox
	if ($fadeEffect or $cbScripts == "body" or $cbScripts == 'head') { 
?> 
<script type="text/javascript">
<!--//--><![CDATA[//><!-- 
jQuery.noConflict();
jQuery(document).ready(function(){
<?php
// Fade Effect on thumbnail images
if ($fadeEffect)
{
	// Fade Effects 
	?>
	jQuery('img.fade').fadeTo('slow', 1.0); // This sets the opacity of the thumbs to fade down to 60% when the page loads
	jQuery('img.fade').hover(function(){
	jQuery(this).fadeTo('slow', 0.6); // This should set the opacity to 100% on hover
		},function(){
			jQuery(this).fadeTo('slow', 1.0); // This should set the opacity back to 60% on mouseout
		});
<?php
}
if ($colorBox) {
	$colorboxGallery = $popupGallery ? 'mbgallery'.$moduleID : 'nofollow';
	// Colorbox settings
?>
		jQuery('a.cBox<?php echo $moduleID?>, a.cBoxi<?php echo $moduleID?>, a.cBoxr<?php echo $moduleID?>').each(function(){
			var mbTarget = jQuery(this).attr('href');
			jQuery(this).colorbox({
				'inline': true,
				'href': mbTarget,
				'current': '{current} of {total}',
				'opacity': '<?php echo $overlayOpacity?>',
				'scrolling': <?php echo $colorboxScrolling?>,
				'innerWidth': '<?php echo $frameWidth?>',
				'innerHeight': '<?php echo $frameHeight?>'
			});	
	    });
<?php
	if($colorboxScrolling == 'false'){
?>		
			jQuery(document).bind('cbox_complete', function(){
			jQuery.fn.colorbox.resize();
		});
<?php
	}
}
?>
});
 //--><!]]> 
</script>
<?php } ?>
<div class="mbClear"></div>