/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

function iloginProcessJson(json, message) {
    if (json.status == false) {
        jQuery("#my_ilogin_modal_message_content").html(json.message);
        jQuery("#my_ilogin_modal_message").show();
    } else {
        if (jQuery('div.quick-access > ul.links').length > 0) {
            jQuery('div.quick-access > ul.links').replaceWith(json.top_links);
        } else if (jQuery('div.shop-access').length > 0) {
            jQuery('div.shop-access').html(json.top_links);
        }
        if (jQuery('div.block-cart').length > 0) {
            jQuery('div.block-cart').replaceWith(json.cart_sidebar);
        } else if (jQuery('div.mini-cart').length > 0) {
            jQuery('div.mini-cart').replaceWith(json.cart_sidebar);
        }
        if (jQuery('p.welcome-msg').length > 0) {
            jQuery('p.welcome-msg').html(json.message);
        }

        var myIloginCounter = 3;
        jQuery.fancybox('<p class="success-msg">'+message+'</p><h1 id="my-ilogin-counter">'+myIloginCounter+'</h1>', {
            'scrolling'		: 'no',
            'padding'		: 20,
            'transitionIn'	: 'none',
            'transitionOut'	: 'none',
            'autoDimensions': false,
            'scrolling'     : false,
            'width'         : 250,
            'height'        : 80
        });
        var myIloginInvertal = setInterval(
            function(){
                myIloginCounter --;
                jQuery('#my-ilogin-counter').html(myIloginCounter);
                if (myIloginCounter < 1) {
                    jQuery.fancybox.close();
                    clearInterval(myIloginInvertal);
                }
            },
            1000
        );
    }
    jQuery.fancybox.hideActivity();
}
function iloginParseLoginLink(loginText) {
    if (jQuery('a[href*="/customer/account/login/"]').length) {
        jQuery('a[href*="/customer/account/login/"]').click(function() {
                jQuery.fancybox({
                    'href'          : '#my_ilogin_modal_outer',
                    'titlePosition' : 'inside',
                    'transitionIn'  : 'none',
                    'transitionOut' : 'none',
                    'autoDimensions': false,
                    'scrolling'     : false,
                    'width'         : 980,
                    'height'        : 410
                });
                jQuery('#my_ilogin_modal_email').focus();
                return false;
        });
    } else if (jQuery("div.quick-access > ul.links > li > a").length > 0) {
        jQuery("div.quick-access > ul.links > li > a").each(function(index) {
            var _title = jQuery(this).attr("title");
            if (_title == loginText) {
                jQuery(this).click(function() {
                    jQuery.fancybox({
                        'href'          : '#my_ilogin_modal_outer',
                        'titlePosition' : 'inside',
                        'transitionIn'  : 'none',
                        'transitionOut' : 'none',
                        'autoDimensions': false,
                        'scrolling'     : false,
                        'width'         : 980,
                        'height'        : 410
                    });
                    jQuery('#my_ilogin_modal_email').focus();
                    return false;
                });
                return false;
            }
        });
    } else if (jQuery("div.shop-access > div > ul > li > a").length > 0) {
        jQuery("div.shop-access > div > ul > li > a").each(function(index) {
            var _title = jQuery(this).attr("title");
            if (_title == loginText) {
                jQuery(this).click(function() {
                    jQuery.fancybox({
                        'href'          : '#my_ilogin_modal_outer',
                        'titlePosition' : 'inside',
                        'transitionIn'  : 'none',
                        'transitionOut' : 'none',
                        'autoDimensions': false,
                        'scrolling'     : false,
                        'width'         : 980,
                        'height'        : 410
                    });
                    jQuery('#my_ilogin_modal_email').focus();
                    return false;
                });
                return false;
            }
        });
    }
}
