/*
View Mode JS for tutorial: "Practical CSS3 for Web Designers"
Written by Ben Lister (darkcrimson.com) revised 24 Apr 2010
Tutorial: http://blog.darkcrimson.com/2010/04/practical-css3

Licensed under the MIT License:
http://www.opensource.org/licenses/mit-license.php
*/

	$(function() {
	

	var wrapper = $('#wrapper');
	$('#view_mode').click(function(){
	
		/* Dim */
		$('#wrapper > *').css('opacity','.4'); // There is certainly a cleaner way than this but I didn't have time to find it
		$('#header').css('opacity','.4');
		
		/* Add fake wrapper to avoid opacity issues */
		wrapper.wrap($('<div id="overlay_wrapper"></div>')); // Creates an additional wrapper to aid with positioning

		/* Number buttons*/
		wrapper.before($('<div class="overlay_button" style="margin: -120px 20px 0pt;"><span>1</span></div>').fadeIn('20'));
		wrapper.before($('<div class="overlay_button" style="margin: -20px 20px 0pt;"><span>2</span></div>').fadeIn('40'));
		wrapper.before($('<div class="overlay_button" style="margin: 15px 340px 0pt;"><span>3</span></div>').fadeIn('60'));
		wrapper.before($('<div class="overlay_button" style="margin: 90px 150px 0pt;"><span>4</span></div>').fadeIn('80'));
		wrapper.before($('<div class="overlay_button" style="margin: 200px 75px 0pt;"><span>5</span></div>').fadeIn('100'));
		wrapper.before($('<div class="overlay_button" style="margin: 475px 384px 0pt;"><span>6</span></div>').fadeIn('120'));
		wrapper.before($('<div class="overlay_button" style="margin: 570px 20px 0pt;"><span>7</span></div>').fadeIn('140'));
		wrapper.before($('<div class="overlay_button" style="margin: 570px 325px 0pt;"><span>8</span></div>').fadeIn('160'));
		wrapper.before($('<div class="overlay_button" style="margin: 570px 630px 0pt;"><span>9</span></div>').fadeIn('180'));
		
		$('<div id="close_btn">Turn this off</div>').appendTo('body');
		
		/*Left side disable button*/
		$('div#close_btn').click(function(){
			
			if($('.overlay').length > 0){ $('.overlay').remove(); }
			
			$('#wrapper > *').css('opacity','1'); 
			$('#header').css('opacity','1');
			$('.overlay_button').each(function(){
			
				$(this).remove();
			});
			
			$('div#close_btn').fadeOut(300, function() { $(this).remove(); });
		});
		
		
		
			/* Overlay info boxes */
			var overlayBtn = $('.overlay_button');

	
			overlayBtn.click(function(){
			
			overlayBtn.css('opacity','1.0');
				
				var btnNumber  = $(this).children().html(); //number in button
				var attrNumber = $(this).attr('num'); 
				var overlay    = $('div.overlay');
			
				
					if (overlay.hasClass('btn_'+attrNumber)) {
						overlay.removeClass('btn_'+attrNumber);
						overlay.fadeOut(200, function() { $(this).remove();});
						$(this).html('<span>'+ attrNumber +'</span>').css('opacity','1.0');
					} else {
					
					
					overlayBtn.each(function(index){ $(this).html('<span>'+ (index + 1)+'</span>').css('opacity','.4'); });
					
					$(this).attr('num',btnNumber); //assign html value of button to attribute 'num'
					
					
					if(overlay.length > 0){ overlay.stop().fadeOut(200, function() { $(this).remove(); }); } 				
					
		
					$(this).html('<span class="close">X</span>').css('opacity','1.0');
					

					
					/* Yeah, that's right, a giant switch with a lot of HTML and Text, enjoy! */
						switch(parseInt(btnNumber)) {
							case 1:

								overlayBox('<h3>Radial Gradient with Stops </h3><div class="overlay_code"><span class="property">background-image:</span><span class="value"> #848484 url(../images/bg.png) no-repeat;</span><span class="comment"> /* Fallback image for other browsers */</span><br /><br /><span class="property">background-image:</span><span class="value"> -webkit-gradient(radial,center 400, 800, center 300, 50, from(#848484), to(#E6E6E6), color-stop(.6,#A4A6A5));</span><span class="comment"> /* Webkit */</span><br /><br /><span class="property">background-image:</span><span class="value"> -moz-radial-gradient(center  50deg, circle farthest-side, #E6E6E6 9% , #A4A6A5 , #848484 100% );</span><span class="comment"> /* Mozilla */</span></div><div class="info"><dl><dt>Compatibility: </dt><dd>Firefox 3.6, Safari 4 , Chrome</dd></dl><dl><dt>Use this now: </dt><dd>Yes</dd></dl><dl><dt>Comments: </dt><dd>CSS Radial Gradients have been around for a while in Safari and were more recently introduced in FireFox 3.6. This technique is applied via the <code>background-image</code> property. The syntax differs between browsers but both allow you to add stops which help create a smooth, image editor-quality gradient. This technique is safe to use in most cases as you can optionally add a background image as a fall back for older and non compliant browsers. See below for links to gradient auto-generation tools and documentation.</dd></dl><dl><dt>Resources: </dt><dd><a href="http://www.westciv.com/tools/radialgradients/index.html" target="_blank">CSS Gradient Generator</a>,<dd><a href="http://gradients.glrzad.com/" target="_blank">CSS Gradient Generator 2</a>, </dd><dd><a href="https://developer.mozilla.org/en/CSS/-moz-radial-gradient" target="_blank">FireFox Documentation</a>,</dd><dd><a href="http://developer.apple.com/safari/library/documentation/InternetWeb/Conceptual/SafariVisualEffectsProgGuide/Gradients/Gradients.html" target="_blank">Safari Documentation</a></dd></dl></div>',-93,52,btnNumber); 
								$('#header').css('opacity','1');
							break;
							
							case 2:
								overlayBox('<h3>"Rounded" Image Borders / Box Shadow</h3><div class="overlay_code"><span class="property">-webkit-border-image:</span><span class="value"> url(../images/border-img.png) 6 6 6 6 stretch;</span><br /><br /><span class="property">-moz-border-image:</span><span class="value"> url(../images/border-img.png) 6 6 6 6 stretch;</span><br /><br /><span class="comment"> /* Rounded corners for DIV (matches radius of image)  */</span><br /><span class="property">-moz-border-radius-topleft,</span><br /><span class="property">-moz-border-radius-topright,</span><br /><span class="property">-webkit-border-top-left-radius,</span><br /><span class="property">-webkit-border-top-right-radius:</span> <span class="value"> 18px;</span><br /><br /><span class="property">-webkit-box-shadow:</span><span class="value"> rgba(0, 0, 0, 0.6) 0 0 12px;</span><br /><span class="property">-moz-box-shadow:</span> <span class="value"> rgba(0, 0, 0, 0.6) 0 0 12px;</span></div><div class="info"><dl><dt>Compatibility: </dt><dd>Firefox 3.1, Safari 3, Chrome, iPhone OS 1.0</dd></dl><dl><dt>Use this now: </dt><dd>Sparingly, or with JS fallback</dd></dl><dl><dt>Comments: </dt><dd>Border images are a much needed property that gives designers even more creative freedom. While there is no standard way to add rounded image borders, the <code>stretch</code> option along with a rounded source image for the border and the conventional border-radius help make this an easy task. Standard border images are even easier and work in the latest Firefox and Webkit browsers. The one major issue for projects with further compatibility requirements is lack of graceful degradation. Luckily this has been solved for older versions of Firefox, Safari / Chrome and even IE7+ through a jQuery plugin. Box Shadow is a convenient replacement to cumbersome image and JavaScript drop shadows. The syntax is very basic &lt;y&gt;, &lt;x&gt;, &lt;blur&gt; | color and can be applied to pretty much any block element </dl><dl><dt>Resources: </dt><dd><a href="http://plugins.jquery.com/project/jbi" target="_blank" >jQuery plugin</a>, </dd><dd><a href="http://www.css3.info/preview/border-image/" target="_blank" >Webkit IB Documentation</a>, </dd><dd><a href="https://developer.mozilla.org/En/CSS/-moz-border-image" target="_blank">Firefox IB Documentation</a>,</dd><dd><a href="https://developer.mozilla.org/En/CSS/-moz-box-shadow" target="_blank">Moz Box Shadow</a>,</dd><dd><a href="http://css.flepstudio.org/en/css3/box-shadow.html" target="_blank">Shadow Effect on elements in CSS3</a></dd></dl></div>',-35,55,btnNumber);						
							break; 
							
							case 3:
								overlayBox('<h3>Webkit Transform Animations</h3><div class="overlay_code"><span class="comment"> /* "Fall down" effect */</span><br /><span class="selector">#photo_slider li.fallDown {</span><br /><span class="property">-webkit-transition:</span><span class="value"> all 2s ease-in;</span><br /><span class="property">-webkit-transform:</span><span class="value"> translate(0px, 2000px) rotate(170deg) scale(0.2) skew(-200deg);</span><br /><span class="selector">}</span><br /><br /><span class="comment"> /* "Twist out" effect */</span><br /><span class="selector">#photo_slider li.twistOut {</span><br /><span class="property">-webkit-transform-style:</span><span class="value"> preserve-3d;</span><br /><span class="property">-webkit-transition-property:</span><span class="value"> -webkit-transform;</span><br /><span class="property">-webkit-transition-duration:</span><span class="value"> 1s;</span><br /><span class="property">-webkit-transform:</span><span class="value"> rotateY(720deg) scale(0.01);</span><br /><span class="selector">}</span></div><div class="info"><dl><dt>Compatibility: </dt><dd>Safari 3, Chrome, iPhone OS 2</dd></dl><dl><dt>Use this now: </dt><dd>Use JS for standard web, OK for iPhone Development</dd></dl><dl><dt>Comments: </dt><dd>These animations will only work in Webkit browsers. Wekit-transition works well with most CSS selectors and can be used with multiple selectors. Very in-depth documentation can be found in the resource links below but the basic concept involves adding one or more CSS selectors / pseudo selectors  (-webkit-transition: all; in this case) and then choosing one or more transitions such as -webkit-transform: rotate(360deg) scale(0.5);. This basic example will rotate the HTML element(s) 360 degrees and scale them to 50%.</dd></dl><dl><dt>Resources: </dt><dd><a href="http://developer.apple.com/safari/library/documentation/InternetWeb/Conceptual/SafariVisualEffectsProgGuide/Transitions/Transitions.html" target="_blank">Safari CSS Visual Effects Guide: Transitions</a>, </dd><dd><a href="http://webkit.org/blog/138/css-animation/" target="_blank">Webkit CSS Animation</a>,<dd><a href="http://dinolatoga.com/demo/webkit-image-hover-effects/" target="_blank">Image Hover Effects</a>, </dd><dd><a href="http://www.ferretarmy.com/css-animation-examples/" target="_blank">CSS Animation Examples</a></dd></dl></div>',44,366,btnNumber);						
							break;

							case 4:
								overlayBox('<h3>RGBa,Webkit Transition, Text Shadow, Border Radius</h3><div class="overlay_code"><span class="selector">ul#leftnav li a {</span><br /><span class="property">-webkit-transition-property:</span><span class="value"> background-color, font-size;</span><br /><span class="property">-webkit-transition-duration:</span><span class="value"> 800ms, 300ms;</span><br /><span class="property">-moz-border-radius:</span><span class="value"> 8px;</span><br /><span class="property">-webkit-border-radius:</span><span class="value"> 8px;</span><br /><span class="property">text-shadow:</span><span class="value"> 2px 1px 2px rgba(0, 0, 0, 0.7);</span><br /><span class="selector">}</span><br /><br /><span class="selector">ul#leftnav li a:hover {</span><br /><span class="property">background:</span><span class="value"> rgba(70, 70, 70, 0.8);</span><br /><span class="property">font-size:</span><span class="value"> 1.1em;</span><br /><span class="selector">}</span></div><div class="info"><dl><dt>Compatibility: </dt><dd>Firefox 3 (no transitions), Safari 3  / Chrome, iPhone OS 2</dd></dl><dl><dt>Use this now: </dt><dd>Yes (IE is unaffected)</dd></dl><dl><dt>Comments: </dt><dd>RGBa (along with <a href="http://www.css3.info/preview/hsla/" target="_blank">HSLa</a>) colors give designers incredible flexibility in their designs with the ability to specify an Alpha value in addition to the standard color values. RGBa / HSLa can be used on any property that allows for color customization (borders, backgrounds, text, etc&#133;) and work properly on FireFox and Webkit browsers without vendor prefixes. Text shadows are actually part of CSS2 and have been in Safari since V1.1 but were not added to FireFox until version 3.5. There have been revisions added since its original introduction such as the inclusion of multiple shadows which give designers the ability to create layered / 3D-like shadows. The basic syntax for a Text Shadow is: &lt;y&gt;, &lt;x&gt;, &lt;blur&gt; | color (RGBa / HSLa are valid for this property). Border radius was touched on in #2, but see resources below for further documentation. </dd></dl><dl><dt>Resources: </dt><dd><a href="https://developer.mozilla.org/En/CSS/text-shadow" target="_blank">FireFox TS Documentation</a>,</dd><dd><a href="http://www.css3.info/preview/rounded-border/" target="_blank">CSS.Info: Border- Radius</a>,</dd><dd><a href="http://developer.apple.com/safari/library/documentation/InternetWeb/Conceptual/SafariVisualEffectsProgGuide/Transitions/Transitions.html" target="_blank">Safari CSS Visual Effects Guide: Transitions</a></dd></dl></div>',-60,186,btnNumber);						
							break;
							
							case 5:
								overlayBox('<h3>Image Mask / Click Animation</h3><div class="overlay_code"><span class="selector">@-webkit-keyframes spin {</span><br /><span class="property">from { none;} </span><br /><span class="property">to { -webkit-transform: rotate(360deg);}</span><br /><span class="selector">}</span><br /><br /><span class="selector">img {</span><br /><span class="property">-webkit-mask-box-image: </span><span class="value"> url(../images/mask.png);</span><br /><span class="selector">}</span><br /><br /><span class="selector">img:hover {</span><br /><span class="property">-webkit-animation-name:</span><span class="value"> spin;</span><br /><span class="property">-webkit-animation-duration:</span><span class="value"> 1.5s;</span><br /><span class="property">-webkit-animation-iteration-count:</span><span class="value"> infinite;</span><br /><span class="property">-webkit-animation-direction:</span><span class="value"> ltr;</span><br /><span class="selector">}</span></div><div class="info"><dl><dt>Compatibility: </dt><dd>Safari 3,  Chrome 3, iPhone OS 2 </dd></dl><dl><dt>Use this now: </dt><dd>Mobile only</dd></dl><dl><dt>Comments: </dt><dd>CSS Masks are a great way to apply image effects without altering the source image file. Currently only supported in Webkit, this technique works with not only PNG images but also SVGs and even CSS gradients. This example also demonstrates a _very_ rudimentary keyframe animation. The basic idea is to declare and name the animation then create keyframes with either from/to OR percentages (1%,10%,55% etc&#133;) and add your animation. To activate, simply apply animation to a CSS selector and define the options such as duration, iteration count (1 - &#8734;)  etc..   This technique has incredible possibilities, for advanced examples please see the resources below. </dd></dl><dl><dt>Resources: </dt><dd><a href="http://webkit.org/blog/181/css-masks/" target="_blank">CSS Masks</a>,</dd><dd><a href="http://developer.apple.com/safari/library/documentation/InternetWeb/Conceptual/SafariVisualEffectsProgGuide/Masks/Masks.html" target="_blank">Safari Visual Effects: Masks</a>,</dd><dd><a href="http://webkit.org/blog/324/css-animation-2/" target="_blank">CSS Keyframe Animation</a>,</dd><dd><a href="http://girliemac.com/iphone/anim.html" target="_blank">CSS Animation Test</a>, </dd><dd><a href="http://girliemac.com/blog/2009/02/18/using-keyframes-webkit-css-animation-examples/" target="_blank">Using Keyframes</a></dd></dl></div>',0,111,btnNumber);						
							break;
							
							case 6:
								overlayBox('<h3>CSS Columns</h3><div class="overlay_code"><span class="property">-moz-column-width:</span> <span class="value"> 288px;</span><br /><span class="property">-webkit-column-width:</span><span class="value"> 288px;</span><br /><br /><span class="property">-moz-column-gap:</span><span class="value"> 19px;</span><br /><span class="property">-webkit-column-gap:</span><span class="value"> 19px;</span><br /><br /><span class="property">-moz-column-count:</span><span class="value"> 3;</span><br /><span class="property">-webkit-column-count:</span><span class="value"> 3;</span><br /></div><div class="info"><dl><dt>Compatibility: </dt><dd>FireFox 1.5 and Safari 3.1, Chrome 2</dd></dl><dl><dt>Use this now: </dt><dd>With fall backs for IE</dd></dl><dl><dt>Comments: </dt><dd>Columns can be applied to a variety of CSS elements, both inline and block, and offer a number of options including column width, column count, gap width and column-rule, which allows you to style the gutter region between columns.</dd></dl><dl><dt>Resources: </dt><dd><a href="http://www.css3.info/preview/multi-column-layout/" target="_blank">CSS3.Info Documentation</a>, </dd><dd><a href="http://www.quirksmode.org/css/multicolumn.html" target="_blank">CSS3 - Columns</a>, </dd><dd><a href="https://developer.mozilla.org/en/CSS3_Columns" target="_blank">CSS3 Columns FireFox Documentation</a></dd></dl></div>',210,420,btnNumber);						
							break;
							
							case 7:
								overlayBox('<h3>Bar Chart with "3D" Transform</h3><div class="overlay_code"><span class="property">-webkit-transform:</span><span class="value"> skew(0deg, 30deg);</span><br /><span class="property">-moz-transform:</span><span class="value"> skew(0deg, 30deg);</span></div><div class="info"><dl><dt>Compatibility: </dt><dd>Firefox 3.5, Safari 4, iPhone OS 3, Chrome 4(?), 5)</dd></dl><dl><dt>Use this now: </dt><dd>With caution, yes for mobile</dd></dl><dl><dt>Comments: </dt><dd>While the sample code listed above is incomplete (<a href="ui/css/screen.css" target="_blank">view complete markup</a>), the basic technique [skew(x,y)] is illustrated. In this example, Skew is used to rotate three divs to form a 3D bar. The graph is set in front of a linear CSS gradient which follows a similar syntax to the radial gradient in #1, see linear gradient generator link in resources below. </dd></dl><dl><dt>Resources: </dt><dd><a href="http://www.fofronline.com/2009-04/3d-cube-using-css-transformations/" target="_blank">3D Cube using CSS transformations</a> ,</dd><dd><a href="http://developer.apple.com/safari/library/documentation/InternetWeb/Conceptual/SafariVisualEffectsProgGuide/Transforms/Transforms.html" target="_blank">Safari CSS Visual Effects Guide: Transforms</a> ,</dd><dd><a href="http://www.westciv.com/tools/gradients/index.html" target="_blank">Linear Gradient Generator</a></dd></dl></div>',300,55,btnNumber);					
							break;
							
							case 8:
								overlayBox('<h3>Multiple Background Images</h3><div class="overlay_code"><span class="property">background:</span><br /><span class="value"> url(../images/bg_4.png) 110px 100px no-repeat,<br />url(../images/bg_3.png) 60px 50px no-repeat,<br />url(../images/bg_2.png) 30px 45px no-repeat,<br />	url(../images/bg_1.png) top left no-repeat;</span></div><div class="info"><dl><dt>Compatibility: </dt><dd>Firefox 3.6, Safari 4, Chrome, iPhone OS 3</dd></dl><dl><dt>Use this now: </dt><dd>Yes for mobile, yes if purely aesthetic</dd></dl><dl><dt>Comments: </dt><dd>This simple technique is applied to HTML elements by adding a comma separated list of background images. The top most defined background will be in the back and the bottom most in front.  From my testing CSS gradients DO work in conjunction with background images, however, since they are applied with vendor prefixes (which don\'t play nicely with commas), cross-browser support will be tricky.  Solid background colors do not work with this property, even after adjusting the alpha value.</dd></dl><dl><dt>Resources: </dt><dd><a href="https://developer.mozilla.org/en/CSS/Multiple_backgrounds" target="_blank">Firefox Documentation</a>, <dd><a href="http://www.css3.info/preview/multiple-backgrounds/" target="_blank">Multiple Background Images</a></dd></dl></div>',275,360,btnNumber);						
							break;
							
							case 9:
								overlayBox('<h3>Pure CSS Accordion w/ Animation</h3><div class="overlay_code"><span class="attribute">.accordion div { </span><br /><span class="property">-webkit-transition:</span><span class="value"> height 500ms ease; </span><br /><span class="attribute"> }</span><br /><br /><span class="attribute">.accordion div:target {</span><br /><span class="property"> height:</span><span class="value"> 105px</span><br /><span class="attribute"> }</span></div><div class="info"><dl><dt>Compatibility: </dt><dd>FireFox 2.1 (no animation), Safari 3, Chrome, iPhone 2</dd></dl><dl><dt>Use this now: </dt><dd>Yes, consider JS for animations</dd></dl><dl><dt>Comments: </dt><dd>This technique has technically been possible for quite a while (:target pseudo selector was introduced in FF 2.1) however supplementing the markup with a basic height transition adds a new, elegant,smooth, sophisticated dimension. For those who have never used :target before: it uses the fragment identifier in a URL to apply specific CSS styles to the matching element. In this example, the links are contained within div.accordian. The links\' fragment identifier corresponds to the ID of a nested div within accordion (a &lt;UL&gt; would probably be more appropriate though ).  The animation is applied to .accordion div which means that when a link is clicked the :target triggers animation. Thanks to <a href="http://www.marcofolio.net/" target="_blank">Marco Kuiper</a> for the inspiration</dd></dl><dl><dt>Resources: </dt><dd><a href="http://demo.marcofolio.net/css3_jquery_animations/" target="_blank">CSS3 Animations &amp; their jQuery equivalents</a>, </dd><dd><a href="http://carsonified.com/blog/features/css/stay-on-target/" target="_blank">Stay on :target</a></dd></dl></div>',91,123,btnNumber);						
							break;						
						}

				}
			});

	});



});


		//Escape key mapping
		$(document).keydown(function(e){
    		
    		
    		if (e.keyCode == 27) { 
    		
    			// Dimmed but no popup
				if($('#header').css('opacity') == "0.4" && $('.overlay').length < 1 ) { 
					$('#wrapper > *').css('opacity','1');
					$('#header').css('opacity','1');	
					$('.overlay_button').each(function(){ $(this).remove(); });
					$('div#close_btn').fadeOut(300, function() { $(this).remove(); });
					
				// Dimmed and popup active
				} else if($('.overlay').length > 0){ 
					$('.overlay').remove(); 
					$('.overlay_button').each(function(){
						$(this).css('opacity','1.0');
						
						if($(this).children().hasClass('close')) { $(this).html('<span>'+$(this).attr('num')+'</span>'); } 
					});
				}
				
       		return false;
    		}
		});		



	// Create a new overlay div (clicking close destroys this)
	function overlayBox(content,y,x,btn){
		$('#wrapper').before($('<div class="overlay btn_'+ btn +'" style="margin-left:'+ x +'px;margin-top:'+ y +'px;">'+ content +'</div>').stop().fadeIn('fast'));
	}

	
