/* =CHANGELOG 

2010-09-04	Ciaran Lyons	<ciaran.lyons@gmail.com>
	* removed called to _kmq which were causing js errors

2010-08-08	Ciaran Lyons	<ciaran.lyons@gmail.com>
	* added fn.center, fn.fixedCenter
	* changed from using showLightbox function to showLightbox2

=============================================================================*/

$.fn.center = function () {
    //this.css("position","fixed");
    this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
    return this;
}

jQuery.fn.fixedCenter = function(){
	return this.each(function(){
		var element = jQuery(this);
		centerElement();
		jQuery(window).bind('resize',function(){
			centerElement();
		});
			
		function centerElement(){
			var elementWidth = jQuery(element).outerWidth();
			var elementHeight = jQuery(element).outerHeight();
			var windowWidth = jQuery(window).width();
			var windowHeight = jQuery(window).height();	
			
			var X2 = windowWidth/2 - elementWidth/2;
			var Y2 = windowHeight/2 - elementHeight/2;
	 
			jQuery(element).css({
				'left':X2,
				'top':Y2,
				'position':'fixed'
			});						
		} //end of centerElement function
					
	}); //end of return this.each
}


$.fn.emailLightbox = function(options) {
	var options = $.extend({ width: 500, top: 150, timetopop: 40000 }, options);
	var lightbox = $(this);

	lightbox.hide();
	initialize();

	function initialize() 
	{
		timer();
	}

	function timer() 
	{
		if($.cookie('iwillteach_email') != 1) 
		{
			setTimeout(showLightbox2, options.timetopop);
		}
	}

	function showLightbox()
	{

		// Build the lightbox 
		var lightboxWidth = options.width + 'px';
		var lightboxMarginLeft = -options.width/2 + 'px';
		var lightboxTop = $(window).scrollTop() + options.top;

		lightbox.css({
			'width': lightboxWidth,
			'margin-left': lightboxMarginLeft,
			'top': lightboxTop
		});

		// Show the lightbox 
		lightbox.show();
		
	}
	
	function showLightbox2()
	{

		// Build the lightbox 
		var lightboxWidth = options.width + 'px';

		lightbox.css({
			'width': lightboxWidth
		});

		// Show the lightbox 
		lightbox.fixedCenter();
		lightbox.show();

	}


	$('.signup-button').bind('click', function()
	{
		$.cookie('iwillteach_subscribed', '1', { expires: 1000, path: '/'});
	});

	$('.close_lightbox').bind('click', function()
	{
		lightbox.hide();
		$.cookie('iwillteach_email', '1', { expires: 60, path: '/' });
		return false;
	});

};

