processDemoControls = function(){
	var selector = '#demo-controls input';
	var self = $(selector);
	var classArray = [];
	var appliedClasses = '';
	var classList = '';
	if($('#demo-content').is(':checked')){
		classArray.push('demo-contents');
	}else{
		classArray.push('demo-labels');
	};
	if($('#show-full-width').is(':checked')){
		classArray.push('full-width');
	};
	if($('#show-page-message').is(':checked')){
		classArray.push('page-message');
	};
	if($('#show-breadcrumbs').is(':checked')){
		classArray.push('breadcrumbs');
	};
	if($('#show-upper-content').is(':checked')){
		classArray.push('upper-content');
	};
	if($('#show-lower-content').is(':checked')){
		classArray.push('lower-content');
	};
	if($('#show-outer-content-left').is(':checked')){
		classArray.push('outer-content-left');
	};
	if($('#show-outer-content-right').is(':checked')){
		classArray.push('outer-content-right');
	};
	if($('#show-2-columns-left').is(':checked')){
		classArray.push('content-2-cols-left');
	}else if($('#show-2-columns-right').is(':checked')){
		classArray.push('content-2-cols-right');
	}else if($('#show-3-columns').is(':checked')){
		classArray.push('content-3-cols');
	};
	
	appliedClasses = classArray.join(' ');
	$('body').attr('class', appliedClasses);
	
	classList = classArray.join('<br/>\n');
	if(classList.length > 0){
		$('#applied-classes').html(classList);
	}else{
		$('#applied-classes').html('(default, no classes applied)');
	}
};

showHideDemoControls = function(){
	$('#demo-controls .swap-labels a').toggleClass('hidden');
	
	if($('#demo-controls .swap-labels a.swap-b').hasClass('hidden')){
		$('#demo-controls-content').slideUp();
	}else{
		$('#demo-controls-content').slideDown();
	};
};


$(document).ready(function(){
	processDemoControls();
	$('#demo-controls').hover(function(){
		$(this).attr('style','');
	});
	$('#demo-controls input').click(function(){
		processDemoControls();
	});
	
	$('#demo-controls .swap-labels a').click(function(){
		showHideDemoControls();
	});
	
	console.log(document.body.clientWidth + ' x ' + document.body.clientHeight);
	console.log('begin enquire.register init');
	enquire.register('all and (max-width: 639px)', [{
		match: function() {
			console.log('enquire.register.match (max-width: 639px)');
			if( $('body.content-2-cols-left').length > 0 || $('body.content-3-cols').length > 0 ){
				var $leftContentInner = $('#left-content-inner');
				var $lowerContentInner = $('#lower-content-inner');
				
				// prepare a placeholder for any existing lower content and then hide the content
				$lowerContentInner.wrapInner('<div id="lower-content-placeholder" class="hidden" />');
				// prepare a placeholder for incoming left content
				$lowerContentInner.prepend('<div id="left-content-placeholder" />');
				// copy left content to lower content
				$('#left-content-placeholder').html( $leftContentInner.html() );
				// delete left content
				$leftContentInner.html('');
			};
		},
		unmatch: function() {
			console.log('enquire.register.unmatch (max-width: 639px)');
			if( $('body.content-2-cols-left').length > 0 || $('body.content-3-cols').length > 0 ){
				var $leftContentInner = $('#left-content-inner');
				var $lowerContentInner = $('#lower-content-inner');
				
				// copy left content back to its original holder
				$leftContentInner.html( $('#left-content-placeholder').html() );
				// clean up and remove left content placeholder entirely
				$('#left-content-placeholder').remove();
				// move the lower content back to it's original place
				$lowerContentInner.html( $lowerContentInner.find(' > div#lower-content-placeholder').html()) ;
				// clean up and remove lower content placeholder entirely
				$('#lower-content-placeholder').remove();
			};
		}
	}]);
	console.log('end enquire.register init');
});
