// JavaScript Document
var image_a;
var image_b;


var m_blending_obj;
var m_is_running = 0;

var m_opacity = 0;
var m_speed = 15;
var m_step = 100;

function fadeOut()
{
	//alert('out');
	if (m_is_running == 0)
	{
		//alert('exiting');
		m_step = -3;
		blendLoop();
	}
}

/*
function fadeIn()
{
	//alert('in');
	
	// create a link to the object
	image_a = document.getElementById('image_a');
	image_b = document.getElementById('image_b');
	
	// hide the image
	image_a.style.display = 'none';
	image_a.style.zIndex = 0;
	
	image_b.style.display = 'block';
	image_b.style.zIndex = 100;
	
	//image_a.parentNode.style.backgroundImage
	
	// blend
	m_step = 3;
	blendLoop();
}
*/


/***
* sets the opacity the passed object
***/
function setOpacity(obj, o)
{
	obj.style.m_opacity = (o / 100);
	obj.style.MozOpacity = (o / 100);
	obj.style.KhtmlOpacity = (o / 100);
	obj.style.filter = 'alpha(m_opacity=' + o + ')';
}


/***
* sets the opacity of the blending object through a loop
***/
function blendLoop()
{	
	// check if the loop should continue
	if (m_opacity + m_step >= 100)
	{
		m_opacity = 100;
		setOpacity(m_blending_obj, 100);
		m_is_running = 0;
		clearTimeout();
	}
	else if (m_opacity + m_step <= 0)
	{
		m_blending_obj.style.display="none";
		m_opacity = 0;
		setOpacity(m_blending_obj, 0);
		m_is_running = 0;
		clearTimeout();
	}
	else
	{
		m_opacity = m_opacity + m_step;
		setOpacity(m_blending_obj, m_opacity);
		m_is_running = 1;
		setTimeout('blendLoop()', m_speed);
	}
}


// --- NEWSLETTER SIGNUP SPECIFIC CODE
function myPopupRelocate_2() {
 var scrolledX, scrolledY;
 if( self.pageYOffset ) {
   scrolledX = self.pageXOffset;
   scrolledY = self.pageYOffset;
 } else if( document.documentElement && document.documentElement.scrollTop ) {
   scrolledX = document.documentElement.scrollLeft;
   scrolledY = document.documentElement.scrollTop;
 } else if( document.body ) {
   scrolledX = document.body.scrollLeft;
   scrolledY = document.body.scrollTop;
 }

 	// position the object using the following matrix
	//
	// 1 2 3
	// 4 5 6
	// 7 8 9
	//
	var position = 9;

	switch (position)
	{
	case 1: // top left
		var leftOffset = scrolledX + 5;
		var topOffset = scrolledY + 5;
	
		m_blending_obj.style.top = topOffset + "px";
		m_blending_obj.style.left = leftOffset + "px";
		
		break;
		
	case 9: // bottom right
		var leftOffset = scrolledX + 934 - 260 - 20;
		var topOffset = document.body.clientHeight - 100 - 10 ;
		
		m_blending_obj.style.top = topOffset + "px";
		m_blending_obj.style.left = leftOffset + "px";
		
		break;
	}
}

function fireMyPopup_2() 
{
	// set default values
	m_opacity = 0;
	m_step = 3;
	
	// connect to the object
	m_blending_obj = document.getElementById("subscribe");
		
	myPopupRelocate_2();
		
	m_blending_obj.style.display = "block";
	setOpacity(m_blending_obj, 0);
	
	document.body.onscroll = myPopupRelocate_2;
	window.onscroll = myPopupRelocate_2;
	
	// begin the blending sequence
	blendLoop();
}

function subscribeToNewsletter()
{
	// link to he field
	var email_field = document.newsletter_signup.newsletter_email;
	
	// add the e-mail address to the mailinglist
	var jsel = document.createElement('SCRIPT');
	jsel.type = 'text/javascript';
	jsel.src = "ajax/newsletter_signup.php?email="+ email_field.value;
	document.body.appendChild(jsel);
	
	//alert( "ajax/newsletter_signup.php?email="+ email_field.value);
	alert("Thank you for signing up.");

	// clear the e-mail field
	clearNewsletterEmail();
	fadeOut();
}

function clearNewsletterEmail()
{
	// link to the field
	var email_field = document.newsletter_signup.newsletter_email;
	
	// clear the cell
	email_field.value = '';
}
