"use strict";

/*globals $, jQuery, document, window */

(function() {
	var fontSz = $('body').hasClass('win') ? '30px' : '32px';
	var CFG = {
		BigImg   	: { width : '24px', height: '24px', top: '-8px'},
		SmallImg 	: { width : '16px', height: '16px', top: '0px'},
		BigNav   	: { fontSize: '36px', lineHeight: '36px' },
		SmallNav 	: { fontSize: fontSz, lineHeight: fontSz },
		QTMovie		: {
			W : '600px',
			H : '450px'
		}
	}
	
	function contract() { 
		$(this).stop().animate(CFG.SmallImg, 'fast'); 
	}	
	
	function expand() { 
		$(this).stop().animate(CFG.BigImg, 'fast'); 
	}		

	function dockIcons() {
		$('#footer').find('a').find('img').mouseover(expand).mouseout(contract);
	}
	
	function grow() { 
		$(this).stop().animate(CFG.BigNav, 'fast'); 
	}
	
	function shrink() {	
		$(this).stop().animate(CFG.SmallNav, 'fast'); 
	}			
	
	function nav() {		
		$('.nav')
			.find('li')
				.find('a').mouseover(grow).mouseout(shrink);
	}	
	
	function openWindow(href, width, height, w, h) {
		window.open(href, '', 'width=' + width + ',height=' + height + ', top=' + h +', left=' + w +', screenX=' + w +', screenY=' + h);			
	}	
	
	function toWindow() {		
		$('.big_window').click(function () {
			var width = 925, height = 700, w, h;
			
			w = (screen.width / 2) - width / 2; 
			h = (screen.height / 2) - (height * 0.65);
			
			openWindow(this.href, width, height, w, h);	
			return false;
		});		
		
		$('.window').click(function () {
			var width = 550, height = 400, w, h;
			
			w = (screen.width / 2) - width / 2; 
			h = (screen.height / 2) - height /2;
			
			openWindow(this.href, width, height, w, h);	
			return false;
		});
	}
	
	function initEmailForm() {
		$('#SubscriberEmailForm').submit(function () {
			$.post('subscribers/email', $(this).serialize(), function (data) {
				$('#response')
					.text('You are ' + (data == 1 ? 'now ' : 'already ') + 'subscribed to the mailing list!')
					.show('fast', function () {
						window.setTimeout(function () {
							$('#response').hide('fast');
						}, 2000);
					});
			});
			return false;
		});
	}
	
	$(document).ready(function () {
		$('#share').jqm();
		
		dockIcons();
		nav();
		toWindow();
		initEmailForm();
	});
})();
