<?php
/* Template Name: Colaboradores */

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

if (!isset($hide_header) OR !$hide_header) {
    get_header();
}

$pp_webcam_url = get_option('pp_webcam_url');

$pp_capturas_style = get_option('pp_capturas_style');

if (empty($pp_capturas_style)) {
    $pp_capturas_style = '1';
}

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

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



if (!isset($hide_header) OR !$hide_header) {
    get_header();
}

$caption_class = "page_caption";
$portfolio_sets_query = '';

/**
 * 	Get Current page object
 * */
$page = get_page($post->ID);

/**
 * 	Get current page id
 * */
if (!isset($current_page_id) && isset($page->ID)) {
    $current_page_id = $page->ID;
}

$caption_style = get_post_meta($current_page_id, 'caption_style', true);

if (empty($caption_style)) {
    $caption_style = 'Title & Description';
}

if (!isset($hide_header) OR !$hide_header) {
    ?>				
    <div class="<?php echo $caption_class ?> capturas">
        <div class="caption_inner">
    <?php
    $page_desc = get_post_meta($current_page_id, 'page_desc', true);

    switch ($caption_style) {
        case 'Description Only':

            if (!empty($page_desc)) {
                ?>

                        <div class="caption_header">
                            <h2 class="cufon"><?php echo $page_desc; ?></h2>
                        </div>
                        <?php
                    }
                    break;

                case 'Title Only':
                    ?>
                    <div class="caption_header">
                        <h1 class="cufon"><?php _(the_title()); ?></h1>
                    </div>
            <?php
            break;

        case 'Title & Description':
            ?>
                    <div class="caption_header">
                        <h1 class="cufon"><?php _(the_title()); ?></h1>
                    </div>
                    <div class="caption_desc">
                        <a href="<?php echo $pp_webcam_url; ?>"><?php _e($page_desc); ?></a>
                    </div>
                    <?php
                    break;
            }
            ?>

            <br class="clear"/>

        </div>
    </div>

    <!-- Begin content -->
    <div id="content_wrapper" class="content_bg">

        <div class="inner">

            <!-- Begin main content -->
            <div class="inner_wrapper capturas"><br class="clear"/>

    <?php
} else {
    echo '<br class="clear"/>';
}
?>	

            <!-- Begin portfolio content -->

<?php
$menu_sets_query = '';

$captura_items = get_option('pp_capturas_items');
if (empty($captura_items)) {
    $captura_items = 12;
}

$captura_sort = get_option('pp_capturas_sort');
if (empty($captura_sort)) {
    $captura_sort = 'DESC';
}

//prepare data for pagination
$offset_query = '';
if (!isset($_GET['page']) OR empty($_GET['page']) OR $_GET['page'] == 1) {
    $current_page = 1;
} else {
    $current_page = $_GET['page'];
    $offset = (($current_page - 1) * $captura_items);
}

$args = array(
    'numberposts' => $captura_items,
    'order' => $captura_sort,
    'orderby' => 'date',
    'post_type' => array('capturas'),
    'offset' => $offset,
);

$page_photo_arr = get_posts($args);


//Get all portfolio items for paging

$args = array(
    'numberposts' => -1,
    'order' => $captura_sort,
    'orderby' => 'date',
    'post_type' => array('capturas'),
);

$all_photo_arr = get_posts($args);
$total = count($all_photo_arr);

if (isset($page_photo_arr) && !empty($page_photo_arr)) {
    ?>

                <?php
                foreach ($page_photo_arr as $key => $captura_item) {

                    $image_url = '';

                    if (has_post_thumbnail($captura_item->ID, 'large')) {
                        $image_id = get_post_thumbnail_id($captura_item->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_capturas_img_height . '&amp;w=' . $pp_capturas_img_width . '&amp;zc=1';

                        $permalink_url = get_permalink($captura_item->ID);
                        
                        $titulo = _($captura_item->post_title);
                        $texto = pp_substr(strip_tags(strip_shortcodes($captura_item->post_content)), 50);                                                
                        
                        if ($texto != "") {
                            $texto =  "&#013;" . $texto;
                        }
                        

                        $last_class = '';
                        $line_break = '';
                        if (($key + 1) % $captura_items == 0) {
                            $last_class = ' last';

                            if (isset($page_photo_arr[$key + 1])) {
                                $line_break = '<br class="clear"/><br/><br/><br/>';
                            } else {
                                $line_break = '<br class="clear"/>';
                            }
                        }
                        ?>
                        <div class="<?php echo $last_class ?> captura" style="height: <?php echo $pp_capturas_img_height;?>px; width: <?php echo $pp_capturas_img_width;?>px;">
                            <img src="<?php echo $small_image_url; ?>" title="<?php echo $titulo.$texto; ?>" class="fade"/>
                        </div>
                        <?php
                    }
                    ?>

                    <?php
                    echo $line_break;
                }
                //End foreach loop
                ?>

                <?php
                $base_link = get_permalink($post->ID);

                echo gen_pagination($total, $current_page, $base_link, TRUE, $captura_items);
            }
            //End if have portfolio items
            ?>


        </div>
        <!-- End main content -->

        <br class="clear"/><br/><br/>

    </div>

            <?php
            if (!isset($hide_header) OR !$hide_header) {
                ?>				

    </div>
    <!-- End content -->


                <?php get_footer(); ?>
                <?php
            }
            ?>