<?php echo $this->render('global/header.phtml', $this); ?>

<div id="Email" role="tabpanel" aria-labelledby="email-tab">

	<div id="actions">
	   <?php include('indexactionsmain.phtml'); ?>
	</div>

	<div id="primary">
		<div id="messageList">
			<div id="primary_header" class='loading'></div>
			<div id="primary_content"></div>
		</div>
	</div>	
	
	<div id="secondary" class="banner-rectangle-off leaderboard-ad-on">
		<?php include('indexfolderlist.phtml'); ?>	
		<div id="banner-rectangle" style="display: none;"><span></span></div>
	</div>
    <div id="draggableMessagesContainer" style="position:absolute;"></div>
</div>

<script type="text/javascript" language="JavaScript">
var oldPos = -1;

var firstLoginFlag = '<?php echo $this->isFirstLogin ?>'

function isFirstLogin()
{
	return firstLoginFlag == '1'? true : false
}

function clearFirstLoginFlag()
{
	firstLoginFlag = ''
}

function confirmOnSend(message)
{
	var needConfirm = "<?php echo $this->UserSettings['confirmOnSend'] ?>"
	if(needConfirm != "1") return true;			// Only show confirm when set confirmOnSend=>1
	
	return confirm(message);	
}

$( function()
{
	
	// ensure mail is selected.
	$('#nav').tabs('select', 0);   
    $('#messageList').attr('listFolder', '<?php echo urlencode(urlencode($this->currentFolder)); ?>');
	$.php('<?php echo $this->moduleBaseUrl ?>/mail/listfoldermessages')
    
	//delay requesting folder totals to give server a chance to server first view
	function updateFolderTotals() 
	{
	
		//CONSIDER: modifying to accept single folder updates
		$.getJSON('<?php echo $this->moduleBaseUrl ?>/mail/updatefoldertotals', null, function (data, textStatus) {
			// data will be a jsonObj
			// textStatus will be one of the following values: 
			//   "timeout","error","notmodified","success","parsererror"
			//this; // the options for this ajax request
			$.each(data, function(i, v) {
	        	//update each folder
	        	var unseen = 0;
	        	if(v === undefined || v.id === undefined)
	        	{
	        		return;
	        	}
	        	if(v.info !== undefined && v.info.unseen !== undefined)
	        	{
	        		unseen = v.info.unseen;
	        	}
				$("#nav_secondary #" + v.id).children('a:first').children('.unread:first').children('strong:first').html( unseen )      
                if( unseen > 0 )
                {
					$("#nav_secondary #" + v.id).children('a:first').children('.unread:first').show()
				}
			})  
		
			}  
		)
         
	}   
	//TODO: create 'done' flag so that others can call it, then call from end of message view. or better yet add eventlistener like ALL loading complete
	folderTotalsUpdate = setTimeout( function() { updateFolderTotals() }, 8000)

	resetMessagesDroppables()
	
	$('#Email #jsddm > li').bind('mousedown', jsddm_open );
	$('#Email #jsddm > li').bind('keydown',function(e){
	  if(e.which==ENTER_KEY){
            $(this).trigger('mousedown');
          }          
	});
	
	$('#menuOptions').each(function() { $(this).bind('click', jsddm_close ); });
	
	
	$('#searchForm').submit(function() {              
		return false
	})
	
	$("#Email #secondary").hover(
		function() { if(oldPos == -1) oldPos = $('#Email #secondary').scrollTop(); else $(this).scrollTo(oldPos); },
		function() { oldPos = $(this).scrollTop(); }
	);
/*
	$('[tabindex]').bind('focus',function(e){
		$(this).css('outline','1px dotted blue');
    $(this).css('outline-offset','-2px');
  });

  $('[tabindex]').bind('blur',function(e){
		$(this).css('outline','none');
		$(this).css('outline-offset','0px');
	});
*/
	// $('#nav_ema :first-child').focus();

	$('#Email #primary #messageList #primary_content').block({ message: "<h1 class='loading-text'><img alt='loading...' class='loadingimg' src='<?php echo $this->siteBaseUrl ?>images/25.gif' width='28' height='28'/><span class='loading'><?php echo $this->translate('Loading...') ?></span></h1>", overlayCSS: {backgroundColor: 'transparent', opacity: 0.4}, css: {backgroundColor: 'transparent',color: '#575757',border: '0'} });
	// Add the loading div
	// Add the welcome dialog
	<?php $this->pluginCall("welcomeMessageJs"); ?>

   $("#Address_Book").attr('role','tabpanel').attr('aria-labelledby','contacts-tab');
	 $("#Settings").attr('role','tabpanel').attr('aria-labelledby','settings-tab');

   	
})
</script>

<?php $this->pluginCall("endBodyTag") ?>
<script type="text/javascript" language="JavaScript" src="<?php echo $this->siteBaseUrl ?>js/charter/accessibility.js"></script>
</body>
</html>
