$(document).ready(function() {
	$("#layout_top_selector").msDropDown({
		height:325,
		visibleRows:9
	});
	if (_isIE(7)) {
		if ($('.rounded_box') && $('.rounded_box').length > 0) {
			$('.rounded_box .middle .right').css('height', $('.rounded_box .middle').height());
		}
	}
});

function switchLanguage(lang) {
	if (lang) {
		if (window.location.href.indexOf('?lang') >= 0) {
			window.location.href = window.location.href.replace(/\?lang=(.*)/gi, '?lang=' + lang);
		} else {
			window.location.href = window.location.href + '?lang=' + lang;
		}	
	}
}

function matchBoxHeight(myBox, sampleBox, adjustment) {
	!adjustment && (adjustment = 0);
	var myObj = $('#'+myBox); 
	var myHeight = myObj.height();
	var sampleHeight = $('#'+sampleBox).height();
	var finalHeight = sampleHeight + adjustment;
	if (myHeight < sampleHeight) {
		myObj.height(finalHeight);
	}
}

function _isIE(version) {
	if (version) {
		return $.browser.msie && parseInt($.browser.version, 10) == version ? true : false;
	}	
	return $.browser.msie ? true : false;
}

function adjustTextSize(adjustment, isReset) {
	$('div.text p, ul.news li span').each(function(i, o) {
    	var size = parseInt($(o).css('font-size'));
    	size = isReset ? 14 : eval(size + adjustment);
		size < 11 && (size = 11);
		size > 19 && (size = 19);
    	$(o).css('font-size', size+'px');
    });
}

function validateEmail(email) {
	// from http://docs.jquery.com/Plugins/Validation/validate
	return /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test(email);
}

function notifyUser(errorMessage, errorLevel, timeout) {
	$('#userNotification').remove();
	var message = $('<div />').css({
		'padding':'10px',
		'font-size':'14px',
		'text-align':'center'
	}).html(errorMessage);
	var holder = $('<div />').css({
		'position':'absolute',
		'top':'-1000px',
		'left':'0px',
		'width':'100%',
		'overflow':'hidden',
		'z-index':'11000'
	}).attr('id', '	').append(message);
	switch (errorLevel) {
		case 1: // Notice
			holder.css({'background':'#F4F4F4','color':'#707070'});
			break;
		case 2: // Success
			holder.css({'background':'#339933','color':'white'});
			break;
		default: // Error
			holder.css({'background':'red','color':'white'});
			break;
	}
	$('body').append(holder);
	var adjustment = 0;
	if ($('#bottomToolbar') && $('#bottomToolbar').length > 0 && $('#bottomToolbar').is(':visible')) { // We have a bottom bar, let's display it ABOVE - this is for calendar & foto wizards
		adjustment = $('#bottomToolbar').outerHeight(); 
	}
	holder.css('top', $(window).scrollTop() + $(window).height() - message.height() - 20 - adjustment + 'px');
	!timeout && (timeout = 7000);
	holder.fadeOut(timeout);
	$(window).scroll(function () {
		holder.css('top', $(window).scrollTop() + $(window).height() - message.height() - 20 - adjustment + 'px'); 
	});
}

function blockUI(style) {
	$.blockUI({
    	overlayCSS: { backgroundColor:'#FFF', opacity:0.8 },
    	css: { backgroundColor:'#fff', color:'#000', border:'none', position:'absolute', bottom:0, top:'none', left:0, width:'100px' },
    	message: '<img src="/pub/images/block_ui.gif" />'
	}); 
}	
