function addOnclickEvents() {
	if(document.getElementById('specdownload')){
      var specTab = document.getElementById('specdownload');
      specTab.onclick = function(){
		showRegistrationBox();
      };
	}
}
window.addEvent('domready', addOnclickEvents);

function showImage(id) {
	var elements = document.getElementsByTagName('img');
	for (var i = 0; i < elements.length; i++) {
		if (elements[i].className == 'layoutimage') {
			elements[i].style.display = 'none';
		}
	}
	document.getElementById(id).style.display = 'block';
}

var numTimesShifted = 0;
var shift = 0;
function movegalleryLeft() {
	var gallery = $('gallery');
	var listItems = gallery.getElements('li');
	var i = 0;
	if (numTimesShifted < listItems.length) {
		listItems.each(function(li) {
			if (i == numTimesShifted) {
				shift = shift - ((li.getSize().size.x + 20));
			}
			i++;
		});
		listItems.each(function(li) {
			var fade = new Fx.Styles(li, {duration: 120, transition: Fx.Transitions.linear});
            fade.start({
                'margin-left': shift + 'px',
                'margin-right': (20 - shift) + 'px'
            });
		});
		numTimesShifted++;
	}
}

function movegalleryRight() {
	var gallery = $('gallery');
	var listItems = gallery.getElements('li');
	var i = 0;
	if (numTimesShifted > 0) {
		listItems.each(function(li) {
			if (i == numTimesShifted - 1) {
				shift = shift + ((li.getSize().size.x + 20));
			}
			i++;
		});
		listItems.each(function(li) {
			var fade = new Fx.Styles(li, {duration: 120, transition: Fx.Transitions.linear});
            fade.start({
                'margin-left': shift + 'px',
                'margin-right': (20 - shift) + 'px'
            });
		});
		numTimesShifted--;
	}
}

function showRegistrationBox() {
}

startList = function() {
	if (document.all&&document.getElementById) {
		if (document.getElementById("landingnav")) {
			navRoot = document.getElementById("landingnav");
			for (i=0; i<navRoot.childNodes.length; i++) {
				node = navRoot.childNodes[i];
				if (node.nodeName=="LI") {
					node.onmouseover=function() {
					this.className+=" over";
					}
					node.onmouseout=function() {
						this.className=this.className.replace(" over", "");
					}
				}
			}
		}
		if (document.getElementById("explorerange")) {
			navRoot = document.getElementById("explorerange");
			for (i=0; i<navRoot.childNodes.length; i++) {
				node = navRoot.childNodes[i];
				if (node.nodeName=="LI") {
					node.onmouseover=function() {
					this.className+=" over";
					}
					node.onmouseout=function() {
						this.className=this.className.replace(" over", "");
					}
				}
			}
		}
		if (document.getElementById("rangenav_s")) {
			navRoot = document.getElementById("rangenav_s");
			for (i=0; i<navRoot.childNodes.length; i++) {
				node = navRoot.childNodes[i];
				if (node.nodeName=="LI") {
					node.onmouseover=function() {
					this.className+=" over";
					}
					node.onmouseout=function() {
						this.className=this.className.replace(" over", "");
					}
				}
			}
		}
		if (document.getElementById("productnav")) {
			navRoot = document.getElementById("productnav");
			for (i=0; i<navRoot.childNodes.length; i++) {
				node = navRoot.childNodes[i];
				if (node.nodeName=="LI") {
					node.onmouseover=function() {
					this.className+=" over";
					}
					node.onmouseout=function() {
						this.className=this.className.replace(" over", "");
					}
				}
			}
		}
	}
}
window.addEvent('domready', startList);

function getUrl() {
    var result = 'http://' + location.hostname + '/';
    
    if(location.hostname.indexOf('lucas') >= 0) {
        var url = location.href.replace(result, '');
        result = result + url.substring(0, url.indexOf('/') + 1);
    } 
    
    return result;
}


function ajaxRequest(){
	new Ajax(getUrl() + 'SpecDownload.aspx',{postBody:'name=' + document.getElementById("TbName").value + '&email=' + document.getElementById("TbEmailAddress").value, onComplete: showResponse}).request();
	return false;
};

function showResponse(request){
    if (request == 'Done') {
		hideRegistrationBox();
		window.open(specUrl);
		document.getElementById('SpecDlLink').href = specUrl;
		document.getElementById('SpecDlLink').onclick = '';
		document.getElementById('SpecDlLink').target = '_blank';
    }
    if (request.indexOf('Failed') > -1) {
		alert('sorry, there is a problem. we have been alerted and will fix it soon.');
    }
};

function showRegistrationBox() {
	document.getElementById('RegistrationBox').style.display = "block";
}

function hideRegistrationBox() {
	document.getElementById('RegistrationBox').style.display = "none";
}