function addEvent(el, ev, func){
	el.attachEvent(ev,'on' + func) || el.addEventListener(ev,func,false);
	return true;
}

function autoscroll(el_id){
	this.el = document.getElementById(el_id);
	var text = this.el.innerHTML;
	
	this.inner = document.createElement('div');
	this.inner.innerHTML = text;
	this.el.scroll = true;
	
	this.el.innerHTML = '';
	this.el.appendChild(this.inner);
	this.el.inner = this.inner;
	
	// css
	with(this.el.style){
		position='relative';
		overflow='hidden';
	}
	
	with(this.inner.style){
		position='absolute';
		top='0px';
	}
	
	this.inner.y = 0;
	this.el.scrollAmount = 1;
	
	this.el.onmouseover=function(){
		this.scroll = false;
	}
	
	this.el.onmouseout=function(){
		this.scroll = true;
	}
	
	setTimeout("autoscroll_animate('" + el_id + "')",2000);
}

function autoscroll_animate(el_id){
	var as = document.getElementById(el_id);
	
	as.inner.y += as.scrollAmount * as.scroll;
	if(as.inner.y >= as.inner.offsetHeight){
		as.inner.y = 0 - as.offsetHeight;
		as.scrollAmount = 4;
	}
	
	if(as.scrollAmount==4 && as.inner.y > 0){
		autoscroll_reset(el_id);
	}
	
	as.inner.style.top = 0-as.inner.y + 'px';
	
	setTimeout("autoscroll_animate('" + el_id + "')",30);
	
}

function autoscroll_slow(el_id){
	var as = document.getElementById(el_id);
	as.scrollAmount = 1;
}

function autoscroll_reset(el_id){
	var as = document.getElementById(el_id);
	as.scrollAmount = 0;
	setTimeout("autoscroll_slow('" + el_id + "')",2000);
}

function changeColor_on(arg0){
	var el = document.getElementById(arg0);
	el.style.backgroundColor="#FFFFDD";
}

function changeColor_out(arg0){
	var el = document.getElementById(arg0);
	el.style.backgroundColor="transparent";
}

function enquiry(popurl){var enquirywindow=window.open(popurl,"","width=480,height=460,")}
function openPage(page) {window.open(page,null,"height=400,width=430,status=yes,toolbar=no,menubar=no,location=no");}

function checkForm(){
	var error = false;
	
	if(document.getElementById('form_email').value==''){
		error = true;
		document.getElementById('form_email').focus();
	}
	
	if(document.getElementById('form_name').value==''){
		error = true;
		document.getElementById('form_name').focus();
	}
	
	if(error){
		alert('You appear to have missed some fields');
		return false;
	}else{
		return true;
	}
}

$(document).ready(function(){
	$('div.images2 a').lightBox();
	
	$('div.gallery a').lightBox();
	
	$('a.galleryLink').lightBox();
	
	$('.optionButtons.radio input').click(function(){
		$(this).parent().addClass('checked').siblings().removeClass('checked');
	});
	
	$('.optionButtons.checkbox input').click(function(){
		var checked = $(this).parent().hasClass('checked');
		switch(checked){
			case true:
				$(this).parent().removeClass('checked');
			break;
			default:
				$(this).parent().addClass('checked');
			break;
		}
	});
	
	// set them on page load
	$('.optionButtons.radio input').each(function(){
		switch($(this).attr('checked')){
			case true:
				$(this).parent().addClass('checked');
			break;
		}
	});
	
	$('.optionButtons.checkbox input').each(function(){
		switch($(this).attr('checked')){
			case true:
				$(this).parent().addClass('checked');
			break;
		}
	});
	
	$('p.ownMotorhome').hide();
});
