<?php

// Load Base Javascripts

if (!is_admin()) add_action( 'init', 'load_base_js' );
function load_base_js( ) {
	
	wp_enqueue_script('jquery');
	wp_enqueue_script('jqueryui', get_bloginfo('template_directory').'/includes/js/jquery-ui-1.7.2.custom.min.js', array('jquery'));
	wp_enqueue_script('superfish', get_bloginfo('template_directory').'/includes/js/nav/superfish.js', array( 'jquery' ) );
	wp_enqueue_script('supersubs', get_bloginfo('template_directory').'/includes/js/nav/supersubs.js', array( 'jquery' ) );
	wp_enqueue_script('search', get_bloginfo('template_directory').'/includes/js/search.js', array( 'jquery' ) );
	wp_enqueue_script('swfobject');

}

// Load Conditional Javascripts

function load_conditional_js() {
	
	if(is_home()){
		if ( get_option('gpp_slideshow') == 'true' || !get_option('gpp_slideshow') || $themename = "F8-Remixed" ) {
			wp_enqueue_script('cycle', get_bloginfo('template_directory').'/includes/js/jquery.cycle.js', array('jquery'));
		}	
		if ( get_option('gpp_slider') == 'true' || !get_option('gpp_slider') ) {	
			wp_enqueue_script('sliderui', get_bloginfo('template_directory').'/includes/js/slider/ui.slider.js', array('jquery'));
		  wp_enqueue_script('slider', get_bloginfo('template_directory').'/includes/js/slider/slider.js', array('jquery'));
		}
		if ( get_option('gpp_slider_posts') == 'true' || !get_option('gpp_slider_posts')) {
		  wp_enqueue_script('cycle', get_bloginfo('template_directory').'/includes/js/jquery.cycle.js', array('jquery'));
		}	
	}
}

// Load Dom Ready Javascripts

function load_dom_ready_js() {

	$slideshow_time = get_option('gpp_slideshow_time');
	$slideshow_speed = get_option('gpp_slideshow_speed');
	
	if(!$slideshow_time) { $slideshow_time = "3500"; }
	if(!$slideshow_speed) { $slideshow_speed = "1000"; }

	$doc_ready_script .= '
	<script type="text/javascript">
		jQuery(document).ready(function(){
		
	        jQuery("ul.sf-menu").supersubs({ 
	            minWidth:    12,
	            maxWidth:    27,
	            extraWidth:  1
	        }).superfish({
	        		delay:       500,
					animation:   {opacity:"show",height:"show"},
					speed:       "fast",
					autoArrows:  true,
					dropShadows: true
	        });';
				
	if(is_home()) {
		if ( get_option('gpp_slideshow') == 'true' || !get_option('gpp_slideshow') ) {
	$doc_ready_script .= '
	
		jQuery(function() {
		    jQuery("#slideshow").cycle({
		        speed: ' . $slideshow_speed . ',
		        timeout: ' . $slideshow_time . ',
				pause: 1
		    });
		});';
		}
			
		if ( get_option('gpp_slider') == 'true' || !get_option('gpp_slider') ) {
	$doc_ready_script .= '
			jQuery("#content-slider").slider({
				animate: true,
				change: handleSliderChange,
				slide: handleSliderSlide
			});';
		}
		
		if($themename = "F8-Remixed") {
			$doc_ready_script .= '
			
				jQuery(function() {
				    jQuery("#static-portfolio").cycle({
				        speed: 4000,
				        timeout: 1000,
						pause: 1
				    });
				});';
		}
			
		if ( get_option('gpp_slider_posts') == 'true' || !get_option('gpp_slider_posts') ) {
	$doc_ready_script .= '
			jQuery(function() {
			
			    jQuery("#slider-posts").cycle({
			        fx:      "scrollHorz",
			        timeout:  0,
			        prev:    "#prev",
			        next:    "#next",
			        pager:   "#slider-nav",
					containerResize: 0
			    });
			});';
		}
	}
	$doc_ready_script .= '});
	</script>
			';
					
	echo $doc_ready_script;
	
}

// Add Javascripts

add_action('template_redirect', 'load_conditional_js');
add_action('wp_head', 'load_dom_ready_js');
?>