<?php
/**
 * Themes functions and definitions
 *
 * @package Melograno Lite
 */
function melograno_setup() {
	global $content_width;
		if ( ! isset( $content_width ) ){
      		$content_width = 1200;
		}
	load_theme_textdomain( 'melograno', get_template_directory() . '/languages' );
	add_theme_support( 'automatic-feed-links' );
	add_theme_support( 'title-tag' );
	add_theme_support( 'custom-logo');
	add_theme_support( 'customize-selective-refresh-widgets' );
	register_nav_menus( array(
			'main-menu' => esc_attr__( 'Primary Menu', 'melograno-lite' ),
			'social' 	=> esc_attr__( 'Social', 'melograno-lite' )
		) );
	add_theme_support( 'custom-background', array(
		'default-color' => '414141',
	) );
	add_theme_support( 'post-thumbnails' );
	add_image_size('melograno-homeimg', 2000, 600, true);
	add_image_size('melograno-blogthumb', 400, 400, true);
	add_image_size('big-header', 2000, 600, true);
}
add_action( 'after_setup_theme', 'melograno_setup' );

/**
 * Register widget areas.
 *
 */
function melograno_widgets_init() {
	register_sidebar( array(
		'name'          => esc_html__( 'Sidebar', 'melograno-lite' ),
		'id'            => 'sidebar-1',
		'description'   => '',
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget'  => '</div>',
		'before_title'  => '<h2 class="widget-title">',
		'after_title'   => '</h2>',
	) );

	register_sidebar( array(
		'name'          => esc_html__( 'Front Widget', 'melograno-lite' ),
		'id'            => 'sidebar-2',
		'description'   => '',
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget'  => '</div>',
		'before_title'  => '<h2 class="widget-title">',
		'after_title'   => '</h2>',
	) );
	
}
add_action( 'widgets_init', 'melograno_widgets_init' );

/**
 * Register Open Sans Google fonts for Melograno.
 *
 * @return string
 */
function melograno_open_sans_font_url() {
	$open_sans_font_url = '';

	/* translators: If there are characters in your language that are not supported
	 * by Open Sans, translate this to 'off'. Do not translate into your own language.
	 */
	if ( 'off' !== _x( 'on', 'Open Sans font: on or off', 'melograno-lite' ) ) {
		$subsets = 'latin,latin-ext';

		/* translators: To add an additional Open Sans character subset specific to your language,
		 * translate this to 'greek', 'cyrillic' or 'vietnamese'. Do not translate into your own language.
		 */
		$subset = _x( 'no-subset', 'Open Sans font: add new subset (greek, cyrillic, vietnamese)', 'melograno-lite' );

		if ( 'cyrillic' == $subset ) {
			$subsets .= ',cyrillic,cyrillic-ext';
		} elseif ( 'greek' == $subset ) {
			$subsets .= ',greek,greek-ext';
		} elseif ( 'vietnamese' == $subset ) {
			$subsets .= ',vietnamese';
		}

		$query_args = array(
			'family' => urlencode( 'Open Sans:300,400,600,700,800' ),
			'subset' => urlencode( $subsets ),
		);

		$open_sans_font_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
	}

	return $open_sans_font_url;
}

/**
 * Register Raleway Google font for Melograno.
 *
 * @return string
 */
function melograno_raleway_font_url() {
	$raleway_font_url = '';

	/* translators: If there are characters in your language that are not supported
	   by this font, translate this to 'off'. Do not translate into your own language. */
	if ( 'off' !== _x( 'on', 'Raleway font: on or off', 'melograno-lite' ) ) {

		$raleway_font_url = add_query_arg( 'family', urlencode( 'Raleway:400,500,600,800' ), "https://fonts.googleapis.com/css" );
	}

	return $raleway_font_url;
}


/**
 * Including theme scrips and styles.
 */
function melograno_scripts_styles() {
	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) )
		wp_enqueue_script( 'comment-reply' );

	if (!is_admin()) {
		wp_enqueue_script( 'melograno-responsive-videos', get_template_directory_uri() . '/js/responsive-videos.js', array( 'jquery' ), '', true );
		wp_enqueue_script( 'melograno-panel', get_template_directory_uri() . '/js/slidereveal.js', array( 'jquery' ), '', true );
		wp_enqueue_script( 'square-menu', get_template_directory_uri() . '/js/square_menu.js', array( 'jquery' ), '', true );
		wp_enqueue_style( 'melograno-open-sans', melograno_open_sans_font_url(), array(), null );
		wp_enqueue_style( 'melograno-raleway', melograno_raleway_font_url(), array(), null );
		wp_enqueue_style( 'genericons', get_template_directory_uri() . '/genericons/genericons.css', array(), '3.0.3' );
		wp_enqueue_style('animate', get_template_directory_uri().'/animate.css', array(), '1', 'screen');  
		wp_enqueue_style( 'melograno-style', get_stylesheet_uri());
	}
}
add_action( 'wp_enqueue_scripts', 'melograno_scripts_styles' );

/**
 * Implement the Custom Header feature.
 */
require get_template_directory() . '/inc/custom-header.php';

/**
 * Custom template tags for this theme.
 */
require get_template_directory() . '/inc/template-tags.php';

/**
 * Custom functions that act independently of the theme templates.
 */
require get_template_directory() . '/inc/extras.php';

/**
 * Customizer additions.
 */
require get_template_directory() . '/inc/customizer.php';