var portal = {
	init: function() {
		portal.activateLoginBox();
	},

	activateLoginBox: function() {
		var wrap = $('.contentWrap');
		wrap.load($('a[rel=overlay]').attr('href'));

		$('a[rel=overlay]').bind('click', function() {
			portal.modalFormsInit();
			$('#overlay').show();
			return false;
		});

		$('#closingX').bind('click', function() {
			$('#overlay').hide();
			return false;
		})
	},

	modalFormsInit: function(){
		$('#modal_content form').each(function(index, formElement){
			$(formElement).bind("submit", function(event) {
				event.preventDefault();
				$.post(
					$(formElement).attr('action'),
					$(formElement).serialize(),
					function(data){
						$('#modal_content').html(data);
						portal.modalFormsInit();
					}
				);
				$('#closingX').hide(50);
				return false;
			});
			$('#closingX').show();
		});

		$('#modal_content a').each(function(index, aElement){
			$(aElement).bind("click", function(event) {
				event.preventDefault();
				$.get(
					$(aElement).attr('href'),
					{},
					function(data){
						$('#modal_content').html(data);
						portal.modalFormsInit();
					}
				);
				$('#closingX').show();
				return false;
			});
		});

		if($('#modal_redirect').length > 0) {
			window.location.href = $('#modal_redirect').attr('href');
		}
	}
}

$(document).ready(function() {
	portal.init();
});


// Resize Gadget IFRAME
setInterval(function() {
  var items= window.location.hash.split('?')
  if (items[0] == '#gadgets') { document.getElementById('gadgets').height=items[1]; }
},500);


