<?php
/**
 * atracium functions and definitions
 *
 * @link https://developer.wordpress.org/themes/basics/theme-functions/
 *
 * @package atracium
 */

if ( ! function_exists( 'atracium_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 atracium_setup() {
		/*
		 * Make theme available for translation.
		 * Translations can be filed in the /languages/ directory.
		 * If you're building a theme based on atracium, use a find and replace
		 * to change 'atracium' to the name of your theme in all the template files.
		 */
		load_theme_textdomain( 'atracium', 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' );
		add_image_size( 'atracium-the-post' , 800, 99999);

		// This theme uses wp_nav_menu() in one location.
		register_nav_menus( array(
			'menu-1' => esc_html__( 'Primary', 'atracium' ),
		) );

		/*
		 * 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',
		) );

		// Set up the WordPress core custom background feature.
		add_theme_support( 'custom-background', apply_filters( 'atracium_custom_background_args', array(
			'default-color' => 'fafafa',
			'default-image' => '',
		) ) );

		// Add theme support for selective refresh for widgets.
		add_theme_support( 'customize-selective-refresh-widgets' );

		/**
		 * Add support for core custom logo.
		 *
		 * @link https://codex.wordpress.org/Theme_Logo
		 */
		add_theme_support( 'custom-logo', array(
			'height'      => 350,
			'width'       => 500,
			'flex-width'  => true,
			'flex-height' => true,
			'header-text' => array( 'site-title', 'site-description' ),
		) );
		
	}
endif;
add_action( 'after_setup_theme', 'atracium_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 atracium_content_width() {
	$GLOBALS['content_width'] = apply_filters( 'atracium_content_width', 800 );
}
add_action( 'after_setup_theme', 'atracium_content_width', 0 );

/*
* Add Custom Picture for page Support
* Add @El-Sayad
*/

function cat_setup()
{
	add_theme_support('image');
	add_image_size('categories', 100, 100, true);
}

add_action('after_setup_theme', 'cat_setup');

/**
 * Register widget area.
 *
 * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
 */
function atracium_widgets_init() {
	register_sidebar( array(
		'name'          => esc_html__( 'Sidebar', 'atracium' ),
		'id'            => 'sidebar-1',
		'description'   => esc_html__( 'Add widgets here.', 'atracium' ),
		'before_widget' => '<section id="%1$s" class="widget %2$s">',
		'after_widget'  => '</section>',
		'before_title'  => '<div class="widget-title"><h3>',
		'after_title'   => '</h3></div>',
	) );
	register_sidebar( array(
		'name'          => esc_html__( 'Push Sidebar', 'atracium' ),
		'id'            => 'sidebar-push',
		'description'   => esc_html__( 'Add widgets here.', 'atracium' ),
		'before_widget' => '<section id="%1$s" class="widget %2$s">',
		'after_widget'  => '</section>',
		'before_title'  => '<div class="widget-title"><h3>',
		'after_title'   => '</h3></div>',
	) );
	register_sidebar( array(
		'name'          => esc_html__( 'Footer Left', 'atracium' ),
		'id'            => 'footer-1',
		'description'   => esc_html__( 'Add widgets here.', 'atracium' ),
		'before_widget' => '<section id="%1$s" class="widget %2$s">',
		'after_widget'  => '</section>',
		'before_title'  => '<div class="widget-title"><h3>',
		'after_title'   => '</h3></div>',
	) );
	register_sidebar( array(
		'name'          => esc_html__( 'Footer Center', 'atracium' ),
		'id'            => 'footer-2',
		'description'   => esc_html__( 'Add widgets here.', 'atracium' ),
		'before_widget' => '<section id="%1$s" class="widget %2$s">',
		'after_widget'  => '</section>',
		'before_title'  => '<div class="widget-title"><h3>',
		'after_title'   => '</h3></div>',
	) );
	register_sidebar( array(
		'name'          => esc_html__( 'Footer Right', 'atracium' ),
		'id'            => 'footer-3',
		'description'   => esc_html__( 'Add widgets here.', 'atracium' ),
		'before_widget' => '<section id="%1$s" class="widget %2$s">',
		'after_widget'  => '</section>',
		'before_title'  => '<div class="widget-title"><h3>',
		'after_title'   => '</h3></div>',
	) );
}
add_action( 'widgets_init', 'atracium_widgets_init' );

/**
 * Enqueue scripts and styles.
 */
function atracium_scripts() {
	// Add animated-headline, used in the main stylesheet.
	wp_enqueue_style( 'animated-headline', get_template_directory_uri() .'/css/animated-headline.css');
	// Load our main stylesheet.
	wp_enqueue_style( 'lightslider', get_template_directory_uri() .'/css/lightslider.min.css');
	// Add Bootstrap File, used in the main stylesheet.
	wp_enqueue_style( 'bootstrap-css', get_template_directory_uri() . '/css/bootstrap.min.css' );
	// Add Font Awesome, used in the main stylesheet.
	wp_enqueue_style( 'font-awesome', get_template_directory_uri() .'/css/font-awesome.min.css');
	// Load our googlefonts
	$query_args = array(
		'family' => 'Playfair+Display:400,700%7CMuli:400,700'
	);
	wp_enqueue_style( 'atracium-googlefonts', add_query_arg( $query_args, "//fonts.googleapis.com/css" ), array(), null );
	// Load our main stylesheet.
	
	wp_enqueue_style( 'atracium-style', get_stylesheet_uri() );



	// Remove Registeration of JQuery
	// wp_deregister_script('jquery');
	// Reregisteration Of JQuery
	wp_register_script('jquery', includes_url('/js/jquery/jquery.js'), false, '', true);

	// Add Bootstrap with Jquery files, used in the main JavaScript.
	wp_enqueue_script( 'bootstrap-js', get_template_directory_uri() . '/js/bootstrap.min.js', array(jquery), false, true );

	// Add bxslider with Jquery files, used in the main JavaScript.
	wp_enqueue_script( 'jquery-bxslider', get_template_directory_uri() . '/js/jquery.bxslider.min.js', array(jquery), false, true );

	// Add animated-headline with Jquery files, used in the main JavaScript.
	wp_enqueue_script( 'animated-headline', get_template_directory_uri() . '/js/animated-headline.js', array(jquery), false, true );

	// Add lightslider with Jquery files, used in the main JavaScript.
	wp_enqueue_script( 'lightslider', get_template_directory_uri() . '/js/lightslider.min.js', array(jquery), false, true );

	// Load our custom JavaScript.
	wp_enqueue_script( 'atracium-custom', get_template_directory_uri() . '/js/jquery.custom.js', array('jquery'), '1.0', true );
	

	wp_enqueue_script( 'atracium-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20151215', true );

	if ( is_active_sidebar( 'sidebar-push' ) ) {
		wp_enqueue_script( 'atracium-nanoScroll', get_template_directory_uri() . '/js/jquery.nanoscroller.min.js', array('jquery'), '1.0', true );
	}

	wp_enqueue_script( 'atracium-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20151215', true );

	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
		wp_enqueue_script( 'comment-reply' );
	}
	
}
add_action( 'wp_enqueue_scripts', 'atracium_scripts' );

	/*
	* Custamize The Excerpt Length
	* Add @El-Sayad
	*/
	function atracium_excerpt_length($length)
	{
		return 12;
	}
	add_filter('excerpt_length', 'atracium_excerpt_length');

	/*
	* Custamize The Excerpt More
	* Add @El-Sayad
	*/
	function atracium_excerpt_more($more)
	{
		return ' ...';
	}
	add_filter('excerpt_more', 'atracium_excerpt_more');



/**
 * Implement the Custom menu feature.
 */
require get_template_directory() . '/inc/options.php';

/**
 * 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';

/**
 * Functions which enhance the theme by hooking into WordPress.
 */
require get_template_directory() . '/inc/template-functions.php';

/**
 * Customizer additions.
 */
require get_template_directory() . '/inc/customizer.php';

/**
 * Load Jetpack compatibility file.
 */
if ( defined( 'JETPACK__VERSION' ) ) {
	require get_template_directory() . '/inc/jetpack.php';
}

/**
 * Load PRO Button in the customizer
 */
require_once( trailingslashit( get_template_directory() ) . 'inc/pro-button/class-customize.php' );

/* Calling in the admin area for the Welcome Page */
if ( is_admin() ) {
	require get_template_directory() . '/inc/admin/atracium-admin-page.php';
}
