$callout_button = get_option_tree('callout_button', $theme_options);
    $callout_button_url = get_option_tree('callout_button_url', $theme_options);
}
?>

        <?php 
$select_type = get_post_meta($post->ID, 'select-type_value', true);
?>
        <?php 
$layer_slider = get_post_meta($post->ID, 'layer-slider_value', true);
?>
        <?php 
$uno_slider = get_post_meta($post->ID, 'uno-slider_value', true);
?>
        <?php 
$video = theme_parse_video(get_post_meta($post->ID, 'video_value', true));
?>
            
        <?php 
if ($select_type == 'layerslider') {
    ?>
		<div id="slider"><?php 
    echo do_shortcode('[layerslider id="' . $layer_slider . '"]');
    ?>
</div>
        <?php 
} elseif ($select_type == 'unoslider') {
    ?>
        <div id="slider"><?php 
    echo unoslider($uno_slider);
    ?>
            			<?php 
$videoURL = theme_parse_video(get_post_meta($post->ID, 'video-url_value', true));
?>
                        <?php 
$linkURL = get_post_meta($post->ID, 'link-url_value', true);
?>
                        
                        <div class="post
                        <?php 
if (function_exists('has_post_thumbnail') && has_post_thumbnail()) {
    ?>
                        <?php 
} elseif ($videoURL) {
    ?>
                        <?php 
} else {
    ?>
                        no-img
                        <?php 
}
?>
                        ">
                            <?php 
if (function_exists('has_post_thumbnail') && has_post_thumbnail()) {
    ?>
                            <div class="frame"><img class="overlay-item-link" src="<?php 
    $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'blog');
    echo $image[0];
    ?>
" width="692"  height="262" alt="<?php 
    _e('Read More', GETTEXT_DOMAIN);
    function widget($args, $instance)
    {
        extract($args);
        global $wpdb;
        $title = apply_filters('widget_title', $instance['title']);
        /* variables from the widget settings. */
        $left_col = $instance['left_col'];
        /* before widget. */
        echo $before_widget;
        /* display Widget */
        ?>
 
                
                <div class="container latest_news">
            		<div class="four columns">
                        <?php 
        $posts_page_id = get_option('page_for_posts');
        $posts_page_url = get_page_link($posts_page_id);
        ?>
                    
                        <div class=" rt-border">
                            <?php 
        /* display the widget title if one was input (before and after defined by themes). */
        if ($title) {
            echo $before_title . $title . $after_title;
        }
        ?>
                            <div class="i"><?php 
        echo !empty($instance['filter']) ? wpautop($left_col) : $left_col;
        ?>
</div>
                            <a class="small_button" href="<?php 
        echo $posts_page_url;
        ?>
"><?php 
        _e('read more', GETTEXT_DOMAIN);
        ?>
</a></p>
                            <div class="clear"></div>                		      
                        </div>
                    </div>
                    <?php 
        $query = new WP_Query();
        ?>
                    <?php 
        $query->query('posts_per_page=3&ignore_sticky_posts=1');
        ?>
                    <?php 
        if ($query->have_posts()) {
            while ($query->have_posts()) {
                $query->the_post();
                ?>
                    <?php 
                $videoURL = theme_parse_video(get_post_meta(get_the_ID(), 'video-url_value', true));
                ?>
                    <?php 
                $linkURL = get_post_meta(get_the_ID(), 'link-url_value', true);
                ?>
            		<div class="four columns post">
                        <?php 
                if ($linkURL) {
                    ?>
                            <?php 
                    if (function_exists('has_post_thumbnail') && has_post_thumbnail()) {
                        ?>
                            <img class="home-overlay-item" src="<?php 
                        $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), '420x207');
                        echo $image[0];
                        ?>
" width="220" height="108"  alt="<?php 
                        _e('view more', GETTEXT_DOMAIN);
                        ?>
" rel="<?php 
                        echo $linkURL;
                        ?>
"/>
                            <?php 
                    } else {
                        ?>
                            <img class="home-overlay-item" src="<?php 
                        echo THEME_ASSETS;
                        ?>
images/post-format-link.png" width="220" height="108"  alt="<?php 
                        _e('view more', GETTEXT_DOMAIN);
                        ?>
" rel="<?php 
                        echo $linkURL;
                        ?>
"/>
                            <?php 
                    }
                    ?>
                        <?php 
                } elseif (function_exists('has_post_thumbnail') && has_post_thumbnail()) {
                    ?>
                        <img class="home-overlay-item" src="<?php 
                    $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), '420x207');
                    echo $image[0];
                    ?>
" width="220" height="108"  alt="<?php 
                    _e('view more', GETTEXT_DOMAIN);
                    ?>
" rel="<?php 
                    the_permalink();
                    ?>
"/>
                        <?php 
                } elseif ($videoURL) {
                    ?>
                        <div class="vimeoOrYoutube">
                            <iframe width="220" height="108" src="<?php 
                    echo $videoURL;
                    ?>
?rel=0&amp;autohide=1&amp;showinfo=0" frameborder="0" allowfullscreen></iframe>
                        </div>
                        <?php 
                } else {
                    ?>
                        <img class="home-overlay-item" src="<?php 
                    echo THEME_ASSETS;
                    ?>
images/post-format-pencil.png" width="220" height="108"  alt="<?php 
                    _e('view more', GETTEXT_DOMAIN);
                    ?>
" rel="<?php 
                    the_permalink();
                    ?>
"/>
                        <?php 
                }
                ?>
                        <h4>
                            <?php 
                if ($videoURL) {
                    ?>
                            <a href="<?php 
                    echo $videoURL;
                    ?>
"><?php 
                    the_title();
                    ?>
</a>
                            <?php 
                } else {
                    ?>
                            <?php 
                    the_title();
                    ?>
                            <?php 
                }
                ?>
                        </h4>
                        <div class="info">
                            <div class="date">
                                <span class="day"><?php 
                echo get_the_time('j');
                ?>
</span>
                                <span class="month"><?php 
                echo get_the_time('M');
                ?>
</span>
                            </div>
                            <span class="comment"><?php 
                comments_number('0', '1', '%');
                ?>
</span>
                        </div>
                        <p><?php 
                echo excerpt(15);
                ?>
</p>
            		</div>
                    <?php 
            }
        }
        ?>
 
                    <?php 
        wp_reset_query();
        ?>
            	</div><!-- container -->
                <div class="container hr"><hr /></div>
		<?php 
        /* after widget (defined by themes). */
        echo $after_widget;
    }
    function widget($args, $instance)
    {
        extract($args);
        $title = apply_filters('widget_title', $instance['title']);
        /* variables from the widget settings. */
        $num = $instance['num'];
        /* before widget. */
        echo $before_widget;
        /* display Widget */
        ?>
 
        <?php 
        /* display the widget title if one was input (before and after defined by themes). */
        if ($title) {
            echo $before_title . $title . $after_title;
        }
        ?>
                
                <div class="carousel-widget">
        			<ul class="sidebar_list_items">
                        <?php 
        $query = new WP_Query();
        ?>
                        <?php 
        $query->query('post_type=portfolio&posts_per_page=' . $num . '&ignore_sticky_posts=1');
        ?>
                        <?php 
        if ($query->have_posts()) {
            while ($query->have_posts()) {
                $query->the_post();
                ?>
                        <?php 
                $lightbox = get_post_meta(get_the_ID(), 'lightbox_value', true);
                ?>
                        <?php 
                $videoURL = theme_parse_video(get_post_meta(get_the_ID(), 'video-url_value', true));
                ?>
                        <?php 
                $linkURL = get_post_meta(get_the_ID(), 'link-url_value', true);
                ?>
                        <?php 
                $rand = rand(2, 9999);
                ?>
  
                        <li class="itemSidebar">
                        <?php 
                if ($lightbox) {
                    ?>
                            <div class="frame">
                                <a rel="prettyPhoto[pp_gal-widget-<?php 
                    echo $rand;
                    ?>
]" href="<?php 
                    $image = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), 'full');
                    echo $image[0];
                    ?>
">
                                    <img class="sb-overlay-item" src="<?php 
                    $image = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), '412x229');
                    echo $image[0];
                    ?>
" height="118" width="212" alt="<?php 
                    _e('view more', GETTEXT_DOMAIN);
                    ?>
"/>
                                </a>
                            </div>
                            <?php 
                    $thumbnail_id = get_post_thumbnail_id(get_the_ID());
                    ?>
                            <?php 
                    $args = array('numberposts' => 9999, 'offset' => 0, 'post_parent' => get_the_ID(), 'post_type' => 'attachment', 'exclude' => $thumbnail_id, 'nopaging' => false, 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID', 'post_status' => 'any');
                    $attachments =& get_children($args);
                    ?>
                            <?php 
                    foreach ($attachments as $attachment) {
                        $imageTitle = $attachment->post_title;
                        $imageDescription = $attachment->post_content;
                        $imageArrayFull = wp_get_attachment_image_src($attachment->ID, 'full', false);
                        ?>
                                <a class="hide" rel="prettyPhoto[pp_gal-widget-<?php 
                        echo $rand;
                        ?>
]" href="<?php 
                        echo $imageArrayFull[0];
                        ?>
" title="<?php 
                        echo $imageDescription;
                        ?>
"></a>
                            <?php 
                    }
                    ?>
                        <?php 
                } elseif ($linkURL) {
                    ?>
                            <div class="frame"><img class="sb-overlay-item" src="<?php 
                    $image = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), '412x229');
                    echo $image[0];
                    ?>
" height="118" width="212" alt="<?php 
                    _e('view more', GETTEXT_DOMAIN);
                    ?>
" rel="<?php 
                    echo $linkURL;
                    ?>
"/></div>
                        <?php 
                } elseif ($videoURL) {
                    ?>
                            <div class="frame">
                                <div class="vimeoOrYoutube">
                                    <iframe height="118" width="212" src="<?php 
                    echo $videoURL;
                    ?>
?rel=0&amp;autohide=1&amp;showinfo=0" frameborder="0" allowfullscreen></iframe>
                                </div>
                            </div>
                        <?php 
                } elseif (function_exists('has_post_thumbnail') && has_post_thumbnail()) {
                    ?>
                            <div class="frame"><img class="sb-overlay-item" src="<?php 
                    $image = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), '412x229');
                    echo $image[0];
                    ?>
" height="118" width="212" alt="<?php 
                    _e('view more', GETTEXT_DOMAIN);
                    ?>
" rel="<?php 
                    the_permalink();
                    ?>
"/></div>
                        <?php 
                }
                ?>
                        </li>  
                        <?php 
            }
        }
        ?>
 
                        <?php 
        wp_reset_query();
        ?>
     
        			</ul>
                    <div class="pager"></div>
                    <div class="clear"></div>
                </div>

		<?php 
        /* after widget (defined by themes). */
        echo $after_widget;
    }
    function widget($args, $instance)
    {
        extract($args);
        $title = apply_filters('widget_title', $instance['title']);
        /* variables from the widget settings. */
        $num = $instance['num'];
        /* before widget. */
        echo $before_widget;
        /* display Widget */
        ?>
 
        <?php 
        /* display the widget title if one was input (before and after defined by themes). */
        if ($title) {
            echo $before_title . $title . $after_title;
        }
        ?>
                    <div class="post-widget-2">
                        <?php 
        $query = new WP_Query();
        ?>
                        <?php 
        $query->query('posts_per_page=' . $num . '&ignore_sticky_posts=1');
        ?>
                        <?php 
        if ($query->have_posts()) {
            while ($query->have_posts()) {
                $query->the_post();
                ?>
                        <?php 
                $videoURL = theme_parse_video(get_post_meta(get_the_ID(), 'video-url_value', true));
                ?>
                        <?php 
                $linkURL = get_post_meta(get_the_ID(), 'link-url_value', true);
                ?>
                        <div class="post">
                            <a href="
                            <?php 
                if ($linkURL) {
                    ?>
                            <?php 
                    echo $linkURL;
                    ?>
                            <?php 
                } else {
                    ?>
                            <?php 
                    the_permalink();
                    ?>
                            <?php 
                }
                ?>
                            " title="<?php 
                the_title();
                ?>
" class="icon-format
                            <?php 
                if (function_exists('has_post_thumbnail') && has_post_thumbnail()) {
                    ?>
                            gallery
                            <?php 
                } elseif ($linkURL) {
                    ?>
                            link
                            <?php 
                } elseif ($videoURL) {
                    ?>
                            video
                            <?php 
                } else {
                    ?>
                            pencil
                            <?php 
                }
                ?>
                            ">
                            <?php 
                if (function_exists('has_post_thumbnail') && has_post_thumbnail()) {
                    the_post_thumbnail('posts-widget');
                }
                ?>
                            </a>
                            <?php 
                if ($linkURL) {
                    ?>
                            <h5><a href="<?php 
                    echo $linkURL;
                    ?>
"><?php 
                    the_title();
                    ?>
</a></h5>
                            <?php 
                } else {
                    ?>
                            <h5><a href="<?php 
                    the_permalink();
                    ?>
"><?php 
                    the_title();
                    ?>
</a></h5>
                            <?php 
                }
                ?>
                            <div class="icons">
                                <div class="iconWrap">
                                    <div class="icon author tooltip text_replace">
                                        <p class="hoveralls_text"><?php 
                echo get_the_author();
                ?>
</p>
                                        <a href="<?php 
                echo get_author_posts_url(get_the_author_meta('ID'));
                ?>
" class="hoveralls_link"></a>
                                    </div>
                                </div>
                                <div class="iconWrap">
                                    <div class="icon tag tooltip text_replace">
                                        <p class="hoveralls_text"><?php 
                comments_number(__('No Comments', GETTEXT_DOMAIN), __('1 Comment', GETTEXT_DOMAIN), __('% Comments', GETTEXT_DOMAIN));
                ?>
</p>
                                        <a href="<?php 
                comments_link($id);
                ?>
" class="hoveralls_link"></a>
                                    </div>
                                </div>
                                <?php 
                if (get_the_tags()) {
                    ?>
                                <div class="iconWrap">
                                    <div class="icon comment tooltip text_replace">
                                        <p class="hoveralls_text">
                                        <?php 
                    $posttags = get_the_tags();
                    $count = 0;
                    if ($posttags) {
                        foreach ($posttags as $tag) {
                            $count++;
                            if (1 == $count) {
                                echo $tag->name;
                                $tag_id = $tag->term_id;
                            }
                        }
                    }
                    ?>
                                        </p>
                                        <a href="<?php 
                    echo get_tag_link($tag_id);
                    ?>
" class="hoveralls_link"></a>
                                    </div>
                                </div>
                                <?php 
                }
                ?>
                                <div class="clear"></div>
                            </div>
                            <div class="clear"></div>
                        </div>
                        <?php 
            }
        }
        ?>
 
                        <?php 
        wp_reset_query();
        ?>
                    </div>
		
		<?php 
        /* after widget (defined by themes). */
        echo $after_widget;
    }
    function widget($args, $instance)
    {
        extract($args);
        global $wpdb;
        $title = apply_filters('widget_title', $instance['title']);
        /* variables from the widget settings. */
        $left_col = $instance['left_col'];
        $button_url = $instance['button_url'];
        $num = $instance['num'];
        $filter = $instance['filter-cat'];
        $rand = rand(2, 9999);
        /* before widget. */
        echo $before_widget;
        /* display Widget */
        ?>
 
                
                <div class="container work">
            		<div class="four columns">
                        <div class=" rt-border">
                            <?php 
        /* display the widget title if one was input (before and after defined by themes). */
        if ($title) {
            echo $before_title . $title . $after_title;
        }
        ?>
                            <div class="i"><?php 
        echo !empty($instance['filter']) ? wpautop($left_col) : $left_col;
        ?>
</div>
                            <?php 
        if ($button_url) {
            ?>
<a class="small_button" href="<?php 
            echo $button_url;
            ?>
"><?php 
            _e('view more', GETTEXT_DOMAIN);
            ?>
</a><?php 
        }
        ?>
                            <div class="clear"></div>               		      
                        </div>
                    </div>
            		<div class="twelve columns alpha omega">
                        <div class="navi_carousel">
                            <?php 
        $filter_slugs = explode(",", $filter);
        foreach ($filter_slugs as $filter_slug) {
            $filter_id .= $wpdb->get_var("SELECT term_id FROM {$wpdb->terms} WHERE slug='{$filter_slug}'") . ',';
        }
        ?>
                            <ul class="filter_navi filter_navi-<?php 
        echo $rand;
        ?>
">
            					<li><a href="javascript:void(0)" rel="all" title="<?php 
        _e('All Categories', GETTEXT_DOMAIN);
        ?>
"><?php 
        _e('All Categories', GETTEXT_DOMAIN);
        ?>
</a></li>
            					<?php 
        if ($filter) {
            ?>
                                    <?php 
            wp_list_categories(array('title_li' => '', 'taxonomy' => 'portfolio_category', 'include' => $filter_id, 'walker' => new portfolio_filter_walker()));
            ?>
            				    <?php 
        } else {
            ?>
                                    <?php 
            wp_list_categories(array('title_li' => '', 'taxonomy' => 'portfolio_category', 'walker' => new portfolio_filter_walker()));
            ?>
                                <?php 
        }
        ?>
            				</ul>
                            <div class="pager pager-<?php 
        echo $rand;
        ?>
"></div>
                            <div class="clear"></div>
                        </div> 
             			<div class="list_carousel list_carousel-<?php 
        echo $rand;
        ?>
">
            				<ul class="list_items-<?php 
        echo $rand;
        ?>
">
                                <?php 
        $query = new WP_Query();
        ?>
                                <?php 
        if ($filter) {
            ?>
                                    <?php 
            $query->query('post_type=portfolio&portfolio_category=' . $filter . '&posts_per_page=' . $num . '');
            ?>
                                <?php 
        } else {
            ?>
                                    <?php 
            $query->query('post_type=portfolio&posts_per_page=' . $num . '');
            ?>
                                <?php 
        }
        ?>
                                <?php 
        if ($query->have_posts()) {
            while ($query->have_posts()) {
                $query->the_post();
                $terms = get_the_terms(get_the_ID(), 'portfolio_category');
                ?>
                                <?php 
                $lightbox = get_post_meta(get_the_ID(), 'lightbox_value', true);
                ?>
                                <?php 
                $videoURL = theme_parse_video(get_post_meta(get_the_ID(), 'video-url_value', true));
                ?>
                                <?php 
                $linkURL = get_post_meta(get_the_ID(), 'link-url_value', true);
                ?>
                                <?php 
                $rand_pp = rand(2, 9999);
                ?>
                                <li class="four columns item item-<?php 
                echo $rand;
                ?>
 all <?php 
                if ($terms) {
                    foreach ($terms as $term) {
                        echo '' . $term->name . ' ';
                    }
                }
                ?>
">
                                    <?php 
                if ($lightbox) {
                    ?>
                                    <div class="img">
                                        <a rel="prettyPhoto[pp_gal-widget-<?php 
                    echo $rand_pp;
                    ?>
]" href="<?php 
                    $image = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), 'full');
                    echo $image[0];
                    ?>
">
                                            <img class="sb-overlay-item" src="<?php 
                    $image = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), '420x207');
                    echo $image[0];
                    ?>
" width="220" height="108" alt="<?php 
                    _e('view more', GETTEXT_DOMAIN);
                    ?>
"/>
                                        </a>
                                    </div>
                                    <?php 
                    $thumbnail_id = get_post_thumbnail_id(get_the_ID());
                    ?>
                                    <?php 
                    $args = array('numberposts' => 9999, 'offset' => 0, 'post_parent' => get_the_ID(), 'post_type' => 'attachment', 'exclude' => $thumbnail_id, 'nopaging' => false, 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID', 'post_status' => 'any');
                    $attachments =& get_children($args);
                    ?>
                                    <?php 
                    foreach ($attachments as $attachment) {
                        $imageTitle = $attachment->post_title;
                        $imageDescription = $attachment->post_content;
                        $imageArrayFull = wp_get_attachment_image_src($attachment->ID, 'full', false);
                        ?>
                                        <a class="hide" rel="prettyPhoto[pp_gal-widget-<?php 
                        echo $rand_pp;
                        ?>
]" href="<?php 
                        echo $imageArrayFull[0];
                        ?>
" title="<?php 
                        echo $imageDescription;
                        ?>
"></a>
                                    <?php 
                    }
                    ?>
                                    <?php 
                } elseif ($linkURL) {
                    ?>
                                        <?php 
                    if (function_exists('has_post_thumbnail') && has_post_thumbnail()) {
                        ?>
                                        <div class="img"><img class="home-overlay-item" src="<?php 
                        $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), '420x207');
                        echo $image[0];
                        ?>
" width="220" height="108"  alt="<?php 
                        _e('view more', GETTEXT_DOMAIN);
                        ?>
" rel="<?php 
                        echo $linkURL;
                        ?>
"/></div>
                                        <?php 
                    }
                    ?>
                                    <?php 
                } elseif ($videoURL) {
                    ?>
                                    <div class="vimeoOrYoutube">
                                        <iframe width="220" height="108" src="<?php 
                    echo $videoURL;
                    ?>
?rel=0&amp;autohide=1&amp;showinfo=0" frameborder="0" allowfullscreen></iframe>
                                    </div>
                                    <?php 
                } elseif (function_exists('has_post_thumbnail') && has_post_thumbnail()) {
                    ?>
                                    <div class="img"><img class="home-overlay-item" src="<?php 
                    $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), '420x207');
                    echo $image[0];
                    ?>
" width="220" height="108"  alt="<?php 
                    _e('view more', GETTEXT_DOMAIN);
                    ?>
" rel="<?php 
                    the_permalink();
                    ?>
"/></div>
                                    <?php 
                }
                ?>
                                    <div class="info">
                                        <?php 
                if ($videoURL) {
                    ?>
                                            <h4><a href="<?php 
                    the_permalink();
                    ?>
"><?php 
                    the_title();
                    ?>
</a></h4>
                                        <?php 
                } else {
                    ?>
                                            <h4><?php 
                    the_title();
                    ?>
</h4>
                                        <?php 
                }
                ?>
                                        <p><?php 
                echo excerpt(8);
                ?>
</p>
                                    </div>
                                    <div class="clear"></div>
                                </li>
                                <?php 
            }
        }
        ?>
           
            				</ul>
                            <script>
                            jQuery(document).ready(function() {
                                
                            carouFredSel_<?php 
        echo $rand;
        ?>
();
                        	carouFredSelFilter_<?php 
        echo $rand;
        ?>
();
                            
                            function carouFredSel_<?php 
        echo $rand;
        ?>
() {
                            
                                if(screen.width < 500 || 
                                navigator.userAgent.match(/Android/i) || 
                                navigator.userAgent.match(/webOS/i) || 
                                navigator.userAgent.match(/iPhone/i) || 
                                navigator.userAgent.match(/iPod/i)){
                                    var iTems = 1;
                                }else{
                                    var iTems = 3;
                                }
                            	$('.list_items-<?php 
        echo $rand;
        ?>
').carouFredSel({
                                    width   : "100%",
                                    align : 'left',
                                    //height   : "auto",
                            		circular: false,
                            		infinite: false,
                            		auto : false,
                            		pagination  : {
                            			container : '.pager-<?php 
        echo $rand;
        ?>
',
                            			items : iTems
                            		}
                            	});
                            }    
                                
                            function carouFredSelFilter_<?php 
        echo $rand;
        ?>
() {
                            	
                            	$('.list_carousel-<?php 
        echo $rand;
        ?>
').append('<ul class="list_archive-<?php 
        echo $rand;
        ?>
" />');
                            	$('.list_archive-<?php 
        echo $rand;
        ?>
').hide();
                            	
                            	$('.filter_navi-<?php 
        echo $rand;
        ?>
 li a').click(function() {
                            			
                                        
                            			var filter_navi = $(this).attr('rel');
                            			
                                        $('.filter_navi-<?php 
        echo $rand;
        ?>
 li').first().addClass('alpha');
                            			$('.filter_navi-<?php 
        echo $rand;
        ?>
 li a').removeClass('active');
                            			$(this).addClass('active');
                            			
                            			if($(this).attr('rel') == 'all') {
                            				$('.item-<?php 
        echo $rand;
        ?>
').attr('rel', 'categ');
                            			}
                            			else {
                            				$('.item-<?php 
        echo $rand;
        ?>
').each(function() {
                            					if($(this).hasClass(filter_navi)) {
                            						$(this).attr('rel', 'categ');
                            					}
                            					else {
                            						$(this).attr('rel', 'archive');
                            					}
                            				});
                            			}
                            			
                                        $('.list_items-<?php 
        echo $rand;
        ?>
').fadeOut(300, function() {
                                			$('.item-<?php 
        echo $rand;
        ?>
[rel="categ"]').appendTo('.list_items-<?php 
        echo $rand;
        ?>
');
                                			$('.item-<?php 
        echo $rand;
        ?>
[rel="archive"]').appendTo('.list_archive-<?php 
        echo $rand;
        ?>
');
                                        $('.list_items-<?php 
        echo $rand;
        ?>
').fadeIn(300);
                                        if($('.list_items-<?php 
        echo $rand;
        ?>
')) carouFredSel_<?php 
        echo $rand;
        ?>
();
                                        });
                                		
                            	});
                                
                            	$('.filter_navi li a').eq(0).click();	
                            	
                            }
                            	
                            });
                            </script>
            			</div>
                        <div class="clear"></div>
                    </div>
            	</div><!-- container -->
                <div class="container hr"><hr /></div>
		<?php 
        /* after widget (defined by themes). */
        echo $after_widget;
    }
    function widget($args, $instance)
    {
        extract($args);
        $title = apply_filters('widget_title', $instance['title']);
        /* variables from the widget settings. */
        $num = $instance['num'];
        /* before widget. */
        echo $before_widget;
        /* display Widget */
        ?>
 
        <?php 
        /* display the widget title if one was input (before and after defined by themes). */
        if ($title) {
            echo $before_title . $title . $after_title;
        }
        ?>
                    <div class="post-widget">
                        <ul>
                            <?php 
        $query = new WP_Query();
        ?>
                            <?php 
        $query->query('posts_per_page=' . $num . '&ignore_sticky_posts=1');
        ?>
                            <?php 
        if ($query->have_posts()) {
            while ($query->have_posts()) {
                $query->the_post();
                ?>
                            <?php 
                $videoURL = theme_parse_video(get_post_meta(get_the_ID(), 'video-url_value', true));
                ?>
                            <?php 
                $linkURL = get_post_meta(get_the_ID(), 'link-url_value', true);
                ?>
                            <li class="post">
                                <div class="icon 
                                <?php 
                if (function_exists('has_post_thumbnail') && has_post_thumbnail()) {
                    ?>
                                gallery
                                <?php 
                } elseif ($linkURL) {
                    ?>
                                link
                                <?php 
                } elseif ($videoURL) {
                    ?>
                                video
                                <?php 
                } else {
                    ?>
                                pencil
                                <?php 
                }
                ?>
                                ">
                                <?php 
                if (function_exists('has_post_thumbnail') && has_post_thumbnail()) {
                    the_post_thumbnail('post-tabs-widget');
                }
                ?>
                                </div>
                                <div class="content">
                                    <?php 
                if ($linkURL) {
                    ?>
                                    <a href="<?php 
                    echo $linkURL;
                    ?>
"><?php 
                    the_title();
                    ?>
</a>
                                    <?php 
                } else {
                    ?>
                                    <a href="<?php 
                    the_permalink();
                    ?>
"><?php 
                    the_title();
                    ?>
</a>
                                    <?php 
                }
                ?>
                                    <a class="date" href="<?php 
                echo get_day_link(get_the_time('Y'), get_the_time('m'), get_the_time('d'));
                ?>
"><span><?php 
                echo get_the_time('j M Y');
                ?>
</span></a> <a class="comments" href="<?php 
                comments_link();
                ?>
 "><span><?php 
                comments_number('0', '1', '%');
                ?>
 </span></a>
                                </div>
                                <div class="clear"></div>
                            </li>
                            <?php 
            }
        }
        ?>
 
                            <?php 
        wp_reset_query();
        ?>
                        </ul>
                    </div>
		<?php 
        /* after widget (defined by themes). */
        echo $after_widget;
    }
    function widget($args, $instance)
    {
        extract($args);
        $rand = rand(2, 999);
        $title = apply_filters('widget_title', $instance['title']);
        /* variables from the widget settings. */
        $num_popular = $instance['num_popular'];
        $num_recent = $instance['num_recent'];
        /* before widget. */
        echo $before_widget;
        /* display Widget */
        ?>
 
        <?php 
        /* display the widget title if one was input (before and after defined by themes). */
        if ($title) {
            echo $before_title . $title . $after_title;
        }
        ?>
                        <div class="tabs-widget post-tabs-widget">
                            <div class="ui-tabs-widget ui-tabs-widget-<?php 
        echo $rand;
        ?>
">
                            	<ul>
                            		<li><a href="#tabs-1"><?php 
        _e('Popular', GETTEXT_DOMAIN);
        ?>
</a></li>
                            		<li><a href="#tabs-2"><?php 
        _e('Recent', GETTEXT_DOMAIN);
        ?>
</a></li>
                                    <li><a href="#tabs-3"><?php 
        _e('Tags', GETTEXT_DOMAIN);
        ?>
</a></li>
                            	</ul>
                            	<div id="tabs-1">
                                    <ul class="news-wrap">
                                     <?php 
        global $wpdb;
        $posts = $wpdb->get_results("SELECT comment_count, ID, post_title FROM {$wpdb->posts} ORDER BY comment_count DESC LIMIT 0 , {$num_popular}");
        foreach ($posts as $post_) {
            setup_postdata($post_);
            $id = $post_->ID;
            $title = $post_->post_title;
            $count = $post_->comment_count;
            $videoURL = theme_parse_video(get_post_meta($id, 'video-url_value', true));
            $linkURL = get_post_meta($id, 'link-url_value', true);
            $comments = get_comments('post_id=' . $id . '&status=approve');
            $comments_number = count($comments);
            if ($count != 0) {
                ?>
<li class="post"><?php 
                ?>
<div class="icon
                                                    <?php 
                if ($linkURL) {
                    ?>
                                                    link
                                                    <?php 
                } elseif (function_exists('has_post_thumbnail') && has_post_thumbnail($post_->ID)) {
                    ?>
                                                    pencil
                                                    <?php 
                } elseif ($videoURL) {
                    ?>
                                                    video
                                                    <?php 
                } else {
                    ?>
                                                    pencil
                                                    <?php 
                }
                ?>
                                                    "><?php 
                if (function_exists('has_post_thumbnail') && has_post_thumbnail($post_->ID)) {
                    echo get_the_post_thumbnail($id, 'post-tabs-widget');
                }
                ?>
</div><?php 
                ?>
<div class="content"><?php 
                ?>
<a href="
                                                        <?php 
                if ($linkURL) {
                    ?>
                                                        <?php 
                    echo $linkURL;
                    ?>
                                                        <?php 
                } else {
                    ?>
                                                        <?php 
                    echo get_permalink($id);
                    ?>
                                                        <?php 
                }
                ?>
                                                        "><?php 
                echo $title;
                ?>
</a><?php 
                ?>
<a class="date" href="<?php 
                echo get_day_link(get_the_time('Y', $id), get_the_time('m', $id), get_the_time('d', $id));
                ?>
"><span><?php 
                echo get_the_time('j M Y', $id);
                ?>
</span></a> <a class="comments" href="<?php 
                echo get_permalink($id);
                ?>
#comments"><span><?php 
                echo $comments_number;
                ?>
 </span></a><?php 
                ?>
</div><?php 
                ?>
<div class="clear"></div><?php 
                ?>
</li><?php 
            }
        }
        ?>
                                    </ul>
                                </div>
                            	<div id="tabs-2">
                                    <ul class="news-wrap">
                                    <?php 
        $query = new WP_Query();
        ?>
                                    <?php 
        $query->query('posts_per_page=' . $num_recent . '&ignore_sticky_posts=1');
        ?>
                                    <?php 
        if ($query->have_posts()) {
            while ($query->have_posts()) {
                $query->the_post();
                ?>
                                    <?php 
                $videoURL = theme_parse_video(get_post_meta(get_the_ID(), 'video-url_value', true));
                ?>
                                    <?php 
                $linkURL = get_post_meta(get_the_ID(), 'link-url_value', true);
                ?>
                                    <li class="post"><?php 
                ?>
<div class="icon
                                        <?php 
                if ($linkURL) {
                    ?>
                                        link
                                        <?php 
                } elseif (function_exists('has_post_thumbnail') && has_post_thumbnail()) {
                    ?>
                                        pencil
                                        <?php 
                } elseif ($videoURL) {
                    ?>
                                        video
                                        <?php 
                } else {
                    ?>
                                        pencil
                                        <?php 
                }
                ?>
                                        "><?php 
                if (function_exists('has_post_thumbnail') && has_post_thumbnail()) {
                    the_post_thumbnail('post-tabs-widget');
                }
                ?>
</div><?php 
                ?>
<div class="content"><?php 
                ?>
<a href="
                                            <?php 
                if ($linkURL) {
                    ?>
                                            <?php 
                    echo $linkURL;
                    ?>
                                            <?php 
                } else {
                    ?>
                                            <?php 
                    the_permalink();
                    ?>
                                            <?php 
                }
                ?>
                                            "><?php 
                the_title();
                ?>
</a><?php 
                ?>
<a class="date" href="<?php 
                echo get_day_link(get_the_time('Y'), get_the_time('m'), get_the_time('d'));
                ?>
"><span><?php 
                echo get_the_time('j M Y');
                ?>
</span></a> <a class="comments" href="<?php 
                comments_link();
                ?>
 "><span><?php 
                comments_number('0', '1', '%');
                ?>
 </span></a><?php 
                ?>
</div><?php 
                ?>
<div class="clear"></div><?php 
                ?>
</li>
                                    <?php 
            }
        }
        ?>
 
                                    <?php 
        wp_reset_query();
        ?>
                                    </ul>
                                </div>
                            	<div id="tabs-3">
                            		<div class="tags">
                                        <?php 
        wp_tag_cloud('smallest=10&largest=10&unit=px&number=0');
        ?>
                                    </div>
                                </div>
                            </div>
                        	<script>
                            	$(function() {
                            		$( ".ui-tabs-widget-<?php 
        echo $rand;
        ?>
" ).tabs();
                            	});
                        	</script> 
                        </div>
		
		<?php 
        /* after widget (defined by themes). */
        echo $after_widget;
    }