// For the my.strose box thingee by Chief @ FMI

var myStRose = function(loggedIn) {

    var setLabels = function(obj) {
        var thisLabels = obj.find('label');

        thisLabels.each(function() {
            $(this)
                .hide()
            		.next()
                .not(':password')
            		.not('#email')
                .val($(this).text());
        });
    }

    setLabels($('#mystrose'));

    $('#mystrose .buttons div').
		hover(function(){ 
				$(this).addClass('buttonhover'); 
			},function(){ 
				$(this).removeClass('buttonhover'); 
	});

    $('#mystrose').bind('mouseleave', function() {
        var subbyIsShown = $('#mystrose #searchform .subby').css('display') == 'block';
        if (subbyIsShown) $('#mystrose #q').removeClass('focused').parent().find('.subby').slideUp('fast');
        if (!$(this).find('#q').val().length) setLabels($(this));
    });
    $('#mystrose #q').bind('focus', function() {
        if ($(this).val() == 'Site Search' || !$(this).val().length) $(this).val(''); else $(this).val($(this).val());
        $(this).addClass('focused').parent().find('.subby').slideDown('fast');
    }).bind('mouseenter', function() { if ($(this).parent().find('.subby').css('display') === 'none') $(this).trigger('focus'); });

    $('#mystrose').click(function(e) {
        var target = $(e.target);
        
        var isLogin = (target.is('a.showlogin') || target.find(':first').is('a.showlogin'));
		var isLogout = (target.is('a.hiddenatstart') && target.parent().is(':visible'));

		/* 
		//COMMENTING OUT LOGIN ON EVERY PAGE BEHAVIOR AS PER REQUEST
        if (isLogin && $('#login').css('display') == 'none') {
            $('.showlogin').parent().addClass('selected').parent().css('margin-bottom', '0');
            $('#login').show(250, function() {
                $('#email')
					.bind('focus', 
						function() 
							{ 
								if (!$(this).val().length) 
									{ $(this).val(''); $(this).select().get(0).focus(); }
								else
									$(this).select();
							});
			$('#email').trigger('focus');
			
			return false;
            }); //end of callback for show
        }
        else if (isLogin) { 
            $('#login').slideUp('slow', function() { $('.showlogin').parent().removeClass().parent().css('margin-bottom', '7px'); return false; });
        }
	if(!isLogout && (target.is('a.showlogin'))) return false
	*/;
	
	
    }); // end of click bind

    if(window.console) console.log('running myStRose('+loggedIn+') with bInEditMode = '+bInEditMode);
    
    if (loggedIn) {
        $("#logoutcontainer").show();
        $("#logincontainer").hide();
        $("#loginsignupcontainer").hide();
        $("#badge").html(sFN + " " + sLN);
	
	//NOTE: trying bInEditMode
    //if(typeof(bPageIsDraft)!=='undefined' && bPageIsDraft)
    
	if(bInEditMode){
            $('#mystrose')
                    .find('div, a, input')
                    .andSelf()
                        .unbind()
                        .css('cursor','default')
                    .filter('a')
                        .removeAttr('href')
                        .end() 
                    .filter('input')
                        .attr('disabled','disabled');
            }
      
    }

}  // end of myStRose function