// This removes and conflict between jquery and mootools
jQuery.noConflict();

// This puts a request to collect the contact form for the visitors.
window.addEvent('domready', function() {
	if (!window.form_path) window.form_path = '';
	var form_path = window.form_path;

	//We can use one Request object many times.
	var req = new Request.HTML({url:form_path+'contact-form.php', 
		onSuccess: function(html) {
			//Clear the text currently inside the results div.
			$('result').set('text', '');
			//Inject the new DOM elements into the results div.
			$('result').adopt(html);
		},
		//Our request will most likely succeed, but just in case, we'll add an
		//onFailure method which will let the user know what happened.
		onFailure: function() {
			$('result').set('text', 'Can not display contact details. Please refresh page and try again.');
		}
	});
	
	$('displayContact').addEvent('click', function() {
		req.send();
	});

});

// This puts a request to collect the list of countries the user can pick from.
window.addEvent('domready', function() {
	if (!window.list_path) window.list_path = '';
	var list_path = window.list_path;

	//We can use one Request object many times.
	var req = new Request.HTML({url:list_path+'countries.php', 
		onSuccess: function(html) {
			//Clear the text currently inside the results div.
			$('result').set('text', '');
			//Inject the new DOM elements into the results div.
			$('result').adopt(html);
		},
		//Our request will most likely succeed, but just in case, we'll add an
		//onFailure method which will let the user know what happened.
		onFailure: function() {
			$('result').set('text', 'Can not load the list of countries at this time. Please refresh page and try again.');
		}
	});
	
	$('collectcountryList').addEvent('click', function() {
		req.send();
	});

});

// This fades a link to allow the user to go back to the top of the page.
jQuery.fn.topLink = function(settings) {
	settings = jQuery.extend({
		min: 1,
		fadeSpeed: 200
	}, settings);
	return this.each(function() {
		//listen for scroll
		var el = $(this);
		el.hide(); //in case the user forgot
		$(window).scroll(function() {
			if($(window).scrollTop() >= settings.min)
			{
				el.fadeIn(settings.fadeSpeed);
			}
			else
			{
				el.fadeOut(settings.fadeSpeed);
			}
		});
	});
};

//usage w/ smoothscroll
$(document).ready(function() {
	//set the link
	$('#top-link').topLink({
		min: 400,
		fadeSpeed: 500
	});
	//smoothscroll
	$('#top-link').click(function(e) {
		e.preventDefault();
		$.scrollTo(0,300);
	});
});

// This toggles the footers element
function btoggle(targ,obj)
{ 	targ = document.getElementById(targ)
    if(!obj.parentNode.mfocus)
	{ targ.style.display = 'none'; }
}

function dtoggle(targ)
{ 	targ = document.getElementById(targ)
	targ.style.display = (targ.style.display=='block')?'none':'block'
}