<?php
// **********************************************************************//
// ! Set Content Width
// **********************************************************************//
if (!isset( $content_width )) $content_width = 1170;

// **********************************************************************//
// ! Include CSS and JS
// **********************************************************************//

if ( !function_exists('wft_register_scripts') ) {
	function wft_register_scripts() {
		wp_register_script('jcarousel', get_template_directory_uri() . '/js/jquery.jcarousel.min.js', array(), false, true );
		wp_register_script( 'wft-brands-slider', get_template_directory_uri() . '/js/brands.js', array(), false, true );
	}
}
add_action( 'wp_enqueue_scripts', 'wft_register_scripts', 30);

if(!function_exists('etheme_enqueue_styles')) {
	function etheme_enqueue_styles() {

		global $wft_responsive;

		if ( !is_admin() ) {

			wp_register_style("cloud-zoom", get_template_directory_uri().'/css/cloud-zoom.css');
			wp_register_script("cloud-zoom", get_template_directory_uri().'/js/cloud-zoom.1.0.2.js', array(), false, true);

			//styles

			wp_enqueue_style("style",get_template_directory_uri().'/css/style.css');
			//wp_enqueue_style("style-lingerie",get_template_directory_uri().'/css/style-lingerie.css');
			if ( etheme_get_option('main_layout', 'wide') == 'boxed' ) {
				wp_enqueue_style("style-boxed",get_template_directory_uri().'/css/style-boxed.css');
			}
			if ( $wft_responsive ) {
				wp_enqueue_style("bootstrap-responsive",get_template_directory_uri().'/css/bootstrap-responsive.css');
			} else {
				wp_enqueue_style("bootstrap-nonresponsive",get_template_directory_uri().'/css/bootstrap-nonresponsive.css');
			}

			wp_enqueue_style("font-oswald", 'http://fonts.googleapis.com/css?family=Oswald:400,700');

			//scripts
			wp_enqueue_script("prototype", 'https://ajax.googleapis.com/ajax/libs/prototype/1.7.1.0/prototype.js', array(), false, true);
			wp_enqueue_script("bootstrap-js", get_template_directory_uri().'/js/bootstrap.js', array(), false, true);
			wp_enqueue_script("jquery-easing", get_template_directory_uri().'/js/jquery.easing.js', array(), false, true);
			wp_enqueue_script("jquery-mousewheel", get_template_directory_uri().'/js/jquery.mousewheel.js', array(), false, true);
			wp_enqueue_script("jquery-flexslider", get_template_directory_uri().'/js/jquery.flexslider.js', array(), false, true);
			wp_enqueue_script("jquery-elastislide", get_template_directory_uri().'/js/jquery.elastislide.js', array(), false, true);
			wp_enqueue_script("jquery-selectbox", get_template_directory_uri().'/js/jquery.selectbox-0.2.js', array(), false, true);
			wp_enqueue_script("jquery-nouislider", get_template_directory_uri().'/js/jquery.nouislider.js', array(), false, true);


			if ( etheme_get_custom_field('page_slider') == 'zoom_slider' ) {
				wp_enqueue_style("layerslider-skin", get_template_directory_uri().'/css/skins/fullwidth/skin.css');
				wp_enqueue_script("jquery-transit-modified", get_template_directory_uri().'/js/jquery-transit-modified.js', array(), false, true);
				wp_enqueue_script("layerslider-transitions", get_template_directory_uri().'/js/layerslider.transitions.js', array(), false, true);
				wp_enqueue_script("layerslider-kreaturamedia", get_template_directory_uri().'/js/layerslider.kreaturamedia.jquery.js', array(), false, true);
				?>
				<script type="text/javascript">
					var zoomSliderEnabled = true;
					var skinsUrl = "<?php echo get_template_directory_uri() . '/css/skins/'; ?>";
				</script>
			<?php
			} else {
				wp_enqueue_style("revslider",get_template_directory_uri().'/css/revslider.css');
				?>
				<script type="text/javascript">
					var zoomSliderEnabled = false;
				</script>
			<?php
			}
			wp_enqueue_script("jquery-parallax", get_template_directory_uri().'/js/jquery.parallax.js', array(), false, true);
			wp_enqueue_script("jquery-inview", get_template_directory_uri().'/js/jquery.inview.js', array(), false, true);

			if ( (!is_admin()) && is_singular() && comments_open() && get_option('thread_comments') ) {
				wp_enqueue_script( 'comment-reply' );
			}
			// Queue jquery search autocomplete
			if ( etheme_get_option('search_autocomplete') ) {
				wp_enqueue_script('search-autocomplete', get_template_directory_uri() . '/js/jquery.autocomplete.js?v=1.2.9', array(), false, true);

			}

			// Isotop plugin
			if ( etheme_get_option('isotope_animation') && !strpos($_SERVER["HTTP_USER_AGENT"], 'MSIE') ) {
				wp_enqueue_style("animate",get_template_directory_uri().'/css/animate.css');
				wp_enqueue_style("isotope-css",get_template_directory_uri().'/css/isotope.css');
				wp_enqueue_script("isotope-js", get_template_directory_uri().'/js/jquery.isotope.js', array(), false, true);
			}

			// Modernizr
			wp_enqueue_script("modernizr", get_template_directory_uri().'/js/modernizr-2.6.2.min.js', array(), false, true);

			// Queue fancybox plugin
			wp_enqueue_style("fancybox-css", get_template_directory_uri() . '/css/jquery.fancybox.css?v=2.1.5', array(), false, true);
			wp_enqueue_script('fancybox-pack', get_template_directory_uri() . '/js/jquery.fancybox.pack.js?v=2.1.5', array(), false, true);

			$script_depends = array();

			if ( class_exists('WooCommerce') ) {
				$script_depends[] = 'wc-add-to-cart-variation';
			}

			wp_enqueue_script("custom", get_template_directory_uri().'/js/custom.js', $script_depends, false, true);
			wp_enqueue_script("retina", get_template_directory_uri().'/js/retina-1.1.0.js', array(), false, true);

			$ajax_cart_en = get_option( 'woocommerce_enable_ajax_add_to_cart' ) == 'yes' ? true : false;
			// Queue frontend scripts conditionally
			if ( $ajax_cart_en ) {

				wp_enqueue_script( 'wft-add-to-cart', get_template_directory_uri() . '/js/add-to-cart.js', array(), false, true );
			}

		}
	}
}

add_action( 'wp_enqueue_scripts', 'etheme_enqueue_styles', 30);

// **********************************************************************//
// ! Screet chat license
// **********************************************************************//
define('SC_CHAT_LICENSE_KEY', '8cd07b91-efaa-4dcc-aa79-98ec154506dc');
if ( !function_exists('wft_scchat_init') ) {
	function wft_scchat_init () {
		update_option('sc_chat_validate_license', 1);
	}
}

add_action( 'after_setup_theme', 'wft_scchat_init');

// **********************************************************************//
// ! Function for disabling Responsive layout
// **********************************************************************//
if(!function_exists('etheme_set_responsive')) {
	function etheme_set_responsive() {
		global $wft_responsive;
		$wft_responsive = etheme_get_option('responsive');
		if(isset($_COOKIE['responsive'])) {
			$wft_responsive = false;
		}
		if(isset($_GET['responsive']) && $_GET['responsive'] == 'off') {
			if (!isset($_COOKIE['responsive'])) {
				setcookie('responsive', 1, time()+1209600, COOKIEPATH, COOKIE_DOMAIN, false);
			}
			wp_redirect(get_home_url()); exit();
		}elseif(isset($_GET['responsive']) && $_GET['responsive'] == 'on') {
			if (isset($_COOKIE['responsive'])) {
				setcookie('responsive', 1, time()-1209600, COOKIEPATH, COOKIE_DOMAIN, false);
			}
			wp_redirect(get_home_url()); exit();
		}
	}
}

add_action( 'init', 'etheme_set_responsive');

// **********************************************************************//
// ! Exclude some css from minifier
// **********************************************************************//


add_filter('bwp_minify_style_ignore', 'et_exclude_css');

if(!function_exists('et_exclude_css')) {
	function et_exclude_css($excluded) {
		$excluded = array('font-awesome');
		return $excluded;
	}
}


// **********************************************************************//
// ! Add classes to body
// **********************************************************************//
add_filter('body_class','et_add_body_classes');
if(!function_exists('et_add_body_classes')) {
	function et_add_body_classes($classes) {

		global $wft_responsive;

		$classes[] = ($wft_responsive) ? 'responsive' : 'nonresponsive';

		$classes[] = etheme_get_option('main_layout');
		$classes[] = 'notouch';
		$classes[] = 'no_msie';

		return $classes;
	}
}

/**
 * Enqueue the Google fonts.
 */
function wft_enqueue_google_fonts() {

	$chosenFonts = etheme_get_chosen_google_font();
	$protocol = is_ssl() ? 'https' : 'http';

	foreach ( $chosenFonts as $font ) {
		wp_enqueue_style( str_replace('+', '-', $font), $protocol . '://fonts.googleapis.com/css?family=' . $font );
	}
}

// **********************************************************************//
// ! Ititialize theme confoguration and variables
// **********************************************************************//
add_action('wp_head', 'etheme_init');
if(!function_exists('etheme_init')) {
	function etheme_init() {

		wft_enqueue_google_fonts();

		$main_layout = etheme_get_option('main_layout', 'wide');

		$selectors = array();

		if ( $main_layout == 'boxed' ) {
			$selectors['header_container'] = '#header .container';
			$selectors['content_container'] = '#content .container';
		} else {
			$selectors['header_container'] = '#header';
			$selectors['content_container'] = '#content';
		}

		$selectors['top_bar'] = '#topline, #topline span, #topline .phone span';
		$selectors['top_bar_menu'] = '#topline .fadelink > a';
		$selectors['top_bar_menu_popup'] = '#topline .fadelink .ul_wrapper ul, #topline .fadelink li a';
		$selectors['header1'] = '#header';
		$selectors['header2'] = '#header input[type="text"]';



		$selectors['content_font'] = '
			#content,
			.woocommerce.widget_price_filter .price_slider_amount span, .woocommerce-page .widget_price_filter .price_slider_amount
		';

		$selectors['box_font'] = '
			.table-striped tbody > tr:nth-child(2n+1) > td, .table-striped tbody > tr:nth-child(2n+1) > th,
			.box-wrapper
		';

		$selectors['links_font'] = '#content a:not(.button), .product a';
		$selectors['links_hover_font'] = '#content a:not(.button):hover, .product a:hover';

		$selectors['price_font'] = '
			.product-price .amount,
			.product-price del .amount,
			.product-shop .old-price .price,
			.product-listing .old-price .price,
			.product-shop .price-box del .amount,
			.price-box del .amount,
			.amount
		';
		$selectors['special_price_font'] = '
			.product-price ins .amount,
			.product-shop .special-price .price,
			.product-listing .special-price .price,
			.product-shop .price-box ins .amount,
			.price-box ins .amount
		';

		$selectors['buttons_font'] = '
			button, .button, a.button, .btn-middle, .more-link, input[type="submit"],
			.button_small, #topline a.button_small,
			#sc_chat_box div.sc-chat-header, #sc_chat_box .sc-chat-wrapper .sc-start-chat-btn > a,
			.form-search button, .form-mail button,
			.shopping_cart_mini .button,
			.color_mark, .promo-box.style4
		';
		$selectors['buttons_hover_text_color'] = '
			button:hover, .button:hover, a.button:hover, .more-link:hover, input[type="submit"]:hover,
			.button_small:hover, #topline a.button_small:hover,
			#sc_chat_box div.sc-chat-header:hover, #sc_chat_box .sc-chat-wrapper .sc-start-chat-btn > a:hover,
			.shopping_cart_mini .button:hover
		';

		$selectors['tabs_font'] = '
			.widget.widget_nav_menu ul.sidenav li a,
			#nav > li > a
		';

		$selectors['tabs_hover_text_color'] = '
			.notouch .widget.widget_nav_menu ul.sidenav li a:hover,
			.widget.widget_nav_menu ul.sidenav li.active a,
			.widget.widget_nav_menu ul.sidenav li.current-menu-item a,
			#nav > li:hover > a,
			.filters-by-category li a.selected,
			.sale_discount
		';

		$selectors['icons_text_color'] = '
			.form-search button,
			.form-mail button,
			a.small_icon_color i,
			a.btn, a.btn[rel="prev"], a.btn[rel="next"]
		';
		$selectors['icons_hover_text_color'] = '
			.form-search button:hover,
			.form-mail button:hover,
			.shoppingcart:hover .fadelink span a,
			a.small_icon_color i:hover,
			.es-nav a.btn:hover,
			a.btn:hover, a.btn[rel="prev"]:hover, a.btn[rel="next"]:hover
		';

		$selectors['footer1'] = '#footer';
		$selectors['footer2'] = '#footer .custom_color';

		$top_bar_font = etheme_get_option('top_bar_font', array());
		$top_bar_menu_font = etheme_get_option('top_bar_menu_font', array());
		$top_bar_menu_popup_font = etheme_get_option('top_bar_menu_popup_font', array());
		$header1_font = etheme_get_option('header1_font', array());
		$header2_font = etheme_get_option('header2_font', array());
		$content_font = etheme_get_option('content_font', array());
		$box_font = etheme_get_option('box_font', array());
		$links_font = etheme_get_option('links_font', array());
		$links_hover_font = etheme_get_option('links_hover_font', array());
		$price_font = etheme_get_option('price_font', array());
		$special_price_font = etheme_get_option('special_price_font', array());
		$buttons_font = etheme_get_option('buttons_font', array());
		$buttons_hover_text_color = etheme_get_option('buttons_hover_text_color', '#FFFFFF');
		$tabs_font = etheme_get_option('tabs_font', array());
		$tabs_hover_text_color = etheme_get_option('tabs_hover_text_color', '#FFFFFF');
		$icons_text_color = etheme_get_option('icons_text_color', '#FFFFFF');
		$icons_hover_text_color = etheme_get_option('icons_hover_text_color', '#FFFFFF');
		$h1 = etheme_get_option('h1', array());
		$h2 = etheme_get_option('h2', array());
		$h3 = etheme_get_option('h3', array());
		$h4 = etheme_get_option('h4', array());
		$h5 = etheme_get_option('h5', array());
		$h6 = etheme_get_option('h6', array());
		$footer1_font = etheme_get_option('footer1_font', array());
		$footer2_font = etheme_get_option('footer2_font', array());

		?>

		<style type="text/css">


			<?php $bg = etheme_get_option('background_img'); ?>
				body {
					<?php if(!empty($bg['background-color'])): ?>  background-color: <?php echo $bg['background-color']; ?>;<?php endif; ?>
					<?php if(!empty($bg['background-image'])): ?>  background-image: url(<?php echo $bg['background-image']; ?>) ; <?php endif; ?>
					<?php if(!empty($bg['background-attachment'])): ?>  background-attachment: <?php echo $bg['background-attachment']; ?>;<?php endif; ?>
					<?php if(!empty($bg['background-repeat'])): ?>  background-repeat: <?php echo $bg['background-repeat']; ?>;<?php  endif; ?>
					<?php if(!empty($bg['background-color'])): ?>  background-color: <?php echo $bg['background-color']; ?>;<?php  endif; ?>
					<?php if(!empty($bg['background-position'])): ?>  background-position: <?php echo $bg['background-position']; ?>;<?php endif; ?>
					<?php if(etheme_get_option('background_cover') == 'enable'): ?>
						background-size: cover;
					<?php endif; ?>
				}

			<?php if ( etheme_get_option('sale_icon') ) : ?>
			.label-icon.sale-label {
				width: <?php echo (etheme_get_option('sale_icon_width')) ? etheme_get_option('sale_icon_width') : 67 ?>px;
				height: <?php echo (etheme_get_option('sale_icon_height')) ? etheme_get_option('sale_icon_height') : 67 ?>px;
			}
			.label-icon.sale-label { background-image: url(<?php echo (etheme_get_option('sale_icon_url')) ? etheme_get_option('sale_icon_url') : get_template_directory_uri() .'/images/label-sale.png' ?>); }
			<?php endif; ?>

			<?php if ( etheme_get_option('new_icon') ) : ?>
			.label-icon.new-label {
				width: <?php echo (etheme_get_option('new_icon_width')) ? etheme_get_option('new_icon_width') : 67 ?>px;
				height: <?php echo (etheme_get_option('new_icon_height')) ? etheme_get_option('new_icon_height') : 67 ?>px;
			}
			.label-icon.new-label { background-image: url(<?php echo (etheme_get_option('new_icon_url')) ? etheme_get_option('new_icon_url') : get_template_directory_uri() .'/images/label-new.png' ?>); }

			<?php endif; ?>

			#topline {
				background-color: <?php echo etheme_get_option('top_bar_bg', '#333333'); ?>;
			}

			<?php echo $selectors['top_bar_menu']; ?> {
				background-color: <?php echo etheme_get_option('top_bar_menu_bg', '#4A4A4A'); ?>;
			}
			#topline .fadelink .ul_wrapper ul {
				background-color: <?php echo etheme_get_option('top_bar_menu_popup_bg', '#4A4A4A'); ?>;
			}
			<?php echo $selectors['header_container']; ?> {
				background-color: <?php echo etheme_get_option('header_bg', '#FFFFFF'); ?>;
			}

			<?php echo $selectors['content_container']; ?>, .span2.product, #spy, .post-preview-small, section.slider {
				background-color: <?php echo etheme_get_option('content_bg', '#FFFFFF'); ?>;
			}

			.box-wrapper {
				background-color: <?php echo etheme_get_option('box_bg', '#FFFFFF'); ?>;
			}

			button, .button, .btn-middle, .more-link, input[type="submit"],
			.button_small, #topline a.button_small,
			a.small_icon_color i,
			#sc_chat_box div.sc-chat-header, #sc_chat_box .sc-chat-wrapper .sc-start-chat-btn > a,
			.form-search button, .form-mail button,
			a.btn, a.btn[rel="prev"], a.btn[rel="next"],
			.shopping_cart_mini .button,
			.color_mark, .promo-box.style4,
			.nav-tabs > li > a:hover, .nav-tabs > .active > a, .nav-tabs > .active > a:hover {
				background-color: <?php echo etheme_get_option('buttons_bg', '#9D3BC6'); ?>;
			}

			.tab-content {
				border-top-color: <?php echo etheme_get_option('buttons_bg', '#9D3BC6'); ?>;
			}

			.infobox .icon i,
			h3 [class^="icon-"], h3 [class*=" icon-"],
			#content .custom_color,
			.tp-leftarrow.default, .tp-rightarrow.default,
			.ls-nav-prev, .ls-nav-next {
				color: <?php echo etheme_get_option('buttons_bg', '#9D3BC6'); ?> !important;
			}

			textarea:focus,
			input[type="text"]:focus,
			input[type="password"]:focus,
			input[type="datetime"]:focus,
			input[type="datetime-local"]:focus,
			input[type="date"]:focus,
			input[type="month"]:focus,
			input[type="time"]:focus,
			input[type="week"]:focus,
			input[type="number"]:focus,
			input[type="email"]:focus,
			input[type="url"]:focus,
			input[type="search"]:focus,
			input[type="tel"]:focus,
			input[type="color"]:focus,
			.uneditable-input:focus,
			input:focus:invalid:focus,
			textarea:focus:invalid:focus,
			select:focus:invalid:focus {
				border-color: <?php echo etheme_get_option('input_focus_color', '#C68DDE'); ?>;
			}

			button:hover, .button:hover, .more-link:hover, input[type="submit"]:hover,
			.button_small:hover, #topline a.button_small:hover,
			a.small_icon_color i:hover,
			#sc_chat_box div.sc-chat-header:hover, #sc_chat_box .sc-chat-wrapper .sc-start-chat-btn > a:hover,
			.form-search button:hover, .form-mail button:hover, .shoppingcart:hover .fadelink span a,
			a.btn:hover, a.btn[rel="prev"]:hover, a.btn[rel="next"]:hover,
			.shopping_cart_mini .button:hover,
			#filters li a:hover, #filters li a.active, #filters li a.selected {
				background-color: <?php echo etheme_get_option('buttons_hover_bg', '#6A2886'); ?>;
			}

			<?php echo jsString($selectors['tabs_font']); ?> {
				background-color: <?php echo etheme_get_option('tabs_bg', '#FFFFFF'); ?>;
			}

			<?php echo jsString($selectors['tabs_hover_text_color']); ?>,
			.tp-bannertimer,
			.jcarousel-skin-brands a.btn:hover,
			.es-nav a.btn:hover, .es-nav a[rel="prev"]:hover, .es-nav a[rel="next"]:hover,
			.flexslider.banners .flex-direction-nav a:hover,
			.direction-nav a:hover,
			.flexslider.vertical .flex-direction-nav a:hover, .flexslider.more-views .flex-direction-nav a:hover {
				background-color: <?php echo etheme_get_option('tabs_active_bg', '#9D3BC6'); ?>;
			}

			.filters-by-category li a.selected, .filters-by-category li a:hover {
				border-color: <?php echo etheme_get_option('tabs_active_bg', '#9D3BC6'); ?>;
			}
			.filters-by-category li {
				border-left-color: <?php echo etheme_get_option('tabs_active_bg', '#9D3BC6'); ?>;
			}

			.custom_blocks .box .inside, .flexslider.banners {
				border-bottom-color: <?php echo etheme_get_option('tabs_active_bg', '#9D3BC6'); ?>;
			}
			#nav>li>ul, #nav li:hover .menu_custom_block {
				border-top-color: <?php echo etheme_get_option('tabs_active_bg', '#9D3BC6'); ?>;
			}

			#footer, #footer_popup {
				background-color: <?php echo etheme_get_option('footer_bg', '#000000'); ?>;
			}

			#footer_line, #footer_button {
				background-color: <?php echo etheme_get_option('bottom_bar_bg', '#333333'); ?>;
			}

			<?php if ( isset($price_font['font-color']) && $price_font['font-color'] ) { ?>
			.product-price del {
				color: <?php echo $price_font['font-color']; ?>
			}
			<?php } ?>

			<?php if ( isset($content_font['font-color']) && $content_font['font-color'] ) { ?>
			.price-box .amount,
			.product-box:not(.quickviewblock) .add_to_wishlist,
			.breadcrumbs a {
				color: <?php echo $content_font['font-color']; ?> !important;
			}
			<?php } ?>

			.nav-tabs > li > a:hover, .nav-tabs > .active > a, .nav-tabs > .active > a:hover {
				color: <?php echo etheme_get_option('buttons_hover_text_color', '#FFFFFF'); ?> !important;
			}

			.product .product-tocart a, .preview .product-tocart a {
				color: <?php echo etheme_get_option('add_to_cart_color', '#9D3BC6'); ?> !important;
			}
			.product .product-tocart a:hover, .preview .product-tocart a:hover {
				color: <?php echo etheme_get_option('add_to_cart_hover_color', '#9D3BC6'); ?> !important;
			}

			<?php

				echo generate_fonts_css($top_bar_font, $selectors['top_bar']);
				echo generate_fonts_css($top_bar_menu_font, $selectors['top_bar_menu']);
				echo generate_fonts_css($top_bar_menu_popup_font, $selectors['top_bar_menu_popup']);

				echo generate_fonts_css($header1_font, $selectors['header1']);
				echo generate_fonts_css($header2_font, $selectors['header2']);

				echo generate_fonts_css($content_font, $selectors['content_font']);
				echo generate_fonts_css($box_font, $selectors['box_font']);

				echo generate_fonts_css($links_font, $selectors['links_font']);
				echo generate_fonts_css($links_hover_font, $selectors['links_hover_font']);

				echo generate_fonts_css($price_font, $selectors['price_font']);
				echo generate_fonts_css($special_price_font, $selectors['special_price_font']);

				echo generate_fonts_css($buttons_font, $selectors['buttons_font']);
				echo jsString($selectors['buttons_hover_text_color']) . ' {'. "\r\n" . ' color: ' . $buttons_hover_text_color . '}'. "\r\n";

				echo generate_fonts_css($tabs_font, $selectors['tabs_font']);
				echo jsString($selectors['tabs_hover_text_color']) . ' {'. "\r\n" . 'color: ' . $tabs_hover_text_color . '}'. "\r\n";

				echo jsString($selectors['icons_text_color']) . ' {'. "\r\n" . ' color: ' . $icons_text_color . '}'. "\r\n";
				echo jsString($selectors['icons_hover_text_color']) . ' {'. "\r\n" . ' color: ' . $icons_hover_text_color . '}'. "\r\n";

				echo generate_fonts_css($h1, 'h1');
				echo generate_fonts_css($h2, 'h2');
				echo generate_fonts_css($h3, 'h3');
				echo generate_fonts_css($h4, 'h4');
				echo generate_fonts_css($h5, 'h5');
				echo generate_fonts_css($h6, 'h6');

				echo generate_fonts_css($footer1_font, $selectors['footer1']);
				echo generate_fonts_css($footer2_font, $selectors['footer2']);

			?>

			<?php if ( isset($buttons_font['font-color']) ) {
				$social_login_link_color = $buttons_font['font-color'];
			} else {
				$social_login_link_color = '#FFFFFF';
			} ?>

			#wp-social-login-connect-options a, #cancel-comment-reply-link, a.more-link {
				color: <?php echo $social_login_link_color; ?> !important;
			}

			<?php if ( etheme_get_option('footer_type') == 2 ) { ?>

				#footer_popup {
					/*background-color: #2B2B2B;*/
					bottom: 0;
					display: block !important;
					padding-bottom: 20px;
					position: relative;
				}

				#footer_button {
					display: none;
				}

			<?php } ?>

		</style>
		<script type="text/javascript">
			var ajaxFilterEnabled = <?php echo (etheme_get_option('ajax_filter')) ? 1 : 0; ?>;
			var successfullyAdded = '<?php _e('Product successfully added to your shopping cart', WFT_DOMAIN) ?>';
			var view_mode_default = '<?php echo etheme_get_option('view_mode'); ?>';
			var catsAccordion = false;
			<?php if (etheme_get_option('cats_accordion')) {
				?>
			catsAccordion = true;
			<?php
		} ?>
			<?php if (class_exists('WooCommerce')) {
				global $woocommerce;
				?>
			var checkoutUrl = '<?php echo esc_url( $woocommerce->cart->get_checkout_url() ); ?>';
			var contBtn = '<?php _e('Continue shopping', WFT_DOMAIN) ?>';
			var checkBtn = '<?php _e('Checkout', WFT_DOMAIN) ?>';
			<?php
		} ?>

			var search_autocomplete_enabled = '<?php echo (etheme_get_option('search_autocomplete')) ? 1 : 0; ?>';
			var isotope_animation_enabled = '<?php echo ( etheme_get_option('isotope_animation') && !strpos($_SERVER["HTTP_USER_AGENT"], 'MSIE') ) ? 1 : 0; ?>';

			var hoverfold_js_url = '<?php echo get_template_directory_uri().'/js/jquery.hoverfold.js'; ?>';
			var fallback_css = '<?php echo get_template_directory_uri().'/css/fallback.css'; ?>';

		</script>

		<?php if ( !etheme_get_option('wp_admin_bar', 0) && !current_user_can( 'manage_options' ) ) {

			add_filter( 'show_admin_bar', '__return_false' );

			?>

			<style type="text/css">
				html { margin-top: 0 !important; }
				* html body { margin-top: 0 !important; }
			</style>

		<?php } //endif;


	}
}


// **********************************************************************//
// ! Add theme support
// **********************************************************************//

if(function_exists('add_theme_support')) {
	add_theme_support('post-thumbnails', array('post'));
	add_theme_support( 'automatic-feed-links' );
	add_theme_support( 'woocommerce' );
}
// **********************************************************************//
// ! Add admin styles and scripts
// **********************************************************************//
function etheme_add_admin_script(){

	wp_enqueue_style('farbtastic');
	wp_enqueue_style('etheme_admin_css', ETHEME_CODE_CSS_URL.'/admin.css');

	add_thickbox();
	wp_enqueue_script('theme-preview');
	wp_enqueue_script('common');
	wp_enqueue_script('wp-lists');
	wp_enqueue_script('postbox');
	wp_enqueue_script('farbtastic');
	wp_enqueue_script('etheme_admin_js', ETHEME_CODE_JS_URL.'/admin.js',array('wpb_php_js','wpb_js_composer_js_view','wpb_js_composer_js_custom_views'),false,true);
	wp_enqueue_style("font-awesome",get_template_directory_uri().'/css/font-awesome.min.css');

	$protocol = is_ssl() ? 'https' : 'http';
	wp_enqueue_style('font-lato', $protocol. 'http://fonts.googleapis.com/css?family=Lato:300,400,700,300italic');
}
add_action( 'admin_enqueue_scripts', 'etheme_add_admin_script' );

// **********************************************************************//
// ! Menus
// **********************************************************************//
if(!function_exists('etheme_register_menus')) {
	function etheme_register_menus() {
		register_nav_menus(array(
			'main-menu' => __('Main menu', WFT_DOMAIN),
			'mobile-menu' => __('Mobile menu', WFT_DOMAIN),
			'account-menu' => __('Account menu', WFT_DOMAIN)
		));
	}
}

add_action('init', 'etheme_register_menus');

// **********************************************************************//
// ! Get logo
// **********************************************************************//
if (!function_exists('etheme_logo')) {
	function etheme_logo() {
		$logoimg = etheme_get_option('logo');
		$logoimg = apply_filters('etheme_logo_src',$logoimg); ?>
		<?php if($logoimg): ?>
			<a href="<?php echo home_url(); ?>"><img src="<?php echo $logoimg ?>" alt="<?php bloginfo( 'description' ); ?>" /></a>
		<?php else: ?>
			<a href="<?php echo home_url(); ?>"><img src="<?php echo PARENT_URL.'/images/logo.png'; ?>" alt="<?php bloginfo('name'); ?>"></a>
		<?php endif ;
	}
}


if(!function_exists('etheme_top_links')) {
	function etheme_top_links() {
		?>
		<ul class="links">
			<?php if ( is_user_logged_in() ) : ?>
				<?php if(class_exists('Woocommerce')): ?> <li class="my-account-link"><a href="<?php echo get_permalink( get_option('woocommerce_myaccount_page_id') ); ?>"><?php _e( 'Your Account', WFT_DOMAIN ); ?></a>
					<div class="submenu-dropdown">
						<?php  if ( has_nav_menu( 'account-menu' ) ) : ?>
							<?php wp_nav_menu(array(
								'theme_location' => 'account-menu',
								'before' => '',
								'after' => '',
								'link_before' => '',
								'link_after' => '',
								'depth' => 4,
								'fallback_cb' => false
							)); ?>
						<?php else: ?>
							<h4 class="a-center">Set your account menu in <em>Apperance &gt; Menus</em></h4>
						<?php endif; ?>
					</div>
					</li><?php endif; ?>
				<li class="logout-link"><a href="<?php echo wp_logout_url(home_url()); ?>"><?php _e( 'Logout', WFT_DOMAIN ); ?></a></li>
			<?php else : ?>
				<?php
				$reg_id = etheme_tpl2id('et-registration.php');
				$reg_url = get_permalink($reg_id);
				?>
				<?php if(class_exists('Woocommerce')): ?><li class="login-link"><a href="<?php echo get_permalink( get_option('woocommerce_myaccount_page_id') ); ?>"><?php _e( 'Sign In', WFT_DOMAIN ); ?></a></li><?php endif; ?>
				<?php if(!empty($reg_id)): ?><li class="register-link"><a href="<?php echo $reg_url; ?>"><?php _e( 'Register', WFT_DOMAIN ); ?></a></li><?php endif; ?>
			<?php endif; ?>
		</ul>
	<?php
	}
}

// **********************************************************************//
// ! Header Type
// **********************************************************************//
function get_header_type() {
	return etheme_get_option('header_type');
}


// **********************************************************************//
// ! Footer Type
// **********************************************************************//
function get_footer_type() {
	return etheme_get_option('footer_type');
}



// **********************************************************************//
// ! Function to display comments
// **********************************************************************//


if(!function_exists('wft_comments')) {
	function wft_comments($comment, $args, $depth) {
		$GLOBALS['comment'] = $comment;

		$comment_type = get_comment_type();

		if ( $comment_type == 'pingback' || $comment_type == 'trackback' ) {
			?>

			<div id="comment-<?php comment_ID(); ?>" class="comment pingback">

			<div class="comment-body">
				<div class="author-link"><?php _e('Pingback:', WFT_DOMAIN) ?></div>
				<div class="comment-author"><?php comment_author_link(); ?></div>
				<div class="comment-reply"> <?php edit_comment_link(); ?></div>

			</div>

		<?php
		} elseif(get_comment_type() == 'comment') { ?>

			<div id="comment-<?php comment_ID(); ?>" <?php comment_class(); ?>>

			<div class="user_pic">
				<?php
				//$avatar_size = 170;
				echo get_avatar($comment, $args['avatar_size']);
				?>
			</div>
			<div class="username"><?php comment_author_link(); ?></div>
			<div class="date"><?php comment_date(); ?> - <?php comment_time(); ?> / <?php comment_reply_link(array_merge($args, array('depth' => $depth, 'max_depth' => $args['max_depth']))); ?></div>



			<div class="text">
				<?php if ($comment->comment_approved == '0'): ?>
					<p class="awaiting-moderation"><?php __('Your comment is awaiting moderation.', WFT_DOMAIN) ?></p>
				<?php endif ?>

				<?php comment_text(); ?>
			</div>
			<div class="clearfix"></div>


		<?php } //endif;
	}
}

// **********************************************************************//
// ! Custom Comment Form
// **********************************************************************//

if(!function_exists('etheme_custom_comment_form')) {
	function etheme_custom_comment_form($defaults) {
		$defaults['comment_notes_before'] = '';
		$defaults['comment_notes_after'] = '';
		$dafaults['id_form'] = 'comments_form';

		$defaults['comment_field'] = '<label for="comment">'.__('Comment', WFT_DOMAIN).'</label>
						<textarea id="comment" name="comment" class="full-width" style="height:190px;" rows="20" cols="1" aria-required="true"></textarea>';

		return $defaults;
	}
}

add_filter('comment_form_defaults', 'etheme_custom_comment_form');


// **********************************************************************//
// ! Register Sidebars
// **********************************************************************//

if ( function_exists('register_sidebar') ) {
	register_sidebar(array(
		'name' => __('Blog Sidebar', WFT_DOMAIN),
		'id' => 'blog-sidebar',
		'description' => __('Blog sidebar area', WFT_DOMAIN),
		'before_widget' => '<div id="%1$s" class="block %2$s">',
		'after_widget' => '</div><!-- //sidebar-widget -->',
		'before_title' => '<div class="block-title"><strong><span>',
		'after_title' => '</span></strong></div>',
	));
	register_sidebar(array(
		'name' => __('Listing Sidebar', WFT_DOMAIN),
		'id' => 'listing-sidebar',
		'description' => __('Listing page widget area', WFT_DOMAIN),
		'before_widget' => '<div id="%1$s" class="block %2$s">',
		'after_widget' => '<div class="clearfix"></div></div><!-- //sidebar-widget -->',
		'before_title' => '<div class="block-title"><strong><span>',
		'after_title' => '</span></strong></div>',
	));
	register_sidebar(array(
		'name' => __('Top right panel area', WFT_DOMAIN),
		'id' => 'top-right-panel-sidebar',
		'description' => __('Top right panel widget area', WFT_DOMAIN),
		'before_widget' => '<div class="pull-right"><div class="alignright"><div id="%1$s" class="sidebar-widget %2$s">',
		'after_widget' => '</div></div></div><!-- //sidebar-widget -->',
		'before_title' => '<h4 class="widget-title">',
		'after_title' => '</h4>',
	));
	register_sidebar(array(
		'name' => __('Place in header top bar', WFT_DOMAIN),
		'id' => 'languages-sidebar',
		'description' => __('Can be used for search, mini-cart widgets, etc.', WFT_DOMAIN),
		'before_widget' => '<div class="pull-right padding-1"><div id="%1$s" class="%2$s">',
		'after_widget' => '</div></div><!-- //sidebar-widget -->',
		'before_title' => '<h4 class="widget-title">',
		'after_title' => '</h4>',
	));

	register_sidebar(array(
		'name' => __('Right Toolbar', WFT_DOMAIN),
		'id' => 'right-toolbar-sidebar',
		'description' => __('Hidden toolbar, will appear when scrolling down page.', WFT_DOMAIN),
		'before_widget' => '<div id="%1$s" class="%2$s">',
		'after_widget' => '</div><!-- //sidebar-widget -->',
		'before_title' => '<h4 class="widget-title">',
		'after_title' => '</h4>',
	));
	register_sidebar(array(
		'name' => __('Footer 1', WFT_DOMAIN),
		'id' => 'footer1',
		'description' => __('Footer widget area', WFT_DOMAIN),
		'before_widget' => '<div id="%1$s" class="footer-sidebar-widget span3 %2$s">',
		'after_widget' => '</div><!-- //footer-sidebar-widget -->',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	));

	register_sidebar(array(
		'name' => __('Footer 2', WFT_DOMAIN),
		'id' => 'footer2',
		'description' => __('Footer widget area', WFT_DOMAIN),
		'before_widget' => '<div id="%1$s" class="footer-sidebar-widget span3 %2$s">',
		'after_widget' => '</div><!-- //sidebar-widget -->',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	));

}

// **********************************************************************//
// ! Set exerpt
// **********************************************************************//
function etheme_excerpt_length( $length ) {
	return 35;
}

add_filter( 'excerpt_length', 'etheme_excerpt_length', 999 );

function etheme_excerpt_more( $more ) {
	return '...';
}

add_filter('excerpt_more', 'etheme_excerpt_more');

// **********************************************************************//
// ! Contact page functions
// **********************************************************************//
if(!function_exists('isValidEmail')){
	function isValidEmail($email){
		return filter_var($email, FILTER_VALIDATE_EMAIL);
	}
}


// **********************************************************************//
// ! Create products slider by args
// **********************************************************************//
if(!function_exists('etheme_create_slider')) {
	function etheme_create_slider($args,$title = false, $shop_link = true, $sidebar_slider = false){
		global $wpdb;
		$product_per_row = etheme_get_option('prodcuts_per_row');
		$box_id = rand(1000,10000);
		$multislides = new WP_Query( $args );
		$sliderHeight = etheme_get_option('default_slider_height');
		$shop_url = get_permalink(woocommerce_get_page_id('shop'));
		$class = '';
		if($sidebar_slider) {
			$class .= ' sidebar-slider';
			$sliderHeight = 410;
		}

		if($multislides->post_count > 1) {
			$class .= ' posts-count-gt1';
		}
		if($multislides->post_count < 4) {
			$class .= ' posts-count-lt4';
		}
		if ( $multislides->have_posts() ) :
			if ($title) {
				$title_output = '<h2 class="title"><span>'.$title.'</span></h2>';
			}
			echo '<div class="slider-container '.$class.'">';
			echo $title_output;
			if($shop_link)
				echo '<a href="'.$shop_url.'" class="show-all-posts hidden-tablet hidden-phone">'.__('View more products', WFT_DOMAIN).'</a>';
			echo '<div class="items-slider products-slider slider-'.$box_id.'">';
			echo '<div class="slider">';
			$_i=0;
			while ($multislides->have_posts()) : $multislides->the_post();
				$_i++;

				if(class_exists('Woocommerce')) {
					global $product;
					if (!$product->is_visible()) continue;
					echo '<div class="slide-item product-slide">';
					woocommerce_get_template_part( 'content', 'product' );
					echo '</div><!-- slide-item -->';
				}

			endwhile;
			echo '</div><!-- slider -->';
			echo '</div><!-- products-slider -->';
			echo '<div class="slider-next next'.$box_id.'"></div>';
			echo '<div class="slider-prev disabled prev'.$box_id.'"></div>';
			echo '</div><!-- slider-container -->';
		endif;
		wp_reset_query();

		echo '
            <style>
                /* slider container */
                .slider-'.$box_id.',
                .slider-'.$box_id.' .slider .slide-item {
                    height: '.$sliderHeight.'px;
                }
            </style>
        ';

		echo '

            <script type="text/javascript">
                jQuery(".slider-'.$box_id.'").iosSlider({
                    snapToChildren: true,
                    desktopClickDrag: true,
                    navNextSelector: jQuery(".next'.$box_id.'"),
                    navPrevSelector: jQuery(".prev'.$box_id.'"),
                    onSlideComplete: function(args){
                        jQuery(".next'.$box_id.',.prev'.$box_id.'").removeClass("disabled");
                        if(args.currentSlideNumber == 1) {
                            jQuery(".prev'.$box_id.'").addClass("disabled");
                        } else if(args.currentSliderOffset == args.data.sliderMax) {
                            jQuery(".next'.$box_id.'").addClass("disabled");
                        }
                    }
                });
            </script>
        ';

	}
}


if(!function_exists('etheme_create_flex_slider')) {
	function etheme_create_flex_slider($args,$title = false, $shop_link = true, $sidebar_slider = false){
		global $wpdb;
		$product_per_row = etheme_get_option('prodcuts_per_row');
		$box_id = rand(1000,10000);
		$multislides = new WP_Query( $args );
		$sliderHeight = etheme_get_option('default_slider_height');
		$shop_url = get_permalink(woocommerce_get_page_id('shop'));
		$class = '';
		if($sidebar_slider) {
			$class .= ' sidebar-slider-flex';
			$sliderHeight = 410;
		}

		if($multislides->post_count > 1) {
			$class .= ' posts-count-gt1';
		}
		if($multislides->post_count < 4) {
			$class .= ' posts-count-lt4';
		}
		if ( $multislides->have_posts() ) :
			if ($title) {
				$title_output = '<h5 class="title"><span>'.$title.'</span></h5>';
			}
			echo '<div class="slider-container '.$class.'">';
			echo $title_output;
			if($shop_link)
				echo '<a href="'.$shop_url.'" class="show-all-posts hidden-tablet hidden-phone">'.__('View more products', WFT_DOMAIN).'</a>';
			echo '<div class="slider-viewport">';
			echo '<div class="slider-'.$box_id.'">';
			echo '<div class="slider">';
			$_i=0;
			echo '<div class="slide-item product-slide">';
			while ($multislides->have_posts()) : $multislides->the_post();
				$_i++;

				if(class_exists('Woocommerce')) {
					global $product;
					if (!$product->is_visible()) continue;
					woocommerce_get_template_part( 'content', 'product' );
					if($sidebar_slider){
						if($_i%2 == 0 && $_i != $multislides->post_count) {
							echo '</div><!-- slide-item -->';
							echo '<div class="slide-item product-slide">';
						}
					} else {
						echo '</div><!-- slide-item -->';
						echo '<div class="slide-item product-slide">';
					}
				}

			endwhile;
			echo '</div><!-- slide-item -->';
			echo '</div><!-- slider -->';
			echo '</div><!-- products-slider -->';
			echo '</div><!-- slider-viewport -->';
			echo '</div><!-- slider-container -->';
		endif;
		wp_reset_query();


		echo '
            <script type="text/javascript">
                jQuery(document).ready(function($) {
                    jQuery(".slider-'.$box_id.'").flexslider({
                        selector: ".slider .slide-item",
                        animation: "slide",
                        slideshow: false,
                        animationLoop: false,
                        controlNav: true,
                        directionNav:true,
                        itemWidth:105,
                        itemMargin:0,
                        move: 1
                    });
                });
            </script>
        ';

	}
}


// **********************************************************************//
// ! Create posts slider by args
// **********************************************************************//
if(!function_exists('etheme_create_posts_slider')) {
	function etheme_create_posts_slider($args,$title = false, $more_link = true, $date = false, $excerpt = false, $width = 300, $height = 200, $crop = true){
		$box_id = rand(1000,10000);
		$multislides = new WP_Query( $args );
		$lightbox = etheme_get_option('blog_lightbox');
		$sliderHeight = etheme_get_option('default_blog_slider_height');
		$posts_url = get_permalink(get_option('page_for_posts'));
		$class = '';
		if($multislides->post_count > 1) {
			$class = ' posts-count-gt1';
		}
		if($multislides->post_count < 4) {
			$class .= ' posts-count-lt4';
		}

		if ( $multislides->have_posts() ) :
			$title_output = '';
			if ($title) {
				$title_output = '<h2 class="title"><span>'.$title.'</span></h2>';
			}
			echo '<div class="slider-container '.$class.'">';
			echo $title_output;
			if($more_link)
				echo '<a href="'.$posts_url.'" class="show-all-posts hidden-tablet hidden-phone">'.__('View more posts', WFT_DOMAIN).'</a>';
			echo '<div class="items-slider posts-slider slider-'.$box_id.'">';
			echo '<div class="slider">';
			$_i=0;
			while ($multislides->have_posts()) : $multislides->the_post();
				$_i++;
				echo '<div class="slide-item post-slide">';
				if(has_post_thumbnail()){
					echo '<div class="post-images">';
					echo '<a href="'.get_permalink().'"><img src="' . etheme_get_image(false, $width, $height, true) . '" class="post-slide-img"></a>';

					echo '<div class="blog-mask">';
					echo '<div class="mask-content">';
					if($lightbox):
						echo '<a href="'.etheme_get_image(false).'" rel="lightbox"><i class="icon-resize-full"></i></a>';
					endif;
					echo '<a href="'.get_permalink().'"><i class="icon-link"></i></a>';
					echo '</div>';
					echo '</div>';
					echo '</div>';
				}

				if($date){
					echo '<div class="post-information">';
					the_category(',&nbsp;');
					echo ' / '.get_the_date('M') . ' <span>' . get_the_date('d') . '</span>' . ', ' . get_the_date('Y');
					echo '</div>';
				}
				echo '<h5><a href="'.get_permalink().'">' . get_the_title() . '</a></h5>';
				if($excerpt) the_excerpt();
				echo '</div><!-- slide-item -->';

			endwhile;
			echo '</div><!-- slider -->';
			echo '</div><!-- items-slider -->';
			echo '<div class="slider-next next'.$box_id.'"></div>';
			echo '<div class="slider-prev disabled prev'.$box_id.'"></div>';
			echo '</div><!-- slider-container -->';

			echo '
                <style>
                    /* slider container */
                    .slider-'.$box_id.',
                    .slider-'.$box_id.' .slider .slide-item {
                        height: '.$sliderHeight.'px;
                    }
                </style>
            ';

			echo '

                <script type="text/javascript">
                    jQuery(".slider-'.$box_id.'").iosSlider({
                        snapToChildren: true,
                        desktopClickDrag: true,
                        navNextSelector: jQuery(".next'.$box_id.'"),
                        navPrevSelector: jQuery(".prev'.$box_id.'"),
                        onSlideComplete: function(args){
                            jQuery(".next'.$box_id.',.prev'.$box_id.'").removeClass("disabled");
                            if(args.currentSlideNumber == 1) {
                                jQuery(".prev'.$box_id.'").addClass("disabled");
                            } else if(args.currentSliderOffset == args.data.sliderMax) {
                                jQuery(".next'.$box_id.'").addClass("disabled");
                            }
                        }

                    });
                </script>
            ';

		endif;
		wp_reset_query();

	}
}

// **********************************************************************//
// ! Custom sidebars
// **********************************************************************//

/**
 *
 *   Function for adding sidebar (AJAX action)
 */

function etheme_add_sidebar(){
	if (!wp_verify_nonce($_GET['_wpnonce_etheme_widgets'],'etheme-add-sidebar-widgets') ) die( 'Security check' );
	if($_GET['etheme_sidebar_name'] == '') die('Empty Name');
	$option_name = 'etheme_custom_sidebars';
	if(!get_option($option_name) || get_option($option_name) == '') delete_option($option_name);

	$new_sidebar = $_GET['etheme_sidebar_name'];


	if(get_option($option_name)) {
		$et_custom_sidebars = etheme_get_stored_sidebar();
		$et_custom_sidebars[] = trim($new_sidebar);
		$result = update_option($option_name, $et_custom_sidebars);
	}else{
		$et_custom_sidebars[] = $new_sidebar;
		$result2 = add_option($option_name, $et_custom_sidebars);
	}


	if($result) die('Updated');
	elseif($result2) die('added');
	else die('error');
}

/**
 *
 *   Function for deleting sidebar (AJAX action)
 */

function etheme_delete_sidebar(){
	$option_name = 'etheme_custom_sidebars';
	$del_sidebar = trim($_GET['etheme_sidebar_name']);

	if(get_option($option_name)) {
		$et_custom_sidebars = etheme_get_stored_sidebar();

		foreach($et_custom_sidebars as $key => $value){
			if($value == $del_sidebar)
				unset($et_custom_sidebars[$key]);
		}


		$result = update_option($option_name, $et_custom_sidebars);
	}

	if($result) die('Deleted');
	else die('error');
}

/**
 *
 *   Function for registering previously stored sidebars
 */
function etheme_register_stored_sidebar(){
	$et_custom_sidebars = etheme_get_stored_sidebar();
	if(is_array($et_custom_sidebars)) {
		foreach($et_custom_sidebars as $name){
			register_sidebar( array(
				'name' => ''.$name.'',
				'id' => $name,
				'class' => 'etheme_custom_sidebar',
				'before_widget' => '<div id="%1$s" class="widget-container %2$s">',
				'after_widget' => '</div>',
				'before_title' => '<h3 class="widget-title">',
				'after_title' => '</h3>',
			) );
		}
	}

}

/**
 *
 *   Function gets stored sidebar array
 */
function etheme_get_stored_sidebar(){
	$option_name = 'etheme_custom_sidebars';
	return get_option($option_name);
}


/**
 *
 *   Add form after all widgets
 */
function etheme_sidebar_form(){
	?>

	<div id="etheme_add_sidebar_form_wrap">
		<form action="<?php echo admin_url( 'widgets.php' ); ?>" method="post" id="etheme_add_sidebar_form">
			<h2>Custom Sidebar</h2>
			<?php wp_nonce_field( 'etheme-add-sidebar-widgets', '_wpnonce_etheme_widgets', false ); ?>
			<input type="text" name="etheme_sidebar_name" id="etheme_sidebar_name" />
			<button type="submit" class="button-primary" value="add-sidebar">Add Sidebar</button>
		</form>
	</div>
	<script type="text/javascript">
		var sidebarFormWrap = jQuery('#etheme_add_sidebar_form_wrap');
		var sidebarFormWrapNew = sidebarFormWrap.clone();
		sidebarFormWrap.remove();
		jQuery('#widgets-right').append('<div class="clearfix"></div>').append(sidebarFormWrapNew);
		var sidebarForm = sidebarFormWrapNew.find('#etheme_add_sidebar_form');

		sidebarForm.submit(function(e){
			e.preventDefault();
			var data =  {
				'action':'etheme_add_sidebar',
				'_wpnonce_etheme_widgets': jQuery('#_wpnonce_etheme_widgets').val(),
				'etheme_sidebar_name': jQuery('#etheme_sidebar_name').val()
			};

			jQuery.ajax({
				url: ajaxurl,
				data: data,
				success: function(response){

					window.location.reload(true);

				},
				error: function(data) {
					console.log('error');

				}
			});
		});

	</script>
<?php
}

//add_action( 'sidebar_admin_page', 'etheme_sidebar_form', 30 );
add_action('wp_ajax_etheme_add_sidebar', 'etheme_add_sidebar');
add_action('wp_ajax_etheme_delete_sidebar', 'etheme_delete_sidebar');
add_action( 'widgets_init', 'etheme_register_stored_sidebar' );


// **********************************************************************//
// ! Get sidebar
// **********************************************************************//

if(!function_exists('etheme_get_sidebar')) {
	function etheme_get_sidebar ($name = false) {
		do_action( 'get_sidebar', $name );
		if($name) {
			include(TEMPLATEPATH . '/sidebar-'.$name.'.php');
		}else{
			include(TEMPLATEPATH . '/sidebar.php');
		}
	}
}

// **********************************************************************//
// ! Site breadcrumbs
// **********************************************************************//
if(!function_exists('etheme_breadcrumbs')) {
	function etheme_breadcrumbs() {

		$showOnHome = 0; // 1 - show breadcrumbs on the homepage, 0 - don't show
		$delimiter = '<span class="delimeter">/</span>'; // delimiter between crumbs
		$home = 'Home'; // text for the 'Home' link
		$blogPage = 'Blog';
		$showCurrent = 1; // 1 - show current post/page title in breadcrumbs, 0 - don't show
		$before = '<span class="current">'; // tag before the current crumb
		$after = '</span>'; // tag after the current crumb

		global $post;
		$homeLink = home_url();

		if (is_front_page()) {

			if ($showOnHome == 1) echo '<div id="crumbs"><a href="' . $homeLink . '">' . $home . '</a></div>';

		} else {

			echo '<div class="breadcrumbs">';
			echo '<div id="breadcrumb">';
			echo '<a href="' . $homeLink . '">' . $home . '</a> ' . $delimiter . ' ';

			if ( is_category() ) {
				$thisCat = get_category(get_query_var('cat'), false);
				if ($thisCat->parent != 0) echo get_category_parents($thisCat->parent, TRUE, ' ' . $delimiter . ' ');
				echo $before . 'Archive by category "' . single_cat_title('', false) . '"' . $after;

			} elseif ( is_search() ) {
				echo $before . 'Search results for "' . get_search_query() . '"' . $after;

			} elseif ( is_day() ) {
				echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';
				echo '<a href="' . get_month_link(get_the_time('Y'),get_the_time('m')) . '">' . get_the_time('F') . '</a> ' . $delimiter . ' ';
				echo $before . get_the_time('d') . $after;

			} elseif ( is_month() ) {
				echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';
				echo $before . get_the_time('F') . $after;

			} elseif ( is_year() ) {
				echo $before . get_the_time('Y') . $after;

			} elseif ( is_single() && !is_attachment() ) {
				if ( get_post_type() == 'etheme_portfolio' ) {
					$portfolioId = etheme_tpl2id('portfolio.php');
					$portfolioLink = get_permalink($portfolioId);
					$post_type = get_post_type_object(get_post_type());
					$slug = $post_type->rewrite;
					echo '<a href="' . $portfolioLink . '/">' . $post_type->labels->name . '</a>';
					if ($showCurrent == 1) echo ' ' . $delimiter . ' ' . $before . get_the_title() . $after;
				} elseif ( get_post_type() != 'post' ) {
					$post_type = get_post_type_object(get_post_type());
					$slug = $post_type->rewrite;
					echo '<a href="' . $homeLink . '/' . $slug['slug'] . '/">' . $post_type->labels->singular_name . '</a>';
					if ($showCurrent == 1) echo ' ' . $delimiter . ' ' . $before . get_the_title() . $after;
				} else {
					$cat = get_the_category(); $cat = $cat[0];
					$cats = get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
					if ($showCurrent == 0) $cats = preg_replace("#^(.+)\s$delimiter\s$#", "$1", $cats);
					echo $cats;
					if ($showCurrent == 1) echo $before . get_the_title() . $after;
				}

			} elseif ( !is_single() && !is_page() && get_post_type() != 'post' && !is_404() ) {
				$post_type = get_post_type_object(get_post_type());
				echo $before . $post_type->labels->singular_name . $after;

			} elseif ( is_attachment() ) {
				if ($showCurrent == 1) echo ' '  . $before . get_the_title() . $after;

			} elseif ( is_page() && !$post->post_parent ) {
				if ($showCurrent == 1) echo $before . get_the_title() . $after;

			} elseif ( is_page() && $post->post_parent ) {
				$parent_id  = $post->post_parent;
				$breadcrumbs = array();
				while ($parent_id) {
					$page = get_page($parent_id);
					$breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a>';
					$parent_id  = $page->post_parent;
				}
				$breadcrumbs = array_reverse($breadcrumbs);
				for ($i = 0; $i < count($breadcrumbs); $i++) {
					echo $breadcrumbs[$i];
					if ($i != count($breadcrumbs)-1) echo ' ' . $delimiter . ' ';
				}
				if ($showCurrent == 1) echo ' ' . $delimiter . ' ' . $before . get_the_title() . $after;

			} elseif ( is_tag() ) {
				echo $before . 'Posts tagged "' . single_tag_title('', false) . '"' . $after;

			} elseif ( is_author() ) {
				global $author;
				$userdata = get_userdata($author);
				echo $before . 'Articles posted by ' . $userdata->display_name . $after;

			} elseif ( is_404() ) {
				echo $before . 'Error 404' . $after;
			}else{

				echo $blogPage;
			}

			if ( get_query_var('paged') ) {
				if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ' (';
				echo ' ('.__('Page') . ' ' . get_query_var('paged').')';
				if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ')';
			}

			echo '</div>';
			et_back_to_page();
			echo '</div>';

		}
	}
}

if(!function_exists('et_back_to_page')) {
	function et_back_to_page() {
		echo '<a class="back-to" href="javascript: history.go(-1)"><span>‹</span>'.__('Return to Previous Page',WFT_DOMAIN).'</a>';
	}
}
// **********************************************************************//
// ! Footer Demo Widgets
// **********************************************************************//

if(!function_exists('etheme_footer_demo')) {
function etheme_footer_demo($position){
switch ($position) {
	case 'footer2':

		?>

		<div class="row-fluid">
			<div class="span3">
				<h4 class="widget-title">About Company</h4>
				<div>
					<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod aliqua, sed do eiusmod aliqua.</p>

					<h6>Contact information</h6>
					30 South Park Avenue
					San Francisco, CA 94108
					Phone: +78 123 456 789
				</div>

			</div>
			<div class="span3">
				<?php
				$args = array(
					'widget_id' => 'etheme_widget_recent_comments',
					'before_widget' => '<div class="footer-sidebar-widget etheme_widget_recent_comments">',
					'after_widget' => '</div><!-- //sidebar-widget -->',
					'before_title' => '<h4 class="widget-title">',
					'after_title' => '</h4>'
				);

				$instance = array(
					'number' => 2,
					'title' => __('Recent Comments', WFT_DOMAIN)
				);


				$widget = new Etheme_Recent_Comments_Widget();
				$widget->widget($args, $instance);
				?>
			</div>
			<div class="span3">
				<?php
				echo do_shortcode('[vc_wp_posts show_date="1" title="Recent Posts" number="3"]');
				?>
			</div>
			<div class="span3">
				<?php
				$args = array(
					'widget_id' => 'etheme_widget_flickr',
					'before_widget' => '<div class="footer-sidebar-widget etheme_widget_flickr">',
					'after_widget' => '</div><!-- //sidebar-widget -->',
					'before_title' => '<h4 class="widget-title">',
					'after_title' => '</h4>'
				);

				$instance = array(
					'screen_name' => 'envato',
					'number' => 6,
					'show_button' => 1,
					'title' => __('Flickr Photos', WFT_DOMAIN)
				);


				$widget = new Etheme_Flickr_Widget();
				$widget->widget($args, $instance);
				?>
			</div>
		</div>

		<?php

		break;
	case 'footer9':
		?>
		<p><a href="<?php home_url(); ?>"><img src="<?php echo PARENT_URL.'/images/'; ?>logo-small.png" class="logo-small"></a></p>
		<?php
		break;
case 'footer10':
	?>
<p style="line-height: 35px;"><?php _e('Wordpress DEMO Store. All Rights Reserved.', WFT_DOMAIN) ?><p>
	<?php
	break;
}
}
}

// **********************************************************************//
// ! Replace variation images
// **********************************************************************//

if(!function_exists('etheme_replace_variation_images')) {
	function etheme_replace_variation_images($variations, $width = 1000, $height = 1000, $crop = false) {

		$newVariations = $variations;

		foreach ($variations as $key => $value) {
			$attachment_id = get_post_thumbnail_id( $variations[$key]['variation_id'] );

			$newImage = etheme_get_image($attachment_id, $width, $height, $crop);

			$newVariations[$key]['image_src'] = $newImage;
		}

		return $newVariations;
	}
}


// **********************************************************************//
// ! Wishlist
// **********************************************************************//

if(!function_exists('etheme_wishlist_btn')) {
	function etheme_wishlist_btn() {
		if(class_exists('YITH_WCWL'))
			echo do_shortcode('[yith_wcwl_add_to_wishlist]');
	}
}

// **********************************************************************//
// ! Get page sidebar position
// **********************************************************************//

if(!function_exists('etheme_get_page_sidebar')) {
	function etheme_get_page_sidebar() {
		$result = array(
			'position' => '',
			'responsive' => '',
			'sidebarname' => '',
			'page_heading' => 'disable',
			'page_slider' => 'no_slider',
			'sidebar_span' => 'span3'
		);


		$result['responsive'] = etheme_get_option('blog_sidebar_responsive');
		$result['position'] = etheme_get_option('blog_sidebar');
		$result['page_heading'] = etheme_get_custom_field('page_heading');
		$result['page_slider'] = etheme_get_custom_field('page_slider');
		$page_sidebar_state = etheme_get_custom_field('sidebar_state');
		$widgetarea = etheme_get_custom_field('widget_area');

		if ( $widgetarea != '' ) {
			$result['sidebarname'] = $widgetarea;
		} else {
			$result['sidebarname'] = 'blog-sidebar';
		}
		if($page_sidebar_state != '') {
			$result['position'] = $page_sidebar_state;
		}

		return $result;

	}
}


// **********************************************************************//
// ! Get blog sidebar position
// **********************************************************************//

if(!function_exists('etheme_get_blog_sidebar')) {
	function etheme_get_blog_sidebar() {

		$result = array(
			'responsive' => '',
			//'sidebarname' => '',
			'sidebar_span' => 'span3',
			'blog_layout' => 'default',
			'enable_filter' => 0,
		);

		$result['responsive'] = etheme_get_option('blog_sidebar_responsive');
		$result['blog_layout'] = etheme_get_option('blog_layout', 'default');
		$result['enable_filter'] = etheme_get_option('enable_filter', 0);
		//$result['sidebarname'] = etheme_get_option('widget_area');

		$result['blog_layout'] = apply_filters('custom_blog_layout', $result['blog_layout']);

		return $result;

	}
}

// **********************************************************************//
// ! Get shop sidebar position
// **********************************************************************//

if(!function_exists('etheme_get_shop_sidebar')) {
	function etheme_get_shop_sidebar() {

		$result = array(
			'position' => 'left',
			'responsive' => '',
			'product_per_row' => 3,
			'product_page_sidebar' => true,
			'sidebar_span' => 'span3',
			'content_span' => 'span9'
		);

		if ( !$result['product_page_sidebar'] || $result['product_per_row'] == 6 ) {
			$result['position'] = 'without';
			$result['content_span'] = 'span12';
		}

		return $result;
	}
}

// **********************************************************************//
// ! Get single product page sidebar position
// **********************************************************************//

if(!function_exists('etheme_get_single_product_sidebar')) {
	function etheme_get_single_product_sidebar() {

		$result = array(
			'position' => 'left',
			'responsive' => '',
			'images_span' => '5',
			'meta_span' => '4'
		);

		$result['single_product_sidebar'] = is_active_sidebar('single-sidebar');
		$result['responsive'] = etheme_get_option('blog_sidebar_responsive');
		$result['position'] = etheme_get_option('single_sidebar');

		$result['single_product_sidebar'] = apply_filters('single_product_sidebar', $result['single_product_sidebar']);

		if(!$result['single_product_sidebar'] || $result['position'] == 'no_sidebar') {
			$result['position'] = 'without';
			$result['images_span'] = '6';
			$result['meta_span'] = '6';
		}

		return $result;
	}
}



// **********************************************************************//
// ! Custom navigation
// **********************************************************************//

/**
 * Displays a navigation menu.
 *
 * Optional $args contents:
 *
 * menu - The menu that is desired. Accepts (matching in order) id, slug, name. Defaults to blank.
 * menu_class - CSS class to use for the ul element which forms the menu. Defaults to 'menu'.
 * menu_id - The ID that is applied to the ul element which forms the menu. Defaults to the menu slug, incremented.
 * container - Whether to wrap the ul, and what to wrap it with. Defaults to 'div'.
 * container_class - the class that is applied to the container. Defaults to 'menu-{menu slug}-container'.
 * container_id - The ID that is applied to the container. Defaults to blank.
 * fallback_cb - If the menu doesn't exists, a callback function will fire. Defaults to 'wp_page_menu'. Set to false for no fallback.
 * before - Text before the link text.
 * after - Text after the link text.
 * link_before - Text before the link.
 * link_after - Text after the link.
 * echo - Whether to echo the menu or return it. Defaults to echo.
 * depth - how many levels of the hierarchy are to be included. 0 means all. Defaults to 0.
 * walker - allows a custom walker to be specified.
 * theme_location - the location in the theme to be used. Must be registered with register_nav_menu() in order to be selectable by the user.
 * items_wrap - How the list items should be wrapped. Defaults to a ul with an id and class. Uses printf() format with numbered placeholders.
 *
 * @since 3.0.0
 *
 * @param array $args Arguments
 */
function wft_wp_nav_menu( $args = array() ) {
	static $menu_id_slugs = array();

	$defaults = array(
		'menu' => '',
		'collapse' => false,
		'container' => 'div',
		'container_class' => '',
		'container_id' => '',
		'menu_class' => 'menu',
		'menu_id' => '',
		'echo' => true,
		'fallback_cb' => 'wp_page_menu',
		'before' => '',
		'after' => '',
		'link_before' => '',
		'link_after' => '',
		'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
		'depth' => 0,
		'walker' => '',
		'theme_location' => ''
	);

	$args = wp_parse_args( $args, $defaults );
	/**
	 * Filter the arguments used to display a navigation menu.
	 *
	 * @since 3.0.0
	 *
	 * @param array $args Arguments from {@see wp_nav_menu()}.
	 */
	$args = apply_filters( 'wp_nav_menu_args', $args );
	$args = (object) $args;

	// Get the nav menu based on the requested menu
	$menu = wp_get_nav_menu_object( $args->menu );

	// Get the nav menu based on the theme_location
	if ( ! $menu && $args->theme_location && ( $locations = get_nav_menu_locations() ) && isset( $locations[ $args->theme_location ] ) )
		$menu = wp_get_nav_menu_object( $locations[ $args->theme_location ] );

	// get the first menu that has items if we still can't find a menu
	if ( ! $menu && !$args->theme_location ) {
		$menus = wp_get_nav_menus();
		foreach ( $menus as $menu_maybe ) {
			if ( $menu_items = wp_get_nav_menu_items( $menu_maybe->term_id, array( 'update_post_term_cache' => false ) ) ) {
				$menu = $menu_maybe;
				break;
			}
		}
	}

	// If the menu exists, get its items.
	if ( $menu && ! is_wp_error($menu) && !isset($menu_items) ) {
		$menu_items = wp_get_nav_menu_items( $menu->term_id, array( 'update_post_term_cache' => false ) );
	}

	/*
	 * If no menu was found:
	 *  - Fall back (if one was specified), or bail.
	 *
	 * If no menu items were found:
	 *  - Fall back, but only if no theme location was specified.
	 *  - Otherwise, bail.
	 */
	if ( ( !$menu || is_wp_error($menu) || ( isset($menu_items) && empty($menu_items) && !$args->theme_location ) )
		&& $args->fallback_cb && is_callable( $args->fallback_cb ) ) {

		return call_user_func( $args->fallback_cb, (array) $args );
	}

	if ( ! $menu || is_wp_error( $menu ) ) {
		return false;
	}

	$nav_menu = $items = '';

	$show_container = false;
	if ( $args->container ) {
		/**
		 * Filter the list of HTML tags that are valid for use as menu containers.
		 *
		 * @since 3.0.0
		 *
		 * @param array The acceptable HTML tags for use as menu containers, defaults as 'div' and 'nav'.
		 */
		$allowed_tags = apply_filters( 'wp_nav_menu_container_allowedtags', array( 'div', 'nav' ) );
		if ( in_array( $args->container, $allowed_tags ) ) {
			$show_container = true;
			$class = $args->container_class ? ' class="' . esc_attr( $args->container_class ) . '"' : ' class="menu-'. $menu->slug .'-container"';
			$id = $args->container_id ? ' id="' . esc_attr( $args->container_id ) . '"' : '';
			$nav_menu .= '<'. $args->container . $id . $class . '>';
		}
	}

	// Set up the $menu_item variables
	_wp_menu_item_classes_by_context( $menu_items );

	$sorted_menu_items = $menu_items_with_children = array();
	foreach ( (array) $menu_items as $menu_item ) {
		$sorted_menu_items[ $menu_item->menu_order ] = $menu_item;
		if ( $menu_item->menu_item_parent )
			$menu_items_with_children[ $menu_item->menu_item_parent ] = true;
	}

	// Add the menu-item-has-children class where applicable
	if ( $menu_items_with_children ) {
		foreach ( $sorted_menu_items as &$menu_item ) {
			if ( isset( $menu_items_with_children[ $menu_item->ID ] ) )
				$menu_item->classes[] = 'menu-item-has-children';
		}
	}

	unset( $menu_items, $menu_item );

	/**
	 * Filter the sorted list of menu item objects before generating the menu's HTML.
	 *
	 * @since 3.1.0
	 *
	 * @param array $sorted_menu_items The menu items, sorted by each menu item's menu order.
	 */
	$sorted_menu_items = apply_filters( 'wp_nav_menu_objects', $sorted_menu_items, $args );

	$items .= walk_nav_menu_tree( $sorted_menu_items, $args->depth, $args );
	unset($sorted_menu_items);

	// Attributes
	if ( ! empty( $args->menu_id ) ) {
		$wrap_id = $args->menu_id;
	} else {
		$wrap_id = 'menu-' . $menu->slug;
		while ( in_array( $wrap_id, $menu_id_slugs ) ) {
			if ( preg_match( '#-(\d+)$#', $wrap_id, $matches ) )
				$wrap_id = preg_replace('#-(\d+)$#', '-' . ++$matches[1], $wrap_id );
			else
				$wrap_id = $wrap_id . '-1';
		}
	}
	$menu_id_slugs[] = $wrap_id;

	$wrap_class = $args->menu_class ? $args->menu_class : '';

	/**
	 * Filter the HTML list content for navigation menus.
	 *
	 * @since 3.0.0
	 *
	 * @param string $items The HTML list content for the menu items.
	 * @param array $args Arguments from {@see wp_nav_menu()}.
	 */
	$items = apply_filters( 'wp_nav_menu_items', $items, $args );
	/**
	 * Filter the HTML list content for a specific navigation menu.
	 *
	 * @since 3.0.0
	 *
	 * @param string $items The HTML list content for the menu items.
	 * @param array $args Arguments from {@see wp_nav_menu()}.
	 */
	$items = apply_filters( "wp_nav_menu_{$menu->slug}_items", $items, $args );

	// Don't print any markup if there are no items at this point.
	if ( empty( $items ) )
		return false;

	$nav_menu .= sprintf( $args->items_wrap, esc_attr( $wrap_id ), esc_attr( $wrap_class ), $items );
	unset( $items );

	if ( $show_container )
		$nav_menu .= '</' . $args->container . '>';

	/**
	 * Filter the HTML content for navigation menus.
	 *
	 * @since 3.0.0
	 *
	 * @param string $nav_menu The HTML content for the navigation menu.
	 * @param array $args Arguments from {@see wp_nav_menu()}.
	 */
	$nav_menu = apply_filters( 'wp_nav_menu', $nav_menu, $args );

	if ( $args->echo ) {
		echo $nav_menu;
	} else {
		return $nav_menu;
	}
}

class Et_Navigation_backup extends Walker_Nav_Menu
{
	protected $middle_row = true;

	function start_lvl( &$output, $depth = 0, $args = array() ) {

		$display_depth = ($depth + 1);

		if ( $display_depth == '1' ) {
			$class_names = 'nav-sublist-dropdown';
			$container = 'container';
		} else {
			$class_names = 'nav-sublist';
			$container = '';
		}

		$indent = str_repeat("\t", $depth);

		$output .= "\n$indent" . '<ul class="level'. $depth .'"><li><ul class="shadow">' . "\n";
	}

	function end_lvl( &$output, $depth = 1, $args = array() ) {
		$indent = str_repeat("\t", $depth);
		$output .= "$indent</ul></li></ul>\n";
	}

	function start_el ( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
		global $wp_query;
		$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';

		$class_names = $value = '';

		$classes = empty( $item->classes ) ? array() : (array) $item->classes;
		$classes[] = 'menu-item-' . $item->ID;

		$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) );
		$class_names = ' class="' . esc_attr( $class_names ) . '"';

		$id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args );
		$id = strlen( $id ) ? ' id="' . esc_attr( $id ) . '"' : '';

		$output .= $indent . '<li ' . $id . $value . $class_names .'>';

		$attributes  = ! empty( $item->attr_title ) ? ' title="'  . esc_attr( $item->attr_title ) .'"' : '';
		$attributes .= ! empty( $item->target )     ? ' target="' . esc_attr( $item->target     ) .'"' : '';
		$attributes .= ! empty( $item->xfn )        ? ' rel="'    . esc_attr( $item->xfn        ) .'"' : '';
		$attributes .= ! empty( $item->url )        ? ' href="'   . esc_attr( $item->url        ) .'"' : '';

		$description = '';
		if ( strpos($class_names, 'image-item') !== false ) {
			$description = '<img src="'.do_shortcode($item->description).'" alt=" "/>';
		}

		$item_output = $args->before;


		if ( strpos($class_names, 'row_top') !== false || strpos($class_names, 'row_bot') !== false ) {
			$this->middle_row = false;
			$item_output .= '<span class="inside">' . $description;
		} else {
			$this->middle_row = true;
			$item_output .= '<a'. $attributes .'>';

			if ( $item->attr_title == 'home' || strpos($class_names, 'home-item') !== false ) {
				$item_output .= '<i class="icon-home"></i></a>';
			} else {
				$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
				$item_output .= $description;
			}
			$item_output .= '</a>';
		}
		$item_output .= $args->after;

		$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
	}

	/**
	 * Ends the element output, if needed.
	 *
	 * @see Walker::end_el()
	 *
	 * @since 3.0.0
	 *
	 * @param string $output Passed by reference. Used to append additional content.
	 * @param object $item   Page data object. Not used.
	 * @param int    $depth  Depth of page. Not Used.
	 * @param array  $args   An array of arguments. @see wp_nav_menu()
	 */
	function end_el( &$output, $item, $depth = 0, $args = array() ) {

		if ( !$this->middle_row ) {
			$output .= '</span>';
		}
		$output .= "</li>\n";
	}

	/**
	 * Traverse elements to create list from elements.
	 *
	 * Display one element if the element doesn't have any children otherwise,
	 * display the element and its children. Will only traverse up to the max
	 * depth and no ignore elements under that depth. It is possible to set the
	 * max depth to include all depths, see walk() method.
	 *
	 * This method should not be called directly, use the walk() method instead.
	 *
	 * @since 2.5.0
	 *
	 * @param object $element           Data object.
	 * @param array  $children_elements List of elements to continue traversing.
	 * @param int    $max_depth         Max depth to traverse.
	 * @param int    $depth             Depth of current element.
	 * @param array  $args              An array of arguments.
	 * @param string $output            Passed by reference. Used to append additional content.
	 * @return null Null on failure with no changes to parameters.
	 */
	function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) {

		if ( !$element ) {
			return;
		}

		$id_field = $this->db_fields['id'];

		//display this element
		if ( isset( $args[0] ) && is_array( $args[0] ) ) {
			$args[0]['has_children'] = ! empty( $children_elements[$element->$id_field] );
		}

		if ( in_array('row_top', $element->classes) || in_array('row_bot', $element->classes) ) {
			var_dump($args);
		}

		$cb_args = array_merge( array(&$output, $element, $depth), $args);
		call_user_func_array(array($this, 'start_el'), $cb_args);

		$id = $element->$id_field;

		// descend only when the depth is right and there are childrens for this element
		if ( ($max_depth == 0 || $max_depth > $depth+1 ) && isset( $children_elements[$id]) ) {

			foreach( $children_elements[ $id ] as $child ){

				if ( !isset($newlevel) ) {
					$newlevel = true;
					//start the child delimiter
					$cb_args = array_merge( array(&$output, $depth), $args);
					call_user_func_array(array($this, 'start_lvl'), $cb_args);
				}
				$this->display_element( $child, $children_elements, $max_depth, $depth + 1, $args, $output );
			}
			unset( $children_elements[ $id ] );
		}

		if ( isset($newlevel) && $newlevel ){
			//end the child delimiter
			$cb_args = array_merge( array(&$output, $depth), $args);
			call_user_func_array(array($this, 'end_lvl'), $cb_args);
		}

		//end this element
		if ( in_array('row_top', $element->classes) || in_array('row_bot', $element->classes) ) {
			var_dump($args);
		}
		$cb_args = array_merge( array(&$output, $element, $depth), $args);
		call_user_func_array(array($this, 'end_el'), $cb_args);
	}

	/**
	 * Display array of elements hierarchically.
	 *
	 * Does not assume any existing order of elements.
	 *
	 * $max_depth = -1 means flatly display every element.
	 * $max_depth = 0 means display all levels.
	 * $max_depth > 0 specifies the number of display levels.
	 *
	 * @since 2.1.0
	 *
	 * @param array $elements  An array of elements.
	 * @param int   $max_depth The maximum hierarchical depth.
	 * @return string The hierarchical item output.
	 */
	function walk( $elements, $max_depth) {

		$args = array_slice(func_get_args(), 2);
		$output = '';

		if ( $max_depth < -1 ) { //invalid parameter
			return $output;
		}

		if ( empty($elements) ) { //nothing to walk
			return $output;
		}

		$id_field = $this->db_fields['id'];
		$parent_field = $this->db_fields['parent'];

		// flat display
		if ( -1 == $max_depth ) {
			$empty_array = array();
			foreach ( $elements as $e ) {
				$this->display_element( $e, $empty_array, 1, 0, $args, $output );
			}
			return $output;
		}

		/*
		 * Need to display in hierarchical order.
		 * Separate elements into two buckets: top level and children elements.
		 * Children_elements is two dimensional array, eg.
		 * Children_elements[10][] contains all sub-elements whose parent is 10.
		 */
		$top_level_elements = array();
		$children_elements  = array();
		foreach ( $elements as $e) {
			if ( 0 == $e->$parent_field )
				$top_level_elements[] = $e;
			else
				$children_elements[ $e->$parent_field ][] = $e;
		}

		/*
		 * When none of the elements is top level.
		 * Assume the first one must be root of the sub elements.
		 */
		if ( empty($top_level_elements) ) {

			$first = array_slice( $elements, 0, 1 );
			$root = $first[0];

			$top_level_elements = array();
			$children_elements  = array();
			foreach ( $elements as $e) {
				if ( $root->$parent_field == $e->$parent_field ) {
					$top_level_elements[] = $e;
				} else {
					$children_elements[ $e->$parent_field ][] = $e;
				}
			}
		}

		foreach ( $top_level_elements as $e ) {
			$this->display_element( $e, $children_elements, $max_depth, 0, $args, $output );
		}

		/*
		 * If we are displaying all levels, and remaining children_elements is not empty,
		 * then we got orphans, which should be displayed regardless.
		 */
		if ( ( $max_depth == 0 ) && count( $children_elements ) > 0 ) {
			$empty_array = array();
			foreach ( $children_elements as $orphans ) {
				foreach( $orphans as $op ) {
					$this->display_element( $op, $empty_array, 1, 0, $args, $output );
				}
			}
		}

		return $output;
	}

}

class Et_Navigation extends Walker_Nav_Menu
{
	private $collapsed_id = '';

	function start_lvl( &$output, $depth = 0, $args = array() ) {

		$display_depth = ($depth + 1);


		$indent = str_repeat("\t", $depth);

		if ( $args->menu_class == 'collapse in' ) {
			$classes = 'collapse in level'. $depth;
			$id = 'id="' . $this->collapsed_id . '"';
		} else {
			$classes = 'level'. $depth;
			$id = '';
		}


		$output .= "\n$indent" . '<ul class="'. $classes .'" ' . $id . '>' . "\n";

		if ( $args->menu_class == 'collapse in' ) {
			$output .= '';
		} else {
			if ( $depth == 0 ) {
				$output .= '<ul class="shadow">' . "\n";
			}

			if ( $display_depth == 1 ) {
				$output .= $indent . '<li class="row_middle"><ul class="rows_outer"><li><ul class="menu_row">' . "\n";
			}
		}
	}

	function end_lvl( &$output, $depth = 1, $args = array() ) {


		$indent = str_repeat("\t", $depth);

		if ( $args->menu_class == 'collapse in' ) {
			$output .= '';
		} else {
			$display_depth = ($depth + 1);

			if ( $display_depth == 1 ) {

				$output .= $indent . '</ul></li></ul></li>' ."\n";
			}

			if ( $depth == 0 ) {
				$output .= '</ul>' . "\n";
			}
		}
		$output .= "$indent</ul>\n";
	}

	function start_el ( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {

		$is_image = in_array('image-item', $item->classes);
		$is_col = in_array('col', $item->classes);

		if ( isset($args->collapse) && $args->collapse && ( $is_image || $is_col ) ) {
			$output .= '';
		} else {

			global $wp_query;

			$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';

			$class_names = $value = '';

			//var_dump($item->classes);

			$classes = empty( $item->classes ) ? array() : (array) $item->classes;

			$classes[] = 'menu-item-' . $item->ID;

			$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) );

			if ( $depth == 0 && strpos($class_names, 'widemenu') === false ) {
				$class_names .= ' dropdown';
			}
			$class_names = ' class="' . esc_attr( $class_names ) . '"';

			$id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args );
			$id = strlen( $id ) ? ' id="' . esc_attr( $id ) . '"' : '';


			$output .= $indent . '<li ' . $id . $value . $class_names .'>';

			$attributes  = ! empty( $item->attr_title ) ? ' title="'  . esc_attr( $item->attr_title ) .'"' : '';
			$attributes .= ! empty( $item->target )     ? ' target="' . esc_attr( $item->target     ) .'"' : '';
			$attributes .= ! empty( $item->xfn )        ? ' rel="'    . esc_attr( $item->xfn        ) .'"' : '';
			$attributes .= ! empty( $item->url )        ? ' href="'   . esc_attr( $item->url        ) .'"' : '';

			$description = '';
			if ( $is_image !== false ) {
				$description = '<img src="'.do_shortcode($item->description).'" alt=" "/>';
			}

			if ( strpos($class_names, 'col') !== false ) {
				$attributes .= ' class="title"';
			}

			$item_output = $args->before;

			$item_output .= $indent . '<a'. $attributes .'>';

			if ( ($item->attr_title == 'home' || strpos($class_names, 'home-item') !== false) && (!isset($args->collapse) || !$args->collapse) ) {
				$item_output .= $indent . '<i class="icon-home"></i></a>';
			} else {
				if ( $is_image == false ) {
					$item_output .= $indent . $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
				}
				$item_output .= $indent . $description;
			}
			$item_output .= $indent . '</a>';

			if ( $args->menu_class == 'collapse in' && in_array('menu-item-has-children', $classes) ) {
				$this->collapsed_id = 'collapsed_item_'. $item->ID;
				$item_output .= '<a class="icon-collapse collapsed" href="#' . $this->collapsed_id . '" title="" data-toggle="collapse" ><i class="icon-up pull-right"></i><i class="icon-down pull-right"></i></a>';
			}

			$item_output .= $indent . $args->after;


			$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
		}
	}

	/**
	 * Ends the element output, if needed.
	 *
	 * @see Walker::end_el()
	 *
	 * @since 3.0.0
	 *
	 * @param string $output Passed by reference. Used to append additional content.
	 * @param object $item   Page data object. Not used.
	 * @param int    $depth  Depth of page. Not Used.
	 * @param array  $args   An array of arguments. @see wp_nav_menu()
	 */
	function end_el( &$output, $item, $depth = 0, $args = array() ) {

		if ( isset($args->collapse) && $args->collapse && (in_array('image-item', $item->classes) || in_array('col', $item->classes))  ) {
			$output .= '';
		} else {
			$output .= "</li>\n";
		}
	}

}

// **********************************************************************//
// ! http://codex.wordpress.org/Function_Reference/wp_nav_menu#How_to_add_a_parent_class_for_menu_item
// **********************************************************************//

add_filter( 'wp_nav_menu_objects', 'add_menu_parent_class' );
function add_menu_parent_class( $items ) {

	$parents = array();
	foreach ( $items as $item ) {
		if ( $item->menu_item_parent && $item->menu_item_parent > 0 ) {
			$parents[] = $item->menu_item_parent;
		}
	}

	foreach ( $items as $item ) {
		if ( in_array( $item->ID, $parents ) ) {
			$item->classes[] = 'menu-parent-item';
		}
	}

	return $items;
}


// **********************************************************************//
// ! Enable shortcodes in text widgets
// **********************************************************************//
add_filter('widget_text', 'do_shortcode');

// **********************************************************************//
// ! Add GOOGLE fonts
// **********************************************************************//

if(!function_exists('etheme_recognized_google_font_families')) {
	function etheme_recognized_google_font_families() {
		$array = array(
			'Open+Sans'           => '"Open Sans", sans-serif',
			'Droid+Sans'          => '"Droid Sans", sans-serif',
			'Lato'                => '"Lato"',
			'Cardo'               => '"Cardo"',
			'Roboto'              => '"Roboto"',
			'Fauna+One'           => '"Fauna One"',
			'Oswald'              => '"Oswald"',
			'Yanone+Kaffeesatz'   => '"Yanone Kaffeesatz"',
			'Muli'                => '"Muli"',
			'ABeeZee' => 'ABeeZee',
			'Abel' => 'Abel',
			'Abril+Fatface' => 'Abril Fatface',
			'Aclonica' => 'Aclonica',
			'Acme' => 'Acme',
			'Actor' => 'Actor',
			'Adamina' => 'Adamina',
			'Advent+Pro' => 'Advent Pro',
			'Aguafina+Script' => 'Aguafina Script',
			'Akronim' => 'Akronim',
			'Aladin' => 'Aladin',
			'Aldrich' => 'Aldrich',
			'Alef' => 'Alef',
			'Alegreya' => 'Alegreya',
			'Alegreya+SC' => 'Alegreya SC',
			'Alex+Brush' => 'Alex Brush',
			'Alfa+Slab+One' => 'Alfa Slab One',
			'Alice' => 'Alice',
			'Alike' => 'Alike',
			'Alike+Angular' => 'Alike Angular',
			'Allan' => 'Allan',
			'Allerta' => 'Allerta',
			'Allerta+Stencil' => 'Allerta Stencil',
			'Allura' => 'Allura',
			'Almendra' => 'Almendra',
			'Almendra+Display' => 'Almendra Display',
			'Almendra+SC' => 'Almendra SC',
			'Amarante' => 'Amarante',
			'Amaranth' => 'Amaranth',
			'Amatic+SC' => 'Amatic SC',
			'Amethysta' => 'Amethysta',
			'Anaheim' => 'Anaheim',
			'Andada' => 'Andada',
			'Andika' => 'Andika',
			'Angkor' => 'Angkor',
			'Annie+Use+Your+Telescope' => 'Annie Use Your Telescope',
			'Anonymous+Pro' => 'Anonymous Pro',
			'Antic' => 'Antic',
			'Antic+Didone' => 'Antic Didone',
			'Antic+Slab' => 'Antic Slab',
			'Anton' => 'Anton',
			'Arapey' => 'Arapey',
			'Arbutus' => 'Arbutus',
			'Arbutus+Slab' => 'Arbutus Slab',
			'Architects+Daughter' => 'Architects Daughter',
			'Archivo+Black' => 'Archivo Black',
			'Archivo+Narrow' => 'Archivo Narrow',
			'Arimo' => 'Arimo',
			'Arizonia' => 'Arizonia',
			'Armata' => 'Armata',
			'Artifika' => 'Artifika',
			'Arvo' => 'Arvo',
			'Asap' => 'Asap',
			'Asset' => 'Asset',
			'Astloch' => 'Astloch',
			'Asul' => 'Asul',
			'Atomic+Age' => 'Atomic Age',
			'Aubrey' => 'Aubrey',
			'Audiowide' => 'Audiowide',
			'Autour+One' => 'Autour One',
			'Average' => 'Average',
			'Average+Sans' => 'Average Sans',
			'Averia+Gruesa+Libre' => 'Averia Gruesa Libre',
			'Averia+Libre' => 'Averia Libre',
			'Averia+Sans+Libre' => 'Averia Sans Libre',
			'Averia+Serif+Libre' => 'Averia Serif Libre',
			'Bad+Script' => 'Bad Script',
			'Balthazar' => 'Balthazar',
			'Bangers' => 'Bangers',
			'Basic' => 'Basic',
			'Battambang' => 'Battambang',
			'Baumans' => 'Baumans',
			'Bayon' => 'Bayon',
			'Belgrano' => 'Belgrano',
			'Belleza' => 'Belleza',
			'BenchNine' => 'BenchNine',
			'Bentham' => 'Bentham',
			'Berkshire+Swash' => 'Berkshire Swash',
			'Bevan' => 'Bevan',
			'Bigelow+Rules' => 'Bigelow Rules',
			'Bigshot+One' => 'Bigshot One',
			'Bilbo' => 'Bilbo',
			'Bilbo+Swash+Caps' => 'Bilbo Swash Caps',
			'Bitter' => 'Bitter',
			'Black+Ops+One' => 'Black Ops One',
			'Bokor' => 'Bokor',
			'Bonbon' => 'Bonbon',
			'Boogaloo' => 'Boogaloo',
			'Bowlby+One' => 'Bowlby One',
			'Bowlby+One+SC' => 'Bowlby One SC',
			'Brawler' => 'Brawler',
			'Bree+Serif' => 'Bree Serif',
			'Bubblegum+Sans' => 'Bubblegum Sans',
			'Bubbler+One' => 'Bubbler One',
			'Buda' => 'Buda',
			'Buenard' => 'Buenard',
			'Butcherman' => 'Butcherman',
			'Butterfly+Kids' => 'Butterfly Kids',
			'Cabin' => 'Cabin',
			'Cabin+Condensed' => 'Cabin Condensed',
			'Cabin+Sketch' => 'Cabin Sketch',
			'Caesar+Dressing' => 'Caesar Dressing',
			'Cagliostro' => 'Cagliostro',
			'Calligraffitti' => 'Calligraffitti',
			'Cambo' => 'Cambo',
			'Candal' => 'Candal',
			'Cantarell' => 'Cantarell',
			'Cantata+One' => 'Cantata One',
			'Cantora+One' => 'Cantora One',
			'Capriola' => 'Capriola',
			'Cardo' => 'Cardo',
			'Carme' => 'Carme',
			'Carrois+Gothic' => 'Carrois Gothic',
			'Carrois+Gothic+SC' => 'Carrois Gothic SC',
			'Carter+One' => 'Carter One',
			'Caudex' => 'Caudex',
			'Cedarville+Cursive' => 'Cedarville Cursive',
			'Ceviche+One' => 'Ceviche One',
			'Changa+One' => 'Changa One',
			'Chango' => 'Chango',
			'Chau+Philomene+One' => 'Chau Philomene One',
			'Chela+One' => 'Chela One',
			'Chelsea+Market' => 'Chelsea Market',
			'Chenla' => 'Chenla',
			'Cherry+Cream+Soda' => 'Cherry Cream Soda',
			'Cherry+Swash' => 'Cherry Swash',
			'Chewy' => 'Chewy',
			'Chicle' => 'Chicle',
			'Chivo' => 'Chivo',
			'Cinzel' => 'Cinzel',
			'Cinzel+Decorative' => 'Cinzel Decorative',
			'Clicker+Script' => 'Clicker Script',
			'Coda' => 'Coda',
			'Coda+Caption' => 'Coda Caption',
			'Codystar' => 'Codystar',
			'Combo' => 'Combo',
			'Comfortaa' => 'Comfortaa',
			'Coming+Soon' => 'Coming Soon',
			'Concert+One' => 'Concert One',
			'Condiment' => 'Condiment',
			'Content' => 'Content',
			'Contrail+One' => 'Contrail One',
			'Convergence' => 'Convergence',
			'Cookie' => 'Cookie',
			'Copse' => 'Copse',
			'Corben' => 'Corben',
			'Courgette' => 'Courgette',
			'Cousine' => 'Cousine',
			'Coustard' => 'Coustard',
			'Covered+By+Your+Grace' => 'Covered By Your Grace',
			'Crafty+Girls' => 'Crafty Girls',
			'Creepster' => 'Creepster',
			'Crete+Round' => 'Crete Round',
			'Crimson+Text' => 'Crimson Text',
			'Croissant+One' => 'Croissant One',
			'Crushed' => 'Crushed',
			'Cuprum' => 'Cuprum',
			'Cutive' => 'Cutive',
			'Cutive+Mono' => 'Cutive Mono',
			'Damion' => 'Damion',
			'Dancing+Script' => 'Dancing Script',
			'Dangrek' => 'Dangrek',
			'Dawning+of+a+New+Day' => 'Dawning of a New Day',
			'Days+One' => 'Days One',
			'Delius' => 'Delius',
			'Delius+Swash+Caps' => 'Delius Swash Caps',
			'Delius+Unicase' => 'Delius Unicase',
			'Della+Respira' => 'Della Respira',
			'Denk+One' => 'Denk One',
			'Devonshire' => 'Devonshire',
			'Didact+Gothic' => 'Didact Gothic',
			'Diplomata' => 'Diplomata',
			'Diplomata+SC' => 'Diplomata SC',
			'Domine' => 'Domine',
			'Donegal+One' => 'Donegal One',
			'Doppio+One' => 'Doppio One',
			'Dorsa' => 'Dorsa',
			'Dosis' => 'Dosis',
			'Dr+Sugiyama' => 'Dr Sugiyama',
			'Droid+Sans' => 'Droid Sans',
			'Droid+Sans+Mono' => 'Droid Sans Mono',
			'Droid+Serif' => 'Droid Serif',
			'Duru+Sans' => 'Duru Sans',
			'Dynalight' => 'Dynalight',
			'EB+Garamond' => 'EB Garamond',
			'Eagle+Lake' => 'Eagle Lake',
			'Eater' => 'Eater',
			'Economica' => 'Economica',
			'Electrolize' => 'Electrolize',
			'Elsie' => 'Elsie',
			'Elsie+Swash+Caps' => 'Elsie Swash Caps',
			'Emblema+One' => 'Emblema One',
			'Emilys+Candy' => 'Emilys Candy',
			'Engagement' => 'Engagement',
			'Englebert' => 'Englebert',
			'Enriqueta' => 'Enriqueta',
			'Erica+One' => 'Erica One',
			'Esteban' => 'Esteban',
			'Euphoria+Script' => 'Euphoria Script',
			'Ewert' => 'Ewert',
			'Exo' => 'Exo',
			'Expletus+Sans' => 'Expletus Sans',
			'Fanwood+Text' => 'Fanwood Text',
			'Fascinate' => 'Fascinate',
			'Fascinate+Inline' => 'Fascinate Inline',
			'Faster+One' => 'Faster One',
			'Fasthand' => 'Fasthand',
			'Fauna+One' => 'Fauna One',
			'Federant' => 'Federant',
			'Federo' => 'Federo',
			'Felipa' => 'Felipa',
			'Fenix' => 'Fenix',
			'Finger+Paint' => 'Finger Paint',
			'Fjalla+One' => 'Fjalla One',
			'Fjord+One' => 'Fjord One',
			'Flamenco' => 'Flamenco',
			'Flavors' => 'Flavors',
			'Fondamento' => 'Fondamento',
			'Fontdiner+Swanky' => 'Fontdiner Swanky',
			'Forum' => 'Forum',
			'Francois+One' => 'Francois One',
			'Freckle+Face' => 'Freckle Face',
			'Fredericka+the+Great' => 'Fredericka the Great',
			'Fredoka+One' => 'Fredoka One',
			'Freehand' => 'Freehand',
			'Fresca' => 'Fresca',
			'Frijole' => 'Frijole',
			'Fruktur' => 'Fruktur',
			'Fugaz+One' => 'Fugaz One',
			'GFS+Didot' => 'GFS Didot',
			'GFS+Neohellenic' => 'GFS Neohellenic',
			'Gabriela' => 'Gabriela',
			'Gafata' => 'Gafata',
			'Galdeano' => 'Galdeano',
			'Galindo' => 'Galindo',
			'Gentium+Basic' => 'Gentium Basic',
			'Gentium+Book+Basic' => 'Gentium Book Basic',
			'Geo' => 'Geo',
			'Geostar' => 'Geostar',
			'Geostar+Fill' => 'Geostar Fill',
			'Germania+One' => 'Germania One',
			'Gilda+Display' => 'Gilda Display',
			'Give+You+Glory' => 'Give You Glory',
			'Glass+Antiqua' => 'Glass Antiqua',
			'Glegoo' => 'Glegoo',
			'Gloria+Hallelujah' => 'Gloria Hallelujah',
			'Goblin+One' => 'Goblin One',
			'Gochi+Hand' => 'Gochi Hand',
			'Gorditas' => 'Gorditas',
			'Goudy+Bookletter+1911' => 'Goudy Bookletter 1911',
			'Graduate' => 'Graduate',
			'Grand+Hotel' => 'Grand Hotel',
			'Gravitas+One' => 'Gravitas One',
			'Great+Vibes' => 'Great Vibes',
			'Griffy' => 'Griffy',
			'Gruppo' => 'Gruppo',
			'Gudea' => 'Gudea',
			'Habibi' => 'Habibi',
			'Hammersmith+One' => 'Hammersmith One',
			'Hanalei' => 'Hanalei',
			'Hanalei+Fill' => 'Hanalei Fill',
			'Handlee' => 'Handlee',
			'Hanuman' => 'Hanuman',
			'Happy+Monkey' => 'Happy Monkey',
			'Headland+One' => 'Headland One',
			'Henny+Penny' => 'Henny Penny',
			'Herr+Von+Muellerhoff' => 'Herr Von Muellerhoff',
			'Holtwood+One+SC' => 'Holtwood One SC',
			'Homemade+Apple' => 'Homemade Apple',
			'Homenaje' => 'Homenaje',
			'IM+Fell+DW+Pica' => 'IM Fell DW Pica',
			'IM+Fell+DW+Pica+SC' => 'IM Fell DW Pica SC',
			'IM+Fell+Double+Pica' => 'IM Fell Double Pica',
			'IM+Fell+Double+Pica+SC' => 'IM Fell Double Pica SC',
			'IM+Fell+English' => 'IM Fell English',
			'IM+Fell+English+SC' => 'IM Fell English SC',
			'IM+Fell+French+Canon' => 'IM Fell French Canon',
			'IM+Fell+French+Canon+SC' => 'IM Fell French Canon SC',
			'IM+Fell+Great+Primer' => 'IM Fell Great Primer',
			'IM+Fell+Great+Primer+SC' => 'IM Fell Great Primer SC',
			'Iceberg' => 'Iceberg',
			'Iceland' => 'Iceland',
			'Imprima' => 'Imprima',
			'Inconsolata' => 'Inconsolata',
			'Inder' => 'Inder',
			'Indie+Flower' => 'Indie Flower',
			'Inika' => 'Inika',
			'Irish+Grover' => 'Irish Grover',
			'Istok+Web' => 'Istok Web',
			'Italiana' => 'Italiana',
			'Italianno' => 'Italianno',
			'Jacques+Francois' => 'Jacques Francois',
			'Jacques+Francois+Shadow' => 'Jacques Francois Shadow',
			'Jim+Nightshade' => 'Jim Nightshade',
			'Jockey+One' => 'Jockey One',
			'Jolly+Lodger' => 'Jolly Lodger',
			'Josefin+Sans' => 'Josefin Sans',
			'Josefin+Slab' => 'Josefin Slab',
			'Joti+One' => 'Joti One',
			'Judson' => 'Judson',
			'Julee' => 'Julee',
			'Julius+Sans+One' => 'Julius Sans One',
			'Junge' => 'Junge',
			'Jura' => 'Jura',
			'Just+Another+Hand' => 'Just Another Hand',
			'Just+Me+Again+Down+Here' => 'Just Me Again Down Here',
			'Kameron' => 'Kameron',
			'Karla' => 'Karla',
			'Kaushan+Script' => 'Kaushan Script',
			'Kavoon' => 'Kavoon',
			'Keania+One' => 'Keania One',
			'Kelly+Slab' => 'Kelly Slab',
			'Kenia' => 'Kenia',
			'Khmer' => 'Khmer',
			'Kite+One' => 'Kite One',
			'Knewave' => 'Knewave',
			'Kotta+One' => 'Kotta One',
			'Koulen' => 'Koulen',
			'Kranky' => 'Kranky',
			'Kreon' => 'Kreon',
			'Kristi' => 'Kristi',
			'Krona+One' => 'Krona One',
			'La+Belle+Aurore' => 'La Belle Aurore',
			'Lancelot' => 'Lancelot',
			'Lato' => 'Lato',
			'League+Script' => 'League Script',
			'Leckerli+One' => 'Leckerli One',
			'Ledger' => 'Ledger',
			'Lekton' => 'Lekton',
			'Lemon' => 'Lemon',
			'Libre+Baskerville' => 'Libre Baskerville',
			'Life+Savers' => 'Life Savers',
			'Lilita+One' => 'Lilita One',
			'Lily+Script+One' => 'Lily Script One',
			'Limelight' => 'Limelight',
			'Linden+Hill' => 'Linden Hill',
			'Lobster' => 'Lobster',
			'Lobster+Two' => 'Lobster Two',
			'Londrina+Outline' => 'Londrina Outline',
			'Londrina+Shadow' => 'Londrina Shadow',
			'Londrina+Sketch' => 'Londrina Sketch',
			'Londrina+Solid' => 'Londrina Solid',
			'Lora' => 'Lora',
			'Love+Ya+Like+A+Sister' => 'Love Ya Like A Sister',
			'Loved+by+the+King' => 'Loved by the King',
			'Lovers+Quarrel' => 'Lovers Quarrel',
			'Luckiest+Guy' => 'Luckiest Guy',
			'Lusitana' => 'Lusitana',
			'Lustria' => 'Lustria',
			'Macondo' => 'Macondo',
			'Macondo+Swash+Caps' => 'Macondo Swash Caps',
			'Magra' => 'Magra',
			'Maiden+Orange' => 'Maiden Orange',
			'Mako' => 'Mako',
			'Marcellus' => 'Marcellus',
			'Marcellus+SC' => 'Marcellus SC',
			'Marck+Script' => 'Marck Script',
			'Margarine' => 'Margarine',
			'Marko+One' => 'Marko One',
			'Marmelad' => 'Marmelad',
			'Marvel' => 'Marvel',
			'Mate' => 'Mate',
			'Mate+SC' => 'Mate SC',
			'Maven+Pro' => 'Maven Pro',
			'McLaren' => 'McLaren',
			'Meddon' => 'Meddon',
			'MedievalSharp' => 'MedievalSharp',
			'Medula+One' => 'Medula One',
			'Megrim' => 'Megrim',
			'Meie+Script' => 'Meie Script',
			'Merienda' => 'Merienda',
			'Merienda+One' => 'Merienda One',
			'Merriweather' => 'Merriweather',
			'Merriweather+Sans' => 'Merriweather Sans',
			'Metal' => 'Metal',
			'Metal+Mania' => 'Metal Mania',
			'Metamorphous' => 'Metamorphous',
			'Metrophobic' => 'Metrophobic',
			'Michroma' => 'Michroma',
			'Milonga' => 'Milonga',
			'Miltonian' => 'Miltonian',
			'Miltonian+Tattoo' => 'Miltonian Tattoo',
			'Miniver' => 'Miniver',
			'Miss+Fajardose' => 'Miss Fajardose',
			'Modern+Antiqua' => 'Modern Antiqua',
			'Molengo' => 'Molengo',
			'Molle' => 'Molle',
			'Monda' => 'Monda',
			'Monofett' => 'Monofett',
			'Monoton' => 'Monoton',
			'Monsieur+La+Doulaise' => 'Monsieur La Doulaise',
			'Montaga' => 'Montaga',
			'Montez' => 'Montez',
			'Montserrat' => 'Montserrat',
			'Montserrat+Alternates' => 'Montserrat Alternates',
			'Montserrat+Subrayada' => 'Montserrat Subrayada',
			'Moul' => 'Moul',
			'Moulpali' => 'Moulpali',
			'Mountains+of+Christmas' => 'Mountains of Christmas',
			'Mouse+Memoirs' => 'Mouse Memoirs',
			'Mr+Bedfort' => 'Mr Bedfort',
			'Mr+Dafoe' => 'Mr Dafoe',
			'Mr+De+Haviland' => 'Mr De Haviland',
			'Mrs+Saint+Delafield' => 'Mrs Saint Delafield',
			'Mrs+Sheppards' => 'Mrs Sheppards',
			'Muli' => 'Muli',
			'Mystery+Quest' => 'Mystery Quest',
			'Neucha' => 'Neucha',
			'Neuton' => 'Neuton',
			'New+Rocker' => 'New Rocker',
			'News+Cycle' => 'News Cycle',
			'Niconne' => 'Niconne',
			'Nixie+One' => 'Nixie One',
			'Nobile' => 'Nobile',
			'Nokora' => 'Nokora',
			'Norican' => 'Norican',
			'Nosifer' => 'Nosifer',
			'Nothing+You+Could+Do' => 'Nothing You Could Do',
			'Noticia+Text' => 'Noticia Text',
			'Noto+Sans' => 'Noto Sans',
			'Noto+Serif' => 'Noto Serif',
			'Nova+Cut' => 'Nova Cut',
			'Nova+Flat' => 'Nova Flat',
			'Nova+Mono' => 'Nova Mono',
			'Nova+Oval' => 'Nova Oval',
			'Nova+Round' => 'Nova Round',
			'Nova+Script' => 'Nova Script',
			'Nova+Slim' => 'Nova Slim',
			'Nova+Square' => 'Nova Square',
			'Numans' => 'Numans',
			'Nunito' => 'Nunito',
			'Odor+Mean+Chey' => 'Odor Mean Chey',
			'Offside' => 'Offside',
			'Old+Standard+TT' => 'Old Standard TT',
			'Oldenburg' => 'Oldenburg',
			'Oleo+Script' => 'Oleo Script',
			'Oleo+Script+Swash+Caps' => 'Oleo Script Swash Caps',
			'Open+Sans' => 'Open Sans',
			'Open+Sans+Condensed' => 'Open Sans Condensed',
			'Oranienbaum' => 'Oranienbaum',
			'Orbitron' => 'Orbitron',
			'Oregano' => 'Oregano',
			'Orienta' => 'Orienta',
			'Original+Surfer' => 'Original Surfer',
			'Oswald' => 'Oswald',
			'Over+the+Rainbow' => 'Over the Rainbow',
			'Overlock' => 'Overlock',
			'Overlock+SC' => 'Overlock SC',
			'Ovo' => 'Ovo',
			'Oxygen' => 'Oxygen',
			'Oxygen+Mono' => 'Oxygen Mono',
			'PT+Mono' => 'PT Mono',
			'PT+Sans' => 'PT Sans',
			'PT+Sans+Caption' => 'PT Sans Caption',
			'PT+Sans+Narrow' => 'PT Sans Narrow',
			'PT+Serif' => 'PT Serif',
			'PT+Serif+Caption' => 'PT Serif Caption',
			'Pacifico' => 'Pacifico',
			'Paprika' => 'Paprika',
			'Parisienne' => 'Parisienne',
			'Passero+One' => 'Passero One',
			'Passion+One' => 'Passion One',
			'Pathway+Gothic+One' => 'Pathway Gothic One',
			'Patrick+Hand' => 'Patrick Hand',
			'Patrick+Hand+SC' => 'Patrick Hand SC',
			'Patua+One' => 'Patua One',
			'Paytone+One' => 'Paytone One',
			'Peralta' => 'Peralta',
			'Permanent+Marker' => 'Permanent Marker',
			'Petit+Formal+Script' => 'Petit Formal Script',
			'Petrona' => 'Petrona',
			'Philosopher' => 'Philosopher',
			'Piedra' => 'Piedra',
			'Pinyon+Script' => 'Pinyon Script',
			'Pirata+One' => 'Pirata One',
			'Plaster' => 'Plaster',
			'Play' => 'Play',
			'Playball' => 'Playball',
			'Playfair+Display' => 'Playfair Display',
			'Playfair+Display+SC' => 'Playfair Display SC',
			'Podkova' => 'Podkova',
			'Poiret+One' => 'Poiret One',
			'Poller+One' => 'Poller One',
			'Poly' => 'Poly',
			'Pompiere' => 'Pompiere',
			'Pontano+Sans' => 'Pontano Sans',
			'Port+Lligat+Sans' => 'Port Lligat Sans',
			'Port+Lligat+Slab' => 'Port Lligat Slab',
			'Prata' => 'Prata',
			'Preahvihear' => 'Preahvihear',
			'Press+Start+2P' => 'Press Start 2P',
			'Princess+Sofia' => 'Princess Sofia',
			'Prociono' => 'Prociono',
			'Prosto+One' => 'Prosto One',
			'Puritan' => 'Puritan',
			'Purple+Purse' => 'Purple Purse',
			'Quando' => 'Quando',
			'Quantico' => 'Quantico',
			'Quattrocento' => 'Quattrocento',
			'Quattrocento+Sans' => 'Quattrocento Sans',
			'Questrial' => 'Questrial',
			'Quicksand' => 'Quicksand',
			'Quintessential' => 'Quintessential',
			'Qwigley' => 'Qwigley',
			'Racing+Sans+One' => 'Racing Sans One',
			'Radley' => 'Radley',
			'Raleway' => 'Raleway',
			'Raleway+Dots' => 'Raleway Dots',
			'Rambla' => 'Rambla',
			'Rammetto+One' => 'Rammetto One',
			'Ranchers' => 'Ranchers',
			'Rancho' => 'Rancho',
			'Rationale' => 'Rationale',
			'Redressed' => 'Redressed',
			'Reenie+Beanie' => 'Reenie Beanie',
			'Revalia' => 'Revalia',
			'Ribeye' => 'Ribeye',
			'Ribeye+Marrow' => 'Ribeye Marrow',
			'Righteous' => 'Righteous',
			'Risque' => 'Risque',
			'Roboto' => 'Roboto',
			'Roboto+Condensed' => 'Roboto Condensed',
			'Roboto+Slab' => 'Roboto Slab',
			'Rochester' => 'Rochester',
			'Rock+Salt' => 'Rock Salt',
			'Rokkitt' => 'Rokkitt',
			'Romanesco' => 'Romanesco',
			'Ropa+Sans' => 'Ropa Sans',
			'Rosario' => 'Rosario',
			'Rosarivo' => 'Rosarivo',
			'Rouge+Script' => 'Rouge Script',
			'Ruda' => 'Ruda',
			'Rufina' => 'Rufina',
			'Ruge+Boogie' => 'Ruge Boogie',
			'Ruluko' => 'Ruluko',
			'Rum+Raisin' => 'Rum Raisin',
			'Ruslan+Display' => 'Ruslan Display',
			'Russo+One' => 'Russo One',
			'Ruthie' => 'Ruthie',
			'Rye' => 'Rye',
			'Sacramento' => 'Sacramento',
			'Sail' => 'Sail',
			'Salsa' => 'Salsa',
			'Sanchez' => 'Sanchez',
			'Sancreek' => 'Sancreek',
			'Sansita+One' => 'Sansita One',
			'Sarina' => 'Sarina',
			'Satisfy' => 'Satisfy',
			'Scada' => 'Scada',
			'Schoolbell' => 'Schoolbell',
			'Seaweed+Script' => 'Seaweed Script',
			'Sevillana' => 'Sevillana',
			'Seymour+One' => 'Seymour One',
			'Shadows+Into+Light' => 'Shadows Into Light',
			'Shadows+Into+Light+Two' => 'Shadows Into Light Two',
			'Shanti' => 'Shanti',
			'Share' => 'Share',
			'Share+Tech' => 'Share Tech',
			'Share+Tech+Mono' => 'Share Tech Mono',
			'Shojumaru' => 'Shojumaru',
			'Short+Stack' => 'Short Stack',
			'Siemreap' => 'Siemreap',
			'Sigmar+One' => 'Sigmar One',
			'Signika' => 'Signika',
			'Signika+Negative' => 'Signika Negative',
			'Simonetta' => 'Simonetta',
			'Sintony' => 'Sintony',
			'Sirin+Stencil' => 'Sirin Stencil',
			'Six+Caps' => 'Six Caps',
			'Skranji' => 'Skranji',
			'Slackey' => 'Slackey',
			'Smokum' => 'Smokum',
			'Smythe' => 'Smythe',
			'Sniglet' => 'Sniglet',
			'Snippet' => 'Snippet',
			'Snowburst+One' => 'Snowburst One',
			'Sofadi+One' => 'Sofadi One',
			'Sofia' => 'Sofia',
			'Sonsie+One' => 'Sonsie One',
			'Sorts+Mill+Goudy' => 'Sorts Mill Goudy',
			'Source+Code+Pro' => 'Source Code Pro',
			'Source+Sans+Pro' => 'Source Sans Pro',
			'Special+Elite' => 'Special Elite',
			'Spicy+Rice' => 'Spicy Rice',
			'Spinnaker' => 'Spinnaker',
			'Spirax' => 'Spirax',
			'Squada+One' => 'Squada One',
			'Stalemate' => 'Stalemate',
			'Stalinist+One' => 'Stalinist One',
			'Stardos+Stencil' => 'Stardos Stencil',
			'Stint+Ultra+Condensed' => 'Stint Ultra Condensed',
			'Stint+Ultra+Expanded' => 'Stint Ultra Expanded',
			'Stoke' => 'Stoke',
			'Strait' => 'Strait',
			'Sue+Ellen+Francisco' => 'Sue Ellen Francisco',
			'Sunshiney' => 'Sunshiney',
			'Supermercado+One' => 'Supermercado One',
			'Suwannaphum' => 'Suwannaphum',
			'Swanky+and+Moo+Moo' => 'Swanky and Moo Moo',
			'Syncopate' => 'Syncopate',
			'Tangerine' => 'Tangerine',
			'Taprom' => 'Taprom',
			'Tauri' => 'Tauri',
			'Telex' => 'Telex',
			'Tenor+Sans' => 'Tenor Sans',
			'Text+Me+One' => 'Text Me One',
			'The+Girl+Next+Door' => 'The Girl Next Door',
			'Tienne' => 'Tienne',
			'Tinos' => 'Tinos',
			'Titan+One' => 'Titan One',
			'Titillium+Web' => 'Titillium Web',
			'Trade+Winds' => 'Trade Winds',
			'Trocchi' => 'Trocchi',
			'Trochut' => 'Trochut',
			'Trykker' => 'Trykker',
			'Tulpen+One' => 'Tulpen One',
			'Ubuntu' => 'Ubuntu',
			'Ubuntu+Condensed' => 'Ubuntu Condensed',
			'Ubuntu+Mono' => 'Ubuntu Mono',
			'Ultra' => 'Ultra',
			'Uncial+Antiqua' => 'Uncial Antiqua',
			'Underdog' => 'Underdog',
			'Unica+One' => 'Unica One',
			'UnifrakturCook' => 'UnifrakturCook',
			'UnifrakturMaguntia' => 'UnifrakturMaguntia',
			'Unkempt' => 'Unkempt',
			'Unlock' => 'Unlock',
			'Unna' => 'Unna',
			'VT323' => 'VT323',
			'Vampiro+One' => 'Vampiro One',
			'Varela' => 'Varela',
			'Varela+Round' => 'Varela Round',
			'Vast+Shadow' => 'Vast Shadow',
			'Vibur' => 'Vibur',
			'Vidaloka' => 'Vidaloka',
			'Viga' => 'Viga',
			'Voces' => 'Voces',
			'Volkhov' => 'Volkhov',
			'Vollkorn' => 'Vollkorn',
			'Voltaire' => 'Voltaire',
			'Waiting+for+the+Sunrise' => 'Waiting for the Sunrise',
			'Wallpoet' => 'Wallpoet',
			'Walter+Turncoat' => 'Walter Turncoat',
			'Warnes' => 'Warnes',
			'Wellfleet' => 'Wellfleet',
			'Wendy+One' => 'Wendy One',
			'Wire+One' => 'Wire One',
			'Yanone+Kaffeesatz' => 'Yanone Kaffeesatz',
			'Yellowtail' => 'Yellowtail',
			'Yeseva+One' => 'Yeseva One',
			'Yesteryear' => 'Yesteryear',
			'Zeyada' => 'Zeyada'

		);

		return $array;

	}
}


if(!function_exists('etheme_get_chosen_google_font')) {
	function etheme_get_chosen_google_font() {
		$chosenFonts = array();
		$fontOptions = array(
			etheme_get_option('top_bar_font'),
			etheme_get_option('header1_font'),
			etheme_get_option('header2_font'),
			etheme_get_option('content_font'),
			etheme_get_option('box_font'),
			etheme_get_option('links_font'),
			etheme_get_option('links_hover_font'),
			etheme_get_option('price_font'),
			etheme_get_option('special_price_font'),
			etheme_get_option('buttons_font'),
			etheme_get_option('tabs_font'),
			etheme_get_option('footer1_font'),
			etheme_get_option('footer2_font'),
			etheme_get_option('h1'),
			etheme_get_option('h2'),
			etheme_get_option('h3'),
			etheme_get_option('h4'),
			etheme_get_option('h5'),
			etheme_get_option('h6'),
		);

		foreach($fontOptions as $value){
			if(!empty($value['google-font']))
				$chosenFonts[] = $value['google-font'];
		}

		return $chosenFonts;
	}
}



// **********************************************************************//
// ! Custom meta fields to categories
// **********************************************************************//
if(function_exists('get_term_meta')){

	function etheme_taxonomy_edit_meta_field($term, $taxonomy) {
		$id = $term->term_id;
		$term_meta = get_term_meta($id,'cat_meta');

		if(!$term_meta){$term_meta = add_term_meta($id, 'cat_meta', '');}
		?>
		<tr class="form-field">
			<th scope="row" valign="top"><label for="term_meta[cat_header]"><?php _e( 'Category Header', WFT_DOMAIN ); ?></label></th>
			<td>
				<?php

				$content = esc_attr( $term_meta[0]['cat_header'] ) ? esc_attr( $term_meta[0]['cat_header'] ) : '';
				wp_editor($content,'term_meta[cat_header]');

				?>
			</td>
		</tr>
	<?php
	}

	add_action( 'product_cat_edit_form_fields', 'etheme_taxonomy_edit_meta_field', 20, 2 );

// **********************************************************************//
// ! Save meta fields
// **********************************************************************//
	function save_taxonomy_custom_meta( $term_id ) {
		if ( isset( $_POST['term_meta'] ) ) {
			$term_meta = get_term_meta($term_id,'cat_meta');
			$cat_keys = array_keys( $_POST['term_meta'] );
			foreach ( $cat_keys as $key ) {
				if ( isset ( $_POST['term_meta'][$key] ) ) {
					$term_meta[$key] = $_POST['term_meta'][$key];
				}
			}
			// Save the option array.
			update_term_meta($term_id, 'cat_meta', $term_meta);

		}
	}
	add_action( 'edited_product_cat', 'save_taxonomy_custom_meta', 10, 2 );
}



// **********************************************************************//
// ! Load option tree plugin
// **********************************************************************//

add_filter( 'ot_show_pages', '__return_false' );
add_filter( 'ot_show_new_layout', '__return_false' );
add_filter( 'ot_theme_mode', '__return_true' );
load_template( trailingslashit( get_template_directory() ) . 'option-tree/ot-loader.php' );

// **********************************************************************//
// ! Add google analytics code
// **********************************************************************//
add_action('init', 'et_google_analytics');
if(!function_exists('et_google_analytics')) {
	function et_google_analytics() {
		$googleCode = etheme_get_option('google_code');

		if(empty($googleCode)) return;

		if(strpos($googleCode,'UA-') === 0) {

			$googleCode = "

<script type='text/javascript'>

var _gaq = _gaq || [];
_gaq.push(['_setAccount', '".$googleCode."']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

</script>

";
		}

		add_action('wp_head', 'et_print_google_code');
	}

	function et_print_google_code() {
		$googleCode = etheme_get_option('google_code');

		if(!empty($googleCode)) {
			echo $googleCode;
		}
	}

}

// **********************************************************************//
// ! Twitter API functions
// **********************************************************************//
function etheme_capture_tweets($consumer_key,$consumer_secret,$user_token,$user_secret,$user, $count) {

	$connection = getConnectionWithAccessToken($consumer_key,$consumer_secret,$user_token, $user_secret);
	$params = array(
		'screen_name' => $user,
		'count' => $count
	);

	$content = $connection->get("statuses/user_timeline",$params);

	return json_encode($content);
}

function etheme_tweet_linkify($tweet) {
	$tweet = preg_replace("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t< ]*)#", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $tweet);
	$tweet = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r< ]*)#", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $tweet);
	$tweet = preg_replace("/@(\w+)/", "<a href=\"http://www.twitter.com/\\1\" target=\"_blank\">@\\1</a>", $tweet);
	$tweet = preg_replace("/#(\w+)/", "<a href=\"http://search.twitter.com/search?q=\\1\" target=\"_blank\">#\\1</a>", $tweet);
	return $tweet;
}

function etheme_store_tweets($file, $tweets) {
	ob_start(); // turn on the output buffering
	$fo = fopen($file, 'w'); // opens for writing only or will create if it's not there
	if (!$fo) return etheme_print_tweet_error(error_get_last());
	$fr = fwrite($fo, $tweets); // writes to the file what was grabbed from the previous function
	if (!$fr) return etheme_print_tweet_error(error_get_last());
	fclose($fo); // closes
	ob_end_flush(); // finishes and flushes the output buffer;
}

function etheme_pick_tweets($file) {
	ob_start(); // turn on the output buffering
	$fo = fopen($file, 'r'); // opens for reading only
	if (!$fo) return etheme_print_tweet_error(error_get_last());
	$fr = fread($fo, filesize($file));
	if (!$fr) return etheme_print_tweet_error(error_get_last());
	fclose($fo);
	ob_end_flush();
	return $fr;
}

function etheme_print_tweet_error($errorArray) {
	return '<p class="eth-error">Error: ' . $errorArray['message'] . 'in ' . $errorArray['file'] . 'on line ' . $errorArray['line'] . '</p>';
}

function etheme_twitter_cache_enabled(){
	return true;
}

function etheme_print_tweets($consumer_key,$consumer_secret,$user_token,$user_secret,$user, $count, $cachetime=50) {
	if(etheme_twitter_cache_enabled()){
		//setting the location to cache file
		$cachefile = ETHEME_CODE_DIR . '/cache/twitterCache.json';

		// the file exitsts but is outdated, update the cache file
		if (file_exists($cachefile) && ( time() - $cachetime > filemtime($cachefile)) && filesize($cachefile) > 0) {
			//capturing fresh tweets
			$tweets = etheme_capture_tweets($consumer_key,$consumer_secret,$user_token,$user_secret,$user, $count);
			$tweets_decoded = json_decode($tweets, true);
			//if get error while loading fresh tweets - load outdated file
			if(isset($tweets_decoded['error'])) {
				$tweets = etheme_pick_tweets($cachefile);
			}
			//else store fresh tweets to cache
			else
				etheme_store_tweets($cachefile, $tweets);
		}
		//file doesn't exist or is empty, create new cache file
		elseif (!file_exists($cachefile) || filesize($cachefile) == 0) {
			$tweets = etheme_capture_tweets($consumer_key,$consumer_secret,$user_token,$user_secret,$user, $count);
			$tweets_decoded = json_decode($tweets, true);
			//if request fails, and there is no old cache file - print error
			if(isset($tweets_decoded['error']))
				return 'Error: ' . $tweets_decoded['error'];
			//make new cache file with request results
			else
				etheme_store_tweets($cachefile, $tweets);
		}
		//file exists and is fresh
		//load the cache file
		else {
			$tweets = etheme_pick_tweets($cachefile);
		}
	} else{
		$tweets = etheme_capture_tweets($consumer_key,$consumer_secret,$user_token,$user_secret,$user, $count);
	}

	$tweets = json_decode($tweets, true);
	$html = '';
	foreach ($tweets as $tweet) {
		$html .= '<div class="tweet">' . $tweet['text'] . '</div>';
	}
	$html = etheme_tweet_linkify($html);
	return $html;
}



// **********************************************************************//
// ! Related posts
// **********************************************************************//

if(!function_exists('et_get_related_posts')) {
	function et_get_related_posts($postId = false, $limit = 5){
		global $post;
		if(!$postId) {
			$postId = $post->ID;
		}
		$categories = get_the_category($postId);
		if ($categories) {
			$category_ids = array();
			foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id;

			$args = array(
				'category__in' => $category_ids,
				'post__not_in' => array($postId),
				'showposts'=>$limit, // Number of related posts that will be shown.
				'caller_get_posts'=>1
			);
			etheme_create_posts_slider($args);
		}
	}
}

// **********************************************************************//
// ! Custom Static Blocks Post Type
// **********************************************************************//

add_action('init', 'et_register_static_blocks');

if(!function_exists('et_register_static_blocks')) {
	function et_register_static_blocks() {
		$labels = array(
			'name' => _x( 'Static Blocks', 'post type general name', WFT_DOMAIN ),
			'singular_name' => _x( 'Block', 'post type singular name', WFT_DOMAIN ),
			'add_new' => _x( 'Add New', 'static block', WFT_DOMAIN ),
			'add_new_item' => sprintf( __( 'Add New %s', WFT_DOMAIN ), __( 'Static Blocks', WFT_DOMAIN ) ),
			'edit_item' => sprintf( __( 'Edit %s', WFT_DOMAIN ), __( 'Static Blocks', WFT_DOMAIN ) ),
			'new_item' => sprintf( __( 'New %s', WFT_DOMAIN ), __( 'Static Blocks', WFT_DOMAIN ) ),
			'all_items' => sprintf( __( 'All %s', WFT_DOMAIN ), __( 'Static Blocks', WFT_DOMAIN ) ),
			'view_item' => sprintf( __( 'View %s', WFT_DOMAIN ), __( 'Static Blocks', WFT_DOMAIN ) ),
			'search_items' => sprintf( __( 'Search %a', WFT_DOMAIN ), __( 'Static Blocks', WFT_DOMAIN ) ),
			'not_found' =>  sprintf( __( 'No %s Found', WFT_DOMAIN ), __( 'Static Blocks', WFT_DOMAIN ) ),
			'not_found_in_trash' => sprintf( __( 'No %s Found In Trash', WFT_DOMAIN ), __( 'Static Blocks', WFT_DOMAIN ) ),
			'parent_item_colon' => '',
			'menu_name' => __( 'Static Blocks', WFT_DOMAIN )

		);
		$args = array(
			'labels' => $labels,
			'public' => true,
			'publicly_queryable' => true,
			'show_ui' => true,
			'show_in_menu' => true,
			'query_var' => true,
			'rewrite' => array( 'slug' => 'staticblocks' ),
			'capability_type' => 'post',
			'has_archive' => 'staticblocks',
			'hierarchical' => false,
			'supports' => array( 'title', 'editor', 'thumbnail', 'page-attributes' ),
			'menu_position' => 8
		);
		register_post_type( 'staticblocks', $args );
	}
}

if(!function_exists('et_get_static_blocks')) {
	function et_get_static_blocks () {
		$return_array = array();
		$args = array( 'post_type' => 'staticblocks', 'posts_per_page' => 50);

		$myposts = get_posts( $args );
		$i=0;
		foreach ( $myposts as $post ) {
			$i++;
			$return_array[$i]['label'] = get_the_title($post->ID);
			$return_array[$i]['value'] = $post->ID;
		}

		return $return_array;
	}
}

if(!function_exists('et_show_block')) {
	function et_show_block ($id) {
		echo do_shortcode(get_post_field('post_content', $id));
	}
}


if(!function_exists('et_get_block')) {
	function et_get_block ($id) {
		return do_shortcode(get_post_field('post_content', $id));
	}
}


// **********************************************************************//
// ! QR Code generation
// **********************************************************************//
if(!function_exists('generate_qr_code')) {
	function generate_qr_code($text='QR Code', $title = 'QR Code', $size = 128, $class = '', $self_link = false, $lightbox = false ) {
		if($self_link) {
			global $wp;
			$text = @$_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://';
			if ( $_SERVER['SERVER_PORT'] != '80' )
				$text .= $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . $_SERVER['REQUEST_URI'];
			else
				$text .= $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
		}
		$image = 'https://chart.googleapis.com/chart?chs=' . $size . 'x' . $size . '&cht=qr&chld=H|1&chl=' . $text;

		if($lightbox) {
			$class .= ' qr-lighbox';
			$output = '<a href="'.$image.'" rel="lightbox" class="'.$class.'">'.$title.'</a>';
		} else{
			$class .= ' qr-image';
			$output = '<img src="'.$image.'"  class="'.$class.'" />';
		}

		return $output;
	}
}


// **********************************************************************//
// ! Helper functions
// **********************************************************************//
if(!function_exists('pr')) {
	function pr($arr) {
		echo '<pre>';
		print_r($arr);
		echo '</pre>';
	}
}

if(!function_exists('jsString')) {
	function jsString($str='') {
		return trim(preg_replace("/('|\"|\r?\n)/", '', $str));
	}
}
if(!function_exists('hex2rgb')) {
	function hex2rgb($hex) {
		$hex = str_replace("#", "", $hex);

		if(strlen($hex) == 3) {
			$r = hexdec(substr($hex,0,1).substr($hex,0,1));
			$g = hexdec(substr($hex,1,1).substr($hex,1,1));
			$b = hexdec(substr($hex,2,1).substr($hex,2,1));
		} else {
			$r = hexdec(substr($hex,0,2));
			$g = hexdec(substr($hex,2,2));
			$b = hexdec(substr($hex,4,2));
		}
		$rgb = array($r, $g, $b);
		//return implode(",", $rgb); // returns the rgb values separated by commas
		return $rgb; // returns an array with the rgb values
	}
}

if(!function_exists('trunc')) {
	function trunc($phrase, $max_words) {
		$phrase_array = explode(' ',$phrase);
		if(count($phrase_array) > $max_words && $max_words > 0)
			$phrase = implode(' ',array_slice($phrase_array, 0, $max_words)).' ...';
		return $phrase;
	}
}

if(!function_exists('et_get_icons')) {
	function et_get_icons() {
		$iconsArray = array("compass","collapse","collapse-top","expand","eur","euro","gbp","usd","dollar","inr","rupee","jpy","yen","cny","renminbi","krw","won","btc","bitcoin","file","file-text","sort-by-alphabet","sort-by-alphabet-alt","sort-by-attributes","sort-by-attributes-alt","sort-by-order","sort-by-order-alt","thumbs-up","thumbs-down","youtube-sign","youtube","xing","xing-sign","youtube-play","dropbox","stackexchange","instagram","flickr","adn","bitbucket","bitbucket-sign","tumblr","tumblr-sign","long-arrow-down","long-arrow-up","long-arrow-left","long-arrow-right","apple","windows","android","linux","dribbble","skype","foursquare","trello","female","male","gittip","sun","moon","archive","bug","vk","weibo","renren","adjust","anchor","archive","asterisk","ban-circle","bar-chart","barcode","beaker","beer","bell","bell-alt","bolt","book","bookmark","bookmark-empty","briefcase","bug","building","bullhorn","bullseye","calendar","calendar-empty","camera","camera-retro","certificate","check","check-empty","check-minus","check-sign","circle","circle-blank","cloud","cloud-download","cloud-upload","code","code-fork","coffee","cog","cogs","collapse","collapse-alt","collapse-top","comment","comment-alt","comments","comments-alt","compass","credit-card","crop","dashboard","desktop","download","download-alt","edit","edit-sign","ellipsis-horizontal","ellipsis-vertical","envelope","envelope-alt","eraser","exchange","exclamation","exclamation-sign","expand","expand-alt","external-link","external-link-sign","eye-close","eye-open","facetime-video","female","fighter-jet","film","filter","fire","fire-extinguisher","flag","flag-alt","flag-checkered","folder-close","folder-close-alt","folder-open","folder-open-alt","food","frown","gamepad","gear","gears","gift","glass","globe","group","hdd","headphones","heart","heart-empty","home","inbox","info","info-sign","key","keyboard","laptop","leaf","legal","lemon","level-down","level-up","lightbulb","location-arrow","lock","magic","magnet","mail-forward","mail-reply","mail-reply-all","male","map-marker","meh","microphone","microphone-off","minus","minus-sign","minus-sign-alt","mobile-phone","money","moon","move","music","off","ok","ok-circle","ok-sign","pencil","phone","phone-sign","picture","plane","plus","plus-sign","plus-sign-alt","power-off","print","pushpin","puzzle-piece","qrcode","question","question-sign","quote-left","quote-right","random","refresh","remove","remove-circle","remove-sign","reorder","reply","reply-all","resize-horizontal","resize-vertical","retweet","road","rocket","rss","rss-sign","screenshot","search","share","share-alt","share-sign","shield","shopping-cart","sign-blank","signal","signin","signout","sitemap","smile","sort","sort-by-alphabet","sort-by-alphabet-alt","sort-by-attributes","sort-by-attributes-alt","sort-by-order","sort-by-order-alt","sort-down","sort-up","spinner","star","star-empty","star-half","star-half-empty","star-half-full","subscript","suitcase","sun","superscript","tablet","tag","tags","tasks","terminal","thumbs-down","thumbs-down-alt","thumbs-up","thumbs-up-alt","ticket","time","tint","trash","trophy","truck","umbrella","unchecked","unlock","unlock-alt","upload","upload-alt","user","volume-down","volume-off","volume-up","warning-sign","wrench","zoom-in","zoom-out","bitcoin","btc","cny","dollar","eur","euro","gbp","inr","jpy","krw","renminbi","rupee","usd","won","yen","align-center","align-justify","align-left","align-right","bold","columns","copy","cut","eraser","file","file-alt","file-text","file-text-alt","font","indent-left","indent-right","italic","link","list","list-alt","list-ol","list-ul","paper-clip","paperclip","paste","repeat","rotate-left","rotate-right","save","strikethrough","table","text-height","text-width","th","th-large","th-list","underline","undo","unlink","angle-down","angle-left","angle-right","angle-up","arrow-down","arrow-left","arrow-right","arrow-up","caret-down","caret-left","caret-right","caret-up","chevron-down","chevron-left","chevron-right","chevron-sign-down","chevron-sign-left","chevron-sign-right","chevron-sign-up","chevron-up","circle-arrow-down","circle-arrow-left","circle-arrow-right","circle-arrow-up","double-angle-down","double-angle-left","double-angle-right","double-angle-up","hand-down","hand-left","hand-right","hand-up","long-arrow-down","long-arrow-left","long-arrow-right","long-arrow-up","backward","eject","fast-backward","fast-forward","forward","fullscreen","pause","play","play-circle","play-sign","resize-full","resize-small","step-backward","step-forward","stop","youtube-play","adn","android","apple","bitbucket","bitbucket-sign","bitcoin","btc","css3","dribbble","dropbox","facebook","facebook-sign","flickr","foursquare","github","github-alt","github-sign","gittip","google-plus","google-plus-sign","html5","instagram","linkedin","linkedin-sign","linux","maxcdn","pinterest","pinterest-sign","renren","skype","stackexchange","trello","tumblr","tumblr-sign","twitter","twitter-sign","vk","weibo","windows","xing","xing-sign","youtube","youtube-play","youtube-sign","ambulance","h-sign","hospital","medkit","plus-sign-alt","stethoscope","user-md");

		return array_unique($iconsArray);

	}
}



if(!function_exists('vc_icon_form_field')) {
	function vc_icon_form_field($settings, $value) {
		$settings_line = '';
		$selected = '';
		$array = et_get_icons();
		if($value != '') {
			$array = array_diff($array, array($value));
			array_unshift($array,$value);
		}

		$settings_line .= '<div class="et-icon-selector">';
		$settings_line .= '<input type="hidden" value="'.$value.'" name="'.$settings['param_name'].'" class="et-hidden-icon wpb_vc_param_value wpb-icon-select '.$settings['param_name'].' '.$settings['type'] . '">';
		foreach ($array as $icon) {
			if ($value == $icon) {
				$selected = 'selected';
			}
			$settings_line .= '<span class="et-select-icon '.$selected.'" data-icon-name='.$icon.'><i class="icon-'.$icon.'"></i></span>';
			$selected = '';
		}

		$settings_line .= '<script>';
		$settings_line .= 'jQuery(".et-select-icon").click(function(){';
		$settings_line .= 'var iconName = jQuery(this).data("icon-name");';
		$settings_line .= 'console.log(iconName);';
		$settings_line .= 'if(!jQuery(this).hasClass("selected")) {';
		$settings_line .= 'jQuery(".et-select-icon").removeClass("selected");';
		$settings_line .= 'jQuery(this).addClass("selected");';
		$settings_line .= 'jQuery(this).parent().find(".et-hidden-icon").val(iconName);';
		$settings_line .= '}';

		$settings_line .= '});';
		$settings_line .= '</script>';

		$settings_line .= '</div>';
		return $settings_line;
	}
}


add_action( 'etheme_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 );
add_action( 'etheme_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
add_action( 'etheme_after_shop_loop_item_title', 'woocommerce_template_loop_add_to_cart', 10 );
add_action( 'etheme_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 5 );

if ( !function_exists('get_sale_products') ) {

	function get_sale_products($per_page = 12, $orderby='title', $order='asc') {

		global $woocommerce;

		// Get products on sale
		$product_ids_on_sale = woocommerce_get_product_ids_on_sale();

		$meta_query = array();
		$meta_query[] = $woocommerce->query->visibility_meta_query();
		$meta_query[] = $woocommerce->query->stock_status_meta_query();
		$meta_query   = array_filter( $meta_query );

		$args = array(
			'posts_per_page'=> $per_page,
			'orderby' 		=> $orderby,
			'order' 		=> $order,
			'no_found_rows' => 1,
			'post_status' 	=> 'publish',
			'post_type' 	=> 'product',
			'meta_query' 	=> $meta_query,
			'post__in'		=> array_merge( array( 0 ), $product_ids_on_sale )
		);

		return new WP_Query( $args );
	}
}

if ( !function_exists('get_best_selling_products') ) {

	function get_best_selling_products($per_page = 12) {

		global $woocommerce_loop;

		$args = array(
			'post_type' => 'product',
			'post_status' => 'publish',
			'ignore_sticky_posts'   => 1,
			'posts_per_page' => $per_page,
			'meta_key' 		 => 'total_sales',
			'orderby' 		 => 'meta_value_num',
			'meta_query' => array(
				array(
					'key' => '_visibility',
					'value' => array( 'catalog', 'visible' ),
					'compare' => 'IN'
				)
			)
		);

		ob_start();

		return new WP_Query( $args );
	}
}

if ( !function_exists('get_top_rated_products') ) {

	function get_top_rated_products($per_page = 12, $orderby = 'title', $order = 'asc') {

		$args = array(
			'post_type' => 'product',
			'post_status' => 'publish',
			'ignore_sticky_posts'   => 1,
			'orderby' => $orderby,
			'order' => $order,
			'posts_per_page' => $per_page,
			'meta_query' => array(
				array(
					'key' => '_visibility',
					'value' => array('catalog', 'visible'),
					'compare' => 'IN'
				)
			)
		);

		add_filter( 'posts_clauses', array( 'WC_Shortcodes', 'order_by_rating_post_clauses' ) );

		$products = new WP_Query( $args );

		remove_filter( 'posts_clauses', array( 'WC_Shortcodes', 'order_by_rating_post_clauses' ) );

		return $products;

	}
}

if ( !function_exists('get_featured_products') ) {

	function get_featured_products($per_page = 12, $orderby = 'date', $order='desc') {

		$args = array(
			'post_type'	=> 'product',
			'post_status' => 'publish',
			'ignore_sticky_posts'	=> 1,
			'posts_per_page' => $per_page,
			'orderby' => $orderby,
			'order' => $order,
			'meta_query' => array(
				array(
					'key' => '_visibility',
					'value' => array('catalog', 'visible'),
					'compare' => 'IN'
				),
				array(
					'key' => '_featured',
					'value' => 'yes'
				)
			)
		);

		return new WP_Query( $args );

	}
}

if ( !function_exists('get_recent_products') ) {

	function get_recent_products($per_page = 12, $orderby='date', $order='desc') {

		global $woocommerce;

		$meta_query = $woocommerce->query->get_meta_query();

		$args = array(
			'post_type'	=> 'product',
			'post_status' => 'publish',
			'ignore_sticky_posts'	=> 1,
			'posts_per_page' => $per_page,
			'orderby' => $orderby,
			'order' => $order,
			'meta_query' => $meta_query
		);

		return new WP_Query( $args );

	}

}

if ( !function_exists('get_related_products') ) {

	function get_related_products($per_page = 12, $orderby='date', $order='desc') {

		global $product;

		$related = $product->get_related( $per_page );

		if ( sizeof( $related ) == 0 ) return;

		$args = apply_filters('woocommerce_related_products_args', array(
			'post_type'				=> 'product',
			'ignore_sticky_posts'	=> 1,
			'no_found_rows' 		=> 1,
			'posts_per_page' 		=> $per_page,
			'orderby' 				=> $orderby,
			'post__in' 				=> $related,
			'post__not_in'			=> array($product->id)
		) );

		return new WP_Query( $args );

	}

}

if ( ! function_exists( 'woocommerce_get_product_thumbnail' ) ) {

	/**
	 * Get the product thumbnail, or the placeholder if not set.
	 *
	 * @access public
	 * @subpackage	Loop
	 * @param string $size (default: 'shop_catalog')
	 * @param int $placeholder_width (default: 0)
	 * @param int $placeholder_height (default: 0)
	 * @return string
	 */
	function woocommerce_get_product_thumbnail( $size = 'shop_single', $placeholder_width = 0, $placeholder_height = 0  ) {
		global $post;

		$link = '<a href="' . esc_url( apply_filters( 'the_permalink', get_permalink() ) ) . '">';

		if ( has_post_thumbnail() ) {
			$link .= get_the_post_thumbnail( $post->ID, $size );
		} else {

			global $product;
			$attachment_ids = $product->get_gallery_attachment_ids();

			if ( $attachment_ids ) {
				$link .= '<img alt="" src="' . wft_get_attachment_thumb_url($attachment_ids[0], $size) . '" />';
			} elseif ( woocommerce_placeholder_img_src() ) {
				$link .= woocommerce_placeholder_img( $size );
			}
		}

		$link .= '</a>';

		return $link;
	}
}

if ( !function_exists('wft_get_attachment_thumb_url') ) {
	/**
	 * Retrieve URL for an attachment thumbnail.
	 *
	 * @since 2.1.0
	 *
	 * @param int $post_id Attachment ID
	 * @return string|bool False on failure. Thumbnail URL on success.
	 */
	function wft_get_attachment_thumb_url( $post_id = 0, $size = 'thumbnail' ) {
		$post_id = (int) $post_id;
		if ( !$post = get_post( $post_id ) )
			return false;
		if ( !$url = wp_get_attachment_url( $post->ID ) )
			return false;

		$sized = image_downsize( $post_id, $size );
		if ( $sized )
			return $sized[0];

		if ( !$thumb = wp_get_attachment_thumb_file( $post->ID ) )
			return false;

		$url = str_replace(basename($url), basename($thumb), $url);

		return apply_filters( 'wp_get_attachment_thumb_url', $url, $post->ID );
	}
}

if ( ! function_exists( 'woocommerce_breadcrumb' ) ) {

	/**
	 * Output the WooCommerce Breadcrumb
	 *
	 * @access public
	 * @return void
	 */
	function woocommerce_breadcrumb( $args = array() ) {

		$defaults = apply_filters( 'woocommerce_breadcrumb_defaults', array(
			'delimiter'   => '<span>›</span>',
			'wrap_before' => '<div class="pull-left"><div class="breadcrumbs">',
			'wrap_after'  => '</div></div>',
			'before'      => '',
			'after'       => '',
			'home'        => _x( 'Home', 'breadcrumb', 'woocommerce' ),
		) );

		$args = wp_parse_args( $args, $defaults );

		woocommerce_get_template( 'shop/breadcrumb.php', $args );
	}
}

if ( ! function_exists('woocommerce_before_main_content_wrapper') ) {
	function woocommerce_before_main_content_wrapper() {
		echo '<div class="content_top"><div class="wrapper_w">';
	}
}

if ( ! function_exists('woocommerce_before_main_content_wrapper_end') ) {
	function woocommerce_before_main_content_wrapper_end() {
		echo '</div></div>';
	}
}


if ( !function_exists('wft_prev_next_product') ) {
function wft_prev_next_product() {
	?>
	<div class="pull-right">
		<div class="direction-nav">
					<span class="prev">
						<?php previous_post_link( '%link', '<i class="icon-left-thin"></i>' ); ?>
					</span>
					<span class="next">
						<?php next_post_link( '%link', '<i class="icon-right-thin"></i>' ); ?>
					</span>

		</div>
	</div>
<?php
}
}
add_action('woocommerce_before_main_content', 'wft_prev_next_product', 25);

add_action('woocommerce_after_add_to_cart_form', 'wft_product_add_to_links', 20);
if ( !function_exists('wft_product_add_to_links') ) {
	function wft_product_add_to_links() {

		$links = array();

		if ( class_exists('YITH_WCWL') ) {

			$links['wishlist'] = add_to_wishlist_link();//do_shortcode('[yith_wcwl_add_to_wishlist]');
		}

		if ( class_exists('YITH_Woocompare') ) {
			global $yith_woocompare;
			$obj = $yith_woocompare->obj;
			remove_action('woocommerce_single_product_summary', array($obj, 'add_compare_link'), 35);
			$links['compare'] = add_to_compare_link();
		}

		if ( !empty($links) ) {

			$html = '<div class="add-to-links">';

			$html .= '<ul>';

			if ( $links['wishlist'] ) {
				$html .= '<li class="yith-wcwl-add-to-wishlist">' . $links['wishlist'] . '</li>';
			}

			if ( isset($links['compare']) && $links['compare'] ) {
				$html .= '<li>'.$links['compare'].'</li>';
			}

			$html .= '</ul>';

			$html .= '</div><div class="clear"></div>';

			echo $html;
		}
	}
}

add_action('woocommerce_after_add_to_cart_form', 'show_share_buttons', 30);
if ( !function_exists('show_share_buttons') ) {
	function show_share_buttons($title = '') {
		echo do_shortcode('[share title="' . $title . '"]');
	}
}

if ( !function_exists('add_to_wishlist_link') ) {
	function add_to_wishlist_link() {

		global $product, $yith_wcwl;

		$url = $yith_wcwl->get_wishlist_url();
		$product_type = $product->product_type;
		$exists = $yith_wcwl->is_product_in_wishlist( $product->id );

		$label = apply_filters( 'yith_wcwl_button_label', get_option( 'yith_wcwl_add_to_wishlist_text' ) );
		$icon = '<a class="small_icon_color" href="'. ( $exists ? esc_url($url) : esc_url($yith_wcwl->get_addtowishlist_url()) ) .'"><i class="icon-heart"></i></a>';//get_option( 'yith_wcwl_add_to_wishlist_icon' ) != 'none' ? '<i class="' . get_option( 'yith_wcwl_add_to_wishlist_icon' ) . '"></i>' : '';

		$classes = get_option( 'yith_wcwl_use_button' ) == 'yes' ? 'class="add_to_wishlist single_add_to_wishlist button alt"' : 'class="add_to_wishlist"';

		if ( $exists ) {
			$html = $icon . '<a href="' . esc_url( $url ) . '">' . apply_filters( 'yith-wcwl-browse-wishlist-label', __( 'Browse Wishlist', 'yit' ) ) . '</a>';
		} else {
			$html = $icon . '<a href="' . esc_url( $yith_wcwl->get_addtowishlist_url() ) . '" data-product-id="' . $product->id . '" data-product-type="' . $product_type . '" ' . $classes . ' >' . $label . '</a>';
			$html .= '<img src="' . esc_url( admin_url( 'images/wpspin_light.gif' ) ) . '" class="ajax-loading" id="add-items-ajax-loading" alt="" width="16" height="16" style="visibility:hidden" />';
		}

		return $html;
	}
}

if ( !function_exists('add_to_compare_link') ) {
	function add_to_compare_link( $product_id = false, $args = array() ) {

		global $yith_woocompare;
		$obj = $yith_woocompare->obj;

		extract( $args );

		if ( ! $product_id ) {
			global $product;
			$product_id = isset( $product->id ) && $product->exists() ? $product->id : 0;
		}

		// return if product doesn't exist
		if ( empty( $product_id ) ) return;

		$is_button = !isset( $button_or_link ) || !$button_or_link ? get_option( 'yith_woocompare_is_button' ) : $button_or_link;


		$icon = sprintf('<a class="small_icon_color" href="%s" data-product_id="%d"><i class="icon-popup"></i></a>', $obj->add_product_url( $product_id ), $product_id);
		$link = sprintf( '<a href="%s" class="%s" data-product_id="%d">%s</a>', $obj->add_product_url( $product_id ), 'compare' . ( $is_button == 'button' ? ' button' : '' ), $product_id, ( isset( $button_text ) && $button_text != 'default' ? $button_text : get_option( 'yith_woocompare_button_text', __( 'Compare', 'yit' ) ) ) );

		return $icon . $link;
	}
}

if ( ! function_exists( 'woocommerce_output_related_products' ) ) {

	/**
	 * Output the related products.
	 *
	 * @access public
	 * @subpackage	Product
	 * @return void
	 */
	function woocommerce_output_related_products() {
		//woocommerce_related_products( 4, 4 );
		echo '<div class="span12">' . do_shortcode('[wft_product_slider type="related" title="Related Products" size="3" with_descr="0" per_page="12" columns="4"]') . '</div>';

	}
}

if ( ! function_exists( 'woocommerce_related_products' ) ) {

	/**
	 * Output the related products.
	 *
	 * @access public
	 * @param int $posts_per_page (default: 2)
	 * @param int $columns (default: 2)
	 * @param string $orderby (default: 'rand')
	 * @return void
	 */
	function woocommerce_related_products( $posts_per_page = 2, $columns = 2, $orderby = 'rand'  ) {
		woocommerce_get_template( 'single-product/related.php', array(
			'posts_per_page'  => $posts_per_page,
			'orderby'    => $orderby,
			'columns'    => $columns
		) );
	}
}

if ( !function_exists('show_product_images_preview') ) {
	function show_product_images_preview() {
		woocommerce_get_template_part( 'content', 'product_images_preview' );

	}
}

if ( etheme_get_option('product_hover_preview') ) {
	add_action('wft_after_product_carousel_item', 'show_product_images_preview');
}

if ( ! function_exists( 'woocommerce_mini_cart' ) ) {

	/**
	 * Output the Mini-cart - used by cart widget
	 *
	 * @access public
	 * @return void
	 */
	function woocommerce_mini_cart( $args = array() ) {

		$defaults = array(
			'list_class' => ''
		);

		$args = wp_parse_args( $args, $defaults );

		woocommerce_get_template( 'cart/mini-cart.php', $args );
	}
}

if ( !function_exists('wft_wsl_render_login_form') ) {

	function wft_wsl_render_login_form() {
		if ( is_user_logged_in() && ! is_admin() ){
			return;
		}

		// Bouncer :: Allow authentication
		if( get_option( 'wsl_settings_bouncer_authentication_enabled' ) == 2 ){
			return;
		}


		// HOOKABLE:
		do_action( 'wsl_render_login_form_start' );

		GLOBAL $WORDPRESS_SOCIAL_LOGIN_PROVIDERS_CONFIG;

		if( empty( $social_icon_set ) ){
			$social_icon_set = "wpzoom/";
		}
		else{
			$social_icon_set .= "/";
		}

		$assets_base_url  = WORDPRESS_SOCIAL_LOGIN_PLUGIN_URL . '/assets/img/32x32/' . $social_icon_set;

		// HOOKABLE: allow use of other icon sets
		$assets_base_url = apply_filters( 'wsl_later_hook_assets_base_url', $assets_base_url );

		$wsl_settings_connect_with_label = get_option( 'wsl_settings_connect_with_label' );

		$current_page_url = 'http';
		if (isset($_SERVER["HTTPS"]) && ($_SERVER["HTTPS"] == "on")) {
			$current_page_url .= "s";
		}
		$current_page_url .= "://";
		if ($_SERVER["SERVER_PORT"] != "80") {
			$current_page_url .= $_SERVER["HTTP_HOST"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
		}
		else {
			$current_page_url .= $_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"];
		}

		$authenticate_base_url = site_url( 'wp-login.php', 'login_post' ) . ( strpos( site_url( 'wp-login.php', 'login_post' ), '?' ) ? '&' : '?' ) . "action=wordpress_social_authenticate&";

		// overwrite endpoint_url if need'd
		if( get_option( 'wsl_settings_hide_wp_login' ) == 1 ){
			$authenticate_base_url = WORDPRESS_SOCIAL_LOGIN_PLUGIN_URL . "/services/authenticate.php?";
		}

		$wsl_settings_authentication_widget_css = get_option( 'wsl_settings_authentication_widget_css' );

		// if not empty and not the default
		if( ! empty( $wsl_settings_authentication_widget_css ) ){
			?>
			<style>
				<?php echo $wsl_settings_authentication_widget_css ?>
			</style>
		<?php
		}
		?>
		<span id="wp-social-login-connect-with" class="hidden-small-desktop"><?php echo $wsl_settings_connect_with_label ?></span>
		<div id="wp-social-login-connect-options" class="login_social hidden-tablet hidden-phone">
			<?php
			$nok = true;

			// display provider icons
			foreach( $WORDPRESS_SOCIAL_LOGIN_PROVIDERS_CONFIG AS $item ){
				$provider_id     = @ $item["provider_id"];
				$provider_name   = @ $item["provider_name"];

				$authenticate_url = $authenticate_base_url . "provider=" . $provider_id . "&redirect_to=" . urlencode( $current_page_url );

				if( get_option( 'wsl_settings_' . $provider_id . '_enabled' ) ){
					// HOOKABLE: allow use of other icon sets
					$provider_icon_markup = apply_filters( 'wsl_alter_hook_provider_icon_markup', $provider_id, $item, $authenticate_url, $assets_base_url );

					$wsl_settings_use_popup = get_option( 'wsl_settings_use_popup' ) ;

					if( $provider_icon_markup != $provider_id ){
						echo $provider_icon_markup;
					}
					elseif( $wsl_settings_use_popup == 1 ){
						?>
						<a rel="nofollow" href="javascript:void(0);" title="Connect with <?php echo $provider_name ?>" class="wsl_connect_with_provider" data-provider="<?php echo $provider_id ?>">
							<img alt="<?php echo $provider_name ?>" title="<?php echo $provider_name ?>" src="<?php echo $assets_base_url . strtolower( $provider_id ) . '.png' ?>" />
						</a>
					<?php
					}
					elseif( $wsl_settings_use_popup == 2 ){
						?>
						<a rel="nofollow" href="<?php echo esc_url( $authenticate_url ) ?>" title="Connect with <?php echo $provider_name ?>" class="wsl_connect_with_provider" >
							<img alt="<?php echo $provider_name ?>" title="<?php echo $provider_name ?>" src="<?php echo $assets_base_url . strtolower( $provider_id ) . '.png' ?>" />
						</a>
					<?php
					}

					$nok = false;
				}
			}

			if( $nok ){
				?>
				<p style="background-color: #FFFFE0;border:1px solid #E6DB55;padding:5px;">
					<?php _wsl_e( '<strong style="color:red;">WordPress Social Login is not configured yet!</strong><br />Please visit the <strong>Settings\ WP Social Login</strong> administration page to configure this plugin.<br />For more information please refer to the plugin <a href="http://hybridauth.sourceforge.net/userguide/Plugin_WordPress_Social_Login.html">online user guide</a> or contact us at <a href="http://hybridauth.sourceforge.net/">hybridauth.sourceforge.net</a>' , 'wordpress-social-login') ?>
				</p>
				<style>
					#wp-social-login-connect-with{display:none;}
				</style>
			<?php
			}

			// provide popup url for hybridauth callback
			if( get_option( 'wsl_settings_use_popup' ) == 1 ){
				?>
				<input id="wsl_popup_base_url" type="hidden" value="<?php echo esc_url( $authenticate_base_url ) ?>" />
				<input type="hidden" id="wsl_login_form_uri" value="<?php echo esc_url( site_url( 'wp-login.php', 'login_post' ) ); ?>" />
			<?php
			}
			?>
		</div>
		<!-- /wsl_render_login_form -->
		<?php

		// HOOKABLE:
		do_action( 'wsl_render_login_form_end' );

		return true;
	}

}
add_filter('wsl_render_login_form_takeover', 'wft_wsl_render_login_form');

if ( !function_exists('wft_wsl_alter_hook_provider_icon_markup') ) {

	function wft_wsl_alter_hook_provider_icon_markup($provider_id, $item, $authenticate_url, $assets_base_url) {

		$html = '';

		$wsl_settings_use_popup = get_option( 'wsl_settings_use_popup' ) ;

		if( $wsl_settings_use_popup == 1 ){

			$html = '<a rel="nofollow" href="javascript:void(0);" title="Connect with ' . $item['provider_name'] . '" class="wsl_connect_with_provider button_small" data-provider="' . $provider_id . '">
						<i class="icon-' . strtolower($provider_id) . '"></i>
						<span>' . $item['provider_name'] . '</span>
					</a>';
		} else {
			$html = '<a rel="nofollow" href="' . esc_url( $authenticate_url ) . '" title="Connect with ' . $item['provider_name'] . '" class="wsl_connect_with_provider button_small" >
					<i class="icon-' . strtolower($provider_id) . '"></i>
					<span>' . $item['provider_name'] . '</span>
				</a>';

		}
		return $html;
	}

}

add_filter('wsl_alter_hook_provider_icon_markup', 'wft_wsl_alter_hook_provider_icon_markup', 10, 4);


if ( ! function_exists( 'get_product_search_form' ) ) {

	/**
	 * Output Product search forms.
	 *
	 * @access public
	 * @subpackage	Forms
	 * @param bool $echo (default: true)
	 * @return void
	 */
	function get_product_search_form( $echo = true, $tablet = false  ) {
		do_action( 'get_product_search_form'  );

		$search_form_template = locate_template( 'product-searchform.php' );
		if ( '' != $search_form_template  ) {
			require $search_form_template;
			return;
		}


		$form = '<div class="form-search-wrapper' . ($tablet ? ' display-small-tablet' : '') .' ">
			<form id="form-search" class="form-search" action="' . esc_url( home_url( '/'  ) ) . '">
				<input type="text" name="s" id="s" value="' . get_search_query() . '" class="search-query" placeholder="' . __( 'Search for products', 'woocommerce' ) . '">
				<button id="searchsubmit" class="btn" type="submit">
					<i class="icon-search-2 icon-large"></i>
				</button>
				<input type="hidden" name="post_type" value="product" />
			</form>
		</div>';

		if ( $echo  ) {
			echo apply_filters( 'get_product_search_form', $form );
		} else {
			return apply_filters( 'get_product_search_form', $form );
		}
	}
}

if ( ! function_exists( 'woocommerce_taxonomy_archive_description' ) ) {

	/**
	 * Show an archive description on taxonomy archives
	 *
	 * @access public
	 * @subpackage	Archives
	 * @return void
	 */
	function woocommerce_taxonomy_archive_description() {
		if ( is_tax( array( 'product_cat', 'product_tag' ) ) && get_query_var( 'paged' ) == 0 ) {
			$description = apply_filters( 'the_content', term_description() );
			if ( $description ) {
				echo '<div class="cleancode">' . $description . '</div>';
			}
		}
	}
}

if ( !function_exists('woocommerce_checkout_payment') ) {

	function woocommerce_checkout_payment() {
		global $woocommerce;
		woocommerce_get_template( 'checkout/form-payment.php', array( 'checkout' => $woocommerce->checkout ) );
	}

}

add_action('woocommerce_checkout_payment', 'woocommerce_checkout_payment');

add_filter('widget_categories_args', 'widget_categories_filter');
if ( !function_exists('widget_categories_filter') ) {
	function widget_categories_filter($args) {

		return $args;
	}
}

if ( !function_exists('wft_walker_nav_menu_edit') ) {
	function wft_walker_nav_menu_edit() {
		return 'wft_walker_nav_menu_edit';
	}
}
add_filter('wp_edit_nav_menu_walker', 'wft_walker_nav_menu_edit', 10);

if ( !function_exists('wft_woocommerce_cart_item_price_html') ) {

	function wft_woocommerce_cart_item_price_html($html) {
		return $html;
	}
}
add_filter('woocommerce_cart_item_price_html', 'wft_woocommerce_cart_item_price_html');

// Search autcomplete ajax function
if ( !function_exists('wft_search_autocomplete') ) {
	function wft_search_autocomplete() {

		$data = array(
			'query' => $_GET['query'],
			'suggestions' => array()
		);

		global $wp_query;

		$args = array(
			's' => $_GET['query'],
			'post_type' => 'product',
			'posts_per_page' => 5
		);
		$wp_query = new WP_Query( $args );

		$posts = $wp_query->get_posts();

		if ( !empty($posts) ) {

			foreach ( $posts as $post) {
				$data['suggestions'][] = $post->post_title;
			}
		}

		echo json_encode($data);
		exit;
	}
}
add_action( 'wp_ajax_wft_search_autocomplete', 'wft_search_autocomplete' );
add_action( 'wp_ajax_nopriv_wft_search_autocomplete', 'wft_search_autocomplete' );

if ( !function_exists('wft_row_fluid_open') ) {
	function wft_row_fluid_open() {
		echo '<div class="row-fluid">';
	}
}
add_action('comment_form_before_fields', 'wft_row_fluid_open', 1);

if ( !function_exists('wft_div_close') ) {
	function wft_div_close() {
		echo '</div>';
	}
}

add_action('comment_form_after_fields', 'wft_div_close', 1000);

if ( !function_exists('wft_comment_form') ) {
	/**
	 * Output a complete commenting form for use within a template.
	 *
	 * Most strings and form fields may be controlled through the $args array passed
	 * into the function, while you may also choose to use the comment_form_default_fields
	 * filter to modify the array of default fields if you'd just like to add a new
	 * one or remove a single field. All fields are also individually passed through
	 * a filter of the form comment_form_field_$name where $name is the key used
	 * in the array of fields.
	 *
	 * @since 3.0.0
	 *
	 * @param array       $args {
	 *     Optional. Default arguments and form fields to override.
	 *
	 *     @type array 'fields' {
	 *         Default comment fields, filterable by default via the 'comment_form_default_fields' hook.
	 *
	 *         @type string 'author' The comment author field HTML.
	 *         @type string 'email'  The comment author email field HTML.
	 *         @type string 'url'    The comment author URL field HTML.
	 *     }
	 *     @type string 'comment_field'        The comment textarea field HTML.
	 *     @type string 'must_log_in'          HTML element for a 'must be logged in to comment' message.
	 *     @type string 'logged_in_as'         HTML element for a 'logged in as <user>' message.
	 *     @type string 'comment_notes_before' HTML element for a message displayed before the comment form.
	 *                                         Default 'Your email address will not be published.'.
	 *     @type string 'comment_notes_after'  HTML element for a message displayed after the comment form.
	 *                                         Default 'You may use these HTML tags and attributes ...'.
	 *     @type string 'id_form'              The comment form element id attribute. Default 'commentform'.
	 *     @type string 'id_submit'            The comment submit element id attribute. Default 'submit'.
	 *     @type string 'title_reply'          The translatable 'reply' button label. Default 'Leave a Reply'.
	 *     @type string 'title_reply_to'       The translatable 'reply-to' button label. Default 'Leave a Reply to %s',
	 *                                         where %s is the author of the comment being replied to.
	 *     @type string 'cancel_reply_link'    The translatable 'cancel reply' button label. Default 'Cancel reply'.
	 *     @type string 'label_submit'         The translatable 'submit' button label. Default 'Post a comment'.
	 *     @type string 'format'               The comment form format. Default 'xhtml'. Accepts 'xhtml', 'html5'.
	 * }
	 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object to generate the form for. Default current post.
	 */
	function wft_comment_form( $args = array(), $post_id = null ) {
		if ( null === $post_id ) {
			$post_id = get_the_ID();
		} else {
			$id = $post_id;
		}

		$commenter = wp_get_current_commenter();
		$user = wp_get_current_user();
		$user_identity = $user->exists() ? $user->display_name : '';

		$args = wp_parse_args( $args );
		if ( ! isset( $args['format'] ) )
			$args['format'] = current_theme_supports( 'html5', 'comment-form' ) ? 'html5' : 'xhtml';

		$req      = get_option( 'require_name_email' );
		$aria_req = ( $req ? " aria-required='true'" : '' );
		$html5    = 'html5' === $args['format'];
		$fields   =  array(

			'author' => '<label for="author">' . __( 'Name', WFT_DOMAIN ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label>
                    <input id="author" name="author" type="text" class="full-width" value="' . esc_attr( $commenter['comment_author'] ) . '" ' . $aria_req . ' />',

			'url'    => '<label for="phone">' . __( 'Telephone', WFT_DOMAIN ) . '</label> ' .
				'<input id="phone" name="phone" ' . ( $html5 ? 'type="tel"' : 'type="text"' ) . ' class="full-width" value="' . ( ( isset($commenter['comment_author_phone']) ) ? esc_attr( $commenter['comment_author_phone'] ) : '' ) . '"  />',

			'email' => '<label for="email">' . __( 'Email', WFT_DOMAIN ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label>
                    <input id="email" name="email" class="full-width" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr(  $commenter['comment_author_email'] ) . '" ' . $aria_req . ' />',
		);

		$required_text = sprintf( ' ' . __('Required fields are marked %s', WFT_DOMAIN), '<span class="required">*</span>' );

		/**
		 * Filter the default comment form fields.
		 *
		 * @since 3.0.0
		 *
		 * @param array $fields The default comment fields.
		 */


		$fields = apply_filters( 'comment_form_default_fields', $fields );

		$defaults = array(
			'fields'               => $fields,
			'comment_field'        => '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun', WFT_DOMAIN ) . '</label> <textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></p>',
			'must_log_in'          => '<p class="must-log-in">' . sprintf( __( 'You must be <a href="%s">logged in</a> to post a comment.' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>',
			'logged_in_as'         => '<p class="logged-in-as">' . sprintf( __( 'Logged in as <a href="%1$s">%2$s</a>. <a href="%3$s" title="Log out of this account">Log out?</a>' ), get_edit_user_link(), $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>',
			'comment_notes_before' => '<p class="comment-notes">' . __( 'Your email address will not be published.', WFT_DOMAIN ) . ( $req ? $required_text : '' ) . '</p>',
			'comment_notes_after'  => '<p class="form-allowed-tags">' . sprintf( __( 'You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes: %s' ), ' <code>' . allowed_tags() . '</code>' ) . '</p>',
			'id_form'              => 'commentform',
			'id_submit'            => 'submit',
			'title_reply'          => __( 'Leave a Reply', WFT_DOMAIN ),
			'title_reply_to'       => __( 'Leave a Reply to %s', WFT_DOMAIN ),
			'cancel_reply_link'    => __( 'Cancel reply', WFT_DOMAIN ),
			'label_submit'         => __( 'Post Comment', WFT_DOMAIN ),
			'format'               => 'xhtml',
		);

		/**
		 * Filter the comment form default arguments.
		 *
		 * Use 'comment_form_default_fields' to filter the comment fields.
		 *
		 * @since 3.0.0
		 *
		 * @param array $defaults The default comment form arguments.
		 */
		$args = wp_parse_args( $args, apply_filters( 'comment_form_defaults', $defaults ) );

		?>
		<?php if ( comments_open( $post_id ) ) : ?>
			<?php
			/**
			 * Fires before the comment form.
			 *
			 * @since 3.0.0
			 */
			do_action( 'comment_form_before' );
			?>
			<div id="respond" class="comment-respond">
				<h3 id="reply-title" class="comment-reply-title"><?php comment_form_title( $args['title_reply'], $args['title_reply_to'] ); ?></h3>
				<?php if ( get_option( 'comment_registration' ) && !is_user_logged_in() ) : ?>
					<?php echo $args['must_log_in']; ?>
					<?php
					/**
					 * Fires after the HTML-formatted 'must log in after' message in the comment form.
					 *
					 * @since 3.0.0
					 */
					do_action( 'comment_form_must_log_in_after' );
					?>
				<?php else : ?>
					<form action="<?php echo site_url( '/wp-comments-post.php' ); ?>" method="post" id="<?php echo esc_attr( $args['id_form'] ); ?>" class="comment-form"<?php echo $html5 ? ' novalidate' : ''; ?>>
						<?php
						/**
						 * Fires at the top of the comment form, inside the <form> tag.
						 *
						 * @since 3.0.0
						 */
						do_action( 'comment_form_top' );
						?>
						<?php if ( is_user_logged_in() ) : ?>
							<?php
							/**
							 * Filter the 'logged in' message for the comment form for display.
							 *
							 * @since 3.0.0
							 *
							 * @param string $args['logged_in_as'] The logged-in-as HTML-formatted message.
							 * @param array  $commenter            An array containing the comment author's username, email, and URL.
							 * @param string $user_identity        If the commenter is a registered user, the display name, blank otherwise.
							 */
							echo apply_filters( 'comment_form_logged_in', $args['logged_in_as'], $commenter, $user_identity );
							?>
							<?php
							/**
							 * Fires after the is_user_logged_in() check in the comment form.
							 *
							 * @since 3.0.0
							 *
							 * @param array  $commenter     An array containing the comment author's username, email, and URL.
							 * @param string $user_identity If the commenter is a registered user, the display name, blank otherwise.
							 */
							do_action( 'comment_form_logged_in_after', $commenter, $user_identity );
							?>
						<?php else : ?>
							<?php echo $args['comment_notes_before']; ?>
							<?php
							/**
							 * Fires before the comment fields in the comment form.
							 *
							 * @since 3.0.0
							 */
							do_action( 'comment_form_before_fields' );

							$args['fields'] = (array) $args['fields'];

							if ( !empty($args['fields']) ) {
								$fields_count = count($args['fields']);

								$fields_middle = round($fields_count/2);

								$fields['left'] = array();
								$fields['right'] = array();

								$i = 1;

								foreach ( $args['fields'] as $name => $field ) {

									if ( $i <= $fields_middle ) {
										$fields['left'][$name] = $field;
									} else {
										$fields['right'][$name] = $field;
									}
									$i++;

								}

								echo '<div class="span6">';
								foreach ( $fields['left'] as $name => $field ) {
									/**
									 * Filter a comment form field for display.
									 *
									 * The dynamic portion of the filter hook, $name, refers to the name
									 * of the comment form field. Such as 'author', 'email', or 'url'.
									 *
									 * @since 3.0.0
									 *
									 * @param string $field The HTML-formatted output of the comment form field.
									 */
									echo apply_filters( "comment_form_field_{$name}", $field ) . "\n";
								}
								echo '</div>';

								if ( !empty($fields['right']) ) {
									echo '<div class="span6">';

									foreach ( $fields['right'] as $name => $field ) {
										/**
										 * Filter a comment form field for display.
										 *
										 * The dynamic portion of the filter hook, $name, refers to the name
										 * of the comment form field. Such as 'author', 'email', or 'url'.
										 *
										 * @since 3.0.0
										 *
										 * @param string $field The HTML-formatted output of the comment form field.
										 */
										echo apply_filters( "comment_form_field_{$name}", $field ) . "\n";
									}

									echo '</div>';
								}

							}
							/**
							 * Fires after the comment fields in the comment form.
							 *
							 * @since 3.0.0
							 */
							do_action( 'comment_form_after_fields' );
							?>
						<?php endif; ?>
						<?php
						/**
						 * Filter the content of the comment textarea field for display.
						 *
						 * @since 3.0.0
						 *
						 * @param string $args['comment_field'] The content of the comment textarea field.
						 */
						echo apply_filters( 'comment_form_field_comment', $args['comment_field'] );
						?>
						<?php echo $args['comment_notes_after']; ?>

						<br/>
						<br/>

						<input name="submit" type="submit" id="<?php echo esc_attr( $args['id_submit'] ); ?>" class="button button_form" value="<?php echo esc_attr( $args['label_submit'] ); ?>" />
						<span class="pull-right button"><?php cancel_comment_reply_link( $args['cancel_reply_link'] ); ?></span>
						<?php comment_id_fields( $post_id ); ?>

						<?php
						/**
						 * Fires at the bottom of the comment form, inside the closing </form> tag.
						 *
						 * @since 1.5.2
						 *
						 * @param int $post_id The post ID.
						 */
						do_action( 'comment_form', $post_id );
						?>
					</form>
				<?php endif; ?>
			</div><!-- #respond -->
			<?php
			/**
			 * Fires after the comment form.
			 *
			 * @since 3.0.0
			 */
			do_action( 'comment_form_after' );
		else :
			/**
			 * Fires after the comment form if comments are closed.
			 *
			 * @since 3.0.0
			 */
			do_action( 'comment_form_comments_closed' );
		endif;
	}
}

if ( !function_exists('filter_prev_post_link') ) {
	function filter_prev_post_link($output, $format, $link, $post) {

		if ( $post && has_post_thumbnail($post->ID) ) {

			$output .= '<div class="small_preview prev hidden-phone hidden-tablet" style="display: none;">' . get_the_post_thumbnail($post->ID, 'thumbnail') . '</div>';


		}

		return $output;
	}
}
add_filter('previous_post_link', 'filter_prev_post_link', 10, 4);

if ( !function_exists('filter_next_post_link') ) {
	function filter_next_post_link($output, $format, $link, $post) {

		if ( $post && has_post_thumbnail($post->ID) ) {

			$output .= '<div class="small_preview next hidden-phone hidden-tablet" style="display: none;">' . get_the_post_thumbnail($post->ID, 'thumbnail') . '</div>';


		}

		return $output;
	}
}
add_filter('next_post_link', 'filter_next_post_link', 10, 4);

if ( !function_exists('mini_cart_product_title_link') ) {
	function mini_cart_product_title_link($product_title, $product, $product_link) {

		$product_title = '<a href="' . $product_link .'">' . $product_title . '</a>';

		return $product_title;
	}
}
add_filter('woocommerce_widget_cart_product_title', 'mini_cart_product_title_link', 10, 3);

if ( !function_exists('generate_fonts_css') ) {
	function generate_fonts_css($options, $selectors) {

		$css = '';

		if ( !empty($options) ) {

			$css .= jsString($selectors) . ' {'. "\r\n";

			foreach ( $options as $k => $v ) {
				if ( !empty($v) ) {
					if ( $k == 'google-font' ) {
						$css .= 'font-family: ' . str_replace("+", " ", $v).';';
					} elseif ( $k == 'font-color' ) {
						$css .= 'color: ' . $v . ';';
					} else {
						$css .= $k . ': ' . $v . ';';
					}
				}
			}

			$css .= '}'. "\r\n";
		}
		return $css;
	}
}

if ( !function_exists('wft_get_price_html') ) {
	function wft_get_price_html($product) {

		if ( $product->price !== '' ) {
			if ( $product->price == $product->sale_price && $product->sale_price < $product->regular_price ) {

				$price = '
					<p class="old-price">
						<span class="price-label">' . __('Regular Price', 'woocommerce') . ':</span>
						<span class="price">'
					. woocommerce_price( $product->regular_price ) .
					'</span>
				</p>

				<p class="special-price">
					<span class="price-label">' . __('Special Price', 'woocommerce') . ':</span>
						<span class="price">'
					. woocommerce_price( $product->sale_price ) .
					'</span>
				</p>
			';


				$price = apply_filters( 'woocommerce_variation_sale_price_html', $price, $product );

			} elseif ( $product->price > 0 ) {

				$price = woocommerce_price( $product->price );
				$price = apply_filters( 'woocommerce_variation_price_html', $price, $product );

			} else {

				$price = __( 'Free!', 'woocommerce' );
				$price = apply_filters( 'woocommerce_variation_free_price_html', $price, $product );

			}
		} else {
			$price = apply_filters( 'woocommerce_variation_empty_price_html', '', $product );
		}

		return $price;

	}
}

if ( !function_exists('wft_wpb_widget_title_filter') ) {
	function wft_wpb_widget_title_filter($output, $params) {
		if($params['title']=='') return;

		$extraclass = (isset($params['extraclass'])) ? " ".$params['extraclass'] : "";
		$output = '<h3 class="wpb_heading'.$extraclass.'">' . $params['title'] . '</h3>';

		return $output;
	}
}
add_filter('wpb_widget_title', 'wft_wpb_widget_title_filter', 10, 2);

if ( !function_exists('wft_blog_slider_image_filter') ) {
	function wft_blog_slider_image_filter($html, $post_id, $post_thumbnail_id, $size, $attr) {
		$html = str_replace('class="', 'class="animate pulse ', $html);
		return $html;
	}
}

if ( !function_exists('wft_blog_table_image_filter') ) {
	function wft_blog_table_image_filter($html, $post_id, $post_thumbnail_id, $size, $attr) {
		$html = str_replace('class="', 'class="img-rounded animate flip ', $html);
		return $html;
	}
}

if ( !function_exists('wft_get_category_filter') ) {
	function wft_get_category_filter($cats) {

		$html = '';

		foreach ( $cats as $cat ) {
			/*
			<li><a href="#filter" data-option-value="*" class="selected">all</a></li>

            <li><a href="#filter" data-option-value=".photogaphy">Photography</a></li>
			*/

			$cat_name = esc_attr( $cat->name );
			$cat_name = apply_filters( 'list_cats', $cat_name, $cat );

			$html .= '<li><a data-cat-id="' . $cat->term_id . '" data-option-value=".' . str_replace(' ', '-', $cat_name) . '" href="'. esc_url( get_term_link($cat) ) .'">'. $cat_name .'</a></li>';
		}

		return $html;
	}
}

if ( !function_exists('wft_get_posts_by_category') ) {
	function wft_get_posts_by_category() {

		$data = array();
		global $wp_query;

		$args = array(
			'cat' => $_GET['cat'],
			'post_type' => 'post',
			'posts_per_page' => 6
		);

		$wp_query = new WP_Query( $args );

		$posts = $wp_query->get_posts();

		if ( !empty($posts) ) {

			$data['posts'] = array();
			$html = '';
			foreach ( $posts as $post) {

				$cat_name = str_replace(' ', '-', get_the_category($post->ID));

				$images = etheme_get_images(null, null, true, $post->ID );

				$link = get_permalink($post->ID);
				$the_time = get_post_time(get_option('time_format'), false, $post, true);
				$more_link_text = __('Read More', WFT_DOMAIN);

				$output = '';
				$content = $post->post_content;
				$content = apply_filters('the_content', $content);
				$content = str_replace(']]>', ']]&gt;', $content);

				if ( preg_match( '/<!--more(.*?)?-->/', $content, $matches ) ) {
					$content = explode( $matches[0], $content, 2 );
					if ( ! empty( $matches[1] ) && ! empty( $more_link_text ) ) {
						$more_link_text = strip_tags( wp_kses_no_null( trim( $matches[1] ) ) );
					}

					$has_teaser = true;
				} else {
					$content = array( $content );
				}

				if ( false !== strpos( $post->post_content, '<!--noteaser-->' ) && ( ! $multipage || $page == 1 ) )
					$strip_teaser = true;

				$teaser = $content[0];

				$output .= $teaser;

				if ( count( $content ) > 1 ) {
					if ( ! empty( $more_link_text ) ) {
						$output .= apply_filters( 'the_content_more_link', ' <a href="' . $link . "#more-{$post->ID}\" class=\"more-link\">$more_link_text</a>", $more_link_text );
					}
					$output = force_balance_tags( $output );
				}

				$html .= '<div class="post-preview-small span4 ' . $cat_name .'" id="post-'  . $post->ID . '">';


				if ( !empty($images) && has_post_thumbnail($post->ID) ) {

					$html .= '<div class="image">
						<a href="' . $link .'">
							<img src="' . $images[0] . '"  alt="" class="img-rounded animate flip animated">
						</a>
					</div>';

				}

				$html .= '<div class="inside">
					<h3 class="post-title"><a href="' . $link .'">' . $post->post_title . '</a></h3>
					<div class="post-meta">
						<span class="meta-date"><i class="icon-clock-alt"></i>' . $the_time . '</span>
						<span class="meta-tags"><i class="icon-tag-1"></i>' . get_the_category_list(',&nbsp;', '', $post->ID) . '</span>
					</div>
					<div class="text">
						' . $output . '
					</div>
				</div>';


				$html .= '</div>';

			}
			$data['posts'] = $html;
		}

		echo json_encode($data);
		exit;

	}
}

add_action( 'wp_ajax_wft_get_posts_by_category', 'wft_get_posts_by_category' );
add_action( 'wp_ajax_nopriv_wft_get_posts_by_category', 'wft_get_posts_by_category' );

function add_custom_option_types( $types ) {

	$types['staticblocks-select'] = 'Static Blocks';


	return $types;

}
add_filter( 'ot_option_types_array', 'add_custom_option_types' );

/**
 * Static Blocks Select option type.
 *
 * See @ot_display_by_type to see the full list of available arguments.
 *
 * @param     array     An array of arguments.
 * @return    string
 *
 * @access    public
 * @since     2.0
 */
if ( ! function_exists( 'ot_type_staticblocks_select' ) ) {

	function ot_type_staticblocks_select( $args = array() ) {

		/* turns arguments array into variables */
		extract( $args );

		/* verify a description */
		$has_desc = $field_desc ? true : false;

		/* format setting outer wrapper */
		echo '<div class="format-setting type-post-select ' . ( $has_desc ? 'has-desc' : 'no-desc' ) . '">';

		/* description */
		echo $has_desc ? '<div class="description">' . htmlspecialchars_decode( $field_desc ) . '</div>' : '';

		/* format setting inner wrapper */
		echo '<div class="format-setting-inner">';

		/* build page select */
		echo '<select name="' . esc_attr( $field_name ) . '" id="' . esc_attr( $field_id ) . '" class="option-tree-ui-select ' . $field_class . '">';

		/* query posts array */
		$my_posts = get_posts( apply_filters( 'ot_type_post_select_query', array( 'post_type' => array( 'staticblocks' ), 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC', 'post_status' => 'any' ), $field_id ) );

		/* has posts */
		if ( is_array( $my_posts ) && ! empty( $my_posts ) ) {
			echo '<option value="">-- ' . __( 'Choose One', 'option-tree' ) . ' --</option>';
			foreach( $my_posts as $my_post ){
				echo '<option value="' . esc_attr( $my_post->ID ) . '"' . selected( $field_value, $my_post->ID, false ) . '>' . esc_attr( $my_post->post_title ) . '</option>';
			}
		} else {
			echo '<option value="">' . __( 'No Posts Found', 'option-tree' ) . '</option>';
		}

		echo '</select>';

		echo '</div>';

		echo '</div>';

	}

}

if ( !function_exists('wft_filter_walker_nav_menu_start_el') ) {
	function wft_filter_walker_nav_menu_start_el($item_output, $item, $depth, $args) {
		return $item_output;
	}
}
add_filter('walker_nav_menu_start_el', 'wft_filter_walker_nav_menu_start_el', 10, 4);