// Create Missing Console
if (window.console === undefined) { window.console = { log: function() {}, error: function() {}, warn: function() {} }; }	
	
	var Site = {
		isIOS: ((navigator.userAgent.match(/iPhone/i) != null) || (navigator.userAgent.match(/iPad/i) != null)),
		
		_init: function()
		{
			Feature._init();
		}
	};
	
	
	var Feature = {
		_init: function()
		{
			Feature.$feature = $("#feature");
			Feature.$images = Feature.$feature.find("img");
			Feature.$captions = Feature.$feature.find(".caption");
			Feature.$menu = Feature.$feature.find("menu");
			Feature.$triggers = Feature.$menu.find("span");
			
			Feature.$menu.on("click", "span", Feature._clickSwap);
			
			if(Feature.$images.length > 1)
			{
				//$.doTimeout("autoFeature", 8000, Feature._autoSwap);
			}
		},
		_autoSwap: function()
		{
			var index = Feature.$triggers.index(Feature.$triggers.filter(".active")) + 1;
			if(index > Feature.$triggers.length-1)
				index = 0;
			
			Feature._swap(index);
			
			$.doTimeout("autoFeature", 8000, Feature._autoSwap);
		},
		_clickSwap: function()
		{
			var $target = $(this);
			var index = Feature.$triggers.index($target);
			
			Feature._swap(index);
			
			$.doTimeout("autoFeature");
		},
		_swap: function(index) 
		{
			Feature.$triggers.filter(".active").removeClass("active");
			Feature.$triggers.eq(index).addClass("active");
			
			Feature.$images.filter(".active").removeClass("active");
			Feature.$images.eq(index).addClass("active");
			
			Feature.$captions.filter(".active").removeClass("active");
			Feature.$captions.eq(index).addClass("active");
		}
	}
	
	
	// Web Fonts
	var WebFontConfig = { 
		google: {
			families: [ 'PT+Serif:400,400italic,700,700italic:latin', 'Francois+One::latin' ] 
		},
		loading: function() {
			Utils.log("WF: LOADING");
		},
		fontloading: function(fontFamily, fontDescription) {
			Utils.log("WF: FONT LOADING: " + fontFamily);
		},
		fontactive: function(fontFamily, fontDescription) {
			Utils.log("WF: FONT ACTIVE: " + fontFamily);
		},
		fontinactive: function(fontFamily, fontDescription) {
			Utils.log("WF: FONT INACTIVE: " + fontFamily);
		},
		active: function() {
			Utils.log("WF: ACTIVE");
		},
		inactive: function() {
			Utils.log("WF: INACTIVE");
		}
	};
	
	
	// Utilities
	var Utils = 
	{
		// Global Settings
		settings: 
		{
			debug: true
		},
		// Smart Logging
		log: function(data, type) 
		{
			if(typeof data !== Array)
			{
				data = [data];
			}
			if(Utils.settings.debug) 
			{
				switch(type)
				{
					case "error": // Utils.log(["one", "two"], "error");
						console.error.apply(console, data);
						break;
					case "warn": // Utils.log(["one", "two"], "warn");
						console.warn.apply(console, data);
						break;
					default: // Utils.log(["one", "two"]);
						console.log.apply(console, data);
						break;
				}
			}
			return false;
		},
		// Allius Utils.log
		error: function(data)
		{
			Utils.log(data, "error");
		},
		// Allius Utils.log 
		warn: function(data) 
		{
			Utils.log(data, "warn");
		},
		// Trim strings
		trim: function(string)
		{
			return string.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
		},
		// Email Validation
		validateEmail: function(email)
		{
			var regex = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
			return regex.test(email);
		},
		// Phone Validation
		validatePhone: function(phone)
		{
			var regex = /^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$/;
			return regex.test(phone);
		},
		//Push Custom Google Analytics Events
		captureAction: function(category, action, label)
		{
			if(typeof _gaq == undefined) _gaq = [];
			_gaq.push(['_trackEvent', category, action, label]);
			this.log("GA ACTION: " + category + ", " + action + ", " + label);
		}
	};
	
	$(document).ready(function() {
		// DOM Ready
		Site._init();
	});
	
	

/*
 * jQuery doTimeout: Like setTimeout, but better! - v1.0 - 3/3/2010
 * http://benalman.com/projects/jquery-dotimeout-plugin/
 * 
 * Copyright (c) 2010 "Cowboy" Ben Alman
 * Dual licensed under the MIT and GPL licenses.
 * http://benalman.com/about/license/
 */
(function($){var a={},c="doTimeout",d=Array.prototype.slice;$[c]=function(){return b.apply(window,[0].concat(d.call(arguments)))};$.fn[c]=function(){var f=d.call(arguments),e=b.apply(this,[c+f[0]].concat(f));return typeof f[0]==="number"||typeof f[1]==="number"?this:e};function b(l){var m=this,h,k={},g=l?$.fn:$,n=arguments,i=4,f=n[1],j=n[2],p=n[3];if(typeof f!=="string"){i--;f=l=0;j=n[1];p=n[2]}if(l){h=m.eq(0);h.data(l,k=h.data(l)||{})}else{if(f){k=a[f]||(a[f]={})}}k.id&&clearTimeout(k.id);delete k.id;function e(){if(l){h.removeData(l)}else{if(f){delete a[f]}}}function o(){k.id=setTimeout(function(){k.fn()},j)}if(p){k.fn=function(q){if(typeof p==="string"){p=g[p]}p.apply(m,d.call(n,i))===true&&!q?o():e()};o()}else{if(k.fn){j===undefined?e():k.fn(j===false);return true}else{e()}}}})(jQuery);	
