var jQ_joinourmaillist_animSpeed = 200;
var i_galleryDelay = 4000;
var i_galleryTransSpeed = 400;
var b_showHover = true;
var _to;

var tmp_timeout = null;

function GetXmlHttpObject() {
    var xmlHttp = null;
    try {
        xmlHttp = new XMLHttpRequest();
    } catch(e) {
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch(e) {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}

function ajaxStateChanged(obj)
{
	var obj = window.document.getElementById(obj);
	if(obj)
	{
		if(xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
		{
			obj.innerHTML = xmlHttp.responseText; // SET NEW TEXT
		}
	}
	return;
}

function showgmaps(obj)
{
	var bgm = window.document.getElementById('hidden-map');
	if(bgm)
	{
		obj.style.visibility = 'hidden';
		bgm.style.visibility = 'visible';
		
		var btn = window.document.getElementById('viewgooglemapsbtn');
		if(btn)
		{
			btn.innerHTML = 'Close Google Map';
			btn.onclick = function()
			{
				this.innerHTML = 'View Google Map';
				hidegmaps(window.document.getElementById('gmapoverlay'));
				this.onclick = function()
				{
					showgmaps(window.document.getElementById('gmapoverlay'));
					return false;
				}
				return false;
			}
		}
	}
	return false;
}

function hidegmaps(obj)
{
	var bgm = window.document.getElementById('hidden-map');
	if(bgm)
	{
		obj.style.visibility = 'visible';
		bgm.style.visibility = 'hidden';
	}
	return false;
}

$(document).ready(function()
{
  
   //fixEmailAddresses();
   
   $('#join-our-mailing-list').hover(
		function()
		{
			if(!b_showHover) return false;
			$('#join-our-mailing-list').animate({
				height:'242px'
			}, jQ_joinourmaillist_animSpeed, 'swing', function(){
				b_showHover = false;
				$('#join-our-mailing-list-form').show('fast');
				$('#join-our-mailing-list-form').animate({
					opacity: 1
				}, jQ_joinourmaillist_animSpeed, 'swing');
			});
		},
		function()
		{
			if(b_showHover) return false;
			$('#join-our-mailing-list').animate({
				height:'40px'
			}, jQ_joinourmaillist_animSpeed, 'swing', function(){
				b_showHover = true;
			});
			$('#join-our-mailing-list-form').animate({
				opacity: 0
			}, jQ_joinourmaillist_animSpeed, 'swing', function(){
				$('#join-our-mailing-list-form').hide();
			});
		}
	);
	
	var slidegallery = window.document.getElementById('slidegallery');
	if(slidegallery)
	{
		_to = setTimeout("initGallery('slidegallery', true)", i_galleryDelay);
	}
	var fadegallery = window.document.getElementById('fadegallery');
	if(fadegallery)
	{
		var delay = i_galleryDelay;
		if((fadegallery.className) && (fadegallery.className == 'homegallery')) delay = 5000;
		_to = setTimeout("initGallery('fadegallery', false, 'imgsubtxt')", delay);
	}
}); 

function initGallery(galleryId, bSlide, mMoveSubTxt)
{
	if($('#' + galleryId + ' > li').size() <= 1) // LESS THAN TWO ITEMS? KILL ANIMATIONS
	{
		clearTimeout(_to);
		return false;
	}
	var currentLi = $('#' + galleryId).children('li.active');
	var currentBig = currentLi.children('big');
	var nextLi = (currentLi.next().length != 0) ? currentLi.next() : $('#' + galleryId + ' li:first-child');
	nextLi.addClass('next');
	if(bSlide) currentBig.css("left", "0");
	
	if(bSlide)
	{
		currentBig.animate({
			left:"-=99%"
		}, i_galleryTransSpeed, 'swing');
	}
	currentLi.animate({
		opacity:0
	}, i_galleryTransSpeed, 'swing', function(){
		currentLi.removeClass();
		if(bSlide) currentBig.css("left", "0");
		currentLi.css("opacity", "1");
		nextLi.removeClass().addClass('active');
		_to = setTimeout("initGallery('" + galleryId + "', " + bSlide + ")", i_galleryDelay);
		
		if(mMoveSubTxt)
		{
			$('#' + mMoveSubTxt).text(nextLi.children('span').html());
		}
	});
}

function fixEmailAddresses()
{
	var spans = window.document.getElementsByTagName('span');
	var spancount = spans.length;
	for(var i = 0; i < spancount; i++){
		if(spans[i].className == 'hidden_mail'){
			var mailAd = spans[i].innerHTML;
			var mailParts = mailAd.split(' AT ');
			var domain = mailParts[0];
			var mailbox = mailParts[1];
			var email = mailbox+'@'+domain;
			var html = '<a href="mailto:'+email+'">'+email+'</a>';
			spans[i].innerHTML = html;
		}
	}
}

function defaultInput(obj, txt, isblur)
{
    if(!isblur)
    {
        if(obj.value == txt)
        {
            obj.value = '';
        }
    } else {
        if(obj.value == '')
        {
            obj.value = txt;
        }
    }
    return false;
}

