function main_margin() {
	
	var main_window_h = $(window).height();
	//alert(main_window_h);
	if(main_window_h > 724) {
		var difference = main_window_h - 724;
		var new_margin = difference / 2;
		//alert(new_margin);
		$("#homeContent").css("margin-top", new_margin); 
		
	}
};

function popupWindow(url, name, attributes){
	// Append popup to the URL if it does not already exist
	var queryStringExists = false;
	if(url.match(/\?/)) {
		queryStringExists = true;
	}
	
	if(queryStringExists) {
		// Only append if we haven't already got the parameter popup defined
		if(!url.match(/(\?|&)popup=/)) {
			url = url + '&popup=true';
		}
	} else {
		url = url + '?popup=true';
	}
	
	var newWindow = window.open(url, name.replace(/[^A-z]/ig, ''), attributes);
	newWindow.focus();
}

$(document).ready(function() {
	main_margin();
	$(window).resize(main_margin);
	
	fadeIn();
	
	$('a.popupLink').bind('click', function(e) { popupWindow($(this).attr('href'), $(this).attr('title'),'width=700, height=600, scrollbars'); e.preventDefault(); });
});

function fadeOut() {
	$('.homeRegisterNormal').css({'background-position': '0px -2000px'});
//	if(fadeOutTimeout) {
//		fadeOutTimeout.clearTimeout();
//	}	
	fadeInTimeout = setTimeout(function() {
		fadeIn();
	}, 400);
}

function fadeIn() {
	$('.homeRegisterNormal').css({'background-position': '0px 0px'});
//	if(fadeInTimeout) {
//		fadeInTimeout.clearTimeout();
//	}
	fadeOutTimeout = setTimeout(function() {
		fadeOut();
	}, 400);
}

