<?php
/**
 * moment functions and definitions.
 *
 * @link https://developer.wordpress.org/themes/basics/theme-functions/
 *
 * @package Moment
 */

/**
 * Get the path for the file ( to support child theme )
 *
 * @since Moment 1.0.0
 *
 * @param string $file_path, path from the theme
 * @return string full path of file inside theme
 *
 */
if( !function_exists('moment_file_directory') ){
	function moment_file_directory( $file_path ){

		if( file_exists( trailingslashit( get_stylesheet_directory() ) . $file_path) ){
			return trailingslashit( get_stylesheet_directory() ) . $file_path;
		}
		else{
			return trailingslashit( get_template_directory() ) . $file_path;
		}
	}
}

/**
 * require moment int.
 */
$moment_init_file_path = moment_file_directory('inc/init.php');
require $moment_init_file_path;

if ( ! function_exists( 'moment_setup' ) ) :
/**
 * Sets up theme defaults and registers support for various WordPress features.
 *
 * Note that this function is hooked into the after_setup_theme hook, which
 * runs before the init hook. The init hook is too late for some features, such
 * as indicating support for post thumbnails.
 */
function moment_setup() {
	/*
	 * Make theme available for translation.
	 * Translations can be filed in the /languages/ directory.
	 * If you're building a theme based on moment, use a find and replace
	 * to change 'moment' to the name of your theme in all the template files.
	 */
	load_theme_textdomain( 'moment', get_template_directory() . '/languages' );

	// Add default posts and comments RSS feed links to head.
	add_theme_support( 'automatic-feed-links' );

	/*
	 * Let WordPress manage the document title.
	 * By adding theme support, we declare that this theme does not use a
	 * hard-coded <title> tag in the document head, and expect WordPress to
	 * provide it for us.
	 */
	add_theme_support( 'title-tag' );

	/*
	 * Enable support for Post Thumbnails on posts and pages.
	 *
	 * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
	 */
	add_theme_support( 'post-thumbnails' );


	/*
	 * Enable support for image sizes on posts and pages.
	 *
	 * @link https://developer.wordpress.org/reference/functions/add_image_size/
	 */
	add_image_size( 'moment-costume-medium', 430, 300, true );
	add_image_size( 'moment-costume-archive', 1095, 455, true );



	// This theme uses wp_nav_menu() in one location.
	register_nav_menus( array(
		'primary' => esc_html__( 'Primary', 'moment' ),
		'social' => esc_html__( 'Social Menu', 'moment' )
	) );

	/*
	 * Switch 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',
		'gallery',
		'caption',
	) );

	/*
	 * Enable support for Post Formats.
	 * See https://developer.wordpress.org/themes/functionality/post-formats/
	 */
	add_theme_support( 'post-formats', array(
		'aside',
		'image',
		'video',
		'quote',
		'link',
	) );

	// Set up the WordPress core custom background feature.
	add_theme_support( 'custom-background', apply_filters( 'moment_custom_background_args', array(
		'default-color' => 'ffffff',
		'default-image' => '',
	) ) );

	/*implimenting new feature from 4.5*/
	add_theme_support( 'custom-logo', array(
	   'height'      => 175,
	   'width'       => 400,
	   'flex-width' => true,
	   'header-text' => array( 'site-title', 'site-description' ),
	) );
	
}
endif;
add_action( 'after_setup_theme', 'moment_setup' );

/**
 * Set the content width in pixels, based on the theme's design and stylesheet.
 *
 * Priority 0 to make it available to lower priority callbacks.
 *
 * @global int $content_width
 */
function moment_content_width() {
	$GLOBALS['content_width'] = apply_filters( 'moment_content_width', 640 );
}
add_action( 'after_setup_theme', 'moment_content_width', 0 );

/**
 * Enqueue scripts and styles.
 */
function moment_scripts() {
		global $moment_customizer_all_values;

		/*google font*/
		$moment_font_family_primary_option = $moment_customizer_all_values['moment-font-family-Primary'];
		$moment_font_family_site_identity_option = $moment_customizer_all_values['moment-font-family-site-identity'];
		$moment_font_family_title_option = $moment_customizer_all_values['moment-font-family-title'];
		$moment_font_family_subtitle_option = $moment_customizer_all_values['moment-font-family-subtitle'];

		wp_enqueue_style( 'moment-googleapis-primary', '//fonts.googleapis.com/css?family='.$moment_font_family_primary_option.'', array(), '' );/*added*/
		wp_enqueue_style( 'moment-googleapis-site-identity', '//fonts.googleapis.com/css?family='.$moment_font_family_site_identity_option.'', array(), '' );/*added*/
		wp_enqueue_style( 'moment-googleapis-title', '//fonts.googleapis.com/css?family='.$moment_font_family_title_option.'', array(), '' );/*added*/
		wp_enqueue_style( 'moment-googleapis-sub-titile', '//fonts.googleapis.com/css?family='.$moment_font_family_subtitle_option.'', array(), '' );/*added*/
	 	/*animation*/
	    wp_enqueue_style( 'animate-css', get_template_directory_uri() . '/assets/frameworks/wow/css/animate.min.css', array(), '3.4.0' );/*added*/

		// Style
		wp_enqueue_style( 'jquery-mmenu-all-style', get_template_directory_uri() . '/assets/frameworks/mmenu/css/jquery.mmenu.all.css' );/*added*/
		
		wp_enqueue_style( 'slick-css', get_template_directory_uri() . '/assets/frameworks/slick/slick.css', array(), '3.4.0' );/*added*/
		
		wp_enqueue_style( 'slick-theme', get_template_directory_uri() . '/assets/frameworks/slick/slick-theme.css', array(), '3.4.0' );/*added*/
		
		wp_enqueue_style( 'prettyphoto-style', get_template_directory_uri() . '/assets/frameworks/prettyphoto/css/prettyPhoto.css', array(), '3.1.6' );/*added*/
		
		wp_enqueue_style( 'moment-style', get_stylesheet_uri() );
		
		wp_enqueue_script( 'modernizr', get_template_directory_uri() . '/assets/js/modernizr.min.js', array('jquery'), '2.8.3', true );
		
		wp_enqueue_script( 'isotope', get_template_directory_uri() . '/assets/frameworks/isotope/isotope.pkgd.js', array('jquery'), '3.0.1', true );
		
		wp_enqueue_script( 'imagesloaded', get_template_directory_uri() . '/assets/frameworks/imagesloaded/imagesloaded.pkgd.min.js', array('jquery'), '4.1.0', true );

		wp_enqueue_script( 'custom-isotopes', get_template_directory_uri() . '/assets/js/custom-isotopes.js',array('jquery'), '1.0.0', true);
		
		wp_enqueue_script( 'navigation', get_template_directory_uri() . '/assets/js/navigation.js', array(), '20120206', true );
		
		wp_enqueue_script('easing-js', get_template_directory_uri() . '/assets/frameworks/jquery.easing/jquery.easing.js', array('jquery'), '0.3.6', 1);

	    wp_enqueue_script('wow', get_template_directory_uri() . '/assets/frameworks/wow/js/wow.min.js', array('jquery'), '1.1.2', 1);

		wp_enqueue_script( 'jquery-mmenu', get_template_directory_uri() . '/assets/frameworks/mmenu/js/jquery.mmenu.min.all.js', array('jquery'), '4.7.5', false );
		
		wp_enqueue_script( 'prettyphoto-script', get_template_directory_uri() . '/assets/frameworks/prettyphoto/js/jquery.prettyPhoto.js', array('jquery'), '3.1.6', false  );
		
		// Script and style of slick

		wp_enqueue_script( 'slick-js', get_template_directory_uri() . '/assets/frameworks/slick/slick.min.js', array('jquery'), '1.6.0', true );
		
		/*cycle2 slider*/
		wp_enqueue_script( 'cycle2-script', get_template_directory_uri() . '/assets/frameworks/cycle2/js/jquery.cycle2.js', array( 'jquery' ), '2.1.6', true );
		
		wp_enqueue_script( 'cycle2-script-flip', get_template_directory_uri() . '/assets/frameworks/cycle2/js/jquery.cycle2.flip.js', array( 'jquery' ), '20140128', true );
		
		wp_enqueue_script( 'cycle2-script-scrollVert', get_template_directory_uri() . '/assets/frameworks/cycle2/js/jquery.cycle2.scrollVert.js', array( 'jquery' ), '20140128', true );
		
		wp_enqueue_script( 'cycle2-script-shuffle', get_template_directory_uri() . '/assets/frameworks/cycle2/js/jquery.cycle2.shuffle.js', array( 'jquery' ), '20140128', true );
		
		wp_enqueue_script( 'cycle2-script-tile', get_template_directory_uri() . '/assets/frameworks/cycle2/js/jquery.cycle2.tile.js', array( 'jquery' ), '20140128', true );
    
    	wp_enqueue_script( 'cycle2-script-swipe', get_template_directory_uri() . '/assets/frameworks/cycle2/js/jquery.cycle2.swipe.js', array( 'jquery' ), '20121120', true );
    	
    	wp_enqueue_script( 'cycle2-script-video-youtube', get_template_directory_uri() . '/assets/frameworks/cycle2/js/jquery.cycle2.video.js', array( 'jquery' ), '20130708', true );

		wp_enqueue_script( 'skip-link-focus-fix', get_template_directory_uri() . '/assets/js/skip-link-focus-fix.js', array(), '20130115', true );

	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
		wp_enqueue_script( 'comment-reply' );
	}
}
add_action( 'wp_enqueue_scripts', 'moment_scripts' );

/**
 * Enqueue custom script.
 */
function moment_custom_scripts() {
	global $moment_customizer_all_values;
		wp_register_script('moment-custom', get_template_directory_uri() . '/assets/js/salientthemes-custom.js', array('jquery'), '1.0.0', 1);
		wp_enqueue_script( "moment-custom" );
	    wp_localize_script( "moment-custom", "google_map_value", $moment_customizer_all_values );
	}
add_action( "wp_enqueue_scripts", "moment_custom_scripts" );

/*admin css*/
function moment_custom_layout_script() {
    wp_enqueue_script( 'moment_custom_layout_scripts', get_template_directory_uri() . 'assets/css/layout-meta.css' );
}
add_action( 'admin_enqueue_scripts', 'moment_custom_layout_script' );
/**
 * 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';

/**
 * Load Jetpack compatibility file.
 */
require get_template_directory() . '/inc/jetpack.php';