var clearedInputList = new Array();

function clearInputBox(elementID) {
	var clearInput = true;

	for(var i = 0; i < clearedInputList.length; i ++) {
		if(clearedInputList[i] == elementID) {
			clearInput = false;
		}
	}

	if(clearInput) {
		document.getElementById(elementID).value = '';
		clearedInputList[clearedInputList.length] = elementID;
	}
}

function loadCalendar(idPrefix) {
	var trCount = $('.calendar tr').length;
	var trIndex = 1;

	$('.calendar tr').each( function () {

		if(trIndex == trCount) {
			$(this).find('td').each( function () {
				$(this).addClass('last-row');
			});
		}
		
		trIndex++;
	});

	$('#' + idPrefix + 'calendar-wrapper .day-number').each( function () {

		var popupLayerID = $(this).attr('id') + '-events';
		var popupLayer = $('#' + popupLayerID);
		
		if(popupLayer.length == 1) {
			$(this).css('cursor', 'pointer');
			
			$(this).click( function(event) {
				
				$('.popup-event-list').each( function () {
					if($(this).attr('id') != popupLayerID)
						$(this).hide();
				});
			
				if(popupLayer.css('display') == 'none') {
					popupLayer.fadeIn('fast');
				} else {
					popupLayer.fadeOut('fast');
				}

				event.stopPropagation();
				
				$('body').click( function(e) {
						popupLayer.fadeOut('fast');
				});
			});
		}
		
	});
}

function typeFigures() {
	$('.figure').jTypeWriter( { duration: 2.5 } );
	window.setTimeout(typeFigures, 10000);
}

$(document).ready( function() {
	/* REMOVED - WHY? Why have this? makes no sense!
	var mainContentHeight = $('#maincontent').height();
	
	if(mainContentHeight < 450)
	{
		var footerTopMargin = 450 - mainContentHeight;
		$('#footer').css('margin-top', (0 - footerTopMargin) + 'px');
	}
	else
	{
		$('#footer').css('margin-top', '-30px');
	}
	*/

	$('.top-menu-item:not(.top-menu-item-selected)').hover(
		function() {
			$(this).addClass('top-menu-item-selected');
		},
		function() {
			$(this).removeClass('top-menu-item-selected');
		}
		);

	$('#home-image-left-scroller, #home-image-right-scroller').innerfade( {
		speed: 2000,
		timeout: 5000,
		containerheight: '270px'
	});

	typeFigures();

	$('#show-login-layer').css('cursor', 'pointer').click( function() {
		$('#header-login-display').slideToggle();
	});
		
	$('#close-header-login').css('cursor', 'pointer').click( function() { 
		$('#header-login-display').slideUp();
	});
		
	$('a.open-new-window').attr('target', '_blank');
		
	var topOfferColumns = $('.top-offer-column');
	
	if(topOfferColumns.size() > 0) {
		var height = 0;
			
		topOfferColumns.each( function() {
			height = Math.max(height, $(this).height());
		});
			
		topOfferColumns.css('height', height + 'px');
	
		var widget = new TWTR.Widget( {
			id: 'top-offer-twitter',
			version: 2,
			type: 'profile',
			rpp: 5,
			interval: 6000,
			width: 225,
			height: Math.max(200, height - 58),
			theme: {
				shell: {
					background: '#bd044b',
					color: '#ffffff'
				},
				tweets: {
					background: '#ffffff',
					color: '#808080',
					links: '#bb9a69'
					}
				},
				features: {
					scrollbar: true,
					loop: false,
					live: true,
					hashtags: true,
					timestamp: true,
					avatars: false,
					behavior: 'all'
				}
			});
			
			widget.render().setUser('IpsCentralPlus').start();
	}
});

