<?php
/**
 * This file loads the CSS and Javascript used for the theme.
 * @package Ultra WordPress Theme
 * @since 1.0
 * @author AJ Clarke : http://wpexplorer.com
 * @copyright Copyright (c) 2012, AJ Clarke
 * @link http://wpexplorer.com
 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 */
 
 
add_action('wp_enqueue_scripts','wpex_load_scripts');
function wpex_load_scripts() {
	
	
	/*******
	*** CSS
	*******************/
	
	// Main
	wp_enqueue_style( 'style', get_stylesheet_uri() );
	
	// Font Awesome
	wp_enqueue_style('font-awesome', WPEX_CSS_DIR . '/font-awesome.min.css', 'style', true);
	
	// Shortcodes
	wp_dequeue_style('symple_shortcode_styles');
	
	// Responsive => call last
	if( of_get_option('responsive','1') == '1') wp_enqueue_style('wpex-responsive', WPEX_CSS_DIR . '/responsive.css');
	

	/*******
	*** jQuery
	*******************/
	
	// Main Scripts = jquery, menu
	wp_enqueue_script('jquery');
	wp_enqueue_script('superfish', WPEX_JS_DIR .'/superfish.js', array('jquery'), '1.4.8', true);
	wp_enqueue_script('tooltipster', WPEX_JS_DIR .'/tooltipster.js', array('jquery'), '2.1', true);
	
	// Responsive
	if( of_get_option('responsive','1') == '1') {
		wp_enqueue_script('uniform', WPEX_JS_DIR .'/uniform.js', array('jquery'), '1.7.5', true);
		wp_enqueue_script('wpex-responsive', WPEX_JS_DIR .'/responsive.js', array('jquery','uniform'), '', true);
		
	}
	
	// Flexslider
	wp_enqueue_script('easing', WPEX_JS_DIR .'/easing.js', array('jquery'), '1.3', true);
	wp_enqueue_script('flexslider', WPEX_JS_DIR .'/flexslider-min.js', array('jquery'), '2', true);
	wp_register_script('gallery-format-flexslider', WPEX_JS_DIR .'/gallery-format-flexslider.js', array('jquery','flexslider'), '1.0', true);
	wp_register_script('portfolio-flexslider', WPEX_JS_DIR .'/portfolio-flexslider.js', array('jquery','flexslider'), '1.0', true);
	wp_register_script('services-flexslider', WPEX_JS_DIR .'/services-flexslider.js', array('jquery','flexslider'), '1.0', true);
	wp_register_script('testimonials-shortcode', WPEX_JS_DIR .'/testimonials-shortcode.js', array('jquery','flexslider'), '1.0', true);
	
	// Lightbox
	wp_enqueue_script('mousewheel', WPEX_JS_DIR .'/mousewheel.js', array('jquery'), '3.0.6', true);
	wp_enqueue_script('fancybox', WPEX_JS_DIR .'/fancybox.js', array('jquery'), '2', true);
	wp_enqueue_script('fancybox-media', WPEX_JS_DIR .'/fancybox-media.js', array('jquery'), '1.0.5', true);
	
	// BX Slider
	wp_register_script('bxslider', WPEX_JS_DIR .'/bxslider.js', array('jquery','easing'), 4.0, true);
	wp_register_script('wpex-posts-carousel-init', WPEX_JS_DIR .'/posts-carousel-init.js', array('jquery','easing','bxslider'), 1.0, true);
	wp_register_script('wpex-related-posts-carousel', WPEX_JS_DIR .'/related-posts-carousel.js', array('jquery','easing','bxslider'), 4.0, true);
	
	// Comment replies
	if( is_single() || is_page() ) wp_enqueue_script('comment-reply');
	
	// Isotope
	wp_register_script('isotope', WPEX_JS_DIR .'/isotope.js', array('jquery'), '1.5.19', true);
	wp_register_script('wpex-isotope-recent-posts', WPEX_JS_DIR .'/isotope-recent-posts.js', array('jquery'), '1.0', true);
	wp_register_script('wpex-isotope-faq', WPEX_JS_DIR .'/isotope-faq.js', array('jquery'), '1.0', true);
	wp_register_script('wpex-isotope-services', WPEX_JS_DIR .'/isotope-services.js', array('jquery'), '1.0', true);
	wp_register_script('wpex-isotope-staff', WPEX_JS_DIR .'/isotope-staff.js', array('jquery'), '1.0', true);
	wp_register_script('wpex-isotope-portfolio', WPEX_JS_DIR .'/isotope-portfolio.js', array('jquery'), '1.0', true);
	
	// FAQ Toggle
	wp_register_script('faq-toggles', WPEX_JS_DIR .'/faq-toggles.js', array('jquery'), '1.0', true);
	
	// Localize responsive nav
	$nav_params = array( 'text' => of_get_option('responsive_menu_text', __('Menu','wpex') ) );
	wp_localize_script( 'wpex-responsive', 'responsiveLocalize', $nav_params );
	
	// Global => initializes scripts
	wp_enqueue_script('wpex-global-init', WPEX_JS_DIR .'/global.js', array('jquery'), '1.0', true);
	
	
} //end wpex_load_scripts()


/**
* Browser Specific CSS
* @Since 1.0
*/
add_action('wp_head', 'wpex_ie_css');
function wpex_ie_css() {
	echo '<!-- Custom CSS For IE -->';
	echo '<!--[if gte IE 9]><style type="text/css">.gradient {filter: none;}</style><![endif]-->';
	echo '<!--[if IE 8]><link rel="stylesheet" type="text/css" href="'. get_template_directory_uri() .'/css/ie8.css" media="screen" /><![endif]-->';
	echo '<!--[if IE 7]><link rel="stylesheet" type="text/css" href="'. get_template_directory_uri() .'/css/font-awesome-ie7.min.css" media="screen" /><![endif]-->';
}


/**
* HTML5 & CSS3 IE Dependencies
* @Since 1.0
*/
add_action('wp_head', 'wpex_html_css_dependencies');
function wpex_html_css_dependencies() {
	echo '<!-- HTML&CSS Dependencies for IE -->';
	echo '<!--[if lt IE 9]>';
	echo '<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>';
	if( of_get_option('responsive','1') == '1') {
		echo '<script src="http://css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js"></script>';
	}
	echo '<![endif]-->';
}


/**
* Retina Logo Support
* @Since 1.0
*/
if( of_get_option('custom_retina_logo') && of_get_option('logo_height') && of_get_option('logo_width') ) {	
	add_action('wp_head', 'wpex_retina_logo');
	function wpex_retina_logo() {
		
		// Get retina options from theme panel and set vars
		$logo_url = of_get_option('custom_retina_logo','');
		$logo_width = of_get_option('logo_height','');
		$logo_height = of_get_option('logo_width','');
				
		$wpex_retina_logo_js = '<!-- Retina Logo -->
		<script type="text/javascript">
		jQuery(function($){
			if (window.devicePixelRatio == 2) {
				$("#logo img").attr("src", "'. $logo_url .'");
				$("#logo img").attr("width", "'. $logo_width .'");
				$("#logo img").attr("height", "'. $logo_height .'");
			 }
		});
		</script>';	
		
		// Remove spacing from js for speed
		$wpex_retina_logo_js =  preg_replace( '/\s+/', ' ', $wpex_retina_logo_js );
		
		// Output the custom retina logo js
		echo $wpex_retina_logo_js;
	}
}