<? $this->load->view( $this->aSystemVar['template_viewer_root'] . '_header') ?>

<script type="text/javascript">


		function initRateUpdate( event, url )
		{

			if ( !event )
				event = window.event;

			oRateEvent = new simplecloneObject(event);

			serverQuery(rateUpdate,url);

			return true;

		}


		function rateUpdate( ans )
		{

			if ( 'up'  == ans || 'down' == ans )
			{
				if ( 'up' == ans )
					var iAddRate = 1;
				else
					var iAddRate = -1;

				var container = document.getElementById('rateValue');
				var iRate = parseInt(container.innerHTML);

				container.innerHTML = iRate + iAddRate;
			}
			else
			{
				getAsyncHelp( oRateEvent, '<?= site_url('async/topic') ?>' + '/' + ans );
			}

			return true;
		}



		function hideForm(id)
		{
			var el = document.getElementById(id);

			if(el.style.display == 'none')
			{
				el.style.display = 'block';
			}
			else
			{
				el.style.display = 'none';
			}
		}


		function charCounter( field,countTarget)
		{
			maxLength = <?= $this->config->item('comment_characters'); ?>;
			countTarget = document.getElementById(countTarget);
			var inputLength = field.value.length;

			if(inputLength >= maxLength)
			{
				field.value = field.value.substring( 0, maxLength );

			}
			countTarget.innerHTML = maxLength-field.value.length;
		}


		function innerForm( targetId )
		{
			var el = document.getElementById( 'container_' + targetId );

			var form = '';
			var oFormKeeper		= document.createElement('div');
			var oForm			= document.createElement('form');
				oForm.action = '<?= $this->aSystemVar['current_location'] ?>';
				oForm.setAttribute( 'method', 'post' );

			var oSubDiv			= document.createElement('div');
				oSubDiv.style.marginBottom = '5px';

			var oTextarea		= document.createElement('textarea');
				oTextarea.className = 'comments';
				oTextarea.name= 'Body';
				oTextarea.onkeyup = function(){return charCounter( this, 'countTarget'+targetId+'');};
				oTextarea.style.width = '97%';
				oTextarea.style.height = '50px';
				oTextarea.id	= 'Body'+targetId;

			var oSubmitDiv		= document.createElement('div');
				oSubmitDiv.className = 'submit';

			var oCounterSpan	= document.createElement('span');
				oCounterSpan.id	= 'countTarget'+targetId;
				oCounterSpan.className = 'counter';
				oCounterSpan.innerHTML = '<?= $this->config->item('comment_characters'); ?>'

			var oCounterSpanText	= document.createElement('span');
				oCounterSpanText.className = 'counter';
				oCounterSpanText.innerHTML = '<?= $this->lang->line('characters_left'); ?>'

			var oActionInput	= document.createElement('input');
				oActionInput.type = 'hidden';
				oActionInput.name = 'action';
				oActionInput.value = 'comment_add';

			var oParenIdInput	= document.createElement('input');
				oParenIdInput.type = 'hidden';
				oParenIdInput.name = 'ParentId';
				oParenIdInput.value = targetId;

			var oUserIdInput	= document.createElement('input');
				oUserIdInput.type = 'hidden';
				oUserIdInput.name = 'UserId';
				oUserIdInput.value = '<?= $this->aSystemVar['current_user']['Id'] ?>';

			var oItemIdInput	= document.createElement('input');
				oItemIdInput.type = 'hidden';
				oItemIdInput.name = 'PostId';
				oItemIdInput.value = '<?=$data['Post']['Id']?>';

			var oSubInputDiv	= document.createElement('div');
				oSubInputDiv.style.marginTop = '5px';
				oSubInputDiv.setAttribute( 'class', 'submit' );

			var oSubInput		= document.createElement('input');
				oSubInput.type = 'submit';
				oSubInput.value = '<?= $this->lang->line('submit'); ?>';
				oSubInput.className = 'submit';
			oSubInputDiv.appendChild(oSubInput);

			var oCounterDiv		= document.createElement('div');
				oCounterDiv.className = 'counterBlock';

			oCounterDiv.appendChild(oCounterSpan);
			oCounterDiv.appendChild(oCounterSpanText);
			oSubmitDiv.appendChild(oCounterDiv);
			oSubmitDiv.appendChild(oActionInput);
			oSubmitDiv.appendChild(oParenIdInput);
			oSubmitDiv.appendChild(oUserIdInput);
			oSubmitDiv.appendChild(oItemIdInput);



			oSubDiv.appendChild(oTextarea);
			oSubDiv.appendChild(oSubmitDiv);
			<? 
//				if ( $this->config->item('security_code_comment') OR empty($this->aSystemVar['current_user']['Id']) ): 
				if ( $this->config->item('security_code_comment') ):
			?>

				var oSIDiv			= document.createElement('div');
				var oSI				= document.createElement('img');
					oSI.src = '<?=site_url('catalog/get_security_image')?>';
					oSI.alt = 'security image';
					oSI.title = 'security image';
				oSIDiv.appendChild(oSI);

				var oSIInputDiv		= document.createElement('div');
				var oSIInput		= document.createElement('input');
					oSIInput.type = 'text';
					oSIInput.calssName = 'text';
					oSIInput.name = 'SecurityCode';
				oSIInputDiv.appendChild(oSIInput);

				oSubDiv.appendChild(oSIDiv);
				oSubDiv.appendChild(oSIInputDiv);

			<? endif; ?>
			oSubDiv.appendChild(oSubInputDiv);
			oForm.appendChild(oSubDiv);
			oFormKeeper.appendChild(oForm);

			if( 0 ==  el.childNodes.length )
			{
				el.appendChild(oFormKeeper);
			}

			if(el.style.display == 'none')
			{
				el.style.display = 'block'
			}
			else
			{
				el.style.display = 'none'
			}
		}


		function showBlockPic( sTarget, sUrlThumb, sUrlPic )
		{

			var target = document.getElementById( sTarget );
			/*target.src = sUrlThumb;*/
			target.style.backgroundImage = 'url('+sUrlThumb+')';
			target.onclick = function(){
				window.open( sUrlPic, null, 'height=600,width=600,status=yes,toolbar=no,menubar=no,location=no');
			}

		}

	</script>
	<h1 style="margin-bottom:5px; padding-bottom:5px;"><?= $data['Post']['Title'] ?></h1>
	<div id="breadcrumb">
		<?
			echo anchor( '', $this->lang->line('home') );
			foreach( $data['Post']['BreadCrambList'] as $iId => $aValue )
			{
				echo '<span class="divider"> ' . $this->config->item('breadcrumb_divider') . ' </span>';
				echo '<span> ' . anchor( $this->config->item('uri_category') . $aValue['BaseName'], $aValue['Title'] ) . ' </span>';
			}
		?>
	</div>

	<div class="">

			<div class="infobox">
					<div class="clearBoth"></div>
					<div class="floatLeft">
						&nbsp;
						<div>
							<span><?= $this->lang->line('views') ?>:</span>
							<span><b><?= $data['Post']['View'] ?></b></span>
						</div>
						<div style="margin-top:10px;">
							<span><?= $this->lang->line('points') ?></span>
							<span><a href="javascript:void(0);" class="autorate" onClick="javascript: initRateUpdate( event, '<?= site_url('async/rate_post/' . $data['Post']['Id'] . '/down'); ?>' ); return false;" >-1</a></span>
							&nbsp;|&nbsp;<b>
							<span id="rateValue"><?= $data['Post']['Rate'] ?></span>
							</b>&nbsp;|&nbsp;
							<span><a href="javascript:void(0);" class="autorate" onClick="javascript: initRateUpdate( event, '<?= site_url('async/rate_post/' . $data['Post']['Id'] . '/up'); ?>' ); return false;" >+1</a></span>
						</div>
					</div>
					<div class="floatRight">
						<img src="<?= $this->config->item('design_pic_url') ?>spacer.gif" style="background-image:url('<?= $data['User']['iconUrl'] ?>'); width:<?= $this->config->item('user_icon_width') ?>px; height:<?= $this->config->item('user_icon_height') ?>px; float:left; margin:0px 10px 0px 0px;" alt="" />
						<div><?= anchor( 'user/profile/' . $data['User']['Name'], ( '0' == $data['User']['Name'] ? 'guest' : $data['User']['Name'] ) ) ?></div>
						<div style="margin-top:10px;">
							<?= anchor('mailbox/compose/' . $data['User']['Id'], $this->lang->line('author_contact') ); ?>
						</div>
					</div>
					<div class="clearBoth"></div>
			</div>


		<div class="toolBar">
			<? if ( $data['User']['Owner'] ): ?>
				<span style="padding-right: 20px;"><?= anchor( 'post/remove/' . $data['Post']['Id'], $this->lang->line('delete_post'), array( 'onclick' => 'return confirm(\'' . $this->lang->line('delete_confirmation') . '\');') ); ?></span>
				<span><?= anchor( 'post/edit/' . $data['Post']['Id'], $this->lang->line('edit_post') ); ?></span>
			<? endif; ?>
		</div>

		<div class="">
			<?
								if ( isset($data['Post']['Images']) )
								{
									if ( 'slideshow' == $data['Post']['PicArrange'] )
									{
											echo '<div class="postImageBlock" style="width:' . $this->config->item('post_thumb_width') . 'px;">
													<img src="' . $this->config->item('design_pic_url') . 'spacer.gif" id="BlockThumbPic" style="width:' . $this->config->item('post_thumb_width')  . 'px; height:' . $this->config->item('post_thumb_height') . 'px; margin-bottom:5px;" alt="" title="' . $this->lang->line('click_to_enlage') . '" onmouseover="this.className=\'imageBorderHover\';" onmouseout="this.className=\'imageBorder\';"  class="imageBorder" />
														';

											echo '<script type="text/javascript">showBlockPic( "BlockThumbPic", "' . $data['Post']['Images'][0]['UrlThumb'] . '", "' . $data['Post']['Images'][0]['UrlPic'] . '");</script>';

											echo    '<div class="postIcondBlock">';

													foreach( $data['Post']['Images'] as $aImage )
													{
														echo '<img src="' . $this->config->item('design_pic_url') . 'spacer.gif" title="" alt="thumb" onclick="javascript: showBlockPic( \'BlockThumbPic\', \'' . $aImage['UrlThumb'] . '\', \'' . $aImage['UrlPic'] . '\');" style="width:' . $this->config->item('post_icon_width')  . 'px; height:' . $this->config->item('post_icon_height') . 'px; background-image:url(' . $aImage['UrlIcon'] . ');" onmouseover="this.className=\'imageBorderHover\';" '.($aImage['Description']?'onMouseMove="javascript: showTitle(event,\''.str_replace("'","\'",$aImage['Description']).'\');"':'').' onmouseout="this.className=\'imageBorder\';hideTitle();"  class="imageBorder" />';
													}

											echo    '</div>';

											echo     '</div>';
									}
									else
									{
										foreach( $data['Post']['Images'] as $aImage )
										{
											echo '<div class="postImageColumn" '.($aImage['Description']?'onMouseMove="javascript: showTitle(event,\''.str_replace("'","\'",$aImage['Description']).'\');"':'').' onMouseOut="javascript: hideTitle();">
													<img src="' . $this->config->item('design_pic_url') . 'spacer.gif" title="" border="0" alt="thumb" onClick="javascript: var bigPic=window.open(\'' . $aImage['UrlPic'] . '\', null, \'height=600,width=600,status=yes,resizable=yes,toolbar=no,menubar=no,location=no\'); bigPic.focus();" style="width:' . $this->config->item('post_thumb_width') . 'px; height:' . $this->config->item('post_thumb_height') . 'px; background-image:url(' . $aImage['UrlThumb'] . ');" onmouseover="this.className=\'imageBorderHover\';" onmouseout="this.className=\'imageBorder\';"  class="imageBorder" />
												</div>';
										}
									}

								}
			?>
			<?= $data['Post']['Body'] ?>
			
			<!-- custom fields -->
			<? foreach( $data['CustomFields'] as $aField )
				{
					$this->load->view($this->aSystemVar['template_viewer_root'].'design_items/custom_v_'.$aField['FieldType'],$aField);
				}
			?>
			
		</div>
	</div>

			<div class="clearBoth"></div>

			<div class="postTitle" style="font-size:12px; margin-top:20px">
				<div class="clearBoth"></div>
				<? if ( !empty($data['PrevPost']['Id']) ) : ?>
					<div style="float:left;">
						<?=anchor($this->config->item('uri_post').$data['PrevPost']['Id'], '&#139;&#139; ' . $data['PrevPost']['Title'])?>
					</div>
				<? endif; ?>
				<? if ( !empty($data['NextPost']['Id']) ) : ?>
					<div style="float:right;">
						<?=anchor($this->config->item('uri_post').$data['NextPost']['Id'], $data['NextPost']['Title'] . ' &#155;&#155;')?>
					</div>
				<? endif; ?>
				<div class="clearBoth"></div>
			</div>


    <div id="commentsBlock">
		<h3><?=$this->lang->line('comments')?>:<a href="javascript:void(0);" onclick="innerForm('0');"><?= $this->lang->line('add_comment'); ?></a></h3>
		<? if( !empty( $data['comment_message'] ) ): ?>
			<div id="comMes" style="display:block;">
				<?= $data['comment_message'] ?>
				<?= $this->validation->error_string; ?>
			</div>
			<script type="text/javascript">
				setTimeout("hideBlock('comMes')", <?=(4*1000)?>);
			</script>
		<? endif; ?>

		<div class="link">

		</div>
		<div id="container_0" style="display:none;"></div>
		<div class="clearBoth"></div>
		<div>
			<?
				if( ! empty($data['Comment']['CommentList']) ):
				$i=0;
				foreach($data['Comment']['CommentList'] as $aComment):
					if( ($i%2) == 0 ):
						$sClassName = 'even';
					else:
						$sClassName = 'odd';
					endif;

					if( empty($aComment['IconUrl']) ):
						$iconUrl = base_url() . $this->config->item('design_icon_url') . $this->config->item('user_no_icon');
					else:
						$iconUrl = $aComment['IconUrl'];
					endif;

			?>

					<div class="comment <?= $sClassName; ?>" style="margin-left:<?= ($aComment['Sublevel']*25) ?>px;">
						<div class="clearBoth"></div>
						<div class="floatLeft textCenter"><img src="<?= $iconUrl ?>" alt="<?= $aComment['Name'] ?>" title="<?= $aComment['Name'] ?>" /></div>
						<div class="floatRight">
							<a href="javascript:void(0);" onclick="innerForm('<?= $aComment['Id']; ?>'); return false;"><?= $this->lang->line('reply') ?></a>
						</div>
						<? if( empty($aComment['UserId']) ): ?>
							<?= $aComment['Name'] ?><span class="info"><?= $aComment['commentTime']; ?></span><br />
						<? else: ?>
							<?=  anchor('user/profile/' . $aComment['Name'], $aComment['Name']); ?><span class="info"><?= $aComment['commentTime']; ?></span><br />
						<? endif;?>
						<?= $aComment['Body']; ?>

						<div class="clearBoth"></div>
					</div>
					<div id="container_<?= $aComment['Id']; ?>" style="display:none;"></div>
			<?
					$i++;
				endforeach;
				else:
			?>
				<div class="advice">
					<?=$this->lang->line('no_comm_yet')?>
				</div>
			<?
				endif;
			?>
		</div>
	</div>




<? $this->load->view( $this->aSystemVar['template_viewer_root'] . '_footer') ?>