var obj = null;
var loadedPages = {};

function isset(variable_name) {
	try {
		if (typeof(eval(variable_name)) != 'undefined')
			if (eval(variable_name) != null)
				return true;
	} catch(e) { }
	return false;
}
function checkHover() {
	if (obj) {
		obj.find('ul').fadeOut('fast');	
	} //if
} //checkHover

$(document).ready(function() {
	createSlider();
	$('#ft-buttons > li').hover(function() {
		if (obj) {
			obj.find('ul').fadeOut('fast');
			obj = null;
		} //if
		
		$(this).find('ul').fadeIn('fast');
	}, function() {
		obj = $(this);
		setTimeout(
			"checkHover()",
			50);
	});
	
	$('#ft-buttons > li').click(function() {
		if($(this).attr('id') != 'gallery' && $(this).attr('id') != 'about' && $(this).attr('id') != 'packages') {
			if(!isset(loadedPages[$(this).attr('id')])) {
				$('#'+$(this).attr('id')).load('/contents/ajax/'+$(this).attr('id')+'/', null, loadDone);
				loadedPages[$(this).attr('id')] = true;
			}
		}
	});
	
	$('#ft-buttons > li > ul > li').click(function() {
		if(!isset(loadedPages[$(this).attr('id')])) {
			$('#'+$(this).attr('id')+'_holder').load('/contents/ajax/'+$(this).attr('id')+'/', null, loadDone);
			loadedPages[$(this).attr('id')] = true;
		}
	});
	
	
	
	function loadDone(rT, tS, req) {
		$("#weddingPackageForm").validate({errorLabelContainer: "#messageBox", wrapper: "li"});
		$("#weddingPackageForm").validate({errorLabelContainer: "#messageBox", wrapper: "li"});
		$(".gallery-panel > a").fancybox({
		'hideOnContentClick': true,
		'overlayShow': true
		}); 
		$(".sample-albums > ul > li > a").fancybox({
		'hideOnContentClick': true,
		'overlayShow': true,
		'frameWidth': '860',
		'frameHeight': '690'
		}); 
		$('.gallery-buttons').click(function() {
			if(!isset(loadedPages[$(this).attr('id')])) {
				$('#'+$(this).attr('id')+'_holder').load('/contents/ajax/'+$(this).attr('id')+'/', null, loadDone);
				loadedPages[$(this).attr('id')] = true;
			}
		});
		createSlider();
	}
	
	$(".gallery-panel > a").fancybox({
	'hideOnContentClick': true,
	'overlayShow': true
	});
	
	$('#welcome-fade').innerfade({speed: 'slow', timeout: 5000 }); 
	
});