LIVENATION.module.my_account = function(item_data) {

    function attachFlyoutHandler(_handler) {

        $(_handler).addEvent('click', function(e) {
            e.stop();
            if ($defined($('login_flyout_sign_in_error'))) $('login_flyout_sign_in_error').empty();

            if (LIVENATION.instances.login != null) {
                LIVENATION.instances.login.each(function(item, index){
                    if (item.module_id == 'login_flyout') {
                        item.send_to_omniture();
                    }
                });
            }

            flyout_sticky = new StickyWin.Modal({
                content: $('login_flyout'),
                relativeTo: $('top'),
                zIndex: 80,
                position: 'center',
                offset: {
                    x: 0,
                    y: 200
                },
                modalOptions: {
                    hideOnClick: false,
                    modalStyle:{
                        'background-color':'#000',
                        'opacity':.3,
                        'z-index':50
                    }
                },
                onDisplay : function(){
                    $('emailAddress').focus();

                    $('login_flyout_close_popup').addEvent('click', function() {
                        flyout_sticky.hide();
                        if ($('activation_resendemail_address')) $('activation_resendemail_address').focus();

                        var ran_number=Math.random()*5; 
                        var post_vars = {
                            'delete' : 'true'	
                        };
                        var unset_cookie = new Request.JSON(
                        {
                            url: '/set_redirect_cookie?' + ran_number,
                            autoCancel: true,
                            onComplete: function(response) {
                            }
                        }).post(post_vars);
                        $('login_flyout_close_popup').removeEvents('click');

                    });
                }

            });

        });
    }
    
    if ($defined($('my_account_login'))) {
        attachFlyoutHandler('my_account_login');
    }
    
/*set a cookie for the page to return the user to upon completion*/    		
    if (!(document.cookie.match ( '(^|;) ?login_ret_url=([^;]*)(;|$)' ))) {
        var cookie_string = "login_ret_url="+escape(document.referrer);
        var expires = new Date ();
        expires.setTime(expires.getTime()+1000*60*60*6); //set cookie to expire in 6 hours
        cookie_string += "; expires=" + expires.toGMTString();
        cookie_string += "; domain=" + item_data['document_domain'];
        cookie_string += "; path=" + "/";
        document.cookie = cookie_string;
    }
          
}

window.addEvent('domready', function() {
	if (LIVENATION.instances.my_account !== 'object') {
		LIVENATION.instances.my_account = new Array();
	}

	if ($type(LIVENATION.registry.my_account) == 'array') {
		for (i = 0; i < LIVENATION.registry.my_account.length; i++) {
			LIVENATION.instances.my_account.push(new LIVENATION.module.my_account(LIVENATION.registry.my_account[i]));
		}
	}

})
