$(document).ready(function(){
	initGall();

	$('.gall-hold.default a:not(.prev):not(.next)').lightBox();
	$('.gallery-large a').lightBox();
	$('.lightbox').lightBox();
	$('.index input[name="contact[EMAIL]"]').focus(function() {
		if ($(this).val() == 'Enter your email address') {
			$(this).val('');
		}
	});
	$('.index input[name="contact[EMAIL]"]').blur(function() {
		if ($(this).val() == '') {
			$(this).val('Enter your email address');
		}
	});
	
	// hack to align the gallery to the bottom so it's not done in normal html/css
	$('.gall-dining').closest('.text-holder').css('position', 'relative');
	$('.gall-dining').closest('.content').css('padding-bottom', '170px');
	$('.gall-dining').css('position', 'absolute').css('bottom', '15px');
	
});
function initGall(){
	var _hold = $('.gall-hold');
	var _info = _hold.children('.gallery-large');
	var list_h = _hold.find('#gallery ul');
	var _list = list_h.children();
	var _btn = _list.children('a');
	var _step = _list.outerWidth();
	var t_a = 0;
	var _m = 0;
	if (_info.length) _info.find('span').html('<a href="' + _btn.eq(t_a).attr('href').replace('-h300', '-m450') + '" title="' + _btn.eq(t_a).attr("title") + '"><img src="' + _btn.eq(t_a).attr('href') + '" alt="' + _btn.eq(t_a).attr("title") + '" /img></a><p>' + _btn.eq(t_a).attr("title") + '</p>');
	_hold.find('#gallery .prev').click(function(){
		changeEl(false);
		return false;
	});
	_hold.find('#gallery .next').click(function(){
		changeEl(true);
		return false;
	});
	_btn.click(function(e){
		var _ind = _btn.index(this);
		if(t_a != _ind){
			var outerThis = $(this);
			_info.find('span').fadeOut(250, function() {
				_info.find('span').html('<a href="' + outerThis.attr('href').replace('-h300', '-m450') + '" title="' + outerThis.attr("title") + '"><img src="' + outerThis.attr('href') + '" alt="' + outerThis.attr("title") + '" /img></a><p>' + outerThis.attr("title") + '</p>');
				_info.find('span').show();
				$('.gallery-large a').lightBox();
			});
			
			t_a = _ind;
		}
		return false;
	});
	var _w = _list.length*_step - _list.parent().parent().width();
	if(_w > 0){
		
	}
	else{
		
	}
	
	function changeEl(_f){
		if(_f) _m += _step;
		else _m -= _step;
		if(_m < 0) _m = _w;
		if(_m > _w) _m = 0;
		list_h.animate({marginLeft: -_m}, {queue:false, duration:300});
	}

}
