<?php
if(isset($_GET['page']) && $_GET['page']=='theme_background'){
	if (! function_exists("theme_bg_load")){
		function theme_bg_load($value, $default){
			$color = theme_get_option('color','default_color');
		
			echo '<tr>';
			echo '<th scope="row"><h4><label for="bg_image">Select Theme Default Background Image</label></h4></th>';
			echo '<td><p class="description"></p><select id="bg_image" name="bg_image">';
			if(!$color || $color == 'default'){
				echo '<option selected="selected" value="default">Default Image</option>';
			}elseif(is_dir(THEME_COLOR_DIR.'/'.$color)){
				$files = array_filter(glob(THEME_COLOR_DIR.'/'.$color.'/*'),'is_file');
				$images = array();
				foreach($files as $file){
					$res = preg_match('/^bg-(.*)\.(.*)/i',basename($file),$matches); 
					if($res){
						$images[] = $matches[1];
					}
				}
				if(empty($default) || $default == 'default'){
					$default = $images[0];
				}
				foreach($images as $image){
					$selected = '';
					if($default == $image)
						$selected = 'selected = "selected"';
					echo '<option '.$selected.' value="'.$image.'">'.ucwords($image).'</option>';
				}
				$selected = '';
				if($default == 'no_image')
					$selected = 'selected = "selected"';
				echo '<option '.$selected.' value="no_image">No Image</option>';
			}
			echo '<br></td></tr>';
				
		}
	}
}
$options = array(
	array(
		"name" => __("Background",THEME_ADMIN_DOMAIN),
		"type" => "title"
	),
	 array(
		"name" => __("BackGround-General",THEME_ADMIN_DOMAIN),
		"type" => "start"
	),
		array(
			"name" => __("Select the default background image",THEME_ADMIN_DOMAIN),
			"id" =>"bg_image",
			"desc" => "",
			"layout" => false,
			"function" => "theme_bg_load",
			"default" => 'default',
			"type" => "custom"
		),	
	   	array(
			"name" => __("Use Custom Image",THEME_ADMIN_DOMAIN),
			"id" => "custom_background",
			"default" => 0,
			"type" => "toggle"
		),
	array(
		"type" => "end"
	),
	array(
		"name" => __("Page Background",THEME_ADMIN_DOMAIN),
		"type" => "start"
	),
		array(
			"name" => __("Custom Image",THEME_ADMIN_DOMAIN),
			"id" => "page_image",
			"default" => "",
			"type" => "upload",
		),
		array(
			"name" => __("Position",THEME_ADMIN_DOMAIN),
			"desc" => "",
			"id" => "page_position",
			"default" => 'top center',
			"options" => array(
				"top left" => __('Top Left',THEME_ADMIN_DOMAIN),
				"top center" => __('Top Center',THEME_ADMIN_DOMAIN),
				"top right" => __('Top Right',THEME_ADMIN_DOMAIN),
				"center left" => __('Center Left',THEME_ADMIN_DOMAIN),
				"center center" => __('Center Center',THEME_ADMIN_DOMAIN),
				"center right" => __('Center Right',THEME_ADMIN_DOMAIN),
				"bottom left" => __('Bottom Left',THEME_ADMIN_DOMAIN),
				"bottom center" => __('Bottom Center',THEME_ADMIN_DOMAIN),
				"bottom right" => __('Bottom Right',THEME_ADMIN_DOMAIN),
			),
			"type" => "select",
		),
		array(
			"name" => __("Repeat",THEME_ADMIN_DOMAIN),
			"desc" => "",
			"id" => "page_repeat",
			"default" => 'no-repeat',
			"options" => array(
				"no-repeat" => __('No Repeat',THEME_ADMIN_DOMAIN),
				"repeat" => __('Repeat',THEME_ADMIN_DOMAIN),
				"repeat-x" => __('Repeat-X',THEME_ADMIN_DOMAIN),
				"repeat-y" => __('Repeat-y',THEME_ADMIN_DOMAIN),
			),
			"type" => "select",
		),
	array(
		"type" => "end"
	),
	array(
		"name" => __("Footer Background",THEME_ADMIN_DOMAIN),
		"type" => "start"
	),
		array(
			"name" => __("Custom Image",THEME_ADMIN_DOMAIN),
			"id" => "footer_image",
			"default" => "",
			"type" => "upload"
		),
		array(
			"name" => __("Position",THEME_ADMIN_DOMAIN),
			"desc" => "",
			"id" => "footer_position",
			"default" => 'center center',
			"options" => array(
				"top left" => __('Top Left',THEME_ADMIN_DOMAIN),
				"top center" => __('Top Center',THEME_ADMIN_DOMAIN),
				"top right" => __('Top Right',THEME_ADMIN_DOMAIN),
				"center left" => __('Center Left',THEME_ADMIN_DOMAIN),
				"center center" => __('Center Center',THEME_ADMIN_DOMAIN),
				"center right" => __('Center Right',THEME_ADMIN_DOMAIN),
				"bottom left" => __('Bottom Left',THEME_ADMIN_DOMAIN),
				"bottom center" => __('Bottom Center',THEME_ADMIN_DOMAIN),
				"bottom right" => __('Bottom Right',THEME_ADMIN_DOMAIN),
			),
			"type" => "select",
		),
		array(
			"name" => __("Repeat",THEME_ADMIN_DOMAIN),
			"desc" => "",
			"id" => "footer_repeat",
			"default" => 'no-repeat',
			"options" => array(
				"no-repeat" => __('No Repeat',THEME_ADMIN_DOMAIN),
				"repeat" => __('Repeat',THEME_ADMIN_DOMAIN),
				"repeat-x" => __('Repeat-X',THEME_ADMIN_DOMAIN),
				"repeat-y" => __('Repeat-y',THEME_ADMIN_DOMAIN),
			),
			"type" => "select",
		),
	array(
		"type" => "end"
	),
);
return array(
	'auto' => true,
	'name' => 'background',
	'options' => $options
);
