/*
MAD Object Literal, stay out of the global scope - it's yucky.
*/
var MAD = {
	
	// Over write some default options with keys specific to the domain
	mode: {
		'localhost' : {
			blogURLFull : "http://localhost/mad/blog"
		},
		'boedesign.com' : {
			blogURLFull : "http://boedesign.com/clients/mad/blog",
			blogURL : 'http://boedesign.com/clients/mad/blog/author/%username%/feed/'
		},
		'beta.mad.ca' : {
			blogURLFull : "http://raving.mad.ca",
			blogURL : 'http://raving.mad.ca/author/%username%/feed/'
		},
		'mad.ca' : {
			blogURLFull : "http://raving.mad.ca",
			blogURL : 'http://raving.mad.ca/author/%username%/feed/'
		}
	},
	
	// Options obj (defaults)
	options: {
		siteTitle: 'MAD INC - Marketing & Communications for the Interactive Age - Ottawa, Canada',
		// slug (hash) with associated title to display in the <title> tag when you go to a new page
		pageTitles: {
			home: 'Home',
			people: 'People',
			projects: 'Projects',
			chatter: 'Chatter',
			help: 'Help Wanted',
			contest: 'Help the Canadian Cancer Society'
		},
		siteDescription: 'We\'re a business that\'s into creating reactions through interactions. You can say we\'re like marketing, web, design, print, and broadcast having a raucous game of twister. However, we\'re really about getting people to interact and react, however and whenever possible.',
		pageDescriptions: {
			contest: 'We\'re happy to announce the launch of our new 2010 Microfilm. So happy, we\'re spreading the word...and a little bit of wealth to a good cause.'
		},
		peopleOffset: 45, // Bring the people menu down a touch
		projectMenuDims: { //  FF: We show the project nums in a certain case on the projects page. Position accordingly.
			0: ['', '-25px'], // index: [left, top]
			1: [182, '-25px'],
			2: [232, '-25px'],
			3: [369, '-25px'],
			4: ['', '35px'],
			5: [257, '35px'],
			6: [307, '35px'],
			7: [464, '35px'],
			8: ['', '70px']
		},
		projectMenuDimsGeneral: { // Everyone except FF
			0: ['', '-25px'], // index: [left, top]
			1: [182, '-25px'],
			2: [232, '-25px'],
			3: [369, '-25px'],
			4: ['', '40px'],
			5: [257, '40px'],
			6: [307, '40px'],
			7: [464, '40px'],
			8: ['', '80px']
		},
		displayJustFollowUs: true, // Display the "just follow us" in chatter
		blogURLFull: 'http://localhost/mad/blog',
		blogURLFeedPath: '/feed/',
		blogURL: 'http://localhost/mad/blog/author/%username%/feed',
		flickrAPIURL: 'http://api.flickr.com/services/rest/?method=flickr.people.getPublicPhotos&api_key=7c0b6a159a9700cf6b930bd779caa0af&per_page=50&format=json&user_id=43124408@N06&jsoncallback=?',
		flickrAccountURL: 'http://www.flickr.com/photos/madinc',
		flickrPhotoLimit: 12,
		twitterTimeline: 'http://twitter.com/statuses/user_timeline/21332730.rss',
		twitterAccount: 'http://twitter.com/MAD_INC_TANK',
		// People page and info
		people: {
			// Name to show up in html, blog name then twitter and image
			'Aim&eacute;e': {
				blog_user: 'aimee',
				twitter_id: 6412902, // Can be found if you go to their twitter.com account and click on RSS feed
				image_url: 'aimee.jpg' // Images found in Images/people
			},
			'Dominic': {
				blog_user: 'dom',
				twitter_id: 9566622,
				image_url: 'dom.jpg'
			},
			'Brittany': {
				blog_user: 'brittany',
				twitter_id: 26076641,
				image_url: 'brit.jpg'
			},
			'David': {
				blog_user: 'david',
				twitter_id: 56654624,
				image_url: 'david.jpg'
			},'Paddy': {
				blog_user: 'paddy',
				twitter_id: 85834698,
				image_url: 'paddy.jpg'
			},			
			'Leisha': {
				blog_user: 'leisha',
				twitter_id: 84409017,
				image_url: 'leisha.jpg'
			},
			'Caroline': {
				blog_user: 'Caroline',
				twitter_id: 116874062,
				image_url: 'carol.jpg'
			},
			'Mike': {
				blog_user: 'mike',
				twitter_id: 9073782,
				image_url: 'mike.jpg'
			},			
			'Jana': {
				blog_user: 'jana',
				twitter_id: 122158114,
				image_url: 'jana.jpg'
			},
				
			'Greg': {
				blog_user: 'greg',
				twitter_id: 16450870,
				image_url: 'greg.jpg'
			},
			'Little Bat': {
				twitter_id: 107487980,
				image_url: 'batty.jpg'
			}
	
		}
	},
	
	// Keep track of a few things
	isIE: false, // is it garbage?
	currentPage: '', // Current page in the main menu
	lastPage: '', // Last page accessed in the main menu
	projectsTotal: 0, // How many projects are we dealing with?
	projectHasScrolled: false, // If they've clicked a Next/Previous button the proj page, restore the proj list menu
	peopleAlreadyAnimated: false,
	projectHomeImages: [ // Image slug and screenshot for the homepage
		['chrome_your_dome', 'chrome_website_home.jpg'],
		['internic', 'internic_website_home.jpg'],
		['kiosk_campaign', 'kioskcampaign_home.jpg'],
		['youstylista', 'youstylista_website_home.jpg'],
		['zip_online', 'zip_website_home.jpg'],
		['identity', 'identity_home.jpg']
	],
	
	loadQuote: function(page){
		
		// We can set the page or we can get it dynamically in the hash
		page = page || location.hash.replace(/#/g, '');
		
		var pages = {
			intro1: [
				"Engagement and experience is what we are into.",
				"It's about getting the right type of attention.",
				"It's not about integrating media.",
				"One part ideas. One part passion. One part experience."
			],
			intro2: [
				"Creating reactions through interactions.",
				"Give your campaign a punch in the interface.",
				"It's about integrating people with ideas.",
				"Brand satisfaction through creative interaction."
			],
			people: [
				"It's always about the people. </br>Always will be.", 
				"It's about people, until we develop an app that replaces them.", 
				"We're kind of a big deal...to our moms.",
				"It's about real people, cause the robots experiment went all stabby on us.",
				"Our family puts the 'fun' in dysfunctional."
			],
			chatter: [
				"Seriously. Get ready to have your mind blown.", 
				"Hope you brought extra pants.</br> Cause you'll need them. ",
				"If it's on the web, it must be true. Who's with us?",
				"LOL. OMG. JK. FTW. OIC. MAO. IMHO. ROTFLMAO. WTF. And Meh. ",
				"Signal vs Noise.<br/>The eternal epic battle."
			],
			help: [
				"Sometimes, first impressions last forever. Let's make this a good one.",
				"Let's join forces like sodium and chlorine. Yeah!",
				"Togetherness is the glue that we can sniff...together.",
				"Mad about you and you and you. You, not so much.",
				"Get in where you fit in. Grease with butter if you have to."
			]
		}
		
		var str = (pages[page]) ? pages[page][Math.floor(Math.random() * pages[page].length)] : 'Not defined';
		
		// If it's the intro page then we need to load 2 quotes in different elements
		if(page == 'intro'){
			
			// They use the same array keys so we can set which 2 quotes to sync up
			var key = Math.floor(Math.random() * pages.intro1.length),
				h1First = pages.intro1[key],
				h1Second = pages.intro2[key];
			
			$('#divHeader #h1First').html(h1First);
			$('#divHeader #h1Second').html(h1Second);
			
		}
		else {
			$('#divHeader h1').html(str);
		}
		
	},
	
	getPeopleFlickrImages: function(cb){
		
		var self = this;
		var ret = [];

		$.getJSON(this.options.flickrAPIURL, function(data, status){
			
			var d = data.photos.photo;
			
			$.each(d, function(i, item){
				ret.push(item);
			});
			
			cb.call(self, ret);
		
		});
		
	},
	
	contactForm: {
		
		currentSlide: 1,
		checkedBoxes: 0,
		lastSlideNum: 6,
		
		init: function(){
			
			var self = this;
			
			$('.close, .help').click(function(){
				window.parent.$.fn.fancybox.close();
				window.parent.focus();
				return false;
			});
			
			$('.yes, .start, .thanks, .ok, .gotcha').live('click', function(){
				if(!$(this).is('.noproceed')){
					self.nextSlide();
					return false;
				}
				else {
					self.closePrompt();
				}
			});
			
			$('.s3 .no').live('click', function(){
				self.prompt($(this));
				return false;
			});
			
			self.attachCheckboxes('.checkboxes div');
			self.attachRadios('.radios div');
			self.attachAnimations();
			
		},
		
		attachAnimations: function(){
			
			var animatedUp = false;
			var first = true;
			
			// Animate the "no" button
			$('.s6 .no').bind('mouseenter', function(){
				
				var marginAnim = '';
				
				if(!animatedUp){
					if(first){
						marginAnim = '-=80px';
						first = false;
					}
					else {
						marginAnim = '-=160px';
					}
					animatedUp = true;
				}
				else {
					marginAnim = '+=160px';
					animatedUp = false;
				} 
				
				$(this).animate({ marginTop: marginAnim }, 100, function(){
					
				});
				
			}).unbind('click');
			
		},
		
		attachCheckboxes: function(target){
			
			var self = this;
			
			$(target).click(function(){
				
				if(!$(this).is('.checked')){
					if(self.checkedBoxes < 2){
						$(this).addClass('checked');
						self.checkedBoxes++;
					}
					else {
						self.prompt($(target));
					}
				}
				else {
					self.checkedBoxes--;
					$(this).removeClass('checked');
				}
				
			});	
			
		},
		
		attachRadios: function(target){
			
			var self = this;
			
			$(target).click(function(){
				
				if(!$(this).is('.checked')){
					$(target).removeClass('checked');
					$(this).addClass('checked');
				}
				
			});
			
		},
		
		closePrompt: function(){
			$('.prompt').hide();
		},
		
		prompt: function(el){
			el.parents('.slide').find('.prompt').fadeIn('fast');
		},
		
		nextSlide: function(){
			
			this.checkedBoxes = 0;
			$('#progress').show();
			$('.s' + this.currentSlide).hide();
			var cs = this.currentSlide = this.currentSlide + 1;
			$('#progress a').eq((cs - 2)).addClass('active');
			if((this.currentSlide - 1) == this.lastSlideNum){
				$('#progress').hide();
			}
			$('.s' + cs).fadeIn();
			
			
		},
		
		cufonReplacements: function(){
			Cufon.replace('h2, .checkboxes div', {
				fontFamily: 'Avenir LT Std',
				hover: true
			});
		}
		
	}
	
}

// Debugging
if(typeof(window.console) === 'undefined' && typeof(clean_host) !== 'undefined' && clean_host == 'localhost'){
	window.console = {};
	window.console.log = function(str){
		alert(str);
	}
}

// Preload script
(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery);