<?php
/**
 * The main template file.
 *
 * @package WordPress
 */

function cleanSource ($src) {
	return str_replace ('http://localhost/lqdvi', '', $src);
}

$pp_slider_sort = get_option('pp_slider_sort');
if(empty($pp_slider_sort))
{
	$pp_slider_sort = 'ASC';
}

$pp_slider_items = get_option('pp_slider_items');
if(empty($pp_slider_items))
{
	$pp_slider_items = 60;
}

$pp_slider_img_width = get_option('pp_slider_img_width');
if(empty($pp_slider_img_width))
{
	$pp_slider_img_width = 240;
}

$pp_slider_img_height = get_option('pp_slider_img_height');
if(empty($pp_slider_img_height))
{
	$pp_slider_img_height = 160;
}

$pp_slider_rows = get_option('pp_slider_rows');
if(empty($pp_slider_rows))
{
	$pp_slider_rows = 3;
}

$pp_slider_opacity = get_option('pp_slider_opacity');
if(empty($pp_slider_opacity))
{
	$pp_slider_opacity = 40;
}

$pp_homepage_auto_scroll = get_option('pp_homepage_auto_scroll');

$args = array(
	'numberposts' => $pp_slider_items,
	'order' => $pp_slider_sort,
	'orderby' => 'date',
	'post_type' => 'slides',
);

$all_photo_arr = get_posts($args);

			
get_header(); ?>
	
		
            <?php
                            $pp_gallery_width = $pp_slider_img_width;
                            $pp_gallery_height = $pp_slider_img_height;
            ?>

            <!-- Begin content -->
            <div id="slider_loading" style="height:<?php echo ($pp_gallery_height*$pp_slider_rows); ?>px"></div>

            <div id="content_wrapper" class="lqdvi" style="height:<?php echo ($pp_gallery_height*$pp_slider_rows); ?>px">

                    <div class="inner">

                            <input type="hidden" id="gallery_width" name="gallery_width" value="<?php echo $pp_slider_img_width; ?>"/>
                            <input type="hidden" id="slider_rows" name="slider_rows" value="<?php echo $pp_slider_rows; ?>"/>
                            <input type="hidden" id="img_opacity" name="img_opacity" value="<?php echo $pp_slider_opacity/100; ?>"/>
                            <input type="hidden" id="pp_gallery_auto_scroll" name="pp_gallery_auto_scroll" value="<?php echo $pp_homepage_auto_scroll; ?>"/>

		<?php
			if(!empty($all_photo_arr))
			{
		?>
				<?php
					$count_row = 0;
                                        
					foreach($all_photo_arr as $key => $photo)
					{       
                                                $title = $photo->post_title;
                                                $content = $photo->post_content;
						$small_image_url = get_bloginfo( 'stylesheet_directory' ).'/images/000_70.png';
						
						$slide_link_to = get_post_meta($photo->ID, 'slide_link_to', true);
						
						if(has_post_thumbnail($photo->ID, 'large'))
						{
                                                        
                                                        
							$image_id = get_post_thumbnail_id($photo->ID);
							$image_url = wp_get_attachment_image_src($image_id, 'large', true);
                                                        //$image_url[0] = cleanSource($image_url[0]);
						
							$small_image_url = get_bloginfo( 'stylesheet_directory' ).'/timthumb.php?src='.cleanSource($image_url[0]).'&amp;h='.$pp_gallery_height.'&amp;w='.$pp_gallery_width.'&amp;zc=1';
							
							if(!empty($slide_link_to) && $slide_link_to != 'Image')
							{
								$hyperlink_url = get_post_meta($photo->ID, 'gallery_link_url', true);
							}
							else
							{
								$hyperlink_url = $image_url[0];
							}
							
						}
				?>
				
				<?php 
					if(empty($count_row))
					{
				?>
					<div style="float:left">
				<?php
					}
					
					$count_row++;
				?>
				<div class="card" style="width:<?php echo intval($pp_gallery_width); ?>px;height:<?php echo intval($pp_gallery_height); ?>px;margin:0px;">
					<?php 
    					if(!empty($small_image_url))
    					{
    				?>		
                                    <a rel="group" title="" href="<?php echo $hyperlink_url; ?>" <?php if(empty($slide_link_to) OR $slide_link_to == 'Image'){ echo 'class="img_link"'; }?>>
								<img src="<?php echo $small_image_url; ?>" alt="" style="width:<?php echo intval($pp_gallery_width); ?>px;height:<?php echo intval($pp_gallery_height); ?>px;" class="fade"/>
							</a>
					<?php
    					}		
    				?>			
					
				</div>
				
				<?php 
					if(($count_row)%$pp_slider_rows==0 OR !isset($all_photo_arr[$key+1]))
					{
						$count_row = 0;
				?>
					</div>
				<?php
					}
				?>
				
				<?php
					}	
				?>
                        <?php
                                }
                        ?>			
			</div>
			
			<div id="move_prev"></div>
			<div id="move_next"></div>
			
			<br class="clear"/>
		</div>
		<!-- End content -->
		

		
		<div id="content_slider_wrapper"><div id="content_slider"></div></div>
		
		<?php 
			$pp_homepage_hide_welcome = get_option('pp_homepage_hide_welcome');
			
			if(!empty($pp_homepage_hide_welcome))
			{
				$pp_homepage_welcome_title = get_option('pp_homepage_welcome_title');
				if(empty($pp_homepage_welcome_title))
				{
					$pp_homepage_welcome_title = 'Welcome...';
				}
				
				$pp_homepage_welcome_desc = get_option('pp_homepage_welcome_desc');
				if(empty($pp_homepage_welcome_desc))
				{
					$pp_homepage_welcome_desc = 'with extensive admin panel, customize every parts of the theme so what are you waiting for?';
				}

				$pp_homepage_welcome_url = get_option('pp_homepage_welcome_url');
                ?>
		
			<div id="welcome_msg">
                            <a href="<?php echo $pp_homepage_welcome_url; ?>">
				<h1 class="cufon"><?php _e($pp_homepage_welcome_title); ?></h1>
				<p><?php echo _e($pp_homepage_welcome_desc); ?></p></a>
			</div>
		
		<?php
			}
		?>
		
                <?php /*
		<div class="content_bg">
			<div class="standard_wrapper">
			
				$pp_home_left_content = get_option('pp_home_left_content');
				$pp_home_right_content = get_option('pp_home_right_content');
			
		
			<br class="clear"/><br/><br/>
			
			<div class="two_third">
				<?php echo html_entity_decode(stripslashes($pp_home_left_content)); ?>
			</div>
			
			<div class="one_third last">
				<?php echo html_entity_decode(stripslashes($pp_home_right_content)); ?>
			</div>
			
			<br class="clear"/><br/><br/><br/><br/>
			</div>
		</div>
                */ ?>
		

<?php get_footer(); ?>