/**
 * Admin side javascript
 *
 */

jQuery(document).ready(function( $ ) {

	$('#page_template').on('change', dynamic_template);
	$( '.plug-shop-notice' ).on( 'click', '.notice-dismiss', plugShopDismiss);
	dynamic_template();

	// Site title and description.
	$('.toggle').on('click', function(){
    	if( $(this).is(':checked') && ! $(this).closest('label').hasClass('active') ){
    		$(this).closest('label').addClass('active').siblings().removeClass('active');
    	}
    });

     $('.toggle:checked').closest('label').addClass('active'); 

     function dynamic_template(e) {
     	if( e && e.type != undefined ) {
	     	var $this = $(this);
	     } else {
	     	var $this = $('#page_template');
	     }

	     if( $this.val() == 'templates/dynamic.php' )
	     	$('#plug_shop_pmeta').addClass('active');
	     else
	     	$('#plug_shop_pmeta').removeClass('active');
     }

	function plugShopDismiss() {
		var $notice = $(this).parent('.notice.is-dismissible');
		var dismiss_url = $notice.attr('data-dismiss-url');
		if ( dismiss_url ) {
			$.get( dismiss_url );
		}
	}

} );
