<?php 
	
		add_action('after_setup_theme', 'helium_theme_support', 10);
		add_action('wp_head', 'helium_setmeta_head', 10);
		add_filter('oembed_result', 'helium_framework_fix_oembeb', 10 );
		add_filter('paginate_links', 'helium_fix_pagination_error',10);
		add_action('wp_enqueue_scripts', 'helium_script_ie', 10);
		add_action( 'admin_enqueue_scripts', 'helium_wpadminjs' );

		/* Add theme support */
		function helium_theme_support(){

			if ( is_singular() && comments_open() && get_option( 'thread_comments' ) )
		        wp_enqueue_script( 'comment-reply' );

		    if ( ! isset( $content_width ) ) $content_width = 900;

		    add_theme_support('title-tag');

		    // Adds RSS feed links to <head> for posts and comments.
		    add_theme_support( 'automatic-feed-links' );

		    // Switches default core markup for search form, comment form, and comments    
		    // to output valid HTML5.
		    add_theme_support( 'html5', array( 'search-form', 'comment-form', 'comment-list' ) );

		    /*
		     * This theme supports all available post formats by default.
		     * See http://codex.wordpress.org/Post_Formats
		     */
		     add_theme_support( 'post-formats', array( 'image', 'gallery', 'audio', 'video') );

		    add_theme_support( 'post-thumbnails' );
		    
		    // add_theme_support( 'custom-header' );
		    add_theme_support( 'custom-background');
		    add_theme_support( 'woocommerce' );
		    
		}

		/* Set meta for head */
		function helium_setmeta_head(){
			ob_start();
			?>
			
				<meta http-equiv="Content-Type" content="text/html; charset=<?php bloginfo( 'charset' ); ?>" />
			    <link rel="profile" href="http://gmpg.org/xfn/11">
			    <link rel="pingback" href="<?php echo get_bloginfo( 'pingback_url' ); ?>">
			    <meta http-equiv="X-UA-Compatible" content="IE=edge">
			    <meta name="viewport" content="width=device-width, initial-scale=1">

			    <!-- For SEO -->
			    <?php if(get_theme_mod('seo_option', 'yes') == 'yes'){ ?>
			    	<?php
			    		$seo_description = get_post_meta(helium_get_current_id(), "helium_met_seo_desc", true) ? get_post_meta(helium_get_current_id(), "helium_met_seo_desc", true) : ''; // Get metabox for each page or post
						$seo_keywords    = get_post_meta(helium_get_current_id(), "helium_met_seo_key", true) ? get_post_meta(helium_get_current_id(), "helium_met_seo_key", true) : ''; // Get metabox for each page or post
			    	?>
			    	<meta name="description" content="<?php echo esc_attr($seo_description); ?>">
			    	<meta name="keywords" content="<?php echo esc_attr($seo_keywords); ?>">
			    <?php } ?>
			    <!-- End SEO-->

			<?php
			echo ob_get_clean();

		}

		function helium_framework_fix_oembeb( $url ){
		    $array = array (
		        'webkitallowfullscreen'     => '',
		        'mozallowfullscreen'        => '',
		        'frameborder="0"'           => '',
		        '</iframe>)'        => '</iframe>'
		    );
		    $url = strtr( $url, $array );

		    if ( strpos( $url, "<embed src=" ) !== false ){
		        return str_replace('</param><embed', '</param><param name="wmode" value="opaque"></param><embed wmode="opaque" ', $url);
		    }
		    elseif ( strpos ( $url, 'feature=oembed' ) !== false ){
		        return str_replace( 'feature=oembed', 'feature=oembed&amp;wmode=opaque', $url );
		    }
		    else{
		        return $url;
		    }
		}

		function helium_script_ie(){

		    wp_enqueue_script( 'html5shiv', OVA_THEME_URI.'/framework/fix_ie/html5shiv.js', array(), '4.5' );
		    wp_script_add_data( 'html5shiv', 'conditional', 'lt IE 9' );

		    wp_enqueue_script( 'respond', OVA_THEME_URI.'/framework/fix_ie/respond.min.js', array(), '4.5' );
		    wp_script_add_data( 'respond', 'conditional', 'lt IE 9' );
		}

		function helium_wpadminjs() {
		    wp_enqueue_script( 'wpadminjs', OVA_THEME_URI.'/extend/wpadmin.js', array('jquery'),false,true );
		}

		// Fix pagination
		function helium_fix_pagination_error($link) {
			return str_replace('#038;', '&', $link);
		}


		function helium_pagination_theme() {
		   
		    if( is_singular() )
		        return;
		 
		    global $wp_query;
		 
		    /** Stop execution if there's only 1 page */
		    if( $wp_query->max_num_pages <= 1 )
		        return;
		 
		    $paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1;
		    $max   = intval( $wp_query->max_num_pages );
		 
		    /** Add current page to the array */
		    if ( $paged >= 1 )
		        $links[] = $paged;
		 
		    /** Add the pages around the current page to the array */
		    if ( $paged >= 3 ) {
		        $links[] = $paged - 1;
		        $links[] = $paged - 2;
		    }
		 
		    if ( ( $paged + 2 ) <= $max ) {
		        $links[] = $paged + 2;
		        $links[] = $paged + 1;
		    }
		 
		    echo wp_kses( __( '<div class="blog_pagination"><ul class="pagination">','helium' ), true ) . "\n";
		 
		    /** Previous Post Link */
		    if ( get_previous_posts_link() )
		        printf( '<li class="prev page-numbers">%s</li>' . "\n", get_previous_posts_link('<i class="fa fa-chevron-left"></i>') );
		 
		    /** Link to first page, plus ellipses if necessary */
		    if ( ! in_array( 1, $links ) ) {
		        $class = 1 == $paged ? ' class="active"' : '';
		 
		        printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( 1 ) ), '1' );
		 
		        if ( ! in_array( 2, $links ) )
		            echo wp_kses( __('<li>...</li>', 'helium' ) , true);
		    }
		 
		    /** Link to current page, plus 2 pages in either direction if necessary */
		    sort( $links );
		    foreach ( (array) $links as $link ) {
		        $class = $paged == $link ? ' class="active"' : '';
		        printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $link ) ), $link );
		    }
		 
		    /** Link to last page, plus ellipses if necessary */
		    if ( ! in_array( $max, $links ) ) {
		        if ( ! in_array( $max - 1, $links ) )
		            echo wp_kses( __('<li>...</li>', 'helium' ) , true) . "\n";
		 
		        $class = $paged == $max ? ' class="active"' : '';
		        printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $max ) ), $max );
		    }
		 
		    /** Next Post Link */
		    if ( get_next_posts_link() )
		        printf( '<li class="next page-numbers">%s</li>' . "\n", get_next_posts_link('<i class="fa fa-chevron-right"></i>') );
		 
		    echo wp_kses( __( '</ul></div>', 'helium' ), true ) . "\n";
		 
		}
		

		

	

