/**
 * Displays when user views a page and does not have the proper permissions
 *
 * @since 1.2
 */
function rolo_permission_message()
{
    ?>
		<li id="entry-0" class="<?php 
    rolopress_entry_class();
    ?>
 no-permission">
			<?php 
    rolopress_before_entry();
    // Before entry hook
    ?>
				<div class="entry-main">
					<p><?php 
    _e('Sorry, you don\'t have permission to view this page.', 'rolopress');
    ?>
</p>
				</div><!-- .entry-main -->
			<?php 
    rolopress_after_entry();
    // After entry hook
    ?>
		</li><!-- #entry-0 -->
<?php 
}
/**
 * RoloPress master loop
 *
 * Currently handles most situations
 *
 * @since 1.2
 */
function rolo_loop()
{
    if (!is_single()) {
        // This class is not needed on single pages
        ?>
	<ul class="item-list">
<?php 
    }
    if (have_posts()) {
        while (have_posts()) {
            the_post();
            ?>

		<li id="entry-<?php 
            the_ID();
            ?>
" class="<?php 
            rolopress_entry_class();
            ?>
">
		
			<?php 
            rolopress_before_entry();
            // Before entry hook
            ?>

				<div class="entry-main group">
				<?php 
            if (is_archive() || is_home()) {
                if (rolo_type_is('contact')) {
                    rolo_contact_header(get_the_ID());
                }
                if (rolo_type_is('company')) {
                    rolo_company_header(get_the_ID());
                }
                ?>
					<?php 
            } elseif (is_single()) {
                if (rolo_type_is('contact')) {
                    rolo_contact_header(get_the_ID());
                    the_content();
                    if (is_active_sidebar("contact-under-main")) {
                        ?>
											<div class="widget-area contact-under-main">
											<?php 
                        dynamic_sidebar("contact-under-main");
                        ?>
											</div> 
										<?php 
                    }
                }
                if (rolo_type_is('company')) {
                    rolo_company_header(get_the_ID());
                    the_content();
                    if (is_active_sidebar("company-under-main")) {
                        ?>
											<div class="widget-area company-under-main">
											<?php 
                        dynamic_sidebar("company-under-main");
                        ?>
											</div> 
										<?php 
                    }
                }
            } elseif (is_search()) {
                ?>
							<?php 
                if (rolo_type_is('contact')) {
                    rolo_contact_header(get_the_ID());
                } elseif (rolo_type_is('company')) {
                    rolo_company_header(get_the_ID());
                } else {
                    ?>
											<li id="entry-<?php 
                    echo basename(get_permalink());
                    ?>
" class="entry-header">
												<?php 
                    echo '<img class="entry-icon" src=' . ROLOPRESS_IMAGES . '/icons/rolo-default.jpg />';
                    ?>
												<a class="entry-title" href="<?php 
                    the_permalink();
                    ?>
" rel="bookmark"><?php 
                    the_title();
                    ?>
</a>
											</li>
								<?php 
                }
            } elseif (is_page()) {
                the_content();
                // show the page content
                if (is_page_template('widgets.php') || is_page_template('widgets-no-sidebar.php')) {
                    // is this a widget page
                    if (is_active_sidebar("widget-page")) {
                        // is the widget area active
                        ?>
										<div class="widget-area">
										<ul class="xoxo">
										<?php 
                        dynamic_sidebar("widget-page");
                        ?>
										</ul> 
										</div><!-- #widget-area -->	
										<?php 
                    } else {
                        rolo_add_some_widgets_message();
                        // if not, show a message
                    }
                }
            } else {
                ?>
								<li id="entry-<?php 
                echo basename(get_permalink());
                ?>
" class="entry-header">
									<?php 
                echo '<img class="entry-icon" src=' . ROLOPRESS_IMAGES . '/icons/rolo-default.jpg />';
                ?>
									<a class="entry-title" href="<?php 
                the_permalink();
                ?>
" rel="bookmark"><?php 
                the_title();
                ?>
</a>
								</li>
					
					<?php 
            }
            ?>
					
				</div><!-- .entry-main -->
					
				<?php 
            rolo_entry_footer();
            ?>

				<?php 
            rolopress_after_entry();
            // After entry hook
            ?>
				
		</li><!-- #entry-<?php 
            the_ID();
            ?>
 -->
<?php 
        }
        ?>

<?php 
        if (!is_single()) {
            // not needed on single pages
            ?>
	</ul><!-- item-list-->
<?php 
        }
        ?>


<?php 
    } else {
        // 404 or no search results
        ?>

		<li id="entry-0" class="<?php 
        rolopress_entry_class();
        ?>
">
			<?php 
        rolopress_before_entry();
        // Before entry hook
        ?>
				<div class="entry-main">
				
					<?php 
        // on inital setup if no contacts or companies are created then
        // the menu items produce a 404
        // This will provide instructions on how to fix
        $referring_page = $_SERVER['REQUEST_URI'];
        if ($referring_page == "/type") {
            rolo_type_tax_message();
        } else {
            rolo_404_message();
        }
        ?>
					
				</div><!-- .entry-main -->
			<?php 
        rolopress_after_entry();
        // After entry hook
        ?>
		</li><!-- #entry-0 -->

<?php 
    }
}
					<div class="entry-main group">
					
					<?php 
        if (rolo_type_is('contact')) {
            rolo_contact_header(get_the_ID());
        }
        ?>
					
					</div><!-- .entry-main -->

					<?php 
        rolo_entry_footer();
        ?>

					<?php 
        rolopress_after_entry();
        // After entry hook
        ?>
					
					</li><!-- #entry-<?php 
        the_ID();
        ?>
 -->

					<?php 
    }
}
?>
	
				</ul><!-- item-list-->
/**
 * RoloPress master loop
 *
 * Currently handles most situations
 *
 * @since 1.2
 */
function rolo_loop()
{
    if (!is_single()) {
        // This class is not needed on single pages
        ?>
<!-- 	<ul class="item-list">  -->
<?php 
    }
    if (have_posts()) {
        while (have_posts()) {
            the_post();
            ?>

	<?php 
            $current_user_id = get_current_user_id();
            global $post;
            $author_id = $post->post_author;
            $skype_status = '';
            if ($current_user_id != $author_id) {
                continue;
            }
            $thumbid = get_post_thumbnail_id($post->ID);
            $frame_number = get_post_meta($post->ID, 'rolo_contact_framename', true);
            $thumb = wp_get_attachment_image_src($thumbid, $frame_number);
            // <------- NAO ESTA A FUNCIONAR
            $srcimage = $thumb[0];
            if (isset($srcimage)) {
                $style = "background:url(" . $srcimage . ") no-repeat;";
            } else {
                $style = "background: transparent no-repeat";
            }
            $link = get_permalink();
            global $_wp_additional_image_sizes;
            $w = $_wp_additional_image_sizes['frame' . $frame_number]['width'];
            $h = $_wp_additional_image_sizes['frame' . $frame_number]['height'];
            if (rolo_type_is('contact')) {
                $contact = get_post_meta($post->ID, 'rolo_contact', true);
                if (isset($contact['rolo_contact_phone'])) {
                    $skype_name = $contact['rolo_contact_phone'];
                    $link_skype = "skype:" . $skype_name . " ?call";
                }
                $importance = get_post_meta($post->ID, 'rolo_contact_importance', true);
            }
            if (is_archive() || is_home()) {
                ?>
		
		<div id="contact-list">		
			<div class="photo" id="<?php 
                echo $frame_number;
                ?>
">			
				<a href="<?php 
                echo $link;
                ?>
">
				<span class="<?php 
                echo $frame_number;
                ?>
" style="background: url('') no-repeat;">
				
				<?php 
                the_post_thumbnail($frame_number, array('alt' => $skype_name, 'title' => get_the_title()));
                // AQUI É ONDE É POSTA A FOTO
                ?>
				
				</span>
				</a>
				    <img src="<?php 
                echo get_bloginfo('template_url') . '/library/images/frames/' . $frame_number . '.png';
                ?>
" alt="">		
			 	<!-- 	<div id="title"> 	 -->
					<?php 
                //the_title();
                ?>
		  		 <!-- </div>  --> 
		  		
			</div>
		</div>	<!-- close div contact -->
		
			<?php 
                continue;
            }
            if (is_single()) {
                if (rolo_type_is('contact')) {
                    if (!empty($skype_name)) {
                        $skype_status = getSkypeStatus($skype_name);
                    }
                    ?>
 
			<h2 class="page-title"><?php 
                    the_title();
                    ?>
</h2>
				<div id="contact-single" > 
				
				<div class="left">
				
 				<div style="float:right;">
				
				<div class="photo" id="<?php 
                    echo $frame_number;
                    ?>
">
					<a href="<?php 
                    echo $link_skype;
                    ?>
">
					<span class="<?php 
                    echo $frame_number . ' ';
                    ?>
" style="background: url('') no-repeat;">
						<?php 
                    the_post_thumbnail($frame_number, array("alt" => $skype_name, 'title' => get_the_title()));
                    // AQUI É ONDE É POSTA A FOTO
                    ?>
					</span>
					</a>
						<img src="<?php 
                    echo get_bloginfo('template_url') . '/library/images/frames/' . $frame_number . '.png';
                    ?>
" alt="">		
				</div>	
				</div>
				</div>
				
				<?php 
                    if (isset($contact['rolo_contact_phone'])) {
                        ?>
					<div class="right">
					
					
					<div class="address">
						<?php 
                        $contact = get_post_meta($post->ID, 'rolo_contact');
                        $contact = $contact[0];
                        $address = $contact['rolo_contact_address'];
                        $city = rolo_get_term_list($contact_id, 'city');
                        $state = rolo_get_term_list($contact_id, 'state');
                        $zip = rolo_get_term_list($contact_id, 'zip');
                        $country = rolo_get_term_list($contact_id, 'country');
                        $city = $city == '' ? '' : $city;
                        //   $state = ($state == '') ? 'State' : $state;
                        $zip = $zip == '' ? '' : $zip;
                        $country = $country == '' ? '' : $country;
                        if (isset($address) && ($address != '' || $zip . $city . $country != '')) {
                            echo "Morada:<br/>";
                            echo $address . ' ' . $zip . ' ' . $city . ' ' . $country;
                        }
                        ?>
					
					</div>
						
					</div>	
				<?php 
                    }
                    the_content();
                }
                rolo_entry_footer();
            } elseif (is_search()) {
                ?>
			
			<div id="contact-list">		
			<div class="photo" id="<?php 
                echo 'frame' . $frame_number;
                ?>
">
				<a href="<?php 
                echo $link;
                ?>
">
				<span class="<?php 
                echo $frame_number;
                ?>
" style="background: url('') no-repeat;">
				
				<?php 
                the_post_thumbnail($frame_number);
                // AQUI É ONDE É POSTA A FOTO
                ?>
				
				</span>
				</a>
				    <img src="<?php 
                echo get_bloginfo('template_url') . '/library/images/frames/' . $frame_number . '.png';
                ?>
" alt="">		
				
			</div>
		</div>	<!-- close div contact -->
			
			<?php 
            } elseif (is_page()) {
                ?>
<div id="contact"><?php 
                the_content();
                // show the page content
                if (is_page_template('widgets.php') || is_page_template('widgets-no-sidebar.php')) {
                    // is this a widget page
                    if (is_active_sidebar("widget-page")) {
                        // is the widget area active
                        ?>
						<div class="widget-area">
						<ul class="xoxo">
				<?php 
                        dynamic_sidebar("widget-page");
                        ?>
						</ul> 
						</div><!-- #widget-area -->	
						<?php 
                    } else {
                        rolo_add_some_widgets_message();
                        // if not, show a message
                    }
                }
            } else {
                ?>
 
					<div id="contact">
						<li id="entry-<?php 
                echo basename(get_permalink());
                ?>
" class="entry-header">
							<?php 
                echo '<img class="entry-icon" src=' . ROLOPRESS_IMAGES . '/icons/rolo-default.jpg />';
                ?>
							<a class="entry-title" href="<?php 
                the_permalink();
                ?>
" rel="bookmark"><?php 
                the_title();
                ?>
</a>
						</li>				
					<?php 
            }
            ?>
					
			<!-- 	</div> --><!-- .entry-main -->
					
			

				<?php 
            rolopress_after_entry();
            // After entry hook
            ?>
				
		</div><!-- #entry-<?php 
            the_ID();
            ?>
 -->
<?php 
        }
        ?>

<?php 
        if (!is_single()) {
            // not needed on single pages
            ?>
<!-- 	</ul> --><!-- item-list-->
<?php 
        }
        ?>


<?php 
    } else {
        // 404 or no search results
        ?>

		<li id="entry-0" class="<?php 
        rolopress_entry_class();
        ?>
">
			<?php 
        rolopress_before_entry();
        // Before entry hook
        ?>
				<div class="entry-main">
				
					<?php 
        // on inital setup if no contacts or companies are created then
        // the menu items produce a 404
        // This will provide instructions on how to fix
        $referring_page = $_SERVER['REQUEST_URI'];
        if ($referring_page == "/type") {
            rolo_type_tax_message();
        } else {
            //rolo_404_message();
        }
        ?>
					
				</div><!-- .entry-main -->
			<?php 
        rolopress_after_entry();
        // After entry hook
        ?>
		</li><!-- #entry-0 -->

<?php 
    }
}