<?php

	/*
		STOP
		-------------------------------
		Serifly Theme Options Panel 1.0
		Updated on May 31st, 2012
		http://serifly.com
	*/

	// Set prefix for theme options
	$prefix = 'serifly_rackhost_';
		
	// Configure theme options
	add_action( 'admin_init', 'theme_options_init' );
	add_action( 'admin_menu', 'theme_options_add_page' );
	add_action('admin_print_scripts', 'theme_options_scripts');
	add_action('admin_print_styles', 'theme_options_styles');

	function theme_options_init()
	{
		global $prefix;
		
		register_setting($prefix . 'options', $prefix . 'theme_options', 'theme_options_validate');
	}

	function theme_options_add_page()
	{
		add_theme_page( __('Theme Options', 'serifly'), __('Theme Options', 'serifly'), 'edit_theme_options', 'theme_options', 'theme_options_build_panel');
	}
	
	function theme_options_scripts()
	{
		wp_enqueue_script('media-upload');
		wp_enqueue_script('thickbox');
		wp_enqueue_script('farbtastic');
		wp_register_script('my-upload', get_template_directory_uri() . '/admin/js/admin.js', array('jquery','media-upload','thickbox'));
		wp_enqueue_script('my-upload');
	}
	
	function theme_options_styles()
	{
		wp_enqueue_style('thickbox');
		wp_enqueue_style('farbtastic');
		wp_enqueue_style('admin', get_template_directory_uri() . '/admin/css/admin.css');
	}

	// Render theme options page
	function theme_options_build_panel()
	{
		global $prefix;
	
		if (!isset($_REQUEST['settings-updated']))
		{
			$_REQUEST['settings-updated'] = false;
		}
		
		require(get_template_directory() . '/admin/admin-setup.php');
		require(get_template_directory() . '/admin/admin-interface.php');
	}
	
	// Validate theme options
	function theme_options_validate($input)
	{	
		// Styling: Color: Link Color
		$input['styling_color_link'] = str_replace('#', '', $input['styling_color_link']);
						
		// Return values to Wordpress
		return $input;
	}

?>