if (typeof window.console === 'undefined') {
	window.console = {
		log: function () {
			void(0);
		}
	};
}

var hoverTime;
function hideDropDownMenu(dropDownMenu) {
	$(dropDownMenu)
		.hide()
	;
}

function promoSlide(max) {
	$('#promoPanel')
		.html(
			$('#promo' + index).html()
		)
	;
	index++;
	if (index > max) {
		index = 1;
	}
}

jQuery(function($) {
	var currContentHeight = 0;
	var maxContentHeight = 0;
	var currTitleHeight = 0;
	var maxTitleHeight = 0;
	var rowLeveler = $('.rowLeveler');
	rowLeveler.each(function() {
		var titleLeveler = $(this).find('.titleLeveler');
		titleLeveler.each(function() {
			currTitleHeight = $(this).height();
			//console.log(this, 'title height:', currTitleHeight, 'px');
			if (currTitleHeight > maxTitleHeight) {
				maxTitleHeight = currTitleHeight;
			}
		});
		titleLeveler.height(maxTitleHeight);
		//console.log('Setting all above objects\' title height to:', maxTitleHeight, 'px');
		currTitleHeight = 0;
		maxTitleHeight = 0;
		
		var contentLeveler = $(this).find('.contentLeveler');
		contentLeveler.each(function() {
			currContentHeight = $(this).height();
			//console.log(this, 'content height:', currContentHeight, 'px');
			if (currContentHeight > maxContentHeight) {
				maxContentHeight = currContentHeight;
			}
		});
		contentLeveler.height(maxContentHeight);
		//console.log('Setting all above objects\' content height to:', maxContentHeight, 'px');
		currContentHeight = 0;
		maxContentHeight = 0;
	});
	
	/*$('input:text')
		.hint()
	;*/
	
	$('.target_blank')
		.attr('target', '_blank')
	;
	
	$('.submitCheck')
		.attr('value', '1')
	;
	
	$('a.inputButton')
		.click(function() {
			$(this)
				.parents('form')
					.submit()
			;
		})
	;
	
	var confirmCode = $('.confirmCode');
	confirmCode
		.click(function () {
			var src = $(this).attr('src');
			var pos = src.lastIndexOf('?');
			if (pos === -1) {
			    pos = src.length;
			}
			src = src.substring(0, pos);
			$(this)
				.attr('src', src + '?' + Math.round(Math.random() * 9999999999));
		})
	;

	var dropMenuShower = $('.dropMenuShower');
	dropMenuShower.not('.clickable')
		.click(function(e) {
			e.preventDefault();
		})
	;
	dropMenuShower
		.hover(function() {
			dropMenuShowerXPos = $(this).position().left;
			dropMenuShowerYPos = $(this).position().top;
			dropMenuShowerWidth = $(this).width();
			dropMenuShowerWidthHalf = $(this).width() / 2;
			dropMenuShowerHeight = $(this).height();
			dropDownMenu = '#' + $(this).attr('id') + 'Drop';
			dropMenuWidthHalf = $(dropDownMenu).width() / 2;
			$(dropDownMenu)
				.css('left', dropMenuShowerXPos + dropMenuShowerWidthHalf - dropMenuWidthHalf)
				.css('top', dropMenuShowerYPos + dropMenuShowerHeight)
				.show()
			;
			$('.dropDownMenu .level2').hide();
			menuLevel2 = $(this).next('.level2');
			menuLevel2
				.css('left', dropMenuShowerXPos + dropMenuShowerWidth + 3)
				.css('top', dropMenuShowerYPos)
				.show()
			;
		}, function() {
			hoverTime = setTimeout("hideDropDownMenu(dropDownMenu)", 100);
		})
	;
	$('.dropDownMenu')
		.hover(function() {
			clearTimeout(hoverTime);
		}, function() {
			$(this)
				.hide()
			;
		})
	;
	
	var body = $('body');
	var defaultFontSize = 3;
	var currentFontSize = $.cookie('CT_FS');
	if (currentFontSize != null) {
		body.removeAttr('class');
		body.addClass('fs' + currentFontSize);
	}
	else {
		currentFontSize = defaultFontSize;
	}
	currentFontSize = parseInt(currentFontSize);
	$('#fontChange .fontInc')
		.click(function(e) {
			e.preventDefault();
			if (currentFontSize + 1 <= 5) {
				body.removeAttr('class');
				currentFontSize++;
				body.addClass('fs' + currentFontSize);
			}
			$.cookie('CT_FS', currentFontSize, { path: '/', expires: 365 });
		})
	;
	$('#fontChange .fontDec')
		.click(function(e) {
			e.preventDefault();
			if (currentFontSize - 1 >= 1) {
				body.removeAttr('class');
				currentFontSize--;
				body.addClass('fs' + currentFontSize);
			}
			$.cookie('CT_FS', currentFontSize, { path: '/', expires: 365 });
		})
	;
	$('#fontChange .fontDef')
		.click(function(e) {
			e.preventDefault();
			body.removeAttr('class');
			currentFontSize = defaultFontSize;
			body.addClass('fs' + currentFontSize);
			$.cookie('CT_FS', currentFontSize, { path: '/', expires: 365 });
		})
	;

	$('#servicesMenu .level2').prev('a').not('.clickable')
		.click(function(e) {
			e.preventDefault();
			$(this)
				.siblings('.level2')
					.slideUp(200)
				.end()
				.next('.level2')
					.slideToggle(200)
			;
		})
	;

	index = 1;
	setInterval("promoSlide(1)", 6000);
});