/**
 * lh.js
 * @author Lewis Howles (lh)
 *
 * Default niceties and other Voodoo.
 */

var lh = {
	init : function() {
		lh.externalLinks();
		lh.highlighter();
		lh.styleSwitcher();
		
		$("a#autostart").fancybox({
		 'width': 610,  //or whatever
		 'height': 300,
		 'type': 'iframe' // see this?
		});
		
		
		$('ul#fader').innerfade({
			speed: 2000,
			timeout: 5000,
			type: 'sequence',
			containerheight: '450px'
		});
	},
	
	/*
	 * Set target blank on external links
	 */
	externalLinks : function() {
		$('a[rel~="external"]')
			.attr('target', '_blank')
	},
	
	highlighter : function() {
		$('.fancy')
			.delegate('input, select, textarea', 'mouseover focusin mouseout focusout', function(e) {
				var isIn = (e.type === 'mouseover' || e.type === 'focusin');
				
				lh.toggleFocus($(this), isIn);
			});
	},
	
	toggleFocus : function($this, modifier) {
		$this.parent('li').not('.submit').toggleClass('focus', modifier);
	},
	
	styleSwitcher : function() {
		styleSwitcher = $('#style-switcher').find('a');
		
		styleSwitcher
			.data('sheet','global')
			.bind('click', function() {
				var params = (styleSwitcher.data('sheet') == 'global') ? ['reader','Visual Mode'] : ['global','Reader Mode'];
				$('link[rel=stylesheet]')
					.eq(1) // 0-indexed position of stylesheet. Change this is you had to move global.
					.attr('href', 'css/'+params[0]+'.css');
				styleSwitcher
					.data('sheet',params[0])
					.text(params[1]);
			});
	}
}

$(lh.init());
