/**
 * Echos or returns main headline
 * @param OBJECT $post
 * @param STRING $headline depreciated
 * @param bool $return
 */
function lp_main_headline($post = null, $headline = null, $return = false)
{
    if (!isset($post)) {
        global $post;
    }
    $main_headline = Landing_Pages_Variations::get_main_headline($post->ID);
    if (!$return) {
        echo $main_headline;
    } else {
        return $main_headline;
    }
}
    /**
     * Displays quick stats metabox
     */
    public static function display_quick_stats_metabox()
    {
        global $post;
        $variations = Landing_Pages_Variations::get_variations($post->ID);
        $variations = array_filter($variations, 'is_numeric');
        ?>
        <div>
            <style type="text/css">

            </style>
            <div class="inside" id="a-b-testing">
                <div id="bab-stat-box">
                    <?php 
        if (isset($_GET['new_meta_key']) && is_numeric($_GET['new_meta_key'])) {
            ?>
                        <script type="text/javascript">
                            jQuery(document).ready(function($) {
                                /* This fixes meta data saves for cloned pages */
                                function isNumber (o) {
                                    return ! isNaN (o-0) && o !== null && o !== "" && o !== false;
                                }
                                var new_meta_key = "<?php 
            echo $_GET['new_meta_key'];
            ?>
";
                                jQuery('#template-display-options input[type=text], #template-display-options select, #template-display-options input[type=radio], #template-display-options textarea').each(function(){
                                    var this_id = jQuery(this).attr("id");
                                    var final_number = this_id.match(/[^-]+$/g);
                                    var new_id = this_id.replace(/[^-]+$/g, new_meta_key);
                                    var is_number = isNumber(final_number);

                                    if (is_number === false) {
                                        jQuery(this).attr("id", this_id + "-" + new_meta_key);
                                        jQuery(this).attr("name", this_id + "-" + new_meta_key);
                                    } else {
                                        jQuery(this).attr("id", new_id);
                                        jQuery(this).attr("name", new_id);
                                    }
                                });
                            });
                        </script>
                    <?php 
        }
        $howmany = count($variations);
        foreach ($variations as $key => $vid) {
            $variation_status = Landing_Pages_Variations::get_variation_status($post->ID, $vid);
            $variation_status_class = $variation_status == 1 ? "variation-on" : 'variation-off';
            $permalink = Landing_Pages_Variations::get_variation_permalink($post->ID, $vid);
            $impressions = Landing_Pages_Variations::get_impressions($post->ID, $vid);
            $conversions = Landing_Pages_Variations::get_conversions($post->ID, $vid);
            $conversion_rate = Landing_Pages_Variations::get_conversion_rate($post->ID, $vid);
            $title = Landing_Pages_Variations::get_main_headline($post->ID, $vid);
            ?>

                        <div id="lp-variation-<?php 
            echo Landing_Pages_Variations::vid_to_letter($post->ID, $key);
            ?>
"
                             class="bab-variation-row <?php 
            echo $variation_status_class;
            ?>
">
                            <div class='bab-varation-header'>
								<span class='bab-variation-name'><?php 
            _e('Variation', 'landing-pages');
            ?>
 <span
                                        class='bab-stat-letter'><?php 
            echo Landing_Pages_Variations::vid_to_letter($post->ID, $key);
            ?>
</span>
                                    <?php 
            if ($variation_status != 1) {
                ?>
                                        <span class='is-paused'>(<?php 
                _e('Paused', 'landing-pages');
                ?>
)</span>
                                    <?php 
            }
            ?>
								</span>


                                <span class="lp-delete-var-stats" data-letter='<?php 
            echo Landing_Pages_Variations::vid_to_letter($post->ID, $key);
            ?>
'
                                      data-vid='<?php 
            echo $vid;
            ?>
' rel='<?php 
            echo $post->ID;
            ?>
'
                                      title="<?php 
            _e('Delete this variations stats', 'landing-pages');
            ?>
"><?php 
            _e('Clear Stats', 'landing-pages');
            ?>
</span>
                            </div>
                            <div class="bab-stat-row">
                                <div class='bab-stat-stats' colspan='2'>
                                    <div class='bab-stat-container-impressions bab-number-box'>
                                        <span class='bab-stat-span-impressions'><?php 
            echo $impressions;
            ?>
</span>
                                        <span class="bab-stat-id"><?php 
            _e('Views', 'landing-pages');
            ?>
 </span>
                                    </div>
                                    <div class='bab-stat-container-conversions bab-number-box'>
                                        <span class='bab-stat-span-conversions'><?php 
            echo $conversions;
            ?>
</span>
                                        <span
                                            class="bab-stat-id"><?php 
            _e('Conversions', 'landing-pages');
            ?>
</span></span>
                                    </div>
                                    <div class='bab-stat-container-conversion_rate bab-number-box'>
                                        <span
                                            class='bab-stat-span-conversion_rate'><?php 
            echo $conversion_rate;
            ?>
</span>
                                        <span
                                            class="bab-stat-id bab-rate"><?php 
            _e('Conversion Rate', 'landing-pages');
            ?>
</span>
                                    </div>
                                    <div class='bab-stat-control-container'>
                                        <span class='bab-stat-control-pause'><a
                                                title="<?php 
            _e('Pause this variation', 'landing-pages');
            ?>
"
                                                href='?post=<?php 
            echo $post->ID;
            ?>
&action=edit&action-variation-id=<?php 
            echo $vid;
            ?>
&ab-action=pause-variation'><?php 
            _e('Pause', 'landing-pages');
            ?>
</a></span>
                                        <span class='bab-stat-seperator pause-sep'>|</span>
                                        <span class='bab-stat-control-play'><a
                                                title="<?php 
            _e('Turn this variation on', 'landing-pages');
            ?>
"
                                                href='?post=<?php 
            echo $post->ID;
            ?>
&action=edit&action-variation-id=<?php 
            echo $vid;
            ?>
&ab-action=play-variation'><?php 
            _e('Play', 'landing-pages');
            ?>
</a></span>
                                        <span class='bab-stat-seperator play-sep'>|</span>
                                        <span class='bab-stat-menu-edit'><a
                                                title="<?php 
            _e('Edit this variation', 'landing-pages');
            ?>
"
                                                href='?post=<?php 
            echo $post->ID;
            ?>
&action=edit&action-variation-id=<?php 
            echo $vid;
            ?>
'><?php 
            _e('Edit', 'landing-pages');
            ?>
</a></span>
                                        <span class='bab-stat-seperator'>|</span>
                                        <span class='bab-stat-menu-preview'><a
                                                title="<?php 
            _e('Preview this variation', 'landing-pages');
            ?>
"
                                                class='thickbox'
                                                href='<?php 
            echo $permalink;
            ?>
&iframe_window=on&post_id=<?php 
            echo $post->ID;
            ?>
&TB_iframe=true&width=1503&height=467'
                                                target='_blank'><?php 
            _e('Preview', 'landing-pages');
            ?>
</a></span>
                                        <span class='bab-stat-seperator'>|</span>
                                        <span class='bab-stat-menu-clone'><a
                                                title="<?php 
            _e('Clone this variation', 'landing-pages');
            ?>
"
                                                href='?post=<?php 
            echo $post->ID;
            ?>
&action=edit&new-variation=1&clone=<?php 
            echo $vid;
            ?>
&new_meta_key=<?php 
            echo $howmany;
            ?>
'><?php 
            _e('Clone', 'landing-pages');
            ?>
</a></span>
                                        <span class='bab-stat-seperator'>|</span>
                                        <span class='bab-stat-control-delete'><a
                                                title="<?php 
            _e('Delete this variation', 'landing-pages');
            ?>
"
                                                href='?post=<?php 
            echo $post->ID;
            ?>
&action=edit&action-variation-id=<?php 
            echo $vid;
            ?>
&ab-action=delete-variation'><?php 
            _e('Delete', 'landing-pages');
            ?>
</a></span>
                                    </div>
                                </div>
                            </div>
                            <div class="bab-stat-row">

                                <div class='bab-stat-menu-container'>

                                    <?php 
            do_action('lp_ab_testing_stats_menu_post');
            ?>

                                </div>
                            </div>
                        </div>
                    <?php 
        }
        ?>
                </div>

            </div>
        </div>
    <?php 
    }