windowHeight = 0;
windowWidth = 0;

replaceFonts = function(){
	Cufon.replace('#navigation li a, #content h2, #content h3, #searchform label, #pricing-grid th, .slideshow h2, .container_mailchimp h3');
}

var homepage = {
	init : function () {
	
	    // configure and activate homepage feature cycle
	    $('.slideshow').cycle({
			fx: 'fade',
			timeout: 10000,
			pager: '#feature-nav',
			pagerAnchorBuilder: function(idx, slide) { return '<a href="#">' + $(slide).attr('title') + '</a>'; }
 		});
		
		$('#in-action li a').addClass('modal').attr({'mheight' : '600'});
		modal.setup();
	}
}


var modal = {
	setup : function () {
		//insert the markup
		$('<div class="mask"></div><div class="modal_window"><a href="#" class="close_modal">close</a><h2 class="modal_title"></h2><div class="target"></div></div>').appendTo('body');
		
		$('.modal').live('click', function(index) {	
			modal.open({
				destination : $(this).attr('href'),
				title : $(this).attr('title'),
				modalWidth : $(this).attr('mwidth'),
				modalHeight : $(this).attr('mheight')
			});
			
								
			return false;
		});	
		
		$('a.close_modal, a.cancel_modal').live('click' , function() {
			modal.close();
		});
		
		setInterval('modal.measureWindow()',500);
	},
	
	open : function (params) {
		params = params || {};
		destination = params.destination;
		title = params.title;
		modalWidth = params.modalWidth || '900';
		modalHeight = params.modalHeight || '300';
		var top = $(window).scrollTop();
		
				
		$('.mask').fadeIn();		
		
		$('.modal_window')
			.find('.target')
				.load(destination)
				.css({
					'width' : modalWidth - 10 + 'px',
					'height' : modalHeight - 30 + 'px'
				})
			.end()
			.find('h2.modal_title')
				.text(title)
			.end()
			.css({
				'top' : modalHeight/4 + 'px',
				'left': windowWidth/2 +'px',
				'width' : modalWidth + 'px',
				'height' : modalHeight + 'px'
			})
			.fadeIn()
			.find('.target')
				.fadeIn('fast');
			
		
		//$('body, html').css('overflow','hidden');
	},
	
	close : function () {
		$('.modal_window .target').empty();
		$('.modal_window, .mask').hide();
		$('body, html').removeAttr('style');
	},
	
	measureWindow : function () {
 		windowHeight = $(window).height();
 		windowWidth = $(window).width();
		//console.log(windowHeight);
	}
};

activeTab = function(){
	var $nav = $('#navigation');
	$nav.find('li.active_tab').removeClass();
	var tab = $('body').attr('id');
	tab = tab.split('body_');
	tab = tab[1];
	$nav.find('li#tab_' + tab).addClass('active_tab');

}

