<?php
function ocmx_add_scripts()
	{
		global $themeid;
		
		//Add support for 2.9 and 3.0 functions and setup jQuery for theme
		wp_enqueue_script("jquery");
		if(!is_admin()) :
			
	        wp_enqueue_script( "maps","http://maps.googleapis.com/maps/api/js?sensor=false");
			wp_enqueue_script( "superfish", get_bloginfo("template_directory")."/scripts/superfish.js", array( "jquery" ) );
			wp_enqueue_script( $themeid."-jquery", get_bloginfo("template_directory")."/scripts/".$themeid."_jquery.js", array( "jquery" ) );
			wp_enqueue_script( "fitvid", get_bloginfo("template_directory")."/scripts/jquery.fitvids.js", array( "jquery" ) );
			wp_enqueue_script( "masonary", get_bloginfo("template_directory")."/scripts/masonry.js", array( "jquery" ) );
			wp_enqueue_script( $themeid."-lightbox", get_bloginfo("template_directory")."/scripts/jquery.lightbox-0.5.js", array( "jquery" ) );
			wp_enqueue_script( "map", get_bloginfo("template_directory")."/scripts/maps.js", array( "jquery" ) );
			wp_enqueue_script( "jplayer", get_bloginfo("template_directory")."/scripts/jquery.jplayer.min.js", array( "jquery" ) );
			
			//Localization
			wp_localize_script( $themeid."-jquery", "ThemeAjax", array( "ajaxurl" => admin_url( "admin-ajax.php" ) ) );
		endif;
		//AJAX Functions
		add_action( 'wp_ajax_nopriv_ocmx_comment-post', 'ocmx_comment_post'  );
		add_action( 'wp_ajax_ocmx_comment-post', 'ocmx_comment_post' );	
		add_action( 'wp_ajax_ocmx_save-options', 'update_ocmx_options');
		add_action( 'wp_ajax_ocmx_reset-options', 'reset_ocmx_options');
		add_action( 'wp_ajax_ocmx_ads-refresh', 'ocmx_ads_refresh' );
		add_action( 'wp_ajax_ocmx_ads-remove', 'ocmx_ads_remove' );
		add_action( 'wp_ajax_ocmx_layout-refresh', 'ocmx_layout_refresh' );
		add_action( 'wp_ajax_ocmx_ajax-upload', 'ocmx_ajax_upload' );
		add_action( 'wp_ajax_ocmx_remove-image', 'ocmx_ajax_remove_image' );
		
		/* Back-end */
		if(is_admin()):
			wp_enqueue_script( 'jquery-ui-draggable' );
			wp_enqueue_script( 'jquery-ui-droppable' );
			wp_enqueue_script( 'jquery-ui-sortable' );
			wp_enqueue_script( 'jquery-ui-tabs' );
			wp_enqueue_script( "ajaxupload", get_bloginfo("template_directory")."/scripts/ajaxupload.js", array( "jquery" ) );
			wp_enqueue_script( "ocmx-jquery", get_bloginfo("template_directory")."/scripts/ocmx_jquery.js", array( "jquery" ) );
			wp_localize_script( "ocmx-jquery", "ThemeAjax", array( "ajaxurl" => admin_url( "admin-ajax.php" ) ) );
			wp_enqueue_script( "ui", get_bloginfo("template_directory")."/scripts/jquery-ui.min.js", array( "jquery" ) );
			wp_enqueue_script( "ocmx-multifile", get_bloginfo("template_directory")."/scripts/multifile.js", array( "jquery" ) );
			
			add_action( 'wp_ajax_ocmx_save-options', 'update_ocmx_options');
			add_action( 'wp_ajax_ocmx_reset-options', 'reset_ocmx_options');
			add_action( 'wp_ajax_ocmx_ads-refresh', 'ocmx_ads_refresh' );
			add_action( 'wp_ajax_ocmx_ads-remove', 'ocmx_ads_remove' );
			add_action( 'wp_ajax_ocmx_layout-refresh', 'ocmx_layout_refresh' );
			add_action( 'wp_ajax_ocmx_ajax-upload', 'ocmx_ajax_upload' );
			add_action( 'wp_ajax_ocmx_remove-image', 'ocmx_ajax_remove_image' );

			wp_enqueue_style( 'welcome-page', get_template_directory_uri() . '/ocmx/welcome-page.css');
			wp_enqueue_style( 'jquery-ui', get_template_directory_uri() . '/jquery-ui.css', false, '1.0', 'all' );
			
			
		endif;
	 	if ( is_singular() ) wp_enqueue_script( "comment-reply" ); 
	}

add_action('init', 'ocmx_add_scripts');