<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magento.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magento.com for more information.
 *
 * @category    design
 * @package     base_default
 * @copyright   Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<?php
/**
 * @see Mage_Page_Block_Template_Links
 */
?>
<?php
    $setting = Mage::helper('themeframework/settings');
    $_links = $this->getLinks();
?>
<div id="em-top-links">
<?php if(count($_links)>0): ?>
    <ul class="list-inline links"<?php if($this->getName()): ?> id="<?php echo $this->getName() ?>"<?php endif;?> >	
        <?php foreach($_links as $_link): ?>
            <?php if ($_link instanceof Mage_Core_Block_Abstract):?>
                <?php echo $_link->toHtml() ?>
            <?php else: ?>
                <!-- Hiep: Add data-hover attribute -->
                <li<?php if($_link->getIsFirst()||$_link->getIsLast()): ?> class="<?php if($_link->getIsFirst()): ?> first<?php endif; ?>"<?php endif; ?> <?php echo $_link->getLiParams() ?>><?php echo $_link->getBeforeText() ?><a data-hover="<?php echo $_link->getTitle() ?>" href="<?php echo $_link->getUrl() ?>" title="<?php echo $_link->getTitle() ?>" <?php echo $_link->getAParams() ?>><?php echo $_link->getLabel() ?></a><?php echo $_link->getAfterText() ?></li>
            <?php endif;?>
        <?php endforeach; ?>
        
        <li class="last">            
            <div id="em-login-link" class="account-link">
                <?php if (Mage::getSingleton('customer/session')->isLoggedIn()==0): ?>
                    <a href="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK).'customer/account/login/'; ?>" class="link-login" id="link-login"><?php echo $this->__('Log In') ?></a>   
                    <?php if($setting->getGeneral_DisableHoverLogin()!=0 && !$setting->checkMobilePhp()): ?>         
                        <?php $login = new Mage_Customer_Block_Form_Login(); ?>                
                        <div class="em-account" id="em-account-login-form" style="display: none;">                
                            <form action="<?php echo $login->getPostActionUrl() ?>" method="post" id="top-login-form">
                                <?php echo $this->getBlockHtml('formkey'); ?>
                                <div class="block-content">
                                    <p class="login-title h6 primary"><?php echo $this->__("Login")?></p>
                                    <p class="login-desc"><?php echo $this->__("If you have an account with us, please log in.")?></p>
                                    <ul class="form-list">
                                    <li><label for="mini-login"><?php echo $this->__('Email Address') ?><em><?php echo $this->__('*') ?></em></label>
                                        <input type="text" name="login[username]" id="mini-login" class="input-text required-entry validate-email" />
                                    </li>
                                    <li><label for="mini-password"><?php echo $this->__('Password') ?><em><?php echo $this->__('*') ?></em></label>
                                        <input type="password" name="login[password]" id="mini-password" class="input-text required-entry validate-password" />
                                    </li>  
                                    </ul>
									<p class="required"><?php echo $this->__('* Required Fields') ?></p>
                                    <div class="action-forgot">
                                        <div class="actions">
                                            <button type="submit" class="button"><span><span><?php echo $this->__('Login') ?></span></span></button>
                                        </div>  
                                        <div class="login_forgotpassword">
                                            <p><a href="<?php echo $login->getForgotPasswordUrl() ?>"><?php echo $this->__('Forgot Your Password?') ?></a></p>                                                
                                            <p><a class="create-account-link-wishlist" href="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK).'customer/account/create/'; ?>"><?php echo $this->__("Don't have an account") ?></a></p>
                                        </div>                              
                                    </div>
                                </div>
                            </form> 
                            <script type="text/javascript">
                            //<![CDATA[
                                var dataTopLoginForm = new VarienForm('top-login-form', true);
                            //]]>
                            </script>                    
                        </div>                    
                    <?php endif; ?>
                <?php else: ?>
                    <a href="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK).'customer/account/logout'; ?>" class="link-login" id="link-login" title="<?php echo $this->__('Log Out') ?>"><?php echo $this->__('Log Out') ?></a>  
                <?php endif;?>
            </div>
                
        </li>      
    </ul>
</div>
    <?php if($setting->getGeneral_DisableHoverLogin()!=0 && !$setting->checkMobilePhp()): ?> 
    <script type="text/javascript">
    //<![CDATA[
        (function($) {           
            function effectLoginForm() {
                var sLogin = $('#em-account-login-form');
                var sLink = $('#link-login');
                var sDivLink = $('#em-login-link');  
                if (sLogin.length > 0) {
                    //hover login form   
                    <?php if($setting->getGeneral_DisableHoverLogin()==1): ?>                          
                        if (isMobile) {
                            
                            sLink.attr('href', 'javascript:void(0);');
                            sLink.click(function(e) {
                                sLogin.slideToggle();
                            });
                        } else {
                            var tmlink;
                                         
                            function showlink(el) {
                                clearTimeout(tmlink);
                                tmlink = setTimeout(function() {
                                    el.slideDown();
                                }, 200);
                            }    
                            function hidelink(el) {
                                clearTimeout(tmlink);
                                tmlink = setTimeout(function() {
                                    el.slideUp();
                                }, 200);
                            }
                            sDivLink.mouseover(function(){
                                showlink(sLogin);
                            });
                            sDivLink.mouseout(function(){
                                hidelink(sLogin);
                            });
                        }
                    // Popup Login Form
                    <?php elseif($setting->getGeneral_DisableHoverLogin()==2): ?>
                        sLink.attr('href', 'javascript:void(0);');
                        $("#link-login").click(function(){                            
                             $.fancybox.open('#em-account-login-form',{                              
                                width : 'auto',
                                height: 'auto',                                                               
                                openEffect  : 'elastic',
                                closeEffect : 'elastic'                        
                            });
                        });                        
                    <?php endif; ?>
                }
            }
			
			$(document).ready(function(){            
                effectLoginForm();     
            });	
        })(jQuery);
    //]]>
    </script> 
    <?php endif;?>
<?php endif; ?>
