<?php
// Copyright 1999-2015. Parallels IP Holdings GmbH. All Rights Reserved.
?>
<div class="r-main-header-navbar">
    <ul>
        <?php if ($this->backToAdminLink): ?>
        <li class="r-top-back"><span></span></li>
        <?php endif; ?>
        <?php if ($this->accountMenu): ?>
        <li class="r-top-user"><span></span></li>
        <?php endif; ?>
        <?php if ($this->subscriptionSwitchingAllowed): ?>
        <li class="r-top-webspace"><span></span></li>
        <?php endif; ?>
        <?php if ($this->helpMenu): ?>
        <li class="r-top-help"><span></span></li>
        <?php endif; ?>
    </ul>
</div>
<div class="main-header-navbar">
    <ul class="main-header-navbar-nav">
        <?php if ($this->backToAdminLink): ?>
        <li class="top-back">
            <a class="s-btn" href="<?php echo $this->backToAdminLink ?>"><i class="icon-top-back"></i> <?php echo $this->lmsg('smb.components.shortcuts.backToAdmin'); ?></a>
        </li>
        <?php endif; ?>

        <?php if ($this->accountMenu): ?>
        <li class="top-user-info">
            <div class="top-user-info-wrapper">
                <div class="top-user-info-row top-user">
                    <div class="top-user-info-name"><?php echo $this->lmsg('smb.components.shortcuts.' . ($this->impersonatedClientName ? 'impersonatedInAs' : 'loggedInAs')); ?></div>
                    <div class="top-user-info-data"></div>
                </div>
                <?php if ($this->subscriptionSwitchingAllowed): ?>
                    <div class="top-user-info-row top-webspace">
                        <div class="top-user-info-name"><?php echo $this->lmsg(Plesk_Mode::isPowerUserPanel()?'smb.components.shortcuts.webspace': 'smb.components.shortcuts.subscription'); ?></div>
                        <div class="top-user-info-data"></div>
                    </div>
                <?php endif; ?>
            </div>
        </li>
        <?php endif; ?>

        <?php if ($this->helpMenu): ?>
        <li class="top-help">
            <?php if (count($this->helpMenu['items']) == 1): ?>
            <?php $href = !empty($this->helpMenu['items'][0]['href']) ? $this->helpMenu['items'][0]['href'] : '#'; ?>
            <a class="s-btn" href="<?php echo $href ?>" <?php echo '#' != $href ? ' target="_blank"' : '' ?>
                <i class="icon-top-help"></i> <?php echo $this->helpMenu['title']; ?>
            </a>
            <?php endif; ?>
        </li>
        <?php endif; ?>

        <?php if ($this->logo()->isRightLogoVisible && !empty($this->logo()->customLogoImage)): ?>
            <li class="top-logo">
                <a href="http://www.plesk.com" target="_blank">
                    <img src="<?php echo $this->skinUrl('/images/logos/powered-logo.png'); ?>"/>
                </a>
            </li>
        <?php endif; ?>
    </ul>
</div>

<script type="text/javascript">
//<![CDATA[
Jsw.onReady(function() {
    <?php if ($this->subscriptionSwitchingAllowed): ?>
        new Jsw.ResponsiveDropdown({
            renderTo: $$('.top-webspace .top-user-info-data')[0],
            id: 'subscription-switch',
            items: <?php echo Zend_Json::encode($this->subscriptions); ?>,
            title: <?php echo $this->jsEscape($this->currentSubscriptionTitle); ?>,
            hasIcons: false,
            onChange: function(event, item) {
                event.preventDefault();
                window.location.href = item.value
                    + '?returnUrl=' + <?php echo $this->jsEscape($this->returnUrl); ?>
                    + '&changeId=1'
                    + '&activeModule=' + <?php echo $this->jsEscape($this->activeModule); ?>;
            },
            responsiveClass: 'r-top-webspace',
            headerClass: 'main-header',
            responsiveHeaderClass: 'r-show-main-header-navbar r-show-top-webspace'
        });
    <?php endif; ?>
    <?php if ($this->backToAdminLink): ?>
    $$('.r-top-back').each(function(link) {
        link.observe('click', function(e) {
            Jsw.redirect(<?php echo $this->jsEscape($this->backToAdminLink) ?>);
        })
    });
    <?php endif; ?>
    <?php if ($this->accountMenu): ?>
    new Jsw.ResponsiveDropdown({
        renderTo: $$('.top-user .top-user-info-data')[0],
        id: 'account-menu',
        items: <?php echo Zend_Json::encode($this->accountMenu['items']); ?>,
        title: <?php echo $this->jsHtml($this->accountMenu['title']); ?>,
        forceDropdown: true,
        responsiveClass: 'r-top-user',
        headerClass: 'main-header',
        responsiveHeaderClass: 'r-show-main-header-navbar r-show-top-user'
    });
    <?php endif; ?>
    <?php if ($this->helpMenu): ?>
    <?php if (count($this->helpMenu['items']) > 1): ?>
    new Jsw.ResponsiveDropdown({
        renderTo: $$('.top-help')[0],
        id: 'help-menu',
        items: <?php echo Zend_Json::encode($this->helpMenu['items']); ?>,
        title: <?php echo $this->jsHtml($this->helpMenu['title']); ?>,
        onChange: function(event, item) {
            if (item.value == 'help') {
                event.preventDefault();
                OpenHelpWindow();
            }
        },
        forceDropdown: true,
        responsiveClass: 'r-top-help',
        headerClass: 'main-header',
        responsiveHeaderClass: 'r-show-main-header-navbar r-show-top-help'
    });
    <?php else: ?>
    $$('.r-top-help,.top-help .s-btn').each(function(link) {
        if ('#' != link.getAttribute('href')) {
            return;
        }
        link.observe('click', function(e) {
            e.preventDefault();
            OpenHelpWindow();
        })
    });
    <?php endif; ?>
    <?php endif; ?>
});
//]]>
</script>
