

jQuery(document).ready(function(){
// Target your #container, #wrapper etc.
    //jQuery("#wrapper").fitVids();

    jQuery('#container').css({ 'opacity': 0});

    // Sub Menu Item Arrows
	jQuery('#theme-menu-main li').each(function(index, element) {
		var item = jQuery(element);
		var parent = jQuery('#theme-menu-main > li:first-child');
		var subMenu = item.children('ul');
		var isSubmenu = item.parent().hasClass('sub-menu');

		// Add dropdown indicators
		// parent
		if ( parent && item.children().hasClass('sub-menu') && !isSubmenu ) {
			var contentHtml = item.children('a').html();
			item.children('a').html('<span>' + contentHtml + '</span>');
			var arrowDown = ' <i class="icon-caret-down fa fa-caret-down"></i>';
			item.children('a').append(arrowDown);
		}

		// Submenus in submenus
		if (isSubmenu && subMenu.length) {
			var arrowRight = ' <i class="icon-double-angle-right fa fa-double-angle-right"></i>';
			item.children('a').append(arrowRight);
		}

	});

	// Append arrows to some elements
	var rarr = jQuery('<i class="icon-double-angle-right fa fa-double-angle-right"></i>');
	jQuery('.widget li > a:first-child').each(function(index, element) {
			element = jQuery(element);
			if( !element.parents(".widget").hasClass('widget_td_categories') && !element.parents(".widget").hasClass('widget_themedutch_posts') ) {
				element.prepend(rarr.clone());
			}
	});

	/* Icons in Menu Items
		================================================== */
	jQuery('.menu li').each(function(index, element) {
		var item = jQuery(element);
		if ( item.attr('class') ) {
			var iconclass = item.attr('class').split(' ')[0];
			if (iconclass.indexOf("fa") === 0){
				var newIcon = '<i class="fa fa-menu '+ iconclass +'"></i>&nbsp;&nbsp;';
				item.children('a').prepend(newIcon);
				item.removeClass(iconclass);
			}
		}
	});

	// insert class buttons
	jQuery(' a[class*="-button"], input[type="submit"] ').each(function(index, element) {
			element = jQuery(element);
			element.addClass('button');
	});

	// Append arrow to buttons
	var barr = ' <span class="arrow">&rarr;</span>';
	jQuery('a.button').each(function(index, element) {
			element = jQuery(element);
			//element.append(barr);
	});

	// Search box animation
	jQuery('#theme-search-box').each(function(index, element) {
		var searchBox = jQuery(element);
		var inputBox = searchBox.find('#searchform');
		var submitButton = searchBox.find('#searchsubmit');
		var originalColor = ''; //'#' + theme_colors.color_search_field;

		var ANIMATE_SPEED = 350;
		var DELAY_COLLAPSE = 1500;

		function collapse() {
			if (inputBox.val() !== '') {
				setTimeout(collapse, DELAY_COLLAPSE);
				return;
			}
			inputBox.stop(true, true).fadeOut(ANIMATE_SPEED / 2);
			searchBox.stop(true, true).animate({width: '44px'}, ANIMATE_SPEED);
			//searchBox.stop(true, true).animate({width: '45px', backgroundColor: '#444'}, ANIMATE_SPEED);
		}

		searchBox.find('.icon-search').click(function(){
			if ( searchBox.hasClass('searchbox-open') ) {
				inputBox.stop(true, true).fadeOut(ANIMATE_SPEED - 150);
				setTimeout(collapse, DELAY_COLLAPSE);
				searchBox.stop(true, true).animate({width: '44px'}, ANIMATE_SPEED);
				searchBox.removeClass('searchbox-open');
			} else {
				inputBox.stop(true, true).fadeIn(ANIMATE_SPEED * 2, function() {
					searchBox.find('#s').focus();
				});
				searchBox.stop(true, true).animate({width: '215px'}, ANIMATE_SPEED);
				searchBox.addClass('searchbox-open');
			}
		});

	});

	// Input field placeholder text
	jQuery('input[placeholder]').each(function(index, element) {
		var element = jQuery(element);

		var placeholderText = element.attr('placeholder');
		if (!placeholderText === ''){
			return;
		}
		element.removeAttr('placeholder');

		// Place first placeholder
		if (element.val() === '') {
			element.val(placeholderText);
			element.addClass('placeholderActive');
		}

		element.bind('focus', function() {
			if (element.val() === placeholderText) {
				element.val('');
				element.removeClass('placeholderActive');
			}
		});
		element.bind('blur', function() {
			if (element.val() === '') {
				element.val(placeholderText);
				element.addClass('placeholderActive');
			}
		});
	});

    // show the back top link
    toTop();

    // Setup PrettyPhoto links
	//
	jQuery('a[data-rel^="prettyPhoto"]').prettyPhoto({
		animationSpeed: 'slow', /* fast/slow/normal */
		theme: "pp_default", /*pp_default/light_rounded/dark_rounded/dark_square/light_square/facebook */
		opacity: 0.5, /* Value between 0 and 1 */
		showTitle: false, /* true/false */
		deeplinking: true
	});

	// Responsive Menu (TinyNav)
	jQuery("#theme-menu-main").tinyNav({
		active: 'current_page_item', // Set the "active" class for default menu
		label: '', // String: Sets the <label> text for the <select> (if not set, no label will be added)
	    header: '' // String: Specify text for "header" and show header instead of the active item
	});

	// Responsive Menu (Selectbox)
	jQuery(function () {
	    jQuery(".tinynav").selectbox();
	});

	// Cleanup empty p tags
	jQuery('p').each(function(index, element) {
		element = jQuery(element);
		if ( element.html() === '' || element.html() === '<br>') {
			element.remove();
		}
	});

	if ( jQuery.isFunction( jQuery.fn.imgLiquid ) ) {
		jQuery('.theme-excerpts .item-image').each( function() {
			var heightH = jQuery(this).parent().height();
			jQuery(this).css( 'height', heightH );
			jQuery(this).imgLiquid({fill:true});
		});
	}

	if ( jQuery('#more').length > 0 ) {
		jQuery('.theme-content').bind('resize', sidebarHeight );
	}

	// Admin Bar On
	if ( jQuery('#sitewide-notice').length > 0 ) {
		jQuery('#sitewide-notice').find('#message').addClass('tds-notify');
	}

});

jQuery(window).load(function() {

	jQuery('#container').css({ 'opacity': 1});

	// Remove loader when ready
	jQuery('.core-loader').delay(50).fadeOut(150);

	// Check for smaller screens
	var w = jQuery(window).width();

	jQuery('#theme-menu-main .sub-menu').each(function(index, element) {
		var padSubMenu = Math.round(jQuery('#site-navigation').height() - 1);
		jQuery(this).css('top', padSubMenu );
	});

	if ( jQuery.isFunction( jQuery.fn.imgLiquid ) ) {
		jQuery('div.gallery').each( function() {
			var maxH = 0;
			jQuery(this).find('.gallery-item').each( function() {
				var heightH = jQuery(this).find('img').height();
				jQuery(this).css( 'height', heightH );
				jQuery(this).imgLiquid({fill:true});

				if ( heightH > maxH ) {
					maxH = heightH;
				}
			});

			jQuery(this).find('.gallery-item').css( 'height', maxH );
		});
	}

    sidebarHeight();

});

function sidebarHeight() {
	var w = jQuery(window).width();
	if ( w > 768 ) {

       // Append arrows to some elements
		var maxHeight = jQuery('#wrapper').height();
		var minHeight = maxHeight;

		if(jQuery('#wrapper .sidebar').length > 0 ) {
			jQuery('#wrapper .sidebar').each(function(index, element){
				var element = jQuery(element);
				var elementHeight = element.height();
				if ( elementHeight < minHeight ){
					minHeight = elementHeight;
				}
			});
		}

		if( maxHeight < minHeight ) {
			jQuery('#wrapper .sidebar').delay(1500).css('height', function(index) {
					return maxHeight;
			});
		} else {
			jQuery('#wrapper .sidebar').delay(1500).css('height', function(index) {
					return maxHeight;
			});
		}

    }
}

/*!
 * Responsive JS Plugins v1.2.2
 */
// Placeholder
jQuery(function(){
    //jQuery('input[placeholder], textarea[placeholder]').placeholder();
});

// Have a custom video player? We now have a customSelector option where you can add your own specific video vendor selector (mileage may vary depending on vendor and fluidity of player):
// jQuery("#thing-with-videos").fitVids({ customSelector: "iframe[src^='http://example.com'], iframe[src^='http://example.org']"});
// Selectors are comma separated, just like CSS
// Note: This will be the quickest way to add your own custom vendor as well as test your player's compatibility with FitVids.

 jQuery(".theme-content .entry-content").fitVids();


// Masonry
//jQuery(function(){
//    jQuery('#container').masonry({
//      itemSelector: '.grid',
//      columnWidth: 200,
      //isAnimated: !Modernizr.csstransitions,
//      isFitWidth: true
//    });
//  });

// To top
//
function toTop() {
	var TOP_MINIMUM = 200;
	var ANIMATE_SPEED = 500;

	var toTop = jQuery('.scroll-top');

	function updateToTop() {
		var scrollTop = jQuery(window).scrollTop();

		if (scrollTop > TOP_MINIMUM) {
			toTop.stop(true, true).slideDown(ANIMATE_SPEED);
		} else if (scrollTop <= TOP_MINIMUM) {
			toTop.stop(true, true).slideUp(ANIMATE_SPEED);
		}
	}

	jQuery(window).scroll(updateToTop);
	updateToTop();

	// To top button
	toTop.bind('click', function() {
		jQuery('html, body').stop(true, true).animate({scrollTop: 0}, ANIMATE_SPEED);
		return false;
	});
}

