<?php
//AJAX callbacks
add_action('wp_ajax_change_options', array('ThemeMakersThemeModel', 'change_options'));
add_action('wp_ajax_render_gall', array('Thememakers_Entity_Gallery', 'render_gallery'));
add_action('wp_ajax_add_sidebar', array('Thememakers_Entity_Custom_Sidebars', 'add_sidebar'));
add_action('wp_ajax_add_sidebar_page', array('Thememakers_Entity_Custom_Sidebars', 'add_sidebar_page'));
add_action('wp_ajax_add_sidebar_category', array('Thememakers_Entity_Custom_Sidebars', 'add_sidebar_category'));
add_action('wp_ajax_add_sidebar_product', array('Thememakers_Entity_Custom_Sidebars', 'add_sidebar_product'));
add_action('wp_ajax_contact_form_request', array('Thememakers_Entity_Contact_Form', 'contact_form_request'));
add_action('wp_ajax_add_comment', array('ThemeMakersHelper', 'add_comment'));
add_action('wp_ajax_get_google_fonts', array('ThemeMakersHelperFonts', 'get_google_fonts_ajax'));
add_action('wp_ajax_get_new_google_fonts', array('ThemeMakersHelperFonts', 'get_new_google_fonts'));
add_action('wp_ajax_save_google_fonts', array('ThemeMakersHelperFonts', 'save_google_fonts'));
add_action('wp_ajax_add_seo_group', array('Thememakers_Entity_SEO_Group', 'add_seo_group'));
add_action('wp_ajax_add_seo_group_category', array('Thememakers_Entity_SEO_Group', 'add_seo_group_category'));
add_action('wp_ajax_get_years_archive_links', array('ThemeMakersHelper', 'get_years_archive_links')); //returns monthes
add_action('wp_ajax_get_monthes_archive_links', array('ThemeMakersHelper', 'get_monthes_archive_links')); //returns weeks
add_action('wp_ajax_get_weeks_archive_links', array('ThemeMakersHelper', 'get_weeks_archive_links')); //returns days
add_action('wp_ajax_search_games', array('Thememakers_Entity_Game', 'search_games'));
add_action('wp_ajax_save_featured_games', array('Thememakers_Entity_Game', 'save_featured_games'));
add_action('wp_ajax_set_rate', array('Thememakers_Entity_Rating', 'set_rate'));
add_action('wp_ajax_save_user_profile', array('ThemeMakersUser', 'save_user_profile'));
add_action('wp_ajax_add_user_to_favourites', array('ThemeMakersUser', 'add_user_to_favourites'));
add_action('wp_ajax_delete_favourite_user', array('ThemeMakersUser', 'delete_favourite_user'));
add_action('wp_ajax_logout', array('ThemeMakersUser', 'logout'));
add_action('wp_ajax_get_unique_ids', array('ThemeMakersHelper', 'get_unique_ids'));

if (!is_user_logged_in()) {
    add_action('wp_ajax_nopriv_render_gall', array('Thememakers_Entity_Gallery', 'render_gallery'));
    add_action('wp_ajax_nopriv_contact_form_request', array('Thememakers_Entity_Contact_Form', 'contact_form_request'));
    add_action('wp_ajax_nopriv_add_comment', array('ThemeMakersHelper', 'add_comment'));
    add_action('wp_ajax_nopriv_get_google_fonts', array('ThemeMakersHelperFonts', 'get_google_fonts_ajax'));
    add_action('wp_ajax_nopriv_get_new_google_fonts', array('ThemeMakersHelperFonts', 'get_new_google_fonts'));
    add_action('wp_ajax_nopriv_get_years_archive_links', array('ThemeMakersHelper', 'get_years_archive_links')); //returns monthes
    add_action('wp_ajax_nopriv_get_monthes_archive_links', array('ThemeMakersHelper', 'get_monthes_archive_links')); //returns weeks
    add_action('wp_ajax_nopriv_get_weeks_archive_links', array('ThemeMakersHelper', 'get_weeks_archive_links')); //returns days
    add_action('wp_ajax_nopriv_set_rate', array('Thememakers_Entity_Rating', 'set_rate'));
    add_action('wp_ajax_nopriv_login', array('ThemeMakersUser', 'login'));
    add_action('wp_ajax_nopriv_register', array('ThemeMakersUser', 'register'));
}

//*****



add_action('admin_menu', 'thememakers_theme_add_admin');
add_action('admin_head', 'thememakers_theme_admin_head');
add_action('admin_bar_menu', 'thememakers_theme_admin_bar_menu', 99);

//add_action('wp_head', 'thememakers_theme_wp_head');
add_action('wp_footer', 'thememakers_theme_wp_footer');
 
add_action('wp_enqueue_scripts', 'theme_styles_woocommerce');

//*****

global $pagenow;
if (is_admin() AND 'themes.php' == $pagenow AND isset($_GET['activated'])) {
    wp_update_nav_menu_object(0, array('menu-name' => 'Primary Menu'));
    wp_update_nav_menu_object(0, array('menu-name' => 'Secondary Menu'));
    //***** set default options
    $theme_was_activated = ThemeMakersThemeModel::get_option('theme_was_activated');
    if (!$theme_was_activated) {
        ThemeMakersThemeModel::update_option('theme_was_activated', 1);
        //*****
        ThemeMakersThemeModel::update_option('slider_nivo_enable_caption', 1);
        ThemeMakersThemeModel::update_option('slider_nivo_control_nav', 1);
        ThemeMakersThemeModel::update_option('show_full_content', 0);
        ThemeMakersThemeModel::update_option('excerpt_symbols_count', 140);
        ThemeMakersThemeModel::update_option('disable_blog_comments', 1);
        ThemeMakersThemeModel::update_option('disable_portfolio_comments', 1);
        ThemeMakersThemeModel::update_option('gallery_height', 365);
        ThemeMakersThemeModel::update_option('gallery_width', 770);
        ThemeMakersThemeModel::update_option('sidebar_position', 'sbl');
        ThemeMakersThemeModel::update_option('reviews_count', 4);
        ThemeMakersThemeModel::update_option('releases_count', 4);
        ThemeMakersThemeModel::update_option('logo_font', 'Marck Script');
        ThemeMakersThemeModel::update_option('disable_content_autoparagraphs', 1);
        ThemeMakersThemeModel::update_option('user_registration_text', 'Hello __USERNAME__! Your password is: __PASSWORD__');
        ThemeMakersThemeModel::update_option('copyright_text', 'Copyright &copy; 2012. <a target="_blank" href="http://webtemplatemasters.com">ThemeMakers</a>. All rights reserved');
    }
}



/* * ****************** functions *********************** */

function thememakers_theme_admin_bar_menu() {
    global $wp_admin_bar;
    if (!is_super_admin() || !is_admin_bar_showing())
        return;
    $wp_admin_bar->add_menu(array(
        'id' => 'thememakers_link',
        'title' => __("Theme Options", THEMEMAKERS_THEME_FOLDER_NAME),
        'href' => site_url() . '/wp-admin/themes.php?page=thememakers_path_theme_options',
    ));
}

function thememakers_theme_add_admin() {
    add_theme_page(__("Theme Options", THEMEMAKERS_THEME_FOLDER_NAME), __("Theme Options", THEMEMAKERS_THEME_FOLDER_NAME), 'edit_themes', 'thememakers_path_theme_options', 'thememakers_theme_admin');
}

function thememakers_theme_admin() {
    echo ThemeMakersThemeView::draw_page('theme_options');
}

//********************
add_action('admin_notices', 'thememakers_print_admin_notice');

function thememakers_print_admin_notice() {
    $notices = "";

    if (!is_writable(THEMEMAKERS_THEME_PATH . "/css/custom1.css")) {
        $notices.='<div class="error"><p>To make your theme work correctly you need to set the permissions 777 for <b>' . THEMEMAKERS_THEME_PATH . '/css/custom1.css</b> folder. Follow <a href="http://webtemplatemasters.com/tutorials/permissions/" target="_blank">the link</a> to read the instructions how to do it properly.</p></div>';
    }

    if (!is_writable(THEMEMAKERS_THEME_PATH . "/css/custom2.css")) {
        $notices.='<div class="error"><p>To make your theme work correctly you need to set the permissions 777 for <b>' . THEMEMAKERS_THEME_PATH . '/css/custom2.css</b> folder. Follow <a href="http://webtemplatemasters.com/tutorials/permissions/" target="_blank">the link</a> to read the instructions how to do it properly.</p></div>';
    }

    echo $notices;
}

//*** sliders
function thememakers_theme_sliders_groups() {
    $slides = Thememakers_Entity_Slider::get_slides();
    echo ThemeMakersThemeView::draw_page('slider/sliders_groups', array('slides' => $slides));
}

function theme_styles_woocommerce(){
		
				wp_register_style( "thememakers_theme_styles_woocommerce_css", plugins_url().'/woocommerce/assets/css/woocommerce.css');
				wp_enqueue_style("thememakers_theme_styles_woocommerce_css");
		 
}

function thememakers_theme_admin_head() {
    wp_enqueue_style("thememakers_theme_styles_css", THEMEMAKERS_THEME_URI . '/admin/css/styles.css');
    wp_enqueue_style('thickbox');

    wp_enqueue_script('jquery');
    wp_enqueue_script('jquery-ui-core');
    wp_enqueue_script('jquery-ui-tabs');
    wp_enqueue_script('jquery.ui.sortable');

    wp_enqueue_script('media-upload');
    wp_enqueue_script('thickbox');
    wp_enqueue_script('thememakers_theme_admin_js', THEMEMAKERS_THEME_URI . '/admin/js/general.js', array('jquery','jquery-ui-sortable'));

    //*****
    wp_enqueue_style("thememakers_theme_fancybox_css", THEMEMAKERS_THEME_URI . '/js/fancybox/jquery.fancybox.css');
    wp_enqueue_style("thememakers_theme_colorpicker_css", THEMEMAKERS_THEME_URI . '/admin/js/colorpicker/colorpicker.css');

    wp_enqueue_script('thememakers_theme_fancybox_js', THEMEMAKERS_THEME_URI . '/js/fancybox/jquery.fancybox.pack.js');
    wp_enqueue_script('thememakers_theme_colorpicker_js', THEMEMAKERS_THEME_URI . '/admin/js/colorpicker/colorpicker.js');
    wp_enqueue_script('thememakers_theme_jquery_raty', THEMEMAKERS_THEME_URI . '/js/jquery.raty.min.js');
    ?>

    <!--[if IE]>
    <script>
    document.createElement('header');
    document.createElement('footer');
    document.createElement('section');
    document.createElement('aside');
    document.createElement('nav');
    document.createElement('article');
    </script>
    <![endif]-->

    <script type="text/javascript">
        var template_directory = "<?php echo THEMEMAKERS_THEME_URI; ?>/";
        var ajaxurl = "<?php echo admin_url('admin-ajax.php'); ?>";
        //*****
        var lang_one_moment = "<?php _e("One moment", THEMEMAKERS_THEME_FOLDER_NAME) ?>";
        var lang_delete = "<?php _e("Delete", THEMEMAKERS_THEME_FOLDER_NAME) ?>";
        var lang_edit = "<?php _e("Edit", THEMEMAKERS_THEME_FOLDER_NAME) ?>";
    </script>
	
  
	
    <?php
    echo ThemeMakersHelperFonts::get_google_fonts_link();
}

function thememakers_theme_wp_head() {
    wp_enqueue_style("thememakers_theme_fancybox_css", THEMEMAKERS_THEME_URI . '/js/fancybox/jquery.fancybox.css');
    wp_enqueue_script('thememakers_theme_fancybox_js', THEMEMAKERS_THEME_URI . '/js/fancybox/jquery.fancybox.pack.js', array('jquery'));
    wp_enqueue_script('thememakers_theme_jquery_easing_js', THEMEMAKERS_THEME_URI . '/js/jquery.easing.1.3.js', array('jquery'));
    wp_enqueue_script('thememakers_theme_jquery_easingcomp_js', THEMEMAKERS_THEME_URI . '/js/jquery.easing.compatibility.js', array('jquery'));
    wp_enqueue_script('thememakers_theme_jquery_quicksand_js', THEMEMAKERS_THEME_URI . '/js/jquery.quicksand.js', array('jquery'));
    wp_enqueue_script('thememakers_theme_jquery_cycle_js', THEMEMAKERS_THEME_URI . '/js/jquery.cycle.all.min.js', array('jquery'));
    wp_enqueue_script('thememakers_theme_auth_js', THEMEMAKERS_THEME_URI . '/js/auth.js', array('jquery'));
    wp_enqueue_script('thememakers_theme_selectivizr_js', THEMEMAKERS_THEME_URI . '/js/selectivizr-and-extra-selectors.min.js', array('jquery'));
    wp_enqueue_script('thememakers_theme_jquery_jscrollpane_js', THEMEMAKERS_THEME_URI . '/js/jquery.jscrollpane.min.js', array('jquery'));
    wp_enqueue_script('thememakers_theme_jquery_carousel_js', THEMEMAKERS_THEME_URI . '/js/jquery.carousel.min.js', array('jquery'));
    wp_enqueue_script('thememakers_theme_jquery_mousewheel_js', THEMEMAKERS_THEME_URI . '/js/jquery.mousewheel.min.js', array('jquery'));
    wp_enqueue_script('thememakers_theme_jquery_ui_js', THEMEMAKERS_THEME_URI . '/js/jquery-ui-1.8.16.custom.min.js', array('jquery'));
    wp_enqueue_script('thememakers_theme_general_js', THEMEMAKERS_THEME_URI . '/js/general.js', array('jquery'));
    wp_enqueue_script('thememakers_theme_jquery_raty', THEMEMAKERS_THEME_URI . '/js/jquery.raty.min.js', array('jquery'));
		
}

function thememakers_theme_wp_footer() {
	wp_enqueue_style("thememakers_theme_fancybox_css", THEMEMAKERS_THEME_URI . '/js/fancybox/jquery.fancybox.css');
    wp_enqueue_script('thememakers_theme_fancybox_js', THEMEMAKERS_THEME_URI . '/js/fancybox/jquery.fancybox.pack.js', array('jquery'));
    wp_enqueue_script('thememakers_theme_jquery_easing_js', THEMEMAKERS_THEME_URI . '/js/jquery.easing.1.3.js', array('jquery'));
    wp_enqueue_script('thememakers_theme_jquery_easingcomp_js', THEMEMAKERS_THEME_URI . '/js/jquery.easing.compatibility.js', array('jquery'));
    wp_enqueue_script('thememakers_theme_jquery_quicksand_js', THEMEMAKERS_THEME_URI . '/js/jquery.quicksand.js', array('jquery'));
    wp_enqueue_script('thememakers_theme_jquery_cycle_js', THEMEMAKERS_THEME_URI . '/js/jquery.cycle.all.min.js', array('jquery'));
    wp_enqueue_script('thememakers_theme_auth_js', THEMEMAKERS_THEME_URI . '/js/auth.js', array('jquery'));
    wp_enqueue_script('thememakers_theme_selectivizr_js', THEMEMAKERS_THEME_URI . '/js/selectivizr-and-extra-selectors.min.js', array('jquery'));
    wp_enqueue_script('thememakers_theme_jquery_jscrollpane_js', THEMEMAKERS_THEME_URI . '/js/jquery.jscrollpane.min.js', array('jquery'));
    wp_enqueue_script('thememakers_theme_jquery_carousel_js', THEMEMAKERS_THEME_URI . '/js/jquery.carousel.min.js', array('jquery'));
    wp_enqueue_script('thememakers_theme_jquery_mousewheel_js', THEMEMAKERS_THEME_URI . '/js/jquery.mousewheel.min.js', array('jquery'));
    wp_enqueue_script('thememakers_theme_jquery_ui_js', THEMEMAKERS_THEME_URI . '/js/jquery-ui-1.8.16.custom.min.js', array('jquery'));
    wp_enqueue_script('thememakers_theme_general_js', THEMEMAKERS_THEME_URI . '/js/general.js', array('jquery'));
    wp_enqueue_script('thememakers_theme_jquery_raty', THEMEMAKERS_THEME_URI . '/js/jquery.raty.min.js', array('jquery'));
		   
}

