var ie = (navigator.userAgent.indexOf('MSIE')>=0) ? true : false;
var ie6 = (navigator.userAgent.indexOf('MSIE 6')>=0) ? true : false;
var ninWii = (navigator.platform.indexOf('Nintendo Wii')>=0) ? true : false;

/*** Platform Redirect ***/

function platformDirect() {
	if(navigator.platform == "Nintendo DSi"){
		document.location = '/dsi';
	}else{	
		return;
	}
}
platformDirect();

/*** JavaScript Enabled ***/

var jsEnabled = function(){
	$('body').removeClass('no-js');
};

/*** Boombox Popup ***/

var popUpWindow;

var popupBoombox = function(){
	var href = '/boombox/index.html';
	popUpWindow = window.open(href, 'boombox', 'menubar=0, location=0, toolbar=0, width=276, height=321');
};

var popupContestRules = function(){
	var href = '/thewarios/rules.html';
	popUpWindow = window.open(href, 'contestRules', 'scrollbars=1, menubar=0, location=0, toolbar=0, width=715, height=700');
};

/*** Main Navigation Animations ***/

var navAnimation = function(){
	var elHeader = $('div#header'),
		elNavMain = $('ul#nav-main'),
		elNavHome = $('li#nav-home'),
		elNavSection = $('li.nav-section'),
		elNavSectionIn = $('li.nav-section.in'),
		elNavSectionAway = $('li.nav-section.away'),
		elBoxArt = $('div#nav-box-art a'),
		elPreorderBtn = $('li#nav-buy-now a');
	
	$(elHeader).css({ backgroundPosition : '10px -20px' });
	$(elNavMain).css({ backgroundPosition : '-3px 0' });
	$('ul', elNavSection).css({ 'display' : 'none', 'opacity' : 0  });
	$('a.section span', elNavSection).css({ 'opacity' : 0 });
	$('div.nav-sub-open ul#nav-main li.in ul').css({ 'opacity' : '1' });
	
	elBoxArt.hover(function() {
		elPreorderBtn.addClass('hover');
	}, function() {
		elPreorderBtn.removeClass('hover');
	});
	
	function enterHeaderAnimation(){
		elHeader.animate(
			{ backgroundPosition : '10px 0' },
			{ queue: false, duration: 400 }
		);
		elNavMain.animate(
			{ backgroundPosition : '-3px -20px' },
			{ queue: false, duration: 400 }
		);
	}
	
	function exitHeaderAnimation(){
		elHeader.animate(
			{ backgroundPosition : '10px -20px' },
			{ queue: false, duration: 400 }
		);
		elNavMain.animate(
			{ backgroundPosition : '-3px 0' },
			{ queue: false, duration: 400 }
		);
	}
	
	function enterNavAnimation(element){
		$('a.section', element).animate(
			{ 'top' : '18px' },
			{ queue: false, duration: 200 }
		);
		$('a.section span', element).animate(
			{ 'opacity' : 1 },
			{ queue: false, duration: 200 }
		);
		$('ul', element).css({ 'display' : 'block' }).animate(
			{ 'opacity' : 1 },
			{ queue: false, duration: 500 }
		).animate(
			{ 'bottom' : 0 },
			{ queue: false, duration: 300 }
		);
	}
	
	function exitNavAnimation(element){
		$('a.section', element).animate(
			{ 'top' : '0' },
			{ queue: false, duration: 200 }
		);
		$('a.section span', element).animate(
			{ 'opacity' : 0 },
			{ queue: false, duration: 200 }
		);
		$('ul', element).animate(
			{ 'opacity' : 0, 'bottom' : '10px' },
			{ queue: false, duration: 300 }
		).queue(function(){
			$(this).css({ 'display' : 'none' });
			$(this).dequeue();
		});
	}
	
	elNavSection.hover(
		function(){
			var element = this;
			var elNavSectionIn = $('li.nav-section.in');
				
			enterDelay = setTimeout(function() {
				enterHeaderAnimation();
				enterNavAnimation(element);
			}, 100);
			if (elHeader.hasClass('nav-sub-open')){
				if ($(element).hasClass('in')){
					return;
				}
				if ($(element).not(elNavSectionIn)){
					exitNavAnimation(elNavSectionIn);
					elNavSectionIn.queue(function(){
						$(this).addClass('away').removeClass('in');
						$(this).dequeue();
					});
				}
			}
		},
		function(){
			var element = this;

			clearTimeout(enterDelay);
			exitHeaderAnimation();
			exitNavAnimation(element);
			if ($(element).hasClass('in')){
				$(element).addClass('away').removeClass('in');
			}
		}
	);
	
	elNavMain.mouseleave(function(){
		if (elNavSection.hasClass('away')){
			var elNavSectionAway = $('li.nav-section.away');
			
			enterHeaderAnimation();
			enterNavAnimation(elNavSectionAway);			
			elNavSectionAway.queue(function(){
				$(this).addClass('in').removeClass('away');
				$(this).dequeue();
			});
		}
	});
	
	if (elHeader.hasClass('nav-sub-open')){
		$('a span', elNavHome).css({ 'opacity' : 0 });
		elNavHome.hover(
			function(){
				elHeader.css({ backgroundPosition : '10px 0' });
				elNavMain.css({ backgroundPosition : '-3px -20px' });
				exitHeaderAnimation();
				elHeader.queue(function(){
					$(this).removeClass('nav-sub-open');
					$(this).dequeue();
				});
				exitNavAnimation(elNavSection);
				elNavSectionIn.queue(function(){
					$(this).addClass('away').removeClass('in');
					$(this).dequeue();
				});
			},
			function(){
				elNavSectionAway.addClass('in').removeClass('away');
				enterNavAnimation(elNavSectionAway);
				elHeader.delay(400).queue(function(){
					$(this).addClass('nav-sub-open');
					$(this).dequeue();
				});
			}
		);
	}
};

/*** Rollover Sounds ***/

var rolloverSounds = function(){
	var flashVersion = swfobject.getFlashPlayerVersion();
	var flashMajor = flashVersion.major;
	
	if (flashMajor >= 9) {
		var thisMovie = function(movieName){
			return $('#flashTargetSounds')[0];
		};
		var playSound = function(sfxStr){
			thisMovie('flashTargetSounds').playSound(sfxStr);
		};
		$('a.btn-horz').mouseenter(
			function(){	playSound('ButtonOver'); }
		);
		$('a.btn-vert').mouseenter(
			function(){	playSound('ButtonOver'); }
		);
		$('li.nav-section > a').mouseenter(
			function(){	playSound('MainMenuOver'); }
		);
		$('li.nav-section ul li a').mouseenter(
			function(){	playSound('SubMenuOver'); }
		);
		$('ul#nav-utility li a').mouseenter(
			function(){	playSound('ButtonOver'); }
		);
		$('ul.trailers li a.btn').mouseenter(
			function(){	playSound('ButtonOver'); }
		);
		$('ul.scroller-links li.btn-prev a.btn').mouseenter(
			function(){	playSound('ButtonOver'); }
		);
		$('ul.scroller-links li.btn-next a.btn').mouseenter(
			function(){	playSound('ButtonOver'); }
		);
		$('div.bucket-video div.video-modal a.btn').mouseenter(
			function(){	playSound('ButtonOver'); }
		);
		$('a#btn-modal-close').mouseenter(
			function(){	playSound('ButtonOver'); }
		);
		$('ul.tabs li a.btn').mouseenter(
			function(){	playSound('ButtonOver'); }
		);
		$('ul.pagination-links li a').mouseenter(
			function(){	playSound('SubMenuOver'); }
		);
		$('a.btn-enter-the-contest').mouseenter(
			function(){	playSound('ButtonOver'); }
		);
	}
};

/*** Kill Popup Sounds ***/

var killBoombox = function(){
	window.videoPlaying = true;
};

/*** Resume Popup Sounds ***/

var resumeBoombox = function(){
	window.videoPlaying = false;
};

/*** Anchor Jump Text ***/

var anchorJump = function(options){
	options = jQuery.extend({
		elAnchor: '.btn',
		scrollDuration: 1000
	},options);
	$('a' + options.elAnchor + '[href*=#]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			var targetID = $(this.hash);
			targetID = targetID.length && targetID || $('[name=' + this.hash.slice(1) +']');
			if (targetID.length) {
				var targetOffset = targetID.offset().top;
				$('html,body').animate(
					{ scrollTop: targetOffset },
					options.scrollDuration
				);
				return false;
			}
		}
	});
};

/*** Tab Switcher ***/

var tabSwitcher = function(options){
	options = jQuery.extend({
		elTab: $('a.tab'),
		elTabsWrapper: $('div.tab-wrapper'),
		elTabContent: $('div.tab-content'),
		showAllAnchor: '#'
	},options);
	var elCurrentTab = options.elTab.filter('.on').attr('href');

	options.elTabContent.hide();
	options.elTabContent.filter('.on').show();

	if(elCurrentTab == options.showAllAnchor){
		options.elTabContent.show();
	}

	options.elTab.click(function(e){
		e.preventDefault();
		var elNextTab = $(this),
			elCurrentTab = options.elTab.filter('.on').attr('href'),
			elTargetTab = elNextTab.attr('href');
		
		options.elTab.removeClass('on');
		$(elNextTab).addClass('on');
		
		if(elTargetTab != elCurrentTab){
			if(elCurrentTab == options.showAllAnchor){
				options.elTabContent.fadeOut(200, function(){
					$(this).removeClass('on');
					
					if(elTargetTab == options.showAllAnchor){
						options.elTabContent.fadeIn(200).addClass('on');
					}else{
						$('div' + elTargetTab).fadeIn(200).addClass('on');
					}
				});
			}else{
				$('div' + elCurrentTab).fadeOut(200, function(){
					$(this).removeClass('on');
					
					if(elTargetTab == options.showAllAnchor){
						options.elTabContent.fadeIn(200).addClass('on');
					}else{
						$('div' + elTargetTab).fadeIn(200).addClass('on');
					}
				});
			}
		}
	});
};

/*** Pagination ***/

$.fn.paginate = function(options) {
	options = jQuery.extend({
		elPagiContent: '',
		limit: 0,
		elLinksOne: '',
		elLinksTwo: ''
	},options);

	return this.each(function() {

		var page = {};
		
		page.parent = $(this);
		page.elPagiContent = page.parent.children(options.elPagiContent);
		page.total = Math.ceil(page.elPagiContent.size() / options.limit);
		page.prev = 0;
		page.next = 2;
		page.linkContainer = $(document.createElement('ul'));

		page.elPagiContent.slice(options.limit).addClass('invisible');
	
		var elBtnPrev = {};

		elBtnPrev.container = $(document.createElement('li'));
		elBtnPrev.anchor = $(document.createElement('a')).addClass('btn btn-prev');
		elBtnPrev.anchor.attr('href', '#btn-prev').attr('rel', 'nofollow').text('Previous').appendTo(elBtnPrev.container);
		elBtnPrev.container.appendTo(page.linkContainer);

		for(var num=0; num < page.total; num++){
			var offset = num + 1,
				min = (offset * options.limit) - (options.limit),
				max = (offset * options.limit);

			var elBtnOffset = {};

			elBtnOffset.container = $(document.createElement('li'));
			elBtnOffset.anchor = $(document.createElement('a')).addClass('btn-num');
			elBtnOffset.anchor.attr('href', offset).attr('rel', 'nofollow').text(offset).appendTo(elBtnOffset.container);
			elBtnOffset.container.appendTo(page.linkContainer);
	
			page[offset] = page.elPagiContent.slice(min, [max]);
		};

		var elBtnNext = {};

		elBtnNext.container = $(document.createElement('li'));
		elBtnNext.anchor = $(document.createElement('a')).addClass('btn btn-next');
		elBtnNext.anchor.attr('href', '#next').attr('rel', 'nofollow').text('Next').appendTo(elBtnNext.container);
		elBtnNext.container.appendTo(page.linkContainer);

		page.anchors = page.linkContainer.find('a');

	    page.anchors.bind('click', function(e){
			e.preventDefault();

			if($(this).is('a.on')){
				return false;
			}
			
			if($(this).is('a.btn-prev')){
	
				if(page.prev === 0){
					return false;
				};

				$('a.btn-num').removeClass('on');

				this.link = $('a[href= ' + page.prev + ']');
				this.link.addClass('on');
				
				page.elPagiContent.addClass('invisible');
				page[page.prev].removeClass('invisible');

				page.prev--;
				page.next--;
	
			}else if($(this).is('a.btn-next')){
	
				if(page.next === (page.total + 1)){
					return false;
				};

				$('a.btn-num').removeClass('on');

				this.link = $('a[href= ' + page.next + ']');
				this.link.addClass('on');
				
				page.elPagiContent.addClass('invisible');
				page[page.next].removeClass('invisible');

				page.prev++;
				page.next++;
	
			}else{
				$('a.btn-num').removeClass('on');

				this.link = $('a[href= ' + $(this).attr('href') + ']');
				this.link.addClass('on');

				this.offset = parseInt(this.link.attr('href'),10);
				
				page.elPagiContent.addClass('invisible');
				page[this.offset].removeClass('invisible');

				page.prev = this.offset - 1;
				page.next = this.offset + 1;
			}

			if(page.prev === 0){
				$('a.btn-prev').parent('li').addClass('disabled');
				$('a.btn-next').parent('li').removeClass('disabled');
			}else if(page.next === (page.total + 1)){
				$('a.btn-prev').parent('li').removeClass('disabled');
				$('a.btn-next').parent('li').addClass('disabled');
			}else{
				$('a.btn-prev').parent('li').removeClass('disabled');
				$('a.btn-next').parent('li').removeClass('disabled');
			}

		});

		if(page.total > 1){
			page.linkContainer.addClass('pagination-links').prependTo(options.elLinksOne);
			page.linkContainer.parent().css({ 'left' :  ($(page.linkContainer.parents()[1]).width() - page.linkContainer.parent().width()) / 2 }).append($(document.createElement('div')).addClass('cap'));
			page.linkContainer.clone(true).prependTo(options.elLinksTwo).parent().css({ 'left' :  ($(page.linkContainer.parents()[1]).width() - page.linkContainer.parent().width()) / 2 }).append($(document.createElement('div')).addClass('cap'));
		}

		$('ul.pagination-links li a.btn-prev').parent('li').addClass('disabled');
		$('ul.pagination-links li:nth-child(2) > a').css({ 
			'background' : 'none',
			'margin' : 0,
			'padding' : 0
		}).addClass('on');

		return this;
	});
};

/*** Content Scroller ***/

$.fn.contentScroller = function(options){
	options = jQuery.extend({
		wrapperClass: 'wrapper',
		scrollOffset: 1,
		scrollSpeed: 400
	},options);

    function repeat(str, num){
        return new Array( num + 1 ).join( str );
    }
  
    return this.each(function(){
		var elWrapper = $('> div.' + options.wrapperClass, this).css('overflow', 'hidden'),
			elScroller = elWrapper.find('> ul'),
			elItems = elScroller.find('> li'),
			elSingleItem = elItems.filter(':first'),
			singleWidth = elSingleItem.outerWidth(), 
			visible = Math.ceil(elWrapper.innerWidth() / singleWidth),
			currentPage = 1,
			pages = Math.ceil(elItems.length / options.scrollOffset);

		var elLinkContainer = $(document.createElement('ul')).addClass('scroller-links'),
			elBtnPrev = $(document.createElement('li')).addClass('btn-prev').append($(document.createElement('a')).attr('href', '#Previous').text('Previous').addClass('btn')),
			elBtnNext = $(document.createElement('li')).addClass('btn-next').append($(document.createElement('a')).attr('href', '#Next').text('Next').addClass('btn'));

		elItems.filter(':first').before(elItems.slice(- visible).clone().addClass('cloned'));
		elItems.filter(':last').after(elItems.slice(0, visible).clone().addClass('cloned'));
		elItems = elScroller.find('> li');

		elWrapper.scrollLeft(singleWidth * visible);
		
		function gotoPage(page) {
			var dir = page < currentPage ? -1 : 1,
				n = Math.abs(currentPage - page),
				left = singleWidth * dir * options.scrollOffset * n;

			elWrapper.filter(':not(:animated)').animate(
				{ scrollLeft: '+=' + left },
				options.scrollSpeed, 'easeOutQuad',
				function(){
				    if (page == 0) {
						elWrapper.scrollLeft(singleWidth * (pages + visible - options.scrollOffset));
						page = pages;
				    } else if (page > pages) {
						elWrapper.scrollLeft(singleWidth * visible);
						page = 1;
				    }
					currentPage = page;
				}
			);
			return false;
		}
		
		elWrapper.after($(elLinkContainer).append(elBtnPrev, elBtnNext));
		
		elBtnPrev.click(function(){
		    return gotoPage(currentPage - 1);                
		});
		
		elBtnNext.click(function(){
		    return gotoPage(currentPage + 1);
		});
		
		$(this).bind('goto', function(event, page){
		    gotoPage(page);
		});
    });
};

/*** Embed Video Player ***/

$.fn.videoPlayerEmbed = function(options) {
	options = jQuery.extend({
		embedVideo: 'video-file',
		embedHeight: '396px',
		embedWidth: '616px',
		embedPoster: 'image-file',
		embedTarget: 'flash-video-target',
		embedTitle: 'video-title'
	},options);

	var settings_tr = {
    	path: mediaPath + '_ui/swf/WWDIYVideoPlayer.swf',
		width: options.embedWidth,
    	height: options.embedHeight,
    	version: '7.0.0',
    	id: options.embedTarget,
    	expressInstall: false
    };

    var flashvars_tr = {
    	swfPath: mediaPath + '_ui/swf/',
		flvFile: '../flv/' + options.embedVideo,
		flvTitle: options.embedTitle,
		posterImage: mediaPath + '_ui/img/flash/' + options.embedPoster,
		liveBool: omnitureLiveStr
    };

    var params = {
		bgcolor: '#000000',
		quality: 'high',
		wmode: 'opaque',
		allowScriptAccess: 'always'
	};
	
	swfobject.embedSWF(settings_tr.path, settings_tr.id, settings_tr.width, settings_tr.height, settings_tr.version, settings_tr.expressInstall, flashvars_tr, params);
};

/*** Modal Window ***/

$.fn.modalPanel = function(options) {
	options = jQuery.extend({
		modalContent: $('div#modal-content')
	},options);

	var modalContentTarget = options.modalContent.html();
	var overlay = $(document.createElement('div')).attr('id','overlay').fadeTo(0, '.85');
	var modalWindow = $(document.createElement('div')).attr('id','modal-window');
	var flashTarget = $(document.createElement('div')).attr('id','flash-video-target');

	function handleEscape(e) {
		if (e.keyCode == 27) {
			modalHide();
		}
	}

	function modalHide() {
		$(document).unbind('keydown', handleEscape);
		var remove = function() { $(this).remove(); };
		overlay.fadeOut(400, remove);
		modalWindow.fadeOut(400, remove).empty();

		if (typeof document.body.style.maxHeight === 'undefined') {
			$('body','html').css({ height: 'auto', overflow: 'auto', width: 'auto' });
		}

		resumeBoombox();
	}

	function positionModal() {
		modalWindow.css({
			left: ($(document.body).width() - modalWindow.width()) / 2 + 'px',
			top: ($(document.body).height() - modalWindow.height()) / 2 + 'px'
		});
	}
	
	return this.each(function() {
		$(this).click(function(e) {
			e.preventDefault();
			$(document).keydown(handleEscape);
			$('body').append(overlay.click(function(){modalHide();})).append(modalWindow);
			overlay.fadeIn(400);
			modalWindow.html(modalContentTarget).append(flashTarget).fadeIn(200);
			$(this).videoPlayerEmbed({
				embedTitle: $(this).siblings('img').attr('alt'),
				embedPoster: $(this).attr('rel'),
				embedVideo: $(this).attr('href')
			});
			positionModal();

			modalWindow.append($('<a id="btn-modal-close"><span class="offscreen">Close</span></a>').click(function() {
				modalHide();
			}));

			rolloverSounds();
			killBoombox();
		});

		$(window).bind('resize', function() {
			positionModal();
		});

		if (typeof document.body.style.maxHeight === 'undefined' || navigator.platform == "Nintendo Wii") {
			overlay.css({
				height: ($(document.viewport).height() > $(document.body).height() ? $(document.viewport).height() : $(document.body).height()) + 'px'
			});
		}
	});
};

/*** Button Animations ***/

$.fn.btnScroll = function(options) {
	options = jQuery.extend({
		elBtn: $('a.btn'),
		direction: 'right',
		easing: 'easeOutQuad',
		duration: 300
	},options);

	var dir;

	options.direction == 'left' ? dir = '-' : dir = '';

	var elWidth = $(options.elBtn, this).width();

	$(this).hover(
		function() {
			$(options.elBtn, this).stop().animate(
				{ backgroundPosition : dir + elWidth + ' 0' },
				{ queue: true, duration: options.duration }
			);
		},
		function() {
			$(options.elBtn, this).stop().animate(
				{ backgroundPosition : dir + (elWidth * 2) + ' 0' },
				options.duration, options.easing,
				function(){
					$(this).css({ backgroundPosition : '0 0' });
				}
			);
		}
	);
};

/*** Inline Field Notes ***/

var fieldNotes = function(){
	var elField = $('fieldset span.note');
	var inactive = 'inactive';
	var active = 'active';
	var focused = 'focused';
	var passSwap = $('.pass-swap');

	elField.each(function(){
		var elInput = document.getElementById($(this).attr('data-for'));

		if(($(elInput).attr('type') == 'text') || ($(elInput).attr('type') == 'password') || (elInput.tagName.toLowerCase() == 'textarea')){
			var text = $(this).text();

			$(this).hide();

			if($(elInput).attr('type') == 'password'){
				passSwap.each(function() {
					$(elInput).hide();
					$(this).show();
					$(this).focus(function() {
						$(this).hide();
						$(this).next(elInput).show().focus();
					});
				});
			};

			$(elInput).addClass(inactive).val(text);

			$(elInput).focus(function() {
				$(this).addClass(focused);
				$(this).removeClass(inactive);
				$(this).removeClass(active);
				if($(this).val() == text) $(this).val('');
			});
			
			$(elInput).blur(function(){
			    $(this).removeClass(focused);

			    if($(this).val() == ''){
					if ($(this).attr('type') == 'password') {
						$(this).hide();
						$(this).prev(passSwap).show();
					};

					// PREVENT RACE CONDITION IN VALIDATION
					setTimeout(function() {
						$(this).val(text);
					},2000);
					
					$(this).addClass(inactive);
			    }else{
					$(this).addClass(active);
			    };
			});
		}
	});
};

/*** Contest Form Validation ***/

var validateFields = function(){
	var elField = $('.validate');
	var error = $('fieldset ol li.error');
	var message;

	function addError(field){
		var errorContainer = $(document.createElement('span')).attr('class','error-message').text(message);

		$(errorContainer).insertBefore(field);
		field.parent('li').addClass('error');
	}

	function removeError(field) {
		field.prev('span.error-message').remove();
		field.parent('li').removeClass('error');
	}

	function validateForm(field){
		var isValid = false;
		
		var errorPresent = field.siblings('span.error-message').length;
		
		var validateEmpty = field.hasClass('inactive') || field.val() == '';
		
		var validateEmail 	=	!!(field.val().match(/^\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}/)) && field.val();
		var validatePhone 	= 	!!(field.val().match(/^[0-9]\d{2}-\d{3}-\d{4}/)) && field.val();
		var validateGeneral = 	!!(field.val().match(/^([a-zA-Z0-9@\s\.\,\-\_]{1,255})/)) && field.val();
		var validate12 		= 	field.val().length <= 12;
		var validate12Alpha	= 	!!(field.val().match(/^([a-zA-Z\s]{1,12})/)) && !(!!(field.val().match(/([\d\W])/))) && !!(field.val()) && (field.val().length <= 12);
		var validate1000 	= 	!!(field.val().match(/^([a-zA-Z0-9@\s\.\,\-\_]{1,1000})/)) && !!(field.val());
		var validate2000 	= 	!!(field.val().match(/^([a-zA-Z0-9@\s\.\,\-\_]{1,2000})/)) && field.val();
		var validateFile 	= 	!!(field.val().match(/(.jpg)|(.JPG)|(.gif)|(.GIF)|(.pdf)|(.PDF)|(.png)/)) && field.val();
		
		function fieldTest(test){
			if(test && !validateEmpty) {
				isValid = true;
				removeError(field);
			} else {
				isValid = false;
				if(!errorPresent) addError(field);
			}
		}

		if(field.is('input#built-creator')){
			message = '- Please provide your Creator Name';
			fieldTest(validateGeneral);
		}else if(field.is('input#built-game')){
			message = '- Please provide your Microgame\'s title';
			fieldTest(validateGeneral);
		}else if(field.is('input#built-brand')){
			message = '- Please provide a brand name for the game';
			fieldTest(validateGeneral);
		}else if(field.is('input#built-email')){
			message = '- Please provide a valid email address';
			fieldTest(validateEmail);
		}else if(field.is('input#concept-game')){
			message = '- Please provide a game title (limit 12 characters)';
			fieldTest(validate12);
		}else if(field.is('input#concept-sketch')){
			message = '- Only jpg, gif, pdf, png files are accepted';
			fieldTest(validateFile);
		}else if(field.is('input#concept-email')){
			message = '- Please provide a valid email address';
			fieldTest(validateEmail);
		}else if(field.is('textarea#concept-describe')){
			message = '- Please provide a game description';
			fieldTest(validate2000);
		}else if(field.is('textarea#concept-message')){
			message = '- Please provide a stylus command (limit 12 characters)';
			fieldTest(validate12Alpha);
		}else if(field.is('textarea#concept-stylus')){
			message = '- Please provide a stylus action';
			fieldTest(validate1000);
		}else if(field.is('textarea#concept-goal')){
			message = '- Please provide the goal of your microgame';
			fieldTest(validate1000);
		}else{
			message = '- Please fill in this field';
			fieldTest(validateEmpty);
		}
		
		return isValid;
	}

	elField.blur(function(){
		var field = $(this);
		validateForm(field);
	});

	$('form.contest').each(function(){
		$(this).submit(function(e){
			var allFieldsValid = true;

			$('.validate', this).each(function(){
				if(!validateForm($(this))) {
					allFieldsValid = false;
				}
			});

			if(allFieldsValid){
				return true;
			}else{
				return false;
			}
		});
	});
};

/*** Cufon Config ***/

var cufonConfig = function(){
	var tenbyFive = {
		fontFamily: 'Tenby Five',
		hover: true
	};
	
	/* Common */
	
	Cufon.replace('ul.screens li h4', { textShadow: '#fff 1px 1px, #abe3f8 3px 3px' }, tenbyFive);
	Cufon.replace('div.bucket-bottom div.callout h4', { textShadow: '#fff 1px 1px, #f9abd9 3px 3px' }, tenbyFive);
	
	/* Home Page Fonts */
	
	Cufon.replace('body#section-home div#bucket-feature h3', { textShadow: '#fff 1px 1px, #d1c2ce 3px 3px' }, tenbyFive);

	/* Do It Yourself Section Fonts */

	Cufon.replace('body#section-do-it-yourself div.page-tutorial-gallery div.bucket-video div.copy h4', { textShadow: '#fff 1px 1px, #bee7c3 3px 3px' }, tenbyFive);

	/* Download and Share Section Fonts */

	Cufon.replace('body#section-download-and-share div.page-overview div.bucket-large div.callout-1 h3', { textShadow: '#433b3b 1px 1px, #774253 3px 3px' }, tenbyFive);
	Cufon.replace('body#section-download-and-share div.page-overview div.bucket-large div.callout-2 h4', { textShadow: '#433b3b 1px 1px, #774253 3px 3px' }, tenbyFive);
	Cufon.replace('body#section-download-and-share div.page-overview div.bucket-large div.callout-3 h4', { textShadow: '#433b3b 1px 1px, #774253 3px 3px' }, tenbyFive);

	Cufon.replace('body#section-download-and-share div.page-weekly-games div.bucket-games ul.games li h4', { textShadow: '#faf3a5 1px 1px, #c7ac9b 3px 3px' }, tenbyFive);
	Cufon.replace('body#section-download-and-share div.page-weekly-games div.bucket-games ul.games li.featured h4', { textShadow: '#fff 1px 1px, #f5c6d8 3px 3px' }, tenbyFive);

	Cufon.replace('body#section-download-and-share div.page-big-name-games div.bucket-games ul.games li h4', { textShadow: '#2e604e 1px 1px, #1e7f7a 3px 3px' }, tenbyFive);

	Cufon.replace('body#section-download-and-share div.page-theme-games div.bucket-large h3', { textShadow: '#433b3b 1px 1px, #7f5d82 3px 3px' }, tenbyFive);
	Cufon.replace('body#section-download-and-share div.page-theme-games div.bucket-large h3 strong', { textShadow: '#433b3b 1px 1px, #316c71 3px 3px' }, tenbyFive);
	Cufon.replace('body#section-download-and-share div.page-theme-games div.bucket-large h5', tenbyFive);
	Cufon.replace('body#section-download-and-share div.page-theme-games div.bucket-2 ul.games li h4', { textShadow: '#faf3a5 1px 1px, #a8d584 3px 3px' }, tenbyFive);
	Cufon.replace('body#section-download-and-share div.page-theme-games div.bucket-2 ul.games li h4 strong', { textShadow: '#faf3a5 1px 1px, #c7ac9b 3px 3px' }, tenbyFive);
	
	/* Game Play Section Fonts */
	
	Cufon.replace('body#section-game-play div.page-media div.bucket-1 ul.trailers li h4', { textShadow: '#fff 1px 1px, #f5c5d6 3px 3px' }, tenbyFive);

	Cufon.now();
};

/*** Nintendo Wii Fixes ***/

var ninWiiSpecific = function(){
	if(ninWii){
		$('body').addClass('nin-wii');
		$('html').css({ 'height' : 'auto' });
		$('ul#nav-main li ul li.nav-tutorial-gallery').hide();
		$('ul#nav-main li ul li.nav-media').hide();
		$('ul#nav-main li ul li.nav-microgames').addClass('last');
		$('div.bucket-bottom div.callout-1 a.btn-vert').attr('href','/download-and-share/');
		$('body#section-download-and-share div.page-big-name-games div.bucket-games ul.games li a.btn-horz').click(function(e){
			e.preventDefault();		
		});
	}
};

/*** Load On DOM Ready ***/

$(function(){
	navAnimation();
	ninWiiSpecific();
	jsEnabled();
});
