/*
*************************************************

SEBASTIAN NITU
jQuery Document & Image Ready Scripts

Created by Sebastian Nitu
http://www.sebnitu.com

*************************************************
*/

/*-------------------------------------------    
	When Document is Ready
---------------------------------------------*/
$(document).ready(function() {

	/**
	 * Form Value Checker
	 */
	var search = $('#search-form #search');
		
	function searchHasValue(search) {
		if ( $(search).val() ) {
			$(search).parent().addClass('has-value');
		} else {
			$(search).parent().removeClass('has-value');
		}
	}
	
	searchHasValue(search);
	
	$('#search-form #search').focus( function() { 
		searchHasValue(this);
	});
	$('#search-form #search').blur( function() { 
		searchHasValue(this);
	});
	$('#search-form #search').keyup( function(event) {
		searchHasValue(this);
	});
	
	/**
	 * Clear Input
	 */
	$('#searchclear').click(function() {
		$(search).val(''); searchHasValue(search); return false;
	});
	
	/**
	 * Main Navigation
	 */
	
	// Has Children Class
	$('#nav ul ul').addClass('children').parent().addClass('has-children');
	$('#nav ul ul ul').removeClass('children').parent().removeClass('has-children').find('> ul').addClass('third-level-children');
	
	/**
	 * Sidebar Dropdown Functionality
	 */

	$('#nav .children').wrap('<div class="dropdown" />');

	// Append span element after first row of links
	$('.dropdown-list > li .dropdown').parent().append('<span></span>');

	// Behave on span click
	$('.dropdown-list li span').click(function() {

		// If clicked item is active
		if( $(this).parent().hasClass('active') ) {

			// Remove all active classes and close all dropdowns
			$('.dropdown-list > li').removeClass('active');
			$('.dropdown').slideUp();

		// Else, it was not active
		} else {

			// Remove all active classes and add to clicked item
			$('.dropdown-list > li').removeClass('active');
			$(this).parent().addClass('active');

			// Close all dropdowns and open active dropdown
			$('.dropdown').slideUp();
			$(this).prev().slideDown();

		}

	});// End of on click
	
	$('.current_page_ancestor').addClass('active').find('.dropdown').show();
	$('.has-children.current_page_item').addClass('active').find('.dropdown').show();
	$('.third-level-children').hide();
	$('.children .current_page_item .third-level-children').show();
	$('.children .third-level-children .current_page_item').parent().show();
	
});

/*-------------------------------------------    
	After Images are Loaded
---------------------------------------------*/

$(window).load(function() {



});

/*-------------------------------------------    
	Fin
---------------------------------------------*/
