var sellercontactdetails = {

	details:[],
	button:0,

	logged:0,
	visible:0,
	advertid:0,

	init: function(advertid) {
                if (!$("#sellerdetailsbutton")) return false;
		sellercontactdetails.advertid=advertid;
                $("#sellerdetailsbutton").css({"overflow": "hidden", "background": "url(/images/contact-details.gif)"});
		sellercontactdetails.details = $(".contactdetails");
		if (!sellercontactdetails.details.length) return false;
		sellercontactdetails.hide();

                $("#sellerdetailsbutton")
                    .click(sellercontactdetails.toggle)
                    .hover(sellercontactdetails.mouseover, sellercontactdetails.mouseout);
	},
	
	toggle: function() {
            with(sellercontactdetails) {
                visible ? hide() : show();
            }
	},

	log: function() {
            if (!sellercontactdetails.logged) {
                $.get("/viewedcontactdetails.php?id=" + sellercontactdetails.advertid);	
                sellercontactdetails.logged=1;
            }
	},

        mouseover: function() {
            if (!sellercontactdetails.visible)
                $("sellerdetailsbutton").css("background-position", "0px 58px");
        },

        mouseout: function() {
            if (!sellercontactdetails.visible)
                $("sellerdetailsbutton").css("background-position", "0px 0px");
        },

	show: function() {
            sellercontactdetails.visible=1;
            $("sellerdetailsbutton").css("background-position", "0px -59px");
            $("sellerdetailsbutton_show").css("display", "none");
            $("sellerdetailsbutton_hide").css("display", "block");
            sellercontactdetails.log();
            sellercontactdetails.details.css("display", "block");
	},

	hide: function() {
            sellercontactdetails.visible=0;
            $("sellerdetailsbutton").css("background-position", "0px 0px");
            $("sellerdetailsbutton_show").css("display", "block");
            $("sellerdetailsbutton_hide").css("display", "none");
            sellercontactdetails.details.css("display", "none");
	}
}

