<?php

/**
 * AIT WordPress Theme
 *
 * Copyright (c) 2011, Affinity Information Technology, s.r.o. (http://ait-themes.com)
 */

define('THEME_SHORT_NAME', 'Impression');
define('THEME_LONG_NAME', 'AIT Impression Theme');
define('THEME_CODE_NAME', 'Impression');

$aitThemeCustomTypes = array(
	'portfolio' => 31,
	'slider-creator' => 32,
	'service-box' => 33,
	/*'partners' => 34*/
);

$aitThemeWidgets = array(
	'post',
	'flickr',
	'submenu',
	'twitter'
);

$aitEditorShortcodes = array(
	'custom',
	'columns',
	'images',
	'posts',
	'buttons',
	'boxesFrames',
	'lists',
	'notifications',
	'modal',
	'social',
	'video',
	'gMaps',
	'gChart',
	'portfolio',
	'language',
	'tabs',
	'econtent'
);

$aitThemeShortcodes = array(
	'boxesFrames' => 2,
	'buttons' => 1,
	'columns'=> 1,
	'custom'=> 1,
	'images'=> 1,
	'lists'=> 1,
	'modal'=> 1,
	'notifications'=> 1,
	'portfolio'=> 1,
	'posts'=> 1,
	'sitemap'=> 1,
	'social'=> 1,
	'video'=> 1,
	'language'=> 1,
	'gMaps'=> 1,
	'gChart'=> 1,
	'tabs'=> 1,
	'econtent' => 1
);

require dirname(__FILE__) . '/AIT/ait-bootstrap.php';

$pageOptions = array(
	'featured-image' => new WPAlchemy_MetaBox(array(
		'id' => '_ait_featured_images_options',
		'title' => __('Featured Image', THEME_CODE_NAME),
		'types' => array('post'),
		'context' => 'normal',
		'priority' => 'core',
		'config' => dirname(__FILE__) . '/conf/post-featured.neon'
	)),
	'slider' => new WPAlchemy_MetaBox(array(
		'id' => '_ait_slider_options',
		'title' => __('Header Page Settings', THEME_CODE_NAME),
		'types' => array('post', 'page'),
		'context' => 'normal',
		'priority' => 'core',
		'config' => dirname(__FILE__) . '/conf/page-slider-meta.neon',
		'js' => dirname(__FILE__) . '/conf/page-slider-meta.js',
	)),
	/*'service-boxes' => new WPAlchemy_MetaBox(array(
		'id' => '_ait_service_boxes_options',
		'title' => __('Service Boxes Page Settings'),
		'types' => array('post', 'page'),
		'context' => 'normal',
		'priority' => 'core',
		'config' => dirname(__FILE__) . '/conf/page-service-boxes-meta.neon'
	)),
	'products' => new WPAlchemy_MetaBox(array(
		'id' => '_ait_products_options',
		'title' => __('Products Page Settings'),
		'types' => array('post', 'page'),
		'context' => 'normal',
		'priority' => 'core',
		'config' => dirname(__FILE__) . '/conf/page-products-meta.neon'
	)),
	'partners' => new WPAlchemy_MetaBox(array(
		'id' => '_ait_partners_options',
		'title' => __('Partners Page Settings'),
		'types' => array('post', 'page'),
		'context' => 'normal',
		'priority' => 'core',
		'config' => dirname(__FILE__) . '/conf/page-partners-meta.neon'
	)),
	'icon-menu' => new WPAlchemy_MetaBox(array(
		'id' => '_ait_icon_menu_options',
		'title' => __('Icon Menu Page Settings'),
		'types' => array('post', 'page'),
		'context' => 'normal',
		'priority' => 'core',
		'config' => dirname(__FILE__) . '/conf/page-icon-menu-meta.neon'
	)),*/
	'testimonials' => new WPAlchemy_MetaBox(array(
		'id' => '_ait_testimonials_options',
		'title' => __('Testimonials Page Settings', THEME_CODE_NAME),
		'types' => array('post', 'page'),
		'context' => 'normal',
		'priority' => 'core',
		'config' => dirname(__FILE__) . '/conf/page-testimonials-meta.neon'
	)),
	'sections-order' => new WPAlchemy_MetaBox(array(
		'id' => '_ait_sections_order',
		'title' => __('Sections order for this page', THEME_CODE_NAME),
		'types' => array('page'),
		'context' => 'normal',
		'priority' => 'core',
		'config' => dirname(__FILE__) . '/conf/sections-order.neon'
	)),
	'footer' => new WPAlchemy_MetaBox(array(
		'id' => '_ait_footer_options',
		'title' => __('Footer Widgets Area', THEME_CODE_NAME),
		'types' => array('post', 'page'),
		'context' => 'normal',
		'priority' => 'core',
		'config' => dirname(__FILE__) . '/conf/page-footer-meta.neon'
	))
);



function aitThemeInit()
{

	if (is_admin()) {

	} elseif (!is_admin()) {

		aitLoadJQuery('1.5.1');

		// HTML 5
		wp_enqueue_script( 'JS_html5', THEME_JS_URL . '/libs/html5.js',  array('jquery') );
		// google maps
		wp_enqueue_script( 'JS_googleMaps', THEME_JS_URL . '/libs/jquery.gmap.min.js',  array('jquery') );
		// jQuery UI
		wp_enqueue_style( 'CSS_jquery_ui', THEME_CSS_URL . '/jquery-ui-1.8.16.custom.css');
		wp_enqueue_script( 'JS_jquery_ui', THEME_JS_URL . '/libs/jquery-ui-1.8.16.custom.min.js',  array('jquery') );

		// Anything slider
		wp_enqueue_style( 'CSS_anything', THEME_CSS_URL . '/anythingslider.css');
		wp_enqueue_script( 'JS_anythingFx', THEME_JS_URL . '/libs/jquery.anythingslider.fx.min.js', array('jquery') );
		wp_enqueue_script( 'JS_anything', THEME_JS_URL . '/libs/jquery.anythingslider.min.js',  array('jquery') );

		//wp_enqueue_script( 'JS_anythingVideo', THEME_JS_URL . '/libs/jquery.anythingslider.video.min.js', array('jquery') );
		wp_enqueue_script( 'JS_easy', THEME_JS_URL . '/libs/jquery.easing.1.3.js',  array('jquery') );

		wp_enqueue_script( 'JS_slider_script', THEME_JS_URL . '/sliders.js',  array('jquery') );

		// Colorbox
		wp_enqueue_style( 'CSS_colorbox', THEME_CSS_URL . '/colorbox.css');
		wp_enqueue_script( 'JS_colorbox', THEME_JS_URL . '/libs/jquery.colorbox-min.js',  array('jquery') );

		// Product JCarousel
		wp_enqueue_script( 'JS_jcarousel', THEME_JS_URL . '/libs/jquery.jcarousel.min.js',  array('jquery') );

		// Header script
		wp_enqueue_style( 'CSS_header', THEME_CSS_URL . '/header.css');
		//wp_enqueue_script( 'JS_cluster', THEME_JS_URL . '/libs/cluster.js',  array('jquery') );

		// fancybox
		wp_enqueue_style( 'CSS_fancybox', THEME_CSS_URL . '/fancybox/jquery.fancybox-1.3.4.css');
		wp_enqueue_script( 'JS_fancybox', THEME_JS_URL . '/libs/jquery.fancybox-1.3.4.js',  array('jquery') );

		// infield labels
		wp_enqueue_script( 'JS_infieldlabel', THEME_JS_URL . '/libs/jquery.infieldlabel.js',  array('jquery') );
		// comments
		wp_enqueue_style( 'CSS_comments', THEME_CSS_URL . '/comments.css');
		// contact
		wp_enqueue_style( 'CSS_contact', THEME_CSS_URL . '/contact.css');
		// scroll to
		wp_enqueue_script( 'JS_scrollto', THEME_JS_URL . '/libs/jquery.scroll-to.js',  array('jquery') );

		// hoverZoom
		wp_enqueue_style( 'CSS_hover_zoom', THEME_CSS_URL . '/hoverZoom.css');
		wp_enqueue_script( 'JS_hover_zoom', THEME_JS_URL . '/libs/hover.zoom.js',  array('jquery') );

		// pretty Sociable
		wp_enqueue_style( 'CSS_prettySociable', THEME_CSS_URL . '/prettySociable.css');
		wp_enqueue_script( 'JS_prettySociable', THEME_JS_URL . '/libs/jquery.prettySociable.js',  array('jquery') );

		// General script
		wp_enqueue_script( 'JS_general_script', THEME_JS_URL . '/script.js',  array('jquery') );
	}
}
add_action('init', 'aitThemeInit');



function aitThemeSetup()
{

	load_theme_textdomain('impression', TEMPLATEPATH . '/languages');

	$locale = get_locale();
	$locale_file = TEMPLATEPATH . "/languages/$locale.php";
	if(is_readable($locale_file))
		require_once($locale_file);

	// This theme styles the visual editor with editor-style.css to match the theme style.
	add_editor_style();

	// Add default posts and comments RSS feed links to <head>.
	add_theme_support('automatic-feed-links');

	// This theme uses wp_nav_menu() in one location.
	register_nav_menu('primary-menu', __('Primary Menu', THEME_CODE_NAME));
	register_nav_menu('footer-menu', __('Footer Menu', THEME_CODE_NAME));

	// This theme uses Featured Images (also known as post thumbnails) for per-post/per-page Custom Header images
	add_theme_support('post-thumbnails');

	// The height and width of your custom header.
	// Add a filter to ait_header_image_width and ait_header_image_height to change these values.
	define('HEADER_IMAGE_WIDTH', apply_filters('ait_header_image_width', 1000));
	define('HEADER_IMAGE_HEIGHT', apply_filters('ait_header_image_height', 288));

	add_image_size('large-feature', HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true); // Used for large feature (header) images
	add_image_size('small-feature', 500, 300); // Used for featured posts if a large-feature doesn't exist

}



/**
 * Register our sidebars and widgetized areas.
 */
function aitWidgetsInit()
{

	/*// Homepage widgets
	register_sidebar(array(
		'name' => __('Homepage Sidebar', 'impression'),
		'id' => 'homepage-widget-slider',
		'description' => __(''),
		'before_widget' => '<div id="%1$s" class="box widget-container %2$s"><div class="box-wrapper">',
		'after_widget' => "</div></div>",
		'before_title' => '<h2 class="widget-title">',
		'after_title' => '</h2>',
	));*/
	// Subpages Sidebar
	register_sidebar(array(
		'name' => __('Subpages Sidebar', THEME_CODE_NAME),
		'id' => 'subpages-sidebar',
		'description' => __('', THEME_CODE_NAME),
		'before_widget' => '<div id="%1$s" class="box widget-container %2$s"><div class="box-wrapper">',
		'after_widget' => "</div></div>",
		'before_title' => '<h2 class="widget-title">',
		'after_title' => '</h2>',
	));

	register_sidebar(array(
		'name' => __('Blog Category Sidebar', THEME_CODE_NAME),
		'id' => 'homepage-widgets-col-2',
		'description' => __('', THEME_CODE_NAME),
		'before_widget' => '<div id="%1$s" class="box widget-container %2$s"><div class="box-wrapper">',
		'after_widget' => "</div></div>",
		'before_title' => '<h2 class="widget-title">',
		'after_title' => '</h2>',
	));

	register_sidebar(array(
		'name' => __('Post Sidebar', THEME_CODE_NAME),
		'id' => 'post-sidebar',
		'description' => __('', THEME_CODE_NAME),
		'before_widget' => '<div id="%1$s" class="box widget-container %2$s"><div class="box-wrapper">',
		'after_widget' => "</div></div>",
		'before_title' => '<h2 class="widget-title">',
		'after_title' => '</h2>',
	));


	// Footer widgets
	register_sidebar(array(
		'name' => __('Footer Widgets Area', THEME_CODE_NAME),
		'id' => 'footer-widgets-area',
		'description' => __('', THEME_CODE_NAME),
		'before_widget' => '<div id="%1$s" class="box widget-container %2$s"><div class="box-wrapper">',
		'after_widget' => "</div></div>",
		'before_title' => '<h2 class="widget-title">',
		'after_title' => '</h2>',
	));
}
add_action('widgets_init', 'aitWidgetsInit');

add_action('after_setup_theme', 'aitThemeSetup');


function default_menu()
{
	wp_nav_menu(array('menu' => 'Main Menu', 'fallback_cb' => 'default_page_menu', 'container' => 'nav', 'container_class' => 'mainmenu', 'menu_class' => 'menu clear'));
}



function default_page_menu()
{
	echo '<nav class="mainmenu">';
	wp_page_menu(array('menu_class' => 'menu clear'));
	echo '</nav>';
}



function default_footer_menu()
{
	wp_nav_menu(array('menu' => 'Main Menu', 'container' => 'nav', 'container_class' => 'footer-menu', 'menu_class' => 'menu clear', 'depth' => 1));
}



remove_action('wp_head', 'wp_generator'); // do not show generator meta element

add_filter('widget_title', 'do_shortcode');
add_filter('widget_text', 'do_shortcode'); // do shortcode in text widget

/* THEME CHECK :: REQUIRED */
if ( ! isset( $content_width ) ) $content_width = 900;
/* THEME CHECK :: REQUIRED */