<?php
/**
 * giant functions and definitions
 *
 * @package giant
 */

/**
 * Set the content width based on the theme's design and stylesheet.
 */
if ( ! isset( $content_width ) )
	$content_width = 750; /* pixels */

if ( ! function_exists( 'giant_setup' ) ) :
/**
 * Set up theme defaults and register 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 post thumbnails.
 */
function giant_setup() {
    global $cap, $content_width;

    // This theme styles the visual editor with editor-style.css to match the theme style.
    add_editor_style();

    if ( function_exists( 'add_theme_support' ) ) {

		/**
		 * Add default posts and comments RSS feed links to head
		*/
		add_theme_support( 'automatic-feed-links' );
		
		/**
		 * Enable support for Post Thumbnails on posts and pages
		 *
		 * @link http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
		*/
		add_theme_support( 'post-thumbnails' );
		
		/**
		 * Enable support for Post Formats
		*/
		add_theme_support( 'post-formats', array( 'aside', 'image', 'video', 'quote', 'link' ) );
		
		/**
		 * Setup the WordPress core custom background feature.
		*/
		add_theme_support( 'custom-background', apply_filters( 'giant_custom_background_args', array(
			'default-color' => 'ffffff',
			'default-image' => '',
		) ) );
	
    }

	/**
	 * Make theme available for translation
	 * Translations can be filed in the /languages/ directory
	 * If you're building a theme based on giant, use a find and replace
	 * to change 'giant' to the name of your theme in all the template files
	*/
	load_theme_textdomain( 'giant', get_template_directory() . '/languages' );

	/**
	 * This theme uses wp_nav_menu() in one location.
	*/ 
    register_nav_menus( array(
        'primary'  => __( 'Header bottom menu', 'giant' ),
    ) );
	
	/**
	 * Enable support for Slider Thumbnails
	*/
	
	add_image_size( 'giant-slider-image', 960, 353, true );
}
endif; // giant_setup
add_action( 'after_setup_theme', 'giant_setup' );

/**
 * Register widgetized area and update sidebar with default widgets
 */
function giant_widgets_init() {
	register_sidebar( array(
		'name'          => __( 'Right Sidebar', 'giant' ),
		'id'            => 'sidebar-1',
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget'  => '</aside>',
		'before_title'  => '<h3 class="widget-title">',
		'after_title'   => '</h3>',
	) );
}
add_action( 'widgets_init', 'giant_widgets_init' );

/**
 * Enqueue scripts and styles
 */
function giant_scripts() {

    // load bootstrap css
    wp_enqueue_style( 'giant-bootstrapcss', get_template_directory_uri() . '/css/bootstrap.min.css' );

    // load giant styles
    wp_enqueue_style( 'giant-style', get_stylesheet_uri() );

    // load bootstrap js
    wp_enqueue_script('giant-bootstrapjs', get_template_directory_uri().'/js/bootstrap.min.js', array('jquery') );

    // load bootstrap wp js
    wp_enqueue_script( 'giant-bootstrapwp', get_template_directory_uri() . '/js/bootstrap-wp.js', array('jquery') );

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

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

    if ( is_singular() && wp_attachment_is_image() ) {
        wp_enqueue_script( 'giant-keyboard-image-navigation', get_template_directory_uri() . '/js/keyboard-image-navigation.js', array( 'jquery' ), '20120202' );
    }
	
	/*
	 * Adds slider Javascript  
	 */
	wp_enqueue_script( 'flexslider', get_template_directory_uri() . '/js/flexslider.min.js', array( 'jquery' ), null, true );
	
	/*
	 * Adds ticker Javascript  
	 */
	wp_enqueue_script( 'ticker', get_template_directory_uri() . '/js/jquery.ticker.min.js', array( 'jquery' ), null, true );
	
}
add_action( 'wp_enqueue_scripts', 'giant_scripts' );

/**
 * 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';

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

/**
 * Load custom WordPress nav walker.
 */
require get_template_directory() . '/inc/bootstrap-wp-navwalker.php';

/*
 * flexslider js customization
 */
function giant_slider_script() {
?>

<?php if( is_front_page() && ! is_paged() ) : ?>
<script>
 jQuery(document).ready(function($){
	$('.flexslider').flexslider({
		selector          : '.slides > li',
		animation         : 'slide',
		easing            : 'swing',
		direction         : 'horizontal',
		animationLoop     : true,
		smoothHeight       : true,
		startAt           : 0,
		slideshow         : true,
		slideshowSpeed    : 7000,
		animationSpeed    : 600,
		initDelay         : 0,
		pauseOnAction     : true,
		pauseOnHover      : true,
		before: function() {
		$('.flexslider .flex-caption').hide();
		},
		after: function() {
		$('.flexslider .flex-caption').fadeIn();
		}
	});
	});
	

</script>
<?php endif;
}
add_action ('wp_head', 'giant_slider_script');

/*
 * Ticker
 */
 
function cute_news_ticker(){
	extract( shortcode_atts( array(
		'id' => 'tickrid',
		'speed' => '3000',
		'typespeed' => '50',
		'text' => 'Latest News',
	), $atts, 'projects' ) );
	
   $cat_id = get_theme_mod( 'giant_category' );
   $count = get_theme_mod('giant_ticker_count');
	
    $q = new WP_Query(
        array(	
			'posts_per_page' => $count, 
			'post_type' => 'post', 
			'category_name' => get_cat_name( $cat_id ),
		)
    );		
		
		
	$list = '
	<script type="text/javascript">
		jQuery(document).ready(function(){
			jQuery("#cutetickr'.$id.'").ticker({
				itemSpeed: '.$speed.',
				cursorSpeed: '.$typespeed.',
			});
		}); 	
	</script>	
	<div id="cutetickr'.$id.'" class="ticker"><strong class="ticker-header">'.$text.'</strong><ul>';
	while($q->have_posts()) : $q->the_post();
		$idd = get_the_ID();
		$list .= '
		
			<li><a href="#">'.get_the_title().'</a></li>
		
		';        
	endwhile;
	$list.= '</ul></div>';
	wp_reset_query();
	return $list;
}