$jq.namespace('MatchSuccess');

MatchSuccess.DisplayPhoto = function(photo) {
    var _photo = photo;
    
    var self = {
        FullUrl : function() {
            return (_photo != null) ? _photo.FullUrl : MatchCore.CP.getAsset("success/images/noPhotoLarge.jpg");
        },
        MediumUrl : function() {
            return (_photo != null) ? _photo.MediumUrl : MatchCore.CP.getAsset("success/images/noPhotoLarge.jpg");
        },
        SmallUrl : function() {
            return (_photo != null) ? _photo.SmallUrl : MatchCore.CP.getAsset("success/images/noPhotoSmall.jpg");
        }
    };
    
    return self;
};

MatchSuccess.Navigation = {
	getMyStoryUrl : function() {
		return (MatchCore.Success.HasApprovedStory()) ? '/success/story.aspx?ownerid=' + MatchCore.Success.UserId() : '/success/addStory.aspx';
	}
};

MatchCore.Page.onInitComplete(function() {
    $jq('.sigin').behavior('MatchCore.Success.Login', function(login) {
        login.onAuthenticated(function(response) {
            response = response[0];
            if (response.Success) {
                window.location = '/success/addStory.aspx';
            }
        });
    });

    $jq(".forgotPass").click(function() {
        $jq(".contentInner").removeClass("loginScene").addClass("forgotPassScene");
    });
});

MatchCore.CP.CurrentUser.onReady(function() {
        if (!MatchCore.CP.CurrentUser.Registered() && !MatchCore.Success.Security.LoggedIn())
            $jq(".pushToMatch a").attr("href", "http://www.match.com/registration/registration.aspx");
});

function WaterMark(targetClass, text, watermarkcss) {
    var _targetClass = targetClass;
    var _text = text;
    var _watermarkCss = watermarkcss;

    return {
        attach: function() {
            $jq(_targetClass).filter(function() {
                return $jq(this).val() != _text
            }).removeClass(_watermarkCss);

            $jq(_targetClass).focus(function() {
                $jq(this).filter(function() {
                    return $jq(this).val() == "" || $jq(this).val() == _text
                }).removeClass(_watermarkCss).val("");
            });

            $jq(_targetClass).blur(function() {
                $jq(this).filter(function() {
                    return $jq(this).val() == ""
                }).addClass(_watermarkCss).val(_text);
            });
        }
    }
}

$jq(document).ready(function() {
    //remove Other form browse success
    $jq(".browseSuccess #category option, .browseStories #category option, .storyCategories a").each(function() {
        if ($jq(this).text().toLowerCase() === "other") {
            if (!$jq(this).attr("href")) {
                $jq(this).remove();
            } else {
                $jq(this).parent("li").hide();
            }
        }
    });
});
