/*
* 	Easy Tooltip 1.0 - jQuery plugin
*	written by Alen Grakalic	
*	http://cssglobe.com/post/4380/easy-tooltip--jquery-plugin
*
*	Copyright (c) 2009 Alen Grakalic (http://cssglobe.com)
*	Dual licensed under the MIT (MIT-LICENSE.txt)
*	and GPL (GPL-LICENSE.txt) licenses.
*
*	Built for jQuery library
*	http://jquery.com
*
*/
(function($) {

    $.fn.easyTooltip = function(options) {
        // default configuration properties
        var defaults = {
            xOffset: 10,
            yOffset: 25,
            tooltipId: "easyTooltip",
            clickRemove: true,
            content: "",
            useElement: ""
        };
        var options = $.extend(defaults, options);

        var myTitle = new Array();
        $(this).click(function(e) {
            var content = "";
            id = $(this).attr("id");
            if (myTitle[id] != undefined)
                content = myTitle[id];
            var ref = $(this).attr("ref");
            var ref1 = "";
            var ref2 = "";
            ref1 = $(this).attr("ref1"); //tham so ben ngoai truyen vao example: hotelid=?&roomtypeid=?
            ref2 = $(this).attr("ref2"); //Tên Hotel
            var _url = "/M/Reservations/WebServices/GetContentToolTip.aspx?" + ref1;
            var _data = "";
            if (ref == "promotion" && content == "") {
                execAjax(_url, _data, e, ref2)
            } else {
            var obj = $("<div id='" + options.tooltipId + "' ><div class='easyTooltip1' ><span style='float:left;font-weight:bold; color:White;padding-left:10px;'>" + ref2 + "</span><a class='close'><img src='/img/icons/xbox.png' /></a></div><div class='easyTooltip2'>" + content + "</div></div>");
                obj.find("a.close").bind("click", function(e) {
                    $("#" + options.tooltipId).remove();
                });
                $("body").append(obj);
                $("#" + options.tooltipId)
						    .css("position", "absolute")
						    .css("top", (e.pageY - options.yOffset) + "px")
						    .css("left", (e.pageX + options.xOffset) + "px")
						    .css("display", "none")
						    .fadeIn("fast")
                return false;
            }
        });

        function execAjax(_url, _data, e, ref2) {
            $.ajax({
                url: _url,
                data: _data,
                cache: true,
                success: function(html) {
                    if (html != "" && html != undefined) {
                        content = html;
                        myTitle[id] = content;
                        $("#" + options.tooltipId).remove();
                        var obj = $("<div id='" + options.tooltipId + "' ><div class='easyTooltip1' ><span style='float:left;font-weight:bold; color:White;padding-left:10px;'>" + ref2 + "</span><a class='close'><img src='/img/icons/xbox.png' /></a></div><div class='easyTooltip2'>" + html + "</div></div>");
                        obj.find("a.close").bind("click", function(e) {
                            $("#" + options.tooltipId).remove();
                        });
                        $("body").append(obj);
                        $("#" + options.tooltipId)
						    .css("position", "absolute")
						    .css("top", (e.pageY - options.yOffset) + "px")
						    .css("left", (e.pageX + options.xOffset) + "px")
						    .css("display", "none")
						    .fadeIn("fast")
                    }
                },
                error: function() {
                    //alert("Error khi lay du lieu gia phong - (2)");
                }
            });
        }

        //ván










        $("#wrapper").click(function(e) {
            $("#" + options.tooltipId).remove();
        });
    };

})(jQuery);
//obj.find("input.RoomDeal").bind("click", function(e){ 