( function( $ ) {

	"use strict";

	/**
	 * Real-time preview of the site title and description text.
	 */
	wp.customize( 'blogname', function( value ) {
		value.bind( function( to ) {
			$( '.site-title a' ).html( to );
		} );
	} );
	wp.customize( 'blogdescription', function( value ) {
		value.bind( function( to ) {
			$( '.site-description' ).html( to );
		} );
	} );

	/**
	 * Real-time preview of the footer site information text.
	 */
	wp.customize( 'organic_startup_footer_text', function( value ) {
		value.bind( function( to ) {
			$( '.footer-site-info' ).html( to );
		} );
	} );

	/**
	 * Real-time preview of the site title.
	 */
	wp.customize( 'organic_startup_site_title', function( value ) {
		value.bind( function( to ) {
			if ( '1' != to ) {
				$( '.site-title' ).css( {
					'padding' : '0',
					'text-indent' : '-9999px',
					'position': 'absolute'
				} );
			} else {
				$( '.site-title' ).css( {
					'padding' : '24px 12px',
					'text-indent' : '0',
					'position': 'relative'
				} );
			}
		} );
	} );

	/**
	 * Real-time preview of the site tagline.
	 */
	wp.customize( 'organic_startup_site_tagline', function( value ) {
		value.bind( function( to ) {
			if ( '1' != to ) {
				$( '.site-description' ).css( {
					'padding' : '0',
					'left' : '-9999px',
					'position': 'absolute'
				} );
			} else {
				$( '.site-description' ).css( {
					'padding' : '12px',
					'left' : '0',
					'position': 'relative'
				} );
			}
		} );
	} );

	/**
	 * Real-time preview of the navigation menu background color.
	 */
	wp.customize( 'organic_startup_colors_nav', function( value ) {
		value.bind( function( to ) {
			$('#nav-bar, .menu ul.sub-menu, .menu ul.children').css('background-color', to );
			$('#nav-bar').bgBrightness();
		} );
	} );

	/**
	 * Real-time preview of the navigation menu background color.
	 */
	wp.customize( 'organic_startup_colors_content', function( value ) {
		value.bind( function( to ) {
			$('#body, .blog-holder .feature-img + .article > h2').css('background-color', to );
			$('#body').bgBrightness();
		} );
	} );

	/**
	 * Real-time preview of the footer background color.
	 */
	wp.customize( 'organic_startup_colors_footer', function( value ) {
		value.bind( function( to ) {
			$('#footer').css('background-color', to );
			$('#footer').bgBrightness();
		} );
	} );

	/**
	 * Real-time preview of the site title color.
	 */
	wp.customize( 'organic_startup_colors_site_title', function( value ) {
		value.bind( function( to ) {
			$('.startup-header-static .site-title a, .startup-header-solid .site-title a').css('color', to );
		} );
	} );

	/**
	 * Real-time preview of the link color.
	 */
	wp.customize( 'organic_startup_colors_links', function( value ) {
		value.bind( function( to ) {
			$('#body p a, #body li a, #body table a').css('color', to );
		} );
	} );

	/**
	 * Real-time preview of the heading link color.
	 */
	wp.customize( 'organic_startup_colors_heading_links', function( value ) {
		value.bind( function( to ) {
			$('#body h1 a, #body h2 a, #body h3 a, #body h4 a, #body h5 a, #body h6 a').css('color', to );
		} );
	} );

	/**
	 * Real-time preview of the button background color.
	 */
	wp.customize( 'organic_startup_colors_button', function( value ) {
		value.bind( function( to ) {
			$('#body button, .button, a.more-link, .reply a, #searchsubmit, #prevLink a, #nextLink a, input#submit').css('background-color', to );
		} );
	} );

})( jQuery );
