mbe = {

	animationSpeed: 'fast',
	searchPlaceHolder: 'Search in table',
	generalSearchUrl: 'dashboard_example.json',

	pbInterval: 0,
	showActions: false,
	showActionObject: false,
	showActionsTimeOut: 0,

	ready: function() {
		//init all the form elements
		mbe.init.form.all();

		//init the message boxes
		mbe.init.message.small();
		mbe.init.message.big();

		//init the login
		mbe.login.ready();

		//init the layout
		mbe.init.header();
		mbe.init.middle();
		mbe.init.footer();

		//init the blocks
		mbe.init.block();

		//init the tabs
		mbe.init.tab.horizontal();
		mbe.init.tab.vertical();

		//init the accordion
		mbe.init.accordion();

		//init the regular table
		mbe.init.table();

		//init the dataTable
		mbe.init.dataTable();

		//init the filter
		mbe.init.imageList();

		//init the fancybox
		mbe.init.fancybox();

		//init the graph
		mbe.init.graph.ready();

		//--- SHOULD BE DELETED
		mbe.presentation.ready();
		//--- END SHOULD BE DELETED

		//detect ipad
		if (mbe.agent.ipad() && !$('div.page').hasClass('login')) {
			mbe.mobile.ipad.ready();
		}

		//detect iphone / ipod
		if (navigator.userAgent.indexOf('iPhone')>=0 || navigator.userAgent.indexOf('iPod')>=0) {
			mbe.mobile.ipad.ready();
		}
	},

	agent: {
		ipad: function () {
			return navigator.userAgent.indexOf('iPad')>=0;
		}
	},

	init: {
		form: {
			all: function() {
				mbe.init.form.input();
				mbe.init.form.button();
				mbe.init.form.select();
				mbe.init.form.checkbox();
				mbe.init.form.radio();
				mbe.init.form.file();
				mbe.init.form.fieldset();
				mbe.init.form.wysiwyg();
				mbe.init.form.date();
			},
			validation: function(id) {
				if (id == undefined) {
					id = 'form';
				}
				$(id).validate({
					errorElement: 'small'
				});
			},
			input: function() {
				$('input[type="text"],input[type="password"]').uniform();
			},
			button: function() {
				$('input[type="button"],input[type="submit"]').each(function(){
					$(this).uniform({
						buttonClass: 'button '+$(this).attr('class')
					});
				});
			},
			select: function(selector) {
				if (selector == undefined) {
					selector = 'select';
				}
				$(selector).uniform();
			},
			checkbox: function() {
				$('input[type="checkbox"]').uniform();
			},
			radio: function() {
				$('input[type="radio"]').uniform();
			},
			file: function() {
				$('input[type="file"]').uniform({
					fileBtnClass: 'button'
				});
				$('.uploader .button').wrapInner('<span />');
				$('.uploader').hover(function(){
					$(this).find('.button').addClass('hover');
				},function(){
					$(this).find('.button').removeClass('hover');
				});
			},
			fieldset: function() {
				$('.page .block .content fieldset p:last').addClass('last');
			},
			wysiwyg: function() {
				$('textarea.wysiwyg').wysiwyg();
			},
			date: function() {
				$('input.date').jdPicker();
			}
		},
		message: {
			small: function() {
				//init small message close
				$('.message span.close').remove();
				$('.message').each(function(){
					if (!$(this).hasClass('no-close')) {
						$(this).append('<span class="close" title="Close">&nbsp;</span>');
					}
				});

				$('.message span.close ').unbind('click touchstart');
				$('.message span.close ').bind('click touchstart',function(e){
					e.preventDefault();

					$(this).closest('.message').fadeTo(mbe.animationSpeed, 0).slideUp(mbe.animationSpeed);
				});
			},
			big: function() {
				//init small message close
				$('.big-message span.close').remove();
				$('.big-message span.bg').remove();
				$('.big-message').each(function(){
					if (!$(this).hasClass('no-close')) {
						$(this).append('<span class="close" title="Close">&nbsp;</span>');
					}
				});
				$('.big-message').append('<span class="bg">&nbsp;</span>');


				$('.big-message span.close').unbind('click touchstart');
				$('.big-message span.close').bind('click touchstart',function(e){
					e.preventDefault();

					$(this).closest('.big-message').fadeTo(mbe.animationSpeed, 0).slideUp(mbe.animationSpeed);
				});
			}
		},
		header: function() {
			$('.page .header').wrapInner('<div class="wrapper" />');
			$('.page .header .wrapper').wrapInner('<div class="inner" />');

			$('.page .header ul li').hover(
				function(){
					$(this).children('ul').show();
					$(this).addClass('iehover');
				},function(){
					$(this).children('ul').hide();
					$(this).removeClass('iehover');
				});

			//to keeph the html clean and simple we add some html and classes from javascript
			$('.page .header .secondary-menu .user-menu').prepend('<div class="pointer">&nbsp;</div>');
			$('.page .header .secondary-menu .search-menu').prepend('<div class="pointer">&nbsp;</div>');
			$('.page .header .secondary-menu .user-menu ul.menu li:first').addClass('first');
			$('.page .header .secondary-menu .user-menu ul.menu li:last').addClass('last');
			$('.page .header .secondary-menu .user-menu ul.menu').prepend('<li class="separator">&nbsp;</li>');

			$('.page .header .secondary-menu a.user-menu-link').click(function(e){
				e.preventDefault();
				mbe.header.user.toggle();
			});

			$('.page .header .secondary-menu a.search-menu-link').click(function(e){
				e.preventDefault();
				mbe.header.search.toggle();
			});

			//bind shortcut
			var combination = 'ctrl+space';
			if ($.client.browser == 'Firefox' && $.client.os == 'Mac') {
				combination = 'alt+space';
			}
			$(document).bind('keydown', combination, function(e) {
				e.preventDefault();

				mbe.header.search.toggle();
			});
			if ($('#header-search-input').size()>0) {
				$('#header-search-input').bind('keydown',function(e){
					if (e.keyCode == 27) { //escape
						mbe.header.search.hide();
					}
				});
				$('#header-search-input').bind('focus',function(){
					$(this).select();
				});

				$('#header-search-input').val('');

				if (mbe.header.links.length <= 0) {
					mbe.header.links = [];
					$('.page .header ul.main-menu li a').each(function(){
						mbe.header.links.push({
							'label': $(this).text(),
							'value': $(this).attr('href'),
							'category': 'Admin Pages'
						});
					});
					$('.page .header ul.secondary-menu li .user-menu ul.menu li a').each(function(){
						mbe.header.links.push({
							'label': $(this).text(),
							'value': $(this).attr('href'),
							'category': 'User Pages'
						});
					});

					if (mbe.generalSearchUrl) {
						$.ajax({
							url: mbe.generalSearchUrl,
							dataType: 'json',
							data: null,
							success: function( elements ) {
								for (x in elements) {
									mbe.header.links.push(elements[x]);
								}
								$('#header-search-input').autocomplete('option', 'source', mbe.header.links);
							}
						});
					}
				}
				//autocomplete for search
				$('#header-search-input').autocomplete({
					source: mbe.header.links,
					delay: 0,
					select: function( event, ui ) {

						mbe.header.search.hide();
						window.location = ui.item.value;
						return false;
					},
					focus: function( event, ui ) {
						return false;

					},
					appendTo: $('.page.ipad').size()>0
						? '.page.ipad .sidebar ul.secondary-menu li .search-menu'
						: '.page .header ul.secondary-menu li .search-menu',
					autoFocus: true
				});
				$('#header-search-input').data('autocomplete')._renderMenu = function( ul, items ) {
					var self = this;

					var category = '';

					$.each( items, function( index, item ) {
						if (item.category == category) {
							item.writeCategory = '';
						} else {
							category = item.category;
							item.writeCategory = item.category;
						}
						self._renderItem( ul, item );
					});
				}
				$('#header-search-input').data('autocomplete')._renderItem = function( ul, item ) {
					return $( '<li></li>' )
						.data( 'item.autocomplete', item )
						.attr('role','menuitem')
						.append( '<a><span class="category">'+item.writeCategory+'</span><span class="label">'+item.label+'</span></a>' )
						.appendTo( ul );
				};

			}
		},
		footer: function() {
			$('.page .footer').wrapInner('<div class="wrapper" />');
			$('.page .footer .wrapper').wrapInner('<div class="inner" />');
		},
		middle: function() {
			//init the middle content
			if ($('.page .middle .wrapper').size()<=0) {
				$('.page .middle').wrapInner('<div class="wrapper" />');
				if (!$('.page .middle').hasClass('grid')) {
					$('.page .middle .wrapper').wrapInner('<div class="inner" />');
				}
			}
		},
		block: function() {

			$('.page .block .top ul li:first-child').addClass('first');
			$('.page .block .top ul li:last-child').addClass('last');

			$('.page .block.small .top').bind('tapOrClick',function(e){
				e.preventDefault();
				var block = $(this).closest('.block');

				block.toggleClass('closed');
				block.find('.content').slideToggle(mbe.animationSpeed);
			});
			$('.page .block.small.closed .content').hide();

			$('.page .block .top').each(function(){
				var block = $(this).closest('.block');

				if (!block.hasClass('small') && !block.is('.page.login .block')) {
					$(this).prepend('<div class="sl">&nbsp;</div><div class="sr">&nbsp;</div>');
				}

				if ($(this).find('input.search').size()>0) {
					$(this).addClass('with-search');
				}
			});
			$('.page .block .top input.search').focus(function(){
				if ($(this).val()==mbe.searchPlaceHolder) {
					$(this).val('');
				}
			});
			$('.page .block .top input.search').blur(function(){
				if ($(this).val()=='') {
					$(this).val(mbe.searchPlaceHolder);
				}
			});
		},
		tab: {
			horizontal: function() {

				$('.page .block .content ul.tab-header li a').each(function(){
					$(this).html('<span class="l">&nbsp;</span><span class="c">'+$(this).html()+'</span><span class="r">&nbsp;</span>');
				});
				$('.page .block .content .tab').hide();
				$('#'+$('.page .block .content ul.tab-header li a.active').attr('href')).show();

				$('.page .block .content ul.tab-header li a').touched(function(e){
					e.preventDefault();

					var tabs = $(e.currentTarget).closest('ul.tab-header');

					tabs.find('li a').removeClass('active');

					$(e.currentTarget).addClass('active');

					$('.page .block .content .tab').hide();
					$('#'+$(e.currentTarget).attr('href')).show();

					return false;
				});
			},
			vertical: function() {

				//init vertical tabs
				$('#'+$('.page .block .content .vertical-tabs .tab-list ul li.active a').attr('href')).show();
				$('.page .block .content .vertical-tabs .tab-list ul li.active').append('<span class="arrow">&nbsp;</span>');

				$('.page .block .content .vertical-tabs .tab-list ul li a').touched(function(e) {
					e.preventDefault();

					var tabs = $(e.currentTarget).closest('.vertical-tabs');

					tabs.find('.tab-list ul li.active').removeClass('active');
					tabs.find('.tab-list ul li.active span.arrow').remove();

					$(e.currentTarget).closest('li').addClass('active');
					$(e.currentTarget).closest('li').append('<span class="arrow">&nbsp;</span>');

					tabs.find('.right-tab').hide();
					$('#'+$(e.currentTarget).attr('href')).show();

					tabs.find('.tab-list').css('minHeight',0);
					tabs.find('.right-tab:visible').css('minHeight',0);

					var maxHeight = tabs.find('.tab-list').height()>tabs.find('.right-tab:visible').height()
						?tabs.find('.tab-list').height()
						:tabs.find('.right-tab:visible').height();

					tabs.find('.right-tab:visible').css('minHeight',maxHeight);
					tabs.find('.tab-list').css('minHeight',maxHeight + 10);

					console.log('MAX: '+maxHeight);
					console.log('left: '+tabs.find('.tab-list').height());
					console.log('right: '+tabs.find('.right-tab').height());

					return false;
				});

				$('.page .block .content .vertical-tabs').each(function(){
					var tabs = $(this);

					tabs.find('.tab-list').css('minHeight',0);
					tabs.find('.right-tab:visible').css('minHeight',0);

					var maxHeight = tabs.find('.tab-list').height()>tabs.find('.right-tab:visible').height()
						?tabs.find('.tab-list').height()
						:tabs.find('.right-tab:visible').height();

					tabs.find('.right-tab:visible').css('minHeight',maxHeight);
					tabs.find('.tab-list').css('minHeight',maxHeight + 10);
				});
			}
		},
		accordion: function() {
			$('.page .block .content .accordion').accordion({
				header: '.title'
			});
		},
		table: function() {

			$('.page .block .content .delete').bind('tapOrClick',function(e){
				if(!confirm('Are you sure you want to delete this item ?')){
					e.preventDefault();
				}
			});
			$('.page .block .content .table-actions').bind('tapOrClick',function(e){
				if(!confirm('Are you sure you want to apply these actions ?')){
					e.preventDefault();
				}
			});

			//init filter show/hide
			$('.page .block .content .filters .high').bind('tapOrClick',function(e){
				e.preventDefault();
				if ($.browser.msie) {
					$(this).closest('.filters').find('.low').toggle();
				} else {
					$(this).closest('.filters').find('.low').slideToggle(mbe.animationSpeed);
				}
			});

			//same height for filters
			$('.page .block .content .filters .low .filter').height($('.page .block .content .filters .low').height()-20);
		},
		dataTable: function() {
			$('table.data-table').dataTable({
				sPaginationType: 'full_numbers',
				sDom: '<"table-top"lf<"clear">>rt<"table-bottom"ip<"clear">>'
			});

			mbe.init.form.select('.page .block .content .dataTables_wrapper .table-top select');
		},
		fancybox: function() {
			$('a.fancybox').fancybox({
				centerOnScroll: true,
				onStart:function(items,index,opts) {
					var obj = $(items[index]).parent();
					if (obj.hasClass('drag_sort')) {
						obj.removeClass('drag_sort');
						return false;
					}
				}
			});
		},
		imageList: function() {
			//image hover
			$('.page .block .content ul.image-list li').mouseenter(function(){
				mbe.showActions = true;
				var _this = this;
				mbe.showActionObject = $(this).index('.page .block .content ul.image-list li');
				clearTimeout(mbe.showActionsTimeOut);
				mbe.showActionsTimeOut = setTimeout(function(){
					if(mbe.showActions){
						$('.page .block .content ul.image-list li:eq('+mbe.showActionObject+')')
							.children('ul').slideDown(mbe.animationSpeed);
					}
				}, 500)

				$(this).children('span.move').show();
			});
			$('.page .block .content ul.image-list li').mouseleave(function(){
				mbe.showActions =  false;
				$(this).children('span.move').hide();
				$(this).children('ul').slideUp(mbe.animationSpeed);
			});

			//image sortable
			$('.page .block .content ul.image-list').sortable({
				start: function(event, ui) {
					ui.item.addClass('drag_sort');
				},
				stop: function(event, ui) {
					$('.page .block .content ul.image-list li span.move').hide();
					$('.page .block .content ul.image-list li ul').hide();
					$('#'+$(this).attr('rel')).val($(this).sortable('toArray'));
					mbe.showActions =  true;
				},
				sort: function(event, ui) {
					 mbe.showActions =  false;
				},
				placeholder: 'ui-state-highlight'
			});
			$('.page .block .content ul.image-list').disableSelection();
		},
		graph: {
			themes: {
				'soft-green': ['#648E25', '#EE931A', '#e7c42d', '#e94d45'],
				'crimson-orange': ['#E95914', '#FECF4C', '#9A9A9A', '#648E25'],
				'soft-blue': ['#3D99B5', '#dcdcdc', '#e7c42d', '#e94d45'],
				'soft-red': ['#A72121', '#dcdcdc', '#9A9A9A', '#648E25'],
				'blue-gray': ['#66858E', '#dcdcdc', '#e7c42d', '#e94d45']
			},
			ready: function() {
				var currentTheme = mbe.getCurrentTheme();

				$('.visualize').remove();
				$('table.stats').css('width','100%');

				$('table.stats').each(function() {
					$(this).siblings('.visualize').remove();

					$(this).show();

					var dim=50;
					if(mbe.agent.ipad()){
						dim=175;
					}

					var width = $(this).width()-dim;


					$(this).hide();

					var statsType = '';

					if ($(this).attr('rel')) {
						statsType = $(this).attr('rel');
					} else {
						statsType = 'area';
					}

					if(statsType == 'line' || statsType == 'pie') {
						$(this).hide().visualize({
							type: statsType,	// 'bar', 'area', 'pie', 'line'
							width: width,
							height: '240px',
							colors: mbe.init.graph.themes[currentTheme],
							lineDots: 'double'
						});
					} else {
						$(this).hide().visualize({
							type: statsType,	// 'bar', 'area', 'pie', 'line'
							width: width,
							height: '240px',
							colors: mbe.init.graph.themes[currentTheme]
						});
					}
				});
			}
		}
	},
	header: {
		links: [],
		search: {
			show: function() {
				$('.page .header ul.secondary-menu li .search-menu,.page.ipad .sidebar ul.secondary-menu li .search-menu').fadeIn(mbe.animationSpeed);
				$('#header-search-input').select();
			},
			hide: function() {
				$('.page .header ul.secondary-menu li .search-menu,.page.ipad .sidebar ul.secondary-menu li .search-menu').fadeOut(mbe.animationSpeed);
			},
			toggle: function() {
				var element = $('.page .header ul.secondary-menu li .search-menu,.page.ipad .sidebar ul.secondary-menu li .search-menu');

				if (element.is(':visible')) {
					mbe.header.search.hide();
				} else {
					mbe.header.search.show();
				}
			}
		},
		user: {
			show: function() {
				$('.page .header ul.secondary-menu li .user-menu,.page.ipad .sidebar ul.secondary-menu li .user-menu').fadeIn(mbe.animationSpeed);
			},
			hide: function() {
				$('.page .header ul.secondary-menu li .user-menu,.page.ipad .sidebar ul.secondary-menu li .user-menu').fadeOut(mbe.animationSpeed);
			},
			toggle: function() {
				var element = $('.page .header ul.secondary-menu li .user-menu,.page.ipad .sidebar ul.secondary-menu li .user-menu');

				if (element.is(':visible')) {
					mbe.header.user.hide();
				} else {
					mbe.header.user.show();
				}
			}
		}
	},
	login: {
		ready: function() {

			//bind event to the forgot my password link
			$('.forgot-link').bind('tapOrClick',function(e){
				e.preventDefault();

				$('.block').rotate3Di(180, 300,{
					sideChange: function() {
						$('#login-form').hide();
						$('#forgot-form').show();
					}
				});

			});

			//bind event to the back to the login link
			$('.login-link').bind('tapOrClick',function(e){
				e.preventDefault();

				$('.block').rotate3Di(0, 300,{
					sideChange: function() {
						$('#login-form').show();
						$('#forgot-form').hide();
					}
				});

			});

			$('.page.login .block .content p:last-child').addClass('last-child'); /*IE FIX*/
		},
		shake: function() {
			var loginWindow = $('.login .block');

			var left = loginWindow.position().left>parseInt(loginWindow.css('margin-left'))
					? loginWindow.position().left
					: loginWindow.css('margin-left');
				loginWindow
					.css('margin-left',left)
					.effect('shake', null, 100);
		}

	},
	click: function(e) {
		if (!$(e.target).is('.page .header ul.secondary-menu li .user-menu')
			&& !$(e.target).is('.page .header ul.secondary-menu li .user-menu *')

			&& !$(e.target).is('.page.ipad .sidebar ul.secondary-menu li .user-menu')
			&& !$(e.target).is('.page.ipad .sidebar ul.secondary-menu li .user-menu *')

			&& !$(e.target).is('a.user-menu-link')
			&& !$(e.target).is('a.user-menu-link *')) {
			mbe.header.user.hide();
		}
		if (!$(e.target).is('.page .header ul.secondary-menu li .search-menu')
			&& !$(e.target).is('.page .header ul.secondary-menu li .search-menu *')
			&& !$(e.target).is('.page.ipad .sidebar ul.secondary-menu li .search-menu')
			&& !$(e.target).is('.page.ipad .sidebar ul.secondary-menu li .search-menu *')
			&& !$(e.target).is('a.search-menu-link')
			&& !$(e.target).is('a.search-menu-link *')) {
			mbe.header.search.hide();
		}
	},
	getCurrentTheme: function () {
		var
			classAttr = $('.page').attr('class'),
			classList = classAttr.split(/\s+/),
			currentTheme = '';
		for (var x in classList) {
			if (classList[x]!= 'page' && classList[x]!='fixed' && classList[x]!='liquid' && classList[x]!= '' && classList[x]!= 'ipad' && classList[x]!= 'iphone') {
				currentTheme = classList[x];
			}
		}
		if (currentTheme == '') {
			currentTheme = 'soft-green';
		}
		return currentTheme;
	},
	mobile: {
		scroll: 0,
		scrollMenu: 0,
		sidebarScroll: 0,
		ipad: {
			ready: function() {

				//add the ipad class
				$('div.page').addClass('ipad');

				//add the ipad css
				$('head')
					.append('<link rel="stylesheet" type="text/css" href="css/ipad.css" />')
					.append('<script type="text/javascript" src="js/iscroll/iscroll.js"></script>')
					.append('<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0" />')
					.append('<meta name="apple-mobile-web-app-capable" content="yes" />')
					.append('<meta name="apple-mobile-web-app-status-bar-style" content="black" />');

				//save the header html
				var
					html_footer = $('.page .footer').html(),
					html_header = $('.page .header .inner').html(),
					html_logo = '<h2>'+$('.page .header h2').html()+'</h2>',
					html_menu = '<ul class="main-menu">'+$('.page .header ul.main-menu').html()+'</ul>',
					html_secondary_menu = '<ul class="secondary-menu">'+$('.page .header ul.secondary-menu').html()+'</ul>';

				//remove the header
				$('.page .header').remove();
				$('.page .footer').remove();

				//make the html
				$('div.page').prepend('<div class="sidebar" id="iPadMenu">'+html_logo+html_secondary_menu+html_menu+'</div>');
				$('.page .sidebar').wrapInner('<div class="inner-wrapper"></div>');
				$('div.page').wrapInner('<div class="ipad-horizontal"></div>');
				$('.page .middle').wrapInner('<div class="inner" id="iPadMiddle"></div>');
				$('.page .middle #iPadMiddle .wrapper').append('<div class="footer">'+html_footer+'</div>');

				$('.page.ipad .sidebar ul').children('li').each(function(){
					if ($(this).is(':first-child')) {
						$(this).addClass('first');
						$(this).children('a').addClass('first');
					} else if ($(this).is(':last-child')) {
						$(this).addClass('last');
						$(this).children('a').addClass('last');
					} else {
						$(this).addClass('regular');
					}
				});

				//on resize (flexible box model)
				mbe.mobile.ipad.resize();
				$(window).resize(mbe.mobile.ipad.resize);

				//add the iscroll to the content
				mbe.mobile.scroll = new iScroll('iPadMiddle',{
					hScroll: false,
					bounce: false,
					useTransition: true,
					ignore: 'select,.page .block .content .accordion .title,.page .block .content .accordion .title *'
				});

				//add the iscroll to the sidebar
				mbe.mobile.scrollMenu = new iScroll('iPadMenu',{
					hScroll: false,
					bounce: false,
					useTransition: true
				});


				//refresh the iscroll when everything loads
				$(window).bind('load',function() {
					mbe.mobile.scroll.refresh();
					mbe.mobile.scrollMenu.refresh();
				});

				//add touch actions to the sidebar
				$('.page.ipad .sidebar .secondary-menu a.user-menu-link').bind('click',function(e){
					e.preventDefault();
				});

				$('.page.ipad .sidebar .secondary-menu a.user-menu-link').bind('tapOrClick', function(e){
					e.preventDefault();
					mbe.header.user.toggle();
				});

				$('.page.ipad .sidebar .secondary-menu a.search-menu-link').bind('click',function(e){
					e.preventDefault();
				});

				$('.page.ipad .sidebar .secondary-menu a.search-menu-link').bind('tapOrClick', function(e){
					e.preventDefault();
					mbe.header.search.toggle();
				});

				$('.page.ipad .sidebar ul.main-menu li a').bind('click',function(e){
					e.preventDefault();
				});

				$('.page.ipad .sidebar ul.main-menu li a').bind('tapOrClick',function(e){

					if($(e.currentTarget).siblings('ul').size()>0){

						$(e.currentTarget).siblings('ul').slideToggle(mbe.animationSpeed, function(){
							mbe.mobile.scrollMenu.refresh();
						});

					} else {
						var url = $(e.currentTarget).attr('href');
						window.location = url;
					}
				});



				$('.page.ipad .sidebar ul.main-menu li a').bind('touchstart mousedown',function(e) {
					$(this).addClass('touched');
				});
				$('.page.ipad .sidebar ul.main-menu li a').bind('touchmove mousemove touchend mouseup mouseout',function(e) {
					$(this).removeClass('touched');
				});


				$('.page.ipad .sidebar ul.secondary-menu li .search-menu ul.ui-autocomplete').remove();

				//reinit the header so the autcomplete would work and everything
				mbe.init.header();
			},
			resize: function() {
				var
					window_height = $(window).height(),
					footer_height = 0,
					window_width = $(window).width(),
					sidebar_width = 250;
				var
					middle_height = window_height - footer_height,
					middle_width = window_width - sidebar_width;

				//$('.page .middle .inner').width(middle_width);

				$('.page .sidebar').height(middle_height);
				$('.page .middle #iPadMiddle').height(middle_height);
			}
		}
	},
	presentation: {
		ready: function() {
			mbe.init.form.validation('form#test-validate-form');

			//login form should not submit unless something is entered
			$('form#login-form').submit(function(e){
				var vars = $(this).serializeArray();
				var shouldContinue = true;
				for (x in vars) {
					if (vars[x].value=='') {
						shouldContinue = false
					}
				}
				if (!shouldContinue) {
					e.preventDefault();
					$(this).find('.message').remove();
					$(this).prepend('<div class="message error">Do not leave the fields empty</div>');

					mbe.init.message.small();
					mbe.login.shake();
				}
			});

			//progress bar init
			$('.page .content .progress-bar .progress').progressbar({
				value:23
			});
			$('.page .content .progress-bar .percentage').html('23%');
		},
		progressBarSimulate:function(){
			$('.page .content .progress-bar .progress').progressbar({value:23});
			$('.page .content .progress-bar .percentage').html('23%');

			mbe.pbInterval = setInterval(function(){
				var element = $( '.page .content .progress-bar' );
				var value = element.find('.progress').progressbar('option','value');
				if (value < 100) {
					value++;
					element.find('.progress').progressbar('option','value',value);
					element.find('.percentage').html(value+'%');
				} else {
					clearInterval(mbe.pbInterval);
				}
			},30);
		}
	}
}
$(mbe.ready);
$(document).bind('click touchstart',mbe.click);
