<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
    ___   __                  _ __
   /   | / /_____ ___  ____ _(_) /
  / /| |/ __/ __ `__ \/ __ `/ / / 
 / ___ / /_/ / / / / / /_/ / / /  
/_/  |_\__/_/ /_/ /_/\__,_/_/_/

(C) Atmail Pty Ltd http://atmail.com/
-->
<?php 
		$this->dbAdapter = Zend_Registry::get('dbAdapter');
	$language = $this->dbAdapter->fetchAll("SELECT Language From UserSettings where Account = ?", array($this->account));
										
		$currentLang = $language[0]['Language'];
?>

<html xmlns="http://www.w3.org/1999/xhtml" lang="<?php echo $currentLang;?>">
<head>
	<?php $this->pluginCall("startHeadTag") ?>
	<meta name="robots" content="noindex, follow" />
	<meta http-equiv="X-UA-Compatible" content="IE=9" />
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<title><?php echo $this->account; ?> - <?php echo $this->translate('Webmail') ?></title>
	
	<?php $version = Zend_registry::get('config')->global['version'] ?>
	
	<!--[if lte IE 6]>
		<script type="text/javascript" src="<?php echo $this->siteBaseUrl; ?>js/dd_png.js?<?php echo $version ?>"></script>
		<script type="text/javascript" src="<?php echo $this->siteBaseUrl; ?>js/pngfix_selectors.js?<?php echo $version ?>"></script>
	<![endif]-->
	
	<link rel="stylesheet" href="<?php echo $this->siteBaseUrl; ?>css/calendar.css?<?php echo $version; ?>" type="text/css" media="screen, print" />
	<link rel="stylesheet" href="<?php echo $this->siteBaseUrl; ?>css/ui.css?<?php echo $version; ?>" type="text/css" media="screen, print" />
	<link rel="stylesheet" href="<?php echo $this->siteBaseUrl ?>css/webmail.css?<?php echo $version; ?>" type="text/css" media="screen, print" />
	<link rel="stylesheet" href="<?php echo $this->siteBaseUrl ?>css/storage.css?<?php echo $version; ?>" type="text/css" media="screen, print" />
<?php if( $this->serviceProvidersEnabled && $this->SIPEnabled && $this->selectedSIPAccount !== null ) : ?>
	<link rel="stylesheet" href="<?php echo $this->siteBaseUrl ?>css/templates.css?<?php echo $version; ?>" type="text/css" media="screen, print" />
	<link rel="stylesheet" href="<?php echo $this->siteBaseUrl ?>css/ucplus.css?<?php echo $version; ?>" type="text/css" media="screen, print" />
	<link rel="stylesheet" href="<?php echo $this->siteBaseUrl ?>css/webphone.css?<?php echo $version; ?>" type="text/css" media="screen, print" />
<?php endif ?>

	<!-- THEME STYLES -->
	<?php 

		$settings = Zend_Registry::get('UserSettings');
		$themePath = $settings['cssStyleTheme'];
		$autoReload = $settings['AutoReload'];

	?>
	
	<!-- branding specific CSS -->
	<link rel="stylesheet" href="<?php echo $this->siteBaseUrl ?>css/welcome.css?<?php echo $version; ?>" type="text/css" media="screen" />
	

	<?php if (file_exists(APP_ROOT . "css/themes/$themePath/calendar.css")): ?>
	<link rel="stylesheet" href="<?php echo $this->siteBaseUrl ?>css/themes/<?php echo $themePath ?>/calendar.css?<?php echo $version; ?>" type="text/css" media="screen" />
	<?php endif; ?>
	<?php if (file_exists(APP_ROOT . "css/themes/$themePath/ui.css")): ?>
	<link rel="stylesheet" href="<?php echo $this->siteBaseUrl ?>css/themes/<?php echo $themePath ?>/ui.css?<?php echo $version; ?>" type="text/css" media="screen" />
	<?php endif; ?>
	<?php if (file_exists(APP_ROOT . "css/themes/$themePath/webmail.css")): ?>
	<link rel="stylesheet" href="<?php echo $this->siteBaseUrl ?>css/themes/<?php echo $themePath ?>/webmail.css?<?php echo $version; ?>" type="text/css" media="screen" />
	<?php endif; ?>
	<?php if (file_exists(APP_ROOT . "css/themes/$themePath/admin.css")): ?>
	<link rel="stylesheet" href="<?php echo $this->siteBaseUrl ?>css/themes/<?php echo $themePath ?>/admin.css?<?php echo $version; ?>" type="text/css" media="screen" />
	<?php endif; ?>
	
	
	<link rel="stylesheet" href="<?php echo $this->siteBaseUrl ?>css/fullcalendar.css?<?php echo $version; ?>" type="text/css" media="screen, print" />	
	<link rel="stylesheet" href="<?php echo $this->siteBaseUrl ?>css/edit_calendar.css?<?php echo $version; ?>" type="text/css" media="screen, print" />
	<link rel="stylesheet" href="<?php echo $this->siteBaseUrl ?>css/scheduler.css?<?php echo $version; ?>" type="text/css" media="screen, print" />
	<link rel="stylesheet" href="<?php echo $this->siteBaseUrl ?>css/scheduler_attendee.css?<?php echo $version; ?>" type="text/css" media="screen, print" />
	
	<?php if($this->iOS == true) :?>
        <meta name="viewport" content="width=600, initial-scale=1.10, user-scalable=0, minimum-scale=1.10, maximum-scale=1.10">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" href="<?php echo $this->siteBaseUrl ?>css/mobile/ios.css?<?php echo $version; ?>" type="text/css" media="screen"  />
		<link rel="stylesheet" href="<?php echo $this->siteBaseUrl ?>css/mobile/ios-portrait.css?<?php echo $version; ?>" type="text/css" media="all and (orientation:portrait)"  />
  	<?php endif ?>

	<!--[if IE]>
	<?php if (file_exists(APP_ROOT . "css/themes/$themePath/ie.css")): ?>
	<link rel="stylesheet" href="<?php echo $this->siteBaseUrl ?>css/themes/<?php echo $themePath ?>/ie.css?<?php echo $version; ?>" type="text/css" media="screen" />
	<?php endif; ?>
	<![endif]-->
	<!--[if IE 7]>
	<?php if (file_exists(APP_ROOT . "css/themes/$themePath/ie7.css")): ?>
	<link rel="stylesheet" href="<?php echo $this->siteBaseUrl ?>css/themes/<?php echo $themePath ?>/ie7.css?<?php echo $version; ?>" type="text/css" media="screen" />
	<?php endif; ?>
	<![endif]-->
	<!--[if IE 8]>
	<?php if (file_exists(APP_ROOT . "css/themes/$themePath/ie8.css")): ?>
	<link rel="stylesheet" href="<?php echo $this->siteBaseUrl ?>css/themes/<?php echo $themePath ?>/ie8.css?<?php echo $version; ?>" type="text/css" media="screen" />
	<?php endif; ?>
	<![endif]-->
	
	<!-- php compatible js functions (htmlentities etc) -->
	<script type="text/javascript" language="JavaScript" src="<?php echo $this->moduleBaseUrl ?>/index/jstranslate/<?php echo $version; ?>"></script>
	<script type="text/javascript" language="JavaScript" src="<?php echo $this->siteBaseUrl ?>js/php.js"></script>
	<script type="text/javascript" language="JavaScript" src="<?php echo $this->siteBaseUrl ?>js/rounded_corners.inc.js"></script>

	<!-- jQuery -->
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/jquery-1.3.2.min.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/ui/jquery-ui-1.7.2.custom.min.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.autocomplete.js"></script> 
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.simpletreeview.js"></script> 
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.json-1.3.min.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.jcacher-1.0.0.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.php.pack.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.flash.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.corners.min.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.ajaxupload.3.9.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.disable.text.select.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.highlight-3.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.single-ddm.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/GrowingInput.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/TextboxList.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/TextboxList.Autocomplete.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/TextboxList.Autocomplete.Binary.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.spellchecker.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.rte.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.blockUI.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.bgiframe.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.dimensions.pack.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.scrollTo-min.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/iphone-style-checkboxes.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.simpletreeview.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.stronglastword.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.ba-resize.min.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.simplemodal.js"></script>
<?php /*	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/confirm.js"></script> */ ?>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.qtip-1.0.0-rc3.min.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.wysiwyg.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.colorpicker.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.autoresize.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.slider.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.mousewheel.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.timeago.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.spritely.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.jplayer.min.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.jscrollpane.min.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.cookie.js?<?php echo $version ?>"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.dnd-file-upload.js?<?php echo $version ?>"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.countdown.pack.js"></script> 
	



	<!-- 
	TODO: Implement keyboard shortcuts
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.hotkeys-0.7.8-packed.js"></script>
	-->

	<!-- Atmail specific files -->
	<script type="text/javascript">	
	function getSelectedCallFolder(){ return false; }
  var AJAXREQ = 0;
	// Global JS name for script access
	var siteBaseUrl 	= "<?php echo $this->siteBaseUrl ?>";
	var moduleBaseUrl	= "<?php echo $this->moduleBaseUrl ?>";

		// HACK FOR EXPERIMENTAL CALENDAR UI
	var todaysDate = new Date()
	var clientIP =  "<?php echo $_SERVER['REMOTE_ADDR']?>";

	// IS GD ENABLED
	<?php 
	if(!function_exists("gd_info")) {
		echo "var gd_enabled = 0;";
	}
	else {
		echo "var gd_enabled = 1;";
	}
	?>

   	var search_timeout = 0;

    var atmailDateFormat = "<?php echo $settings['DateFormat'] ?>";
    
<?php $debugEnabled = isset(Zend_Registry::get('config')->global['debug'])? (Zend_Registry::get('config')->global['debug']?true:false):false; ?>
	var debugEnabled = <?php echo $debugEnabled?'true':'false' ?>;

	function iOS()
	{
		iOSflag = "<?php echo $this->iOS ?>";
		return iOSflag=='1'? true : false
	}

	</script>
	
	<script type="text/javascript" language="JavaScript" src="<?php echo $this->siteBaseUrl ?>js/atmail/mail/mail.js?<?php echo $version; ?>"></script>
	<script type="text/javascript" language="JavaScript" src="<?php echo $this->siteBaseUrl ?>js/atmail/mail/viewmessage.js?<?php echo $version; ?>"></script>
	<script type="text/javascript" language="JavaScript" src="<?php echo $this->siteBaseUrl ?>js/atmail/mail/templateEngine.js?<?php echo $version; ?>"></script>
	<script type="text/javascript" language="JavaScript" src="<?php echo $this->siteBaseUrl ?>js/atmail/abook/abook.js?<?php echo $version; ?>"></script>
	<script type="text/javascript" language="JavaScript" src="<?php echo $this->siteBaseUrl ?>js/atmail/calendar/calendarCache.js?<?php echo $version; ?>"></script>
	<script type="text/javascript" language="JavaScript" src="<?php echo $this->siteBaseUrl ?>js/atmail/calendar/quickview.js?<?php echo $version; ?>"></script>
	<script type="text/javascript" language="JavaScript" src="<?php echo $this->siteBaseUrl ?>js/atmail/calendar/calendar.js?<?php echo $version; ?>"></script>
	<script type="text/javascript" language="JavaScript" src="<?php echo $this->siteBaseUrl ?>js/atmail/calendar/fullcalendar.js?<?php echo $version; ?>"></script>
	<script type="text/javascript" language="JavaScript" src="<?php echo $this->siteBaseUrl ?>js/atmail/calendar/minicalendar.js?<?php echo $version; ?>"></script>
	<script type="text/javascript" language="JavaScript" src="<?php echo $this->siteBaseUrl ?>js/atmail/calendar/edit_calendar.js?<?php echo $version; ?>"></script>
	<script type="text/javascript" language="JavaScript" src="<?php echo $this->siteBaseUrl ?>js/atmail/files/files.js?<?php echo $version ?>"></script>
	
	<!-- Calendar alarm qTip -->
	<div id="alarmholder"></div>
	<?php if( $this->serviceProvidersEnabled && $this->SIPEnabled && $this->selectedSIPAccount !== null ) require_once('webphone.phtml'); ?>
	
	<!-- Welcome qTip -->
	<div id="welcomeholder"></div>
	<?php $this->pluginCall('welcomeMessageHtml'); ?>

	<!-- Fav icon -->
	<?php 	
		$favicon = getFavicon(Zend_registry::get('config')->global['install_dir'], $this->siteBaseUrl);
	?>
	<link id='favicon' rel="shortcut icon" href="<?php echo $favicon; ?>" type="image/x-icon" />

	<!-- Safari -->
	<script type="text/javascript">
	ua = navigator.userAgent.toLowerCase();
	if ( ua && ua.indexOf("safari") != -1 ) {
		document.write('<link rel="stylesheet" href="<?php echo $this->siteBaseUrl ?>css/safari.css?<?php echo $version ?>" type="text/css">')
	}
	</script>
	
	<!-- Highlight Search Bar -->
	<script type="text/javascript">
	$(document).ready(function(){
		$("#searchQuery").bind("focus", function() {
			$(this).parent().removeClass("searchFormDiv").addClass("searchFormFocus")
		});
		$("#searchQuery").bind("blur", function() {
			$(this).parent().removeClass("searchFormFocus").addClass("searchFormDiv")
		});
	});
	</script>
	
	<script type="text/javascript">	
	
	// Tab control
	var lastTabNumber = 0;

	// keyboard access globals
	var ENTER_KEY = 13;
	var ESC_KEY   = 27;

<?php $tabNumber = 0; ?>
	var WEBMAIL_TAB_ID 	= <?php echo $tabNumber++ ?>;
	var ABOOK_TAB_ID 	= <?php echo $tabNumber++ ?>;

<?php if( $this->group['Calendar'] == '1' ) : ?>
	var CALENDAR_TAB_ID = <?php echo $tabNumber++ ?>;
<?php endif ?>

<?php if( $this->group['WebDavEnabled'] == '1' &&  $this->group['StorageTabEnabled'] == '1') : ?>
	var FILES_TAB_ID 	= <?php echo $tabNumber++ ?>;
<?php endif ?>

	var SETTINGS_TAB_ID = <?php echo $tabNumber++ ?>;

<?php if( $this->group['Calendar'] != '1' ) : ?>
	var CALENDAR_TAB_ID = <?php echo $tabNumber++ ?>;
<?php endif ?>

<?php if( $this->group['WebDavEnabled'] != '1' ||  $this->group['StorageTabEnabled'] != '1') : ?>
	var FILES_TAB_ID 	= <?php echo $tabNumber++ ?>;
<?php endif ?>
	
	// drop down menu		
	var timeout = 500;
	var ddmenuitem = 0;
	var firstclick = 0;
	var jsddm_target = 0;
	
	// error flash
	var flashTimeout 	= null;
	
	// configure timeago
	jQuery.timeago.settings.strings.seconds = '<?php echo "< 1 " . addslashes($this->translate("min")) ?>';
	jQuery.timeago.settings.strings.minute = '<?php echo "1 " . addslashes($this->translate("min")) ?>';
	jQuery.timeago.settings.strings.minutes = '<?php echo "%d " . addslashes($this->translate("mins")) ?>'; 
	jQuery.timeago.settings.strings.hour = '<?php echo "1 " . addslashes($this->translate("hour")) ?>';
	jQuery.timeago.settings.strings.hours = '<?php echo "%d " . addslashes($this->translate("hours")) ?>';
	jQuery.timeago.settings.strings.day = '<?php echo "1 " . addslashes($this->translate("day")) ?>';
	jQuery.timeago.settings.strings.days = '<?php echo "%d " . addslashes($this->translate("days")) ?>';
	jQuery.timeago.settings.strings.month = '<?php echo "1 " . addslashes($this->translate("month")) ?>';
	jQuery.timeago.settings.strings.months = '<?php echo "%d " . addslashes($this->translate("months")) ?>';
	jQuery.timeago.settings.strings.year = '<?php echo "1 " . addslashes($this->translate("year")) ?>';
	jQuery.timeago.settings.strings.years = '<?php echo "%d " . addslashes($this->translate("years")) ?>';
	jQuery.timeago.settings.strings.suffixAgo = '<?php echo addslashes($this->translate("ago")) ?>';
	
	loadCount = 0;
	loadTimeoutArray = new Array();
	loadTimeout = 30 * 1000; // after 30 seconds, assume timeout operation.
	
	// Add the loading div
	function showLoadingIconInVisibleContext()
	{
		visiblePanelContext = $('.ui-tabs-selected a', 'div#nav').attr('href');
		$('#primary_header', visiblePanelContext).addClass('loading');
		if(typeof(loadTimeoutArray[loadCount]) != "undefined")
		{
			clearTimeout(loadTimeoutArray[loadCount]);
			delete loadTimeoutArray[loadCount];
		}
		loadTimeoutArray[loadCount] = setTimeout( hideAllLoadingIcons, loadTimeout);
		
		loadCount++;
	}   

	function updateTabCaption(tabName, newCaption)
	{
		$('li[name=' + tabName + '] > a > span', 'ul#navMessages').html(newCaption);
	}

	function hideAllLoadingIcons()
	{
		loadCount --;

		if(loadCount < 0)
		{
			loadCount = 0;
		}

		if(typeof(loadTimeoutArray[loadCount]) != "undefined")
		{
			clearTimeout(loadTimeoutArray[loadCount]);
			delete loadTimeoutArray[loadCount];
		}
		
		if(loadCount==0)
		{
			$('.loading').removeClass('loading');
		}
	}
	
	php.beforeSend = function ()
	{
		showLoadingIconInVisibleContext()		
	}

	php.complete = function(XMLHttpRequest)
	{ 
		hideAllLoadingIcons();
	 	setFocusableElements();
    setEmailContextTabOrder();
	}

	$("body").bind("ajaxSend", function()
	{
		showLoadingIconInVisibleContext()
	}).bind("ajaxComplete", function()
	{
		hideAllLoadingIcons();
	});
	
	// Drop down menu functions
	function jsddm_open(e)
	{
	   if(e.type == 'mousedown' || (e.type == 'keypress' || e.type == 'keydown' && e.which == ENTER_KEY)){
			if(ddmenuitem){
			  ddmenuitem.css('visibility', 'hidden')
			}
			if( $(this).children('a').hasClass('disabled') )
				return;
			ddmenuitem = $(this).find('ul').eq(0).css('visibility', 'visible');
			jsddm_target = e.target.firstElementChild;
			var left = Math.round($(this).offset().left - 8) + 'px';
			// Must manually set !important, to get the more button to display on the right position for different UI languages
			ddmenuitem.css("cssText", "visibility:visible; position: absolute; left: " + left + " !important; display:block;");

			firstclick = 1;
	  }

	}
	
	function jsddm_close()
	{
		if(ddmenuitem){
			ddmenuitem.css('visibility', 'hidden');
			ddmenuitem.css('display', 'none');
			
    }
	}
	
	function jsddm_timer()
	{
	}   
	
	function jsddm_canceltimer()
	{
	}
	document.onclick = function () 
	{ 
		
		if( firstclick != 1 ) 
		{ 
			
			jsddm_close(); 
			
		} 
		firstclick = 0;
		
	};
	
	function refreshAccountPhoto()
	{
		$('.account-dropdown .contact-photo img').attr('src', "<?php echo $this->moduleBaseUrl ?>/contacts/viewphoto/id/-1000/resize/1/" + Math.round(Math.random() * 9999));
	}

	function displaySessionTimeout()
	{
		window.location.replace("<?php echo $this->siteBaseUrl ?>index.php/default/index/sessiontimeout");
	}

	function toggleColorTheme(color)
	{
		var url = "<?php echo $this->moduleBaseUrl; ?>/settings/webmailsave";
		var postData = {
			"fields[cssColorTheme]" : color,
			save : 1
		}

		$.getJSON(url, postData);
	}

	$( function() {

<?php if( config::generateLogo('webmail') ) :?>
		var src = "<?php echo $this->siteBaseUrl; ?>" + "index.php/default/index/logo?" + "<?php echo '' . rand(0, 9999); ?>"
		// $('h3.branding a', '#header').css('background', 'url("' + src + '") no-repeat scroll 17px 12px #FFFFFF');
<?php endif ?>


		$('.menu_drop_more', '#account-options').bind('mouseleave', function() { setTimeout(jsddm_close, 500); });
        $('.menu_drop_more', '#account-options').bind('blur',function(){ setTimeout(jsddm_close, 250); });
		
		$("#nav_secondary a, #actions a, #header a").bind("contextmenu",function(e){ e.preventDefault(); return false;  }); //prevent right click (opening new windows or tabs breaks the UI)
		
		// check if browser >= IE7
		// and ensure that the browser is not actually ie7 or ie8 reporting that its ie6
		if ($.browser.msie && $.browser.version < 8 && navigator.userAgent.indexOf("MSIE 8.0") == -1 && navigator.userAgent.indexOf("MSIE 9.0") == -1) 
		{
			window.location.replace("<?php echo $this->siteBaseUrl ?>index.php/default/index/ie6");
		}
	
		// open account options dd
		$('.account-dropdown #jsddm > li').bind('mousedown', jsddm_open);
		$('.account-dropdown .contact-photo img').bind('click', function() {
			$('.account-dropdown #jsddm > li').trigger('mousedown');
		});
		
		$('.account-dropdown .contact-photo img').keydown(function(e) {
			if(e.which==ENTER_KEY){
		  	$('.account-dropdown #jsddm > li').trigger('mousedown');
			}
		});
		
		// set the body to trap <esc> and close menus
 		$('body').keydown(function(e){
			if(e.which == ESC_KEY){
				rcvr = document.activeElement;

				if(ddmenuitem  && ddmenuitem.is(":visible") ){
					rcvr.blur();
					$(jsddm_target).focus();
					ddmenuitem.css('visibility','hidden') ;
				}
			  
	    	if($('#advSearch').is(":visible")){
					if( $(rcvr,'#advSearch').length == 1 ) {
						$('#search_anything .drop-arrow-search').focus();
					}
			    $('#search_anything #advSearch').slideUp();
			  }

				if($('#nodeActionsDropdown').css('display') == "block"){
					$('#nodeActionsDropdown').css('display','none');
				}
		  }
		});
		// hide calendar if not enabled
		<?php
		$configGlobal = Zend_registry::get('config')->global;
		if ( isset($this->group['Calendar']) && $this->group['Calendar'] != '1')
		{
		?>
		
			$('#newContactButton').parent().addClass('bottom');
			$('#newEventButton').hide();
			$('#nav_cal').hide();
			//$('#navMessages','#navMessages').css({left: parseInt($('#navMessages','#navMessages').css('left')) - $('#nav_cal').width()}); //N.B. ul#navMessages not supported by IE7 // $('ul#navMessages').css('left') = 'auto' (bad)
		<?php
		}
		unset($configGlobal);
		?>
		
		//position #navMessages after #nav_set (settings)
		$('#navMessages','#navMessages').css({left: parseInt($('#nav_set').position().left) + parseInt($('#nav_set').width()) });
		
		// allow 

		function unbind_search()
		{
			$('#searchQuery').unbind('keyup');
			$('#searchForm').unbind('submit');
			$('.adv-srch-btns').find('input').unbind('submit')
		}
		
		function showAdvSearch(){
		  isOpening = false;
			if( !$('#search_anything #advSearch').is(":visible") )
			{
				$('#search_anything #advSearch').slideDown(400,function(){ 
					 $("select[name=goBack]").focus();
					setFocusableElements();
					setEmailContextTabOrder();
				  isOpening = true;
				});
			}
			else if( isOpening==false ){
				$('#search_anything #advSearch').hide();
			}
		}
		
		function handle_search(obj, type)
		{
			if(type == 'focus')
			{
				if( obj.val().indexOf('...') >= 0)
				{
					obj.data('original', obj.val());
					obj.val('');
				}	
			}
			else
			{
				if( obj.val() == '')
				{
					obj.val(obj.data('original'));
				}	
			}
		}
		$('div#nav').tabs({
			select: function(event, ui) 
			{
			},
			show: function(event, ui) 
			{
			  if(ui.index == 4){
					$('#skip-link').css('margin-left','-100px');
				} else {
					$('#skip-link').css('margin-left','-360px');
				}

				$("ul#nav a[id$='-tab']").attr('aria-selected',"false");
				$("#"+ui.tab.id).attr('aria-selected',"true");

				var searchQueryObj = $('#search_anything #searchQuery');
				searchQueryObj.unbind('focus');
				searchQueryObj.unbind('blur');
				
				if(ui.index == WEBMAIL_TAB_ID)
				{
					var dropArrowObj = $('#search_anything .drop-arrow-search');
					dropArrowObj.unbind('click');
					dropArrowObj.bind('click', showAdvSearch )
					dropArrowObj.keydown( function(e){ 
					  if(e.which==ENTER_KEY){ 
						  $(this).trigger('click'); 
							$(this).blur();
						} 
					} );
					
					dropArrowObj.show();
					
					$("#search_anything #advSearch").hover(
						function()
						{
							$(this).data("in", true);
						},
						function()
						{
							$(this).removeData("in");
						}
					);
				
					searchQueryObj.bind('blur', function ()
					{
						handle_search($(this), 'blur');
						if(!$('#search_anything #advSearch').data('in'))
						{
							$('#search_anything #advSearch').slideUp();
						}
					});
				}
				else
				{
					$('#search_anything .drop-arrow-search').hide();
				}
				searchQueryObj.bind('focus', function ()
				{
					handle_search($(this), 'focus');
					$(this).select();
				});
				searchQueryObj.bind('blur', function ()
				{
					handle_search($(this), 'blur');
				});

				selector = $('#search_anything #searchQuery');
				$searchUnused = selector.length ? (selector.val().indexOf("<?php echo $this->translate('Search'); ?>")!=-1 || selector.val() == '') : true;
				var myFavicon = '';

				// close popup from calendar if displayed
				if($('#Calendar').data("qtip"))
				{
					$(".qtip-contentWrapper").unblock();
					$('#Calendar').qtip("hide");
				}
				switch( ui.index )
				{
					
					case WEBMAIL_TAB_ID:
					{
						var autoreload = <?php echo (($autoReload & Atmail_Enum::AUTORELOAD_FAVICON) ? 'true' : 'false'); ?>;
						if(autoreload && $('#Email .messageItem[new=true] .unread, #Email .mail_row[new=true] .unread').length != 0)
						{
							myFavicon = '<?php echo getFavicon(Zend_registry::get('config')->global['install_dir'], $this->siteBaseUrl, 'newemail'); ?>';
						}
						else
						{
							myFavicon = '<?php echo getFavicon(Zend_registry::get('config')->global['install_dir'], $this->siteBaseUrl, 'email'); ?>';
						}
						
						document.title = "<?php echo addslashes($this->account) ?> - <?php echo addslashes($this->translate('Webmail')) ?>";
		
						//TODO: refactor quick fix for non-conext aware search method bound on abook tab
						unbind_search();
						
						$('#searchForm').bind('submit', function(e) 
						{
							
							e.stopPropagation();
							e.preventDefault();
							if(getSelectedCallFolder() == 'SMS')
							{
								searchCallLog();
							}
							else
							{
								searchMail();
							}
							return false;
							
						});
						
						$('#searchQuery', '#searchForm').bind('keyup', function(e) 
						{
							if( e.which == ENTER_KEY && !$.browser.mozilla)
							{
								e.stopPropagation();
								e.preventDefault();
								$(this).parent().parent().submit();
							}
							return false;
						});
												
						
						$('body').removeClass('no_actions');
						searchQueryObj.data('original', "<?php echo addslashes($this->translate('Search Mail')) . '...'; ?>");
						if($searchUnused)
						{
							searchQueryObj.val(searchQueryObj.data('original'));
						}
						$('#search_anything').show();

						var mailInfoSelector = $('#mail_info', "#Email");
						var messageListCompactSelector = $('#messageListCompact', "#Email");
						
						//scroll the message list back to its last pos
						if( messageListCompactSelector != undefined && messageListCompactSelector.length !=0 )
						{
							var pos = messageListCompactSelector.data('OldScrollPos');
							// compact view
							if(pos > 0) {
								messageListCompactSelector.scrollTo(pos, 'fast');
							}
							if(mailInfoSelector != undefined && mailInfoSelector.length != 0)
							{
								var pos2 = mailInfoSelector.data('OldScrollPos');

								if(pos2 > 0)
								{
									//scroll 3 pane message view back to its last pos
									mailInfoSelector.scrollTo(pos2, 'fast')
								}
							}
						}
						else if($('#messagesListForm','#Email').length != 0)
						{
							var primarySelector = $('#primary_content', '#messageList');
							var pos = $('#messageList', "#Email").data('OldScrollPos');
							
							// normal view
							if(pos > 0 && primarySelector != undefined && primarySelector.length != 0)
								primarySelector.scrollTo(pos, 'fast');
						}
						
					} 
					break;
					case ABOOK_TAB_ID:
					{
						myFavicon = '<?php echo getFavicon(Zend_registry::get('config')->global['install_dir'], $this->siteBaseUrl, 'contacts'); ?>';

						document.title = "<?php echo addslashes($this->account) ?> - <?php echo addslashes($this->translate('Contacts')) ?>";
		
						// unbind
						unbind_search();
            $('#searchForm').bind('submit', function() { return false; });
            $('#searchQuery', '#searchForm').bind('keypress', function() 
						{
							if ( search_timeout != undefined ) 
								clearTimeout(search_timeout);
							
							var thecall = this; // save reference to 'this' so we can use it in timeout function
							search_timeout = setTimeout(function() 
							{
								search_timeout = undefined;
								searchAbook(thecall);
							}, 300);
						});
						
						$('body').removeClass('no_actions');
						
						searchQueryObj.data('original', "<?php echo addslashes($this->translate('Search Contacts')) . '...'; ?>");
						if( $searchUnused )
							searchQueryObj.val(searchQueryObj.data('original'));
						$('#search_anything').show();
						$('#advSearch').hide();
						$('#navMessages').tabs('select', 0);
					} break;
					case CALENDAR_TAB_ID:
					{
						myFavicon = '<?php echo getFavicon(Zend_registry::get('config')->global['install_dir'], $this->siteBaseUrl, 'calendar'); ?>';

						if( $searchUnused )
						{
							//$('#search_anything input').val("<?php echo addslashes($this->translate('Search Calendar')) . '...'; ?>");
						}
						$('#search_anything').hide();
						
						
						
						$('body').removeClass('no_actions');
						unbind_search();
						$('#searchForm').bind('submit', function() 
						{
							searchCalendar();
							return false
						});
												
						document.title = "<?php echo addslashes($this->account) ?> - <?php echo addslashes($this->translate('Calendar')) ?>";
						$('#Calendar').show();
	
						$('#Calendar #primary #primary_content_edit').hide();
						$('#Calendar #primary #primary_content').show();
						$('#primary_content_cal').parent().show();
						$('#primary_content_inner_cal').show();
						$('#primary_header_cal').parent().show();
						$('#search_anything').hide();
						$('#advSearch').hide();
						$('#navMessages').tabs('select', 0);
					} break;
					case FILES_TAB_ID:
					{
						myFavicon = '<?php echo getFavicon(Zend_registry::get('config')->global['install_dir'], $this->siteBaseUrl, 'storage'); ?>';

						$('.help-tooltip[tabname=storage]').show()
						$('body').removeClass('no_actions');
						unbind_search();
						$('#search_anything').hide();
						$("#Flash", "#Settings").each(function() 
						{
							$(this).hide();
						});
						document.title = "<?php echo $this->account; ?> - <?php echo addslashes($this->translate('Storage')) ?>";
						$('#navMessages').tabs('select', 0);
					} break;
					case 4:
					{
						myFavicon = '<?php echo getFavicon(Zend_registry::get('config')->global['install_dir'], $this->siteBaseUrl, 'settings'); ?>';

						$('body').addClass('no_actions');
						unbind_search();
						$('#search_anything').hide();
						$('#advSearch').hide();
						$("#Flash", "#Settings").each(function() 
						{
							$(this).hide();
						});
						document.title = "<?php echo $this->account; ?> - <?php echo addslashes($this->translate('Settings')) ?>";
						$('#navMessages').tabs('select', 0);
					} break;
					default:
					{	
						document.title = "<?php echo $this->account; ?>";
						$('#search_anything').hide();
					} break;
				}
				
				if(myFavicon != '')
				{
					$('#favicon').attr('href', myFavicon);
					$('#favicon').attr('originalhref', myFavicon);
					newfavicon = $('#favicon').clone();
					$('#favicon').remove();
					$('body').append(newfavicon);
				}				
			},
			cache: true
		});
		 
		$('div#navMessages').tabs(
		{
			tabTemplate: '<li name="#{href}"><a href="#{href}" tabindex="0"><span>#{label}<a class="removetab" href="#" name="#{href}" onClick="removeTab($(this))" tabindex="0">&nbsp;</a></span></a></li>', 
			add: function(e, ui) 
			{
				$('div#navMessages').tabs('select', '#' + ui.panel.id); // show new tab body
			},
			select: function(event, ui) {
			},
			show: function(event, ui) 
			{	
				if ($(this).tabs('length') <= 1)
				{
					// nothing to show, we have been called by internal tabs ui
					return true;
				}
				
				if(ui.panel.id != 'messageList' && ui.panel.id.indexOf('calendarTab') == -1)
				{
					$('#nav').tabs('select', 0);
				}
				if(ui.panel.id.indexOf('calendarTab') != -1)
				{
					$('#nav ul').children().each(function() { $(this).removeClass('ui-tabs-selected'); $($(this).children('a').attr('href')).addClass('ui-tabs-hide'); });
				}

				$(ui.panel).trigger('tabSelected');
				$('#nav li:first').removeClass('ui-tabs-selected');
				
				document.title = "<?php echo $this->account; ?>...";
				
				$('#search_anything').show();

				enableMailActions('all');
				
				//resize other objects on screen
				$(window).resize()
				
				
				//only reset message list scroll if switching to mesage list
				if( ui.index == 0 )
				{
					if($('#messageListCompact', '#' + ui.panel.id).length !=0 )
					{
						// compact view
						var pos = $('#messageListCompact',  '#' + ui.panel.id).data('OldScrollPos');
						if(pos > 0)
						{
							$('#messageListCompact', '#' + ui.panel.id).scrollTo(pos, 'fast');
						}

						pos = $('#mail_info',  '#' + ui.panel.id).data('OldScrollPos');
						if(pos > 0)
						{
							$('#mail_info', '#' + ui.panel.id).scrollTo(pos, 'fast');
						}
					}
					else if($('#messagesListForm', '#' + ui.panel.id).length != 0)
					{
						// normal view
						var pos = $('#primary_content', '#' + ui.panel.id).data('OldScrollPos');
						
						if(pos > 0) {
							$('#primary_content', '#' + ui.panel.id).scrollTo(pos, 'fast');
						}
					}
				}
				else
				{
					//if selected panel has a previously saved scroll position, then scroll back to there
					if( $('#' + ui.panel.id).children('#primary_content').length != 0 )
					{
						var pos = $('#' + ui.panel.id).children('#primary_content').data('OldScrollPos');
						if(pos > 0)
						{
							$('#' + ui.panel.id).children('#primary_content').scrollTop( pos )
						}
					}
				}
			},
			remove: function(event, ui)
			{
			}, 
			cache: true
		});
		$('div#navMessages').data('lastTabNumber', 0);
<?php
		$configGlobal = Zend_registry::get('config')->global;
		if ( isset($this->group['Calendar']) && !$this->group['Calendar'] != 1)
		{
?>
		$.ajax({data: "&func=ping", 
 			type: "POST", 
			cache: false, 
			url: "<?php echo $this->siteBaseUrl ?>index.php/mail/calendar/caldavglue"
// to load the calendar as soon as possible uncommment below
//			,complete: function(XMLHttpRequest, textStatus){ $('#nav').tabs('select', 2) },
		});
		
		$.php("<?php echo $this->siteBaseUrl ?>index.php/mail/calendar/alarms");
		setInterval(function() { $.php("<?php echo $this->siteBaseUrl ?>index.php/mail/calendar/alarms"); }, 10 * 60 * 1000);
<?php
		}
		unset($configGlobal);
?>	
		// init calendar alarms, then check the every 10 mins
		
		$("#dialog").dialog(
		{
			autoOpen: false, 
			height: 250,
			minHeight: 250,
			minWidth: 350,
			modal: true,
			overlay: 
			{
				opacity: 0.5,
				background: "white"
			},
			width: 350
		});
			
		$('#exclamation').hide();
	
		function messageBubble(type, message) {
			switch (type)
			{
				case 'Error': 
					var noticeIcon = '<img src="<?php echo $this->siteBaseUrl ?>images/rte-light/link.png" alt="error" />'
				break;
				default:
					var noticeIcon = '<img src="<?php echo $this->siteBaseUrl ?>images/rte-light/link.png" alt="error" />'
			}
			$('#exclamation').show();
			$('#exclamation').bt(noticeIcon + '<span>' + type + '</span><br /><small>' + message + '</small>', 
			{
				width: 200,
				fill: 'white',
				cornerRadius: 20,
				padding: 20,
				strokeWidth: 1,
				trigger: ['none']
			});
			
			$('#exclamation').btOn();
			setTimeout( "$('#exclamation').btOff()" , 10000);
			$('#exclamation').bind('click', function() 
			{
				$('#exclamation').btOn();
				setTimeout( "$('#exclamation').btOff()" , 10000);
			});
		}
		
		php.errors.defaultCallBack = function (msg, params) 
		{
			$.simpleFlash(msg, 'error');
		}

		php.messages.defaultCallBack = function (msg, params) 
		{
			$.simpleFlash(msg, 'notice');
		}
		
		
		// add a custom error handler to suppress aborted requests or empty responses
		// keep existing error handler to be called if other
		php.debugError = php.error;
		php.error = function (xmlEr, typeEr, except) 
		{
			hideAllLoadingIcons();
			if( xmlEr.readyState == 4 && xmlEr.status == '200' && xmlEr.statusText == 'OK' && (xmlEr.responseText == undefined || xmlEr.responseText.length == 0)  )
			{
				if( xmlEr.responseText == undefined || xmlEr.responseText.length == 0 )
				{
					//empty
					return;
				}
				else
				{
					//corrupted/damaged
				}
			}
			
			if( xmlEr.readyState == 4 && xmlEr.status == '0' && (xmlEr.responseText == undefined || xmlEr.responseText.length == 0) )
			{
				// abort
				return;
			}
			php.debugError(xmlEr, typeEr, except);
			
		}

		// lets add a session timeout handler
		// but save current one
		previous_php_error_handler = php.error;
		php.error = function(XMLHttpRequest, textStatus, errorThrown) 
		{
			// check for session timeout
			if( XMLHttpRequest.responseText.indexOf("__ATMAIL_SESSION_TIMEOUT") != -1 )
			{
				displaySessionTimeout();
				return;
			}
			
			if( debugEnabled )
			{				
				// use the default handler
				previous_php_error_handler(XMLHttpRequest, textStatus, errorThrown);
			}

		}

		current_php_succcess_handler = php.success;
		php.success = function (response, textStatus)
		{
			// might be customized/invalid/corrupt json resp
			response['q'] = (typeof(response['q']) != 'undefined') ? response['q'] : new Array();
			response['a'] = (typeof(response['a']) != 'undefined') ? response['a'] : new Array();
			return current_php_succcess_handler(response, textStatus);
		}

		$("#jquery_jplayer")
		.jPlayer({
			nativeSupport: true,
			oggSupport: false,
			swfPath: '<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/',
			customCssIds: true, 
			onSoundComplete : function() { this.element.jPlayer('clearFile'); }
		})
		
		//$("#navMessages").attr("style", "left: " + Number($("#nav", "#header").position().left+$("#nav", "#header").width()) + "px" )

		// Color picker change
		$(".color-palette a", "#account-options").bind('click', function(e) {
			var color = $(this).attr('themeColor');
			$("body").removeClass('blue green purple red orange').addClass(color);
			toggleColorTheme(color);
		})
			
		$("#navMessages").attr("style", "left: " + Number($("#nav", "#header").position().left+$("#nav", "#header").width()) + "px" )

	}); //EO $( function() {
	
	</script>
	<?php $this->pluginCall("endHeadTag") ?>
</head>

<body class="leaderboard-ad-off footer-ad-off <?php echo $this->UserSettings['Language'] ?> <?php echo $themePath ?> <?php echo $this->UserSettings['cssColorTheme'] ?>" id="<?php if( $this->group['Calendar'] != '1' ) { echo "caloff"; } else { echo "calon"; } ?>">

<?php $this->pluginCall("startBodyTag") ?>
<!--
<div style="display:none;" id="templates">
<?php 

	//$data = array( 'siteBaseUrl' => $this->siteBaseUrl, 'appBaseUrl' => $this->appBaseUrl , 'mobuleBaseUrl' => $this->mobuleBaseUrl ); //shows what fields are needed
//	echo $this->partial('service/templateFacebook.phtml', $this); 
//	echo $this->partial('service/templateTwitter.phtml', $this); 
	// echo '<div id="templateCDR">' . $this->partial('service/templateCDR.phtml', $this) . '</div>'; 
	// echo '<div id="templateSMS">' . $this->partial('service/templateSMS.phtml', $this) . '</div>'; 
	
?>
</div>
-->
<!-- Calendar alarm qTip -->
<div id="alarmholder"></div>

<div id="webPhone"><?php if( $this->SIPEnabled && $this->selectedSIPAccount !== null ) require_once('webphone.phtml'); ?></div>


<!-- Welcome qTip -->
<div id="welcomeholder"></div>
<?php $this->pluginCall('welcomeMessageHtml'); ?>
<div id="banner-leaderboard" style="display: none;"><span></span></div>
<div id="banner-footer" style="display: none;"><span></span></div>
	<div id="header">
		<div id="EmailSignature" class='Signature' style="display:none;"><?php echo $this->UserSettings['Signature']; ?></div>
		<div class="preload" style="display:none;">
			<img src="<?php echo $this->siteBaseUrl ?>images/email_drag.png" alt="drag email"/>
			<img src="<?php echo $this->siteBaseUrl ?>images/drag_left.png" alt="drag left" />
			<img src="<?php echo $this->siteBaseUrl ?>images/drag_right.png" alt="drag right" />
			<img src="<?php echo $this->siteBaseUrl ?>images/ui-images.png" alt="image" />
			<img src="<?php echo $this->siteBaseUrl ?>images/icons/contact_card_drag.png" alt="contact card" />
			
			<?php if (file_exists(APP_ROOT . "images/themes/$themePath/action_btn_right.png")): ?>
			<img src="<?php echo $this->siteBaseUrl ?>images/themes/<?php echo $themePath ?>/action_btn_right.png" />
			<?php endif; ?>
			<?php if (file_exists(APP_ROOT . "images/themes/$themePath/$themePath.png")): ?>
			<img src="<?php echo $this->siteBaseUrl ?>images/themes/<?php echo $themePath ?>/<?php echo $themePath ?>.png" />
			<?php endif; ?>
			<?php if (file_exists(APP_ROOT . "images/themes/$themePath/action_blue_right.png")): ?>
			<img src="<?php echo $this->siteBaseUrl ?>images/themes/<?php echo $themePath ?>/action_blue_right.png" />
			<?php endif; ?>
			<?php if (file_exists(APP_ROOT . "images/themes/$themePath/folder_add_active.png")): ?>
			<img src="<?php echo $this->siteBaseUrl ?>images/themes/<?php echo $themePath ?>/folder_add_active.png" />
			<?php endif; ?>
			<?php if (file_exists(APP_ROOT . "images/themes/$themePath/folder_remove_active.png")): ?>
			<img src="<?php echo $this->siteBaseUrl ?>images/themes/<?php echo $themePath ?>/folder_remove_active.png" />
			<?php endif; ?>
			<?php if (file_exists(APP_ROOT . "images/themes/$themePath/drop_gradient_roll.png")): ?>
			<img src="<?php echo $this->siteBaseUrl ?>images/themes/<?php echo $themePath ?>/drop_gradient_roll.png" />
			<?php endif; ?>
			<?php if (file_exists(APP_ROOT . "images/themes/$themePath/drop_gradient_roll_btm.png")): ?>
			<img src="<?php echo $this->siteBaseUrl ?>images/themes/<?php echo $themePath ?>/drop_gradient_roll_btm.png" />
			<?php endif; ?>
			<?php if (file_exists(APP_ROOT . "images/themes/$themePath/button_blue_left.png")): ?>
			<img src="<?php echo $this->siteBaseUrl ?>images/themes/<?php echo $themePath ?>/button_blue_left.png" />
			<?php endif; ?>
			<?php if (file_exists(APP_ROOT . "images/themes/$themePath/button_blue_right_blue.png")): ?>
			<img src="<?php echo $this->siteBaseUrl ?>images/themes/<?php echo $themePath ?>/button_blue_right_blue.png" />
			<?php endif; ?>
			<?php if (file_exists(APP_ROOT . "images/themes/$themePath/button_blue_right.png")): ?>
			<img src="<?php echo $this->siteBaseUrl ?>images/themes/<?php echo $themePath ?>/button_blue_right.png" />
			<?php endif; ?>
			<?php if (file_exists(APP_ROOT . "images/themes/$themePath/button_grey_left.png")): ?>
			<img src="<?php echo $this->siteBaseUrl ?>images/themes/<?php echo $themePath ?>/button_grey_left.gif" />
			<?php endif; ?>
			<?php if (file_exists(APP_ROOT . "images/themes/$themePath/button_grey_right.png")): ?>
			<img src="<?php echo $this->siteBaseUrl ?>images/themes/<?php echo $themePath ?>/button_grey_right.gif" />
			<?php endif; ?>
			
		</div>
			<a onclick="return false;" onkeydown="skipToContent(event);" tabindex="1" href="#skip_to_content" id="skip-link" style="color:grey;position:absolute;right:330px;top:25px;z-index:0;">Skip to content &gt;</a>
			<?php if(!empty($this->company_url)): ?>
			<a style="position:absolute; top:0px; left:0px;" href="<?php echo $this->company_url; ?>" target="_blank" tabindex="0"><img src="<?php echo $this->siteBaseUrl; ?>index.php/default/index/logo?<?php echo '' . rand(0, 9999); ?>" alt="Charter Communication Logo" /></a>
			<?php else: ?>
			<a><?php echo $this->brandname ?></a>
			<?php endif; ?>
		<div class='branding'> </div>
		
		<div id='nav' style="position:relative;z-index:16777270;background:white;">
			<ul id='nav' role="tablist">
				<li id="nav_ema" role="presentation"><a href="#Email" title="Email" tabindex="0" id="email-tab" role="tab" aria-controls="Email" aria-selected="true" onclick="$('#navMessages').tabs('select',0)"><span><?php print $this->translate('Email')?></span></a></li>
				<li id="nav_add" role="presentation"><a href="<?php echo $this->moduleBaseUrl ?>/contacts" id="contacts-tab" role="tab" aria-controls="Address_Book" aria-selected="false" title="Address Book" tabindex="0"><span><?php print $this->translate('Contacts')?></span></a></li>
				<li id="nav_cal" role="presentation" style="<?php if( !$this->calendarLicensed || $this->group['Calendar'] != '1' ) { echo "display: none"; } ?>" tabindex="0"><a href="<?php echo $this->moduleBaseUrl ?>/calendar" role="tab" aria-conttrols="Calendar" aria-selected="false"  title="Calendar"><span><?php print $this->translate('Calendar')?></span></a></li>
				<li id="nav_files" role="presentation" style="<?php if( !$this->storageLicensed || $this->group['WebDavEnabled'] != '1' || $this->group['StorageTabEnabled'] != '1' ) { echo "display: none"; } ?>"><a role="tab" aria-controls="Files" aria-selected="false"  href="<?php echo $this->moduleBaseUrl ?>/webdav" title="Files" tabindex="0"><span><?php print $this->translate('Storage')?></span></a></li>
				<li id="nav_set" role="presentation"><a id="settings-tab" role="tab" aria-controls="Settings" aria-selected="false" href="<?php echo $this->moduleBaseUrl ?>/settings" title="Settings" tabindex="0"><span><?php print $this->translate('Settings')?></span></a></li>
			</ul>
		</div>

		<div id='navMessages' style="position:relative;z-index:16777270;background:white">
			<ul id='navMessages'>
				<li name="#messageList"><a href="#messageList" style="display:none;" tabindex="-1"></a></li>
			</ul>
		</div>
	
		<div id="search_anything">
			<form action="" method="POST" id='searchForm'>
				<div class="searchFormDiv"><label for="searchQuery" class="offscreen">Search Mail</label>
					<input tabindex="0" type="text" name="searchQuery" value="<?php echo addslashes($this->translate('Search Mail')) . '...'; ?>" id="searchQuery" />
					<div class="drop-arrow-search" style="display:none;" tabindex="0"><span class="offscreen">Advanced Search Button...</span></div>
				</div>

				<div id="advSearch">
					<div class="search-rule" style="color:#454545; border-bottom: 1px solid #CCCCCC; color: #454545; height: 20px; width: 187px; margin-bottom:14px;"><?php echo $this->translate("Advanced Search") ?></div>
					<div>
						<label for="advSearchGoBack" style="margin-top:-4px;"><?php echo $this->translate("Date") ?></label>
						<select name="goBack" class="focusable" id="advSearchGoBack">
							<option value="1"><?php echo $this->translate("Up to 1 month old") ?></option>
							<option value="3"><?php echo $this->translate("Up to 3 months old") ?></option>
							<option value="6" selected><?php echo $this->translate("Up to 6 months old") ?></option>
							<option value="9"><?php echo $this->translate("Up to 9 months old") ?></option>
							<option value="12"><?php echo $this->translate("Up to 1 year old") ?></option>
							<option value="24"><?php echo $this->translate("Up to 2 years old") ?></option>
							<option value="0"><?php echo $this->translate("Forever") ?></option>
						</select>
					</div>
					<div >
						<label for="advSearchFrom"><?php echo $this->translate("From") ?></label>
						<input type="text" id="advSearchFrom" name="from" size="20" />
					</div>
					<div>
						<label for="advSearchTo"><?php echo $this->translate("To") ?></label>
						<input type="text" id="advSearchTo" name="to" />
					</div>
					<div>
						<label for="advSearchSubject"><?php echo $this->translate("Subject") ?></label>
						<input type="text" id="advSearchSubject" name="subject"  />
					</div>
					<div>
						<label for="advSearchBody"><?php echo $this->translate("Body") ?></label>
						<input type="text" id="advSearchBody" name="body"  />
					</div>
					<div>
						<label for="advSearchUnseen"><?php echo $this->translate("Unread") ?></label>
						<input class="checkbox focusable" type="checkbox" name="unseen" id="advSearchUnseen" />
					</div>
					<div>
						<label for="advSearchFlagged"><?php echo $this->translate("Flagged") ?></label>
						<input class="checkbox" type="checkbox" name="flagged"  id="advSearchFlagged" />
					</div>

					<!--<div>
						<label for="hasAttach"><?php echo $this->translate("Has Attachment") ?></label>
						<input type="checkbox" name="hasAttach" />
					</div>-->
					<div class="adv-srch-btns">
						<a><span><input  type="submit" value="Search" onClick="$('#advSearch').hide()" onSubmit="$('#searchForm', '#search_anything').submit()"/></span></a>
					</div>
					<div class="adv-srch-btns cancel" style="float:right; margin-right: 41px; margin-top: 0; clear:none !important;">
						<a><span><input  type="button" value="Cancel" onclick="$('#advSearch').slideUp()" /></span></a>
					</div>
				</div>
				<div class="hidden-fields" style="display:none">
					<input type="hidden" value="" name="filter" />
				</div>
			</form>
		</div>
<!--
		<div id="help">
			<a href="#">&nbsp;</a>
		</div>
		
		<div id="sign_out">
			<a href="<?php echo $this->moduleBaseUrl ?>/auth/logout"><span id="signOut"><?php print $this->translate('Sign Out')?></span></a>
		</div>
	-->	
		<div class="account-dropdown" style="display:none;">
			<div class="contact-photo">
				<img src="<?php echo $this->moduleBaseUrl ?>/contacts/viewphoto/id/-1000/resize/1/" tabindex="0" alt="Contact photo"/>
			</div>
			<ul id="jsddm">
				<li id="account-options"><a class="moredrop" tabindex="-1" href="#" style="display:none"><span><strong><?php print $this->translate('More')?><span class="arrow">▼</span></strong></span></a>
					<ul class="menu_drop_more">
					    <!-- REMOVE PER PRODUCT
						<li class="color-palette">
							<a class="blue" themeColor="blue"></a>
							<a class="green" themeColor="green"></a>
							<a class="purple" themeColor="purple"></a>
							<a class="red" themeColor="red"></a>
							<a class="orange" themeColor="orange"></a>
						</li>
						-->
						<li><a href="#" onclick="$('#nav_set a').click(); jsddm_close();" tabindex="0"><?php print $this->translate('Settings')?></a></li>
						<li id="user-help"><a href="<?php echo $this->moduleBaseUrl ?>/settings/help/helpFile/help" target="_blank" onclick="jsddm_close()" tabindex="0"><?php print $this->translate('Help')?></a></li>
						<li class="bottom"><a href="<?php echo $this->moduleBaseUrl ?>/auth/logout" tabindex="0">Exit Email<!--<?php print $this->translate('Sign Out')?>--></a></li>
					</ul>
				</li>
			</ul>

		</div>
		<!-- sound player placeholder -->
		<div id="jquery_jplayer"></div>
	</div>


