function Grafik_Shortcode_SearchResults_Callback($atts, $content = null)
{
    $a = shortcode_atts(array('c_param' => 'c', 'q_param' => 'q', 'type' => 'any', 'class' => '', 'id' => ''), $atts);
    // Not a search, return content...
    if (empty($a['c_param']) || empty($a['q_param'])) {
        return Grafik_ShortcodeLoop($content);
    }
    // Is a search, perform query...
    $results = '';
    $search = new WP_Query(array('s' => $_GET[$a['q_param']], 'post_type' => $a['type'], 'post_status' => 'publish', 'posts_per_page' => -1));
    if ($search->have_posts()) {
        while ($search->have_posts()) {
            $search->the_post();
            if (get_post_type($search->post->ID) == 'page') {
                $results .= '<div class="theme-searchresults-page">' . '<div class="theme-searchresults-info id-' . $search->post->ID . '">[Breadcrumbs postid="' . $search->post->ID . '" includehome="1" includeself="0"]</div>' . '<div class="theme-searchresults-title">' . '<a href="' . get_permalink($search->post->ID) . '">' . get_the_title($search->post->ID) . '</a>' . '</div>' . '<div class="theme-searchresults-short">' . 'Truncated content here...' . '</div>' . '</div>';
            } else {
                $excerpt = get_the_excerpt($search->post->ID);
                $results .= '<div class="theme-searchresults-post">' . '<div class="theme-searchresults-info">Posted: ' . get_the_date('F dS, Y', $search->post->ID) . '</div>' . '<div class="theme-searchresults-title">' . '<a href="' . get_permalink($search->post->ID) . '">' . get_the_title($search->post->ID) . '</a>' . '</div>' . '<div class="theme-searchresults-short">' . $excerpt . '</div>' . '</div>';
            }
        }
    }
    if (empty($results)) {
        $results .= '<div class="theme-searchresults-pages-none">' . '<p><strong>Search returned zero results...</strong></p>' . '</div>';
    }
    return '<div class="theme-searchresults' . (empty($a['class']) ? null : ' ' . $a['class']) . '"' . (empty($a['id']) ? null : ' id="' . $a['id'] . '"') . '>' . '<h2>Showing Matches: ' . htmlspecialchars($_GET[$a['q_param']]) . '</h2>' . $results . '</div>';
}
function Grafik_Shortcode_Hero_Callback($atts, $content = null)
{
    $a = shortcode_atts(array('title' => '', 'bgcolor' => '', 'bgimage' => '', 'bgsize' => 'cover', 'btnlink' => '', 'btntext' => '', 'class' => '', 'id' => ''), $atts);
    $id = "";
    if (!empty($a['id'])) {
        $id .= $a['id'];
    }
    if (!empty($id)) {
        $id = " id=\"{$id}\"";
    }
    $classes = "theme-hero";
    if (!empty($a['class'])) {
        $classes .= " {$a['class']}";
    }
    if (!empty($classes)) {
        $classes = " class=\"{$classes}\"";
    }
    $styles = "";
    if (!empty($a['bgimage'])) {
        $styles .= "background: url( {$a['bgimage']} ) no-repeat 50% 50%;";
    }
    if (!empty($a['bgcolor'])) {
        $styles .= "background-color: {$a['bgcolor']};";
    }
    if (!empty($a['bgsize'])) {
        $styles .= "background-size: {$a['bgsize']};";
    }
    if (!empty($styles)) {
        $styles = " style=\"{$styles}\"";
    }
    return '<div' . $id . $classes . $styles . '>' . '<div class="theme-hero-interior">' . '<div class="theme-hero-content">' . (empty($a['title']) ? null : '<div class="theme-hero-content-title">' . '<h2>' . $a['title'] . '</h2>' . '</div>') . '<div class="theme-hero-content-main">' . Grafik_ShortcodeLoop($content) . '</div>' . (empty($a['btntext']) || empty($a['btnlink']) ? null : '<div class="theme-hero-content-button">' . '<a href="' . $a['btnlink'] . '" title="' . $a['btntext'] . '">' . $a['btntext'] . '</a>' . '</div>') . '</div>' . '</div>' . '</div>';
}
function Grafik_Functions_Shortcode_ToggleBox($atts, $content = null)
{
    $a = shortcode_atts(array('bindto' => '', 'scrollto_enabled' => 'true', 'scrollto_offset' => 0, 'scrollto_speed' => 500, 'class' => '', 'id' => ''), $atts);
    usleep(1);
    $binding = 'togglebox_' . microtime();
    return '<div class="theme-togglebox ' . $binding . (empty($a['class']) ? null : ' ' . $a['class']) . '"' . (empty($a['id']) ? null : ' id="' . $a['id'] . '"') . '>' . '<div class="theme-togglebox-interior">' . '<div class="theme-togglebox-toggle"></div>' . Grafik_ShortcodeLoop($content) . '</div>' . '</div>' . '<script>' . '$( document ).on( "ready", function() {' . '$( "' . $a['bindto'] . ', .' . $binding . ' .theme-togglebox-toggle" )' . '.on( "click", function(e) {' . 'e.preventDefault();' . '$( ".' . $binding . '" )' . '.toggleClass( "toggled" );' . ($a['scrollto_enabled'] != 'true' ? null : 'if( $( ".' . $binding . '" ).hasClass( "toggled" ) ) {' . '$( "html, body" )' . '.animate( {' . 'scrollTop: $( ".' . $binding . '" ).offset().top' . (empty($a['scrollto_offset']) ? null : ' - ' . $a['scrollto_offset']) . '}' . (empty($a['scrollto_speed']) ? null : ', ' . $a['scrollto_speed']) . ' );' . '}') . '} );' . '} );' . '</script>';
}
function Grafik_Shortcode_RandomBackground_Callback($atts, $content = null)
{
    $a = shortcode_atts(array('size' => 'cover', 'position' => '50% 50%', 'desktop_images' => '', 'tablet_images' => '', 'phone_images' => '', 'class' => '', 'id' => ''), $atts);
    $desktop_images = empty($a['desktop_images']) ? null : explode(' ', $a['desktop_images']);
    $tablet_images = empty($a['tablet_images']) ? null : explode(' ', $a['tablet_images']);
    $phone_images = empty($a['phone_images']) ? null : explode(' ', $a['phone_images']);
    $style_base = (empty($a['size']) ? null : 'background-size:' . $a['size'] . ';') . (empty($a['position']) ? null : 'background-position:' . $a['position'] . ';');
    $desktop_style = $style_base . (empty($desktop_images) ? null : 'background-image:url(' . $desktop_images[array_rand($desktop_images, 1)] . ');');
    $tablet_style = $style_base . (empty($tablet_images) ? null : 'background-image:url(' . $tablet_images[array_rand($tablet_images, 1)] . ');');
    $phone_style = $style_base . (empty($phone_images) ? null : 'background-image:url(' . $phone_images[array_rand($phone_images, 1)] . ');');
    return '<div class="theme-randombackground' . (empty($a['class']) ? null : ' ' . $a['class']) . '"' . (empty($a['id']) ? null : ' id="' . $a['id'] . '"') . '>' . (empty($desktop_images) ? null : '<div class="theme-randombackground-desktop" style="' . $desktop_style . '">') . (empty($tablet_images) ? null : '<div class="theme-randombackground-tablet" style="' . $tablet_style . '">') . (empty($phone_images) ? null : '<div class="theme-randombackground-phone" style="' . $phone_style . '">') . Grafik_ShortcodeLoop($content) . (empty($phone_images) ? null : '</div>') . (empty($tablet_images) ? null : '</div>') . (empty($desktop_images) ? null : '</div>') . '</div>';
}
function Grafik_ShortcodeLoop($content = '')
{
    if (empty($content)) {
        return '';
    }
    $old_md5 = md5($content);
    $content = do_shortcode($content);
    $new_md5 = md5($content);
    if ($old_md5 == $new_md5) {
        return $content;
    }
    return Grafik_ShortcodeLoop($content);
}
function Grafik_Shortcode_JumpScroller_Callback($atts, $content = null)
{
    global $GRAFIK_ID;
    $a = shortcode_atts(array('legend_links' => '', 'scrollto_enabled' => true, 'scrollto_speed' => 500, 'scrollto_offset' => 0, 'class' => '', 'id' => ''), $atts);
    if (empty($a['legend_links'])) {
        return null;
    }
    $legend_links = explode('|', $a['legend_links']);
    $links = array();
    foreach ($legend_links as $legend_link) {
        $link_parts = explode(' ', $legend_link);
        $link_id = array_shift($link_parts);
        $link_title = implode(' ', $link_parts);
        $links[] = array('id' => $link_id, 'title' => $link_title);
    }
    $binding_id = 'jumpscroller_' . microtime(true) * 10000;
    $link_list = '';
    foreach ($links as $link) {
        $link_list .= '<li><a href="#' . trim($link['id'], '#') . '">' . $link['title'] . '</a></li>';
    }
    return '<div class="theme-jumpscroller' . (empty($a['class']) ? null : ' ' . $a['class']) . '"' . (empty($a['id']) ? null : ' id="' . $a['id'] . '"') . '>' . '<div class="theme-jumpscroller-interior">' . '<div class="theme-jumpscroller-legend">' . '<div class="theme-jumpscroller-legend-interior">' . '<ul id="' . $binding_id . '">' . $link_list . '</ul>' . '</div>' . '</div>' . '<div class="theme-jumpscroller-content">' . '<div class="theme-jumpscroller-content-interior">' . Grafik_ShortcodeLoop($content) . '</div>' . '</div>' . '</div>' . '</div>' . '<script>' . '(function() {' . 'var JumpScroller_Top = 0;' . 'var JumpScroller_Offset = ' . $a['scrollto_offset'] . ';' . 'var JumpScroller_Object;' . 'function JumpScroller_UpdateTop() {' . 'JumpScroller_Top = $( this ).scrollTop();' . 'var FirstNotScrolled = true;' . '$.each( JumpScroller_Object, function( i ) {' . 'var targetA = $( "a[href=#" + $( this ).attr( "id" ) + "]" );' . 'if( $( this ).offset().top < JumpScroller_Top + ' . $a['scrollto_offset'] . ' ) {' . 'targetA.addClass( "scrolled" ).removeClass( "first-unscrolled" );' . '} else {' . 'targetA.removeClass( "scrolled" );' . 'if( FirstNotScrolled ) {' . 'FirstNotScrolled = false;' . 'targetA.addClass( "first-unscrolled" );' . '} else {' . 'targetA.removeClass( "first-unscrolled" );' . '}' . '}' . '} );' . '}' . '$( document ).on( "ready", function() {' . 'var JumpScroller_Ids = [];' . '$( "#' . $binding_id . ' a" )' . '.each( function( i ) {' . 'JumpScroller_Ids[JumpScroller_Ids.length] = $( this ).attr( "href" ).replace( "#", "" );' . '} );' . 'var JumpScroller_Nodes = $.map( JumpScroller_Ids, function( i ) { return document.getElementById( i ); } );' . 'JumpScroller_Object = $( JumpScroller_Nodes );' . '$( "#' . $binding_id . ' a" )' . '.on( "click", function(e) {' . 'var thisA = $( this );' . ($a['scrollto_enabled'] != true ? null : 'e.preventDefault();' . '$( "html, body" )' . '.animate( {' . 'scrollTop: $( $( thisA ).attr( "href" ) ).offset().top' . (empty($a['scrollto_offset']) ? null : ' - ' . $a['scrollto_offset']) . '}' . (empty($a['scrollto_speed']) ? null : ', ' . $a['scrollto_speed']) . ' );') . '} );' . '$( window ).on( "scroll", JumpScroller_UpdateTop );' . '} );' . '})(jQuery);' . '</script>';
}
function Grafik_Shortcode_CalloutBox_Callback($atts, $content = null)
{
    $a = shortcode_atts(array('imgsrc' => '', 'imgurl' => '', 'title' => '', 'class' => '', 'id' => ''), $atts);
    return '<div class="theme-calloutbox' . (empty($a['class']) ? null : ' ' . $a['class']) . '"' . (empty($a['id']) ? null : ' id="' . $a['id'] . '"') . '>' . (empty($a['imgsrc']) ? null : '<div class="theme-calloutbox-image">' . (empty($a['imgurl']) ? null : '<a href="' . $a['imgurl'] . '">') . '<img src="' . $a['imgsrc'] . '" alt="' . $a['title'] . '" />' . (empty($a['imgurl']) ? null : '</a>') . '</div>') . '<div class="theme-calloutbox-interior">' . (empty($a['title']) ? null : '<div class="theme-calloutbox-title"><strong>' . $a['title'] . '</strong></div>') . (empty($content) ? null : '<div class="theme-calloutbox-content">' . Grafik_ShortcodeLoop($content) . '</div>') . '</div>' . '</div>';
}
function Grafik_Templates_GetHTML($template, $single_id = false)
{
    $inherits = Grafik_Templates_GetInherits();
    $sections = Grafik_Templates_GetFields();
    $order = $inherits[$template];
    $order[] = $template;
    $options = array();
    foreach ($order as $current) {
        $options[] = Grafik_Templates_GetOptions($current);
    }
    if ($single_id !== false) {
        $options[] = get_post_meta($single_id, 'Grafik_Metaboxes');
    }
    $html = array();
    foreach ($options as $option) {
        foreach ($sections as $section => $fields) {
            foreach ($fields as $field) {
                $key = $section . '_' . $field;
                if (!is_array($html[$key])) {
                    $html[$key] = array();
                }
                if (isset($option[$key . '_Mode'])) {
                    switch ($option[$key . '_Mode']) {
                        case '0':
                            continue;
                            break;
                        case '1':
                            array_unshift($html[$key], $option[$key . '_HTML']);
                            break;
                        case '2':
                            array_push($html[$key], $option[$key . '_HTML']);
                            break;
                        case '3':
                            $html[$key] = array($option[$key . '_HTML']);
                            break;
                    }
                }
            }
            // foreach( $fields )
        }
        // foreach ( $sections )
    }
    // foreach ( $options )
    foreach ($html as $section => $blocks) {
        $output = '';
        foreach ($blocks as $block) {
            $output .= Grafik_ReadDecode($block);
        }
        $html[$section] = Grafik_Menus_GetHTML($section, Grafik_ShortcodeLoop($output));
    }
    return $html;
}
function Grafik_ShortcodeLoop($content = '')
{
    $old_length = count($content);
    if (empty($content)) {
        return '';
    }
    $content = do_shortcode($content);
    $new_length = count($content);
    if ($old_length != $new_length) {
        $content = Grafik_ShortcodeLoop($content);
    }
    return $content;
}