<?php
// ======================================================    
// Website Logo
// ======================================================
function serpentsoft_header_logo() { ?>
    <a href="<?php echo esc_url(home_url('/')); ?>" title="<?php echo esc_attr(get_bloginfo('name', 'display')); ?>" rel="home">
        <?php if(serpentsoft_get_data('rdo_serpentsoft_website_main_logo') == 'logoTitle' ): ?>
            <h1 class="site-title" itemprop="name"><?php bloginfo('name'); ?></h1>
            <h2 class="site-description"><?php bloginfo('description'); ?></h2>
        <?php elseif(serpentsoft_get_data('rdo_serpentsoft_website_main_logo') == 'logoCustom' ): ?>
            <h1 class="hidden" itemprop="name"><?php bloginfo('name'); ?></h1>
            <h2 class="hidden"><?php bloginfo('description'); ?></h2>
            <img itemprop="logo" src="<?php echo serpentsoft_get_data('serpentsoft_upload_main_logo'); ?>" alt="<?php bloginfo('name'); ?>" />
        <?php endif; ?>    
    </a>
<?php }

// ======================================================    
// Header Advertisements
// ======================================================
function serpentsoft_header_adv() {
    if (serpentsoft_get_data('serpentsoft_adv_header_switch')):
        $x_headerCode = serpentsoft_get_data('serpentsoft_adv_header_code');
        $x_headerBanner = serpentsoft_get_data('serpentsoft_adv_header_banner');
        $x_headerBannerURL = serpentsoft_get_data('serpentsoft_adv_header_link');
        $x_headerOpenNewTab = serpentsoft_get_data('serpentsoft_adv_header_openNewTab_switch') ? '_blank' : '';  ?>
    
        <div class="adv-970 pull-right visible-desktop">
                <?php if ($x_headerCode): echo $x_headerCode;
                    elseif ($x_headerBanner):
                        if (isset($x_headerBannerURL) && $x_headerBannerURL != ''): ?>
                        <a href="<?php echo esc_url($x_headerBannerURL); ?>" target="<?php echo $x_headerOpenNewTab; ?>">
                            <img class="pull-right" src="<?php echo $x_headerBanner; ?>" alt="Header Advertisement" />
                        </a>
                <?php else: ?>
                    <img class="pull-right" src="<?php echo $x_headerBanner; ?>" alt="Header Advertisement" />
                <?php endif; endif; ?>
        </div>
    <?php endif;
}

// ======================================================    
// Footer Advertisements
// ======================================================
function serpentsoft_footer_adv() {    
    if (serpentsoft_get_data('serpentsoft_adv_footer_switch')):
        $x_footerCode = serpentsoft_get_data('serpentsoft_adv_footer_code');
        $x_footerBanner = serpentsoft_get_data('serpentsoft_adv_footer_banner');
        $x_footerBannerURL = serpentsoft_get_data('serpentsoft_adv_footer_link');
        $x_footerOpenNewTab = serpentsoft_get_data('serpentsoft_adv_footer_openNewTab_switch') ? '_blank' : '';  ?>
    
        <div class="adv-970 visible-desktop">
                <?php if ($x_footerCode): echo $x_footerCode;
                    elseif ($x_footerBanner):
                        if (isset($x_footerBannerURL) && $x_footerBannerURL != ''): ?>
                        <a href="<?php echo esc_url($x_footerBannerURL); ?>" target="<?php echo $x_footerOpenNewTab; ?>">
                            <img src="<?php echo $x_footerBanner; ?>" alt="Footer Advertisement" />
                        </a>
                <?php else: ?>
                    <img src="<?php echo $x_footerBanner; ?>" alt="Footer Advertisement" />
                <?php endif; endif; ?>
        </div>
    <?php endif;
}
    
// ======================================================    
// Breaking News
// ======================================================
function serpentsoft_header_breakingnews() {
    if( serpentsoft_get_data('serpentsoft_switch_breakingnews') ):
        
    $cat_posts_num = serpentsoft_get_data('serpentsoft_breakingnews_no_of_posts');

    if( !is_numeric($cat_posts_num) || $cat_posts_num < 0 ) { $cat_posts_num = 6; }

    $cat_id = serpentsoft_get_data('lst_serpentsoft_breakingnews_categories'); ?>

        <section class="breaking-news-widget">
            <div class="row-fluid">

                <?php $breakingNewsTitle = serpentsoft_get_data('serpentsoft_breakingnews_box_title');
                if ( !empty($breakingNewsTitle) ){ ?>
                <div class="title">
                    <h3><?php echo $breakingNewsTitle; ?></h3>
                </div>
                <?php } ?>
                
                <?php if ($cat_id != 0) {
                    $wp_query = new WP_Query(array('post_type' => 'post', 'cat' => $cat_id, 'posts_per_page' => $cat_posts_num, 'post_status' => 'publish'));
                } else {
                    $wp_query = new WP_Query(array('post_type' => 'post', 'posts_per_page' => $cat_posts_num, 'post_status' => 'publish'));
                }
                if ($wp_query->have_posts()) : ?>

                    <div id="divBreakingNewsTicker" class="content">
                        <ul id="js-news" class="js-hidden">
                            <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
                                <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
                            <?php endwhile; ?>
                        </ul>
                    </div>
                <?php endif; ?>
                
                <script type="text/javascript">
                    //<![CDATA[
                    jQuery(document).ready(function () {
                        var writeSpeed = <?php echo serpentsoft_get_data('serpentsoft_slider_breakingnews_writingSpeed'); ?>;
                        var pauseInSeconds = <?php echo serpentsoft_get_data('serpentsoft_slider_breakingnews_pauseInSeconds'); ?>;
                        
                        breakingNewsTicker('#js-news', <?php echo is_rtl() ? '"rtl"' : '"ltr"'; ?>, writeSpeed, pauseInSeconds);
                    });
                    //]]>
                </script>
            </div>
        </section>

<?php endif; } ?>