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();
	$('#topnav > li').hover(function() {
		if (obj) {
			obj.find('ul').fadeOut('fast');
			obj = null;
		} //if
		
		$(this).find('ul').fadeIn('fast');
	}, function() {
		obj = $(this);
		setTimeout(
			"checkHover()",
			50);
	});
	
	$('#topnav > li').click(function() {
		if(!isset(loadedPages[$(this).attr('id')])) {
			$('#'+$(this).attr('id')+'_holder').load('./contents/ajax/'+$(this).attr('id')+'/'+$(this).attr('id')+'.php', null, loadDone);
//	alert('./contents/ajax/'+$(this).attr('id')+'/'+$(this).attr('id')+'.php');
			loadedPages[$(this).attr('id')] = true;
		}
	});
	
	
	
	function loadDone(rT, tS, req) {
		$("#contactForm").validate({errorLabelContainer: "#messageBox", wrapper: "li"});
		$(".gallery-panel > a").fancybox({
		'hideOnContentClick': true,
		'hideOnOverlayClick': true,
		'overlayShow': true
		}); 
		$(".gallery-panel > a").click(function(){
			var href = $(this).attr('href');
			_gaq.push(['_trackEvent', 'Gallery', 'Image', href]);
			});
		$('.gallery-buttons').click(function() {
			if(!isset(loadedPages[$(this).attr('id')])) {
				$('#'+$(this).attr('id')+'_holder').load('./contents/ajax/'+$(this).attr('id')+'/', null, loadDone);
				alert('./contents/ajax/'+$(this).attr('id')+'/');
				loadedPages[$(this).attr('id')] = true;
			}
		});
		createSlider();
	}
	
	$(".gallery-panel > a").fancybox({
	'hideOnContentClick': true,
	'overlayShow': true
	});
	
	$('#welcome-fade').innerfade({speed: 'slow', timeout: 5000 }); 
	
});