(function ($) {
    $.widget("ui.AgentInfo", {
        // default options
        options: {
            AgentName: "",
            AgentEmail: "",
            AgentCellPhone: "",
            AgentOfficePhone: "",
            AgentPhotoUrl: "",
            Header: "",
            FacebookIconUrl: "",
            FacebookLink: "",
            TwitterIconUrl: "",
            TwitterLink: "",
            YouTubeIconUrl: "",
            YouTubeLink: "",
            LinkedInIconUrl: "",
            LinkedInLink: "",
            Layout: "default"
        },
        _create: function () {

            $(this.element).html(
            '<div class="aiContainer">' +
		    '<div class="aiHeader"></div>' +
		    '<div class="aiPhoto"></div>' +
		    '<div class="aiAgentName"></div>' +
		    '<div class="aiCellPhoneLabel">Cell: </div>' +
		    '<div class="aiCellPhone"></div>' +
		    '<div class="aiOfficePhoneLabel">Office: </div>' +
		    '<div class="aiOfficePhone"></div>' +
		    '<div class="aiAgentEmail"></div>' +
		    '<div class="aiSocialMedia">' +
		    '<span class="aiFacebook"></span>' +
		    '<span class="aiTwitter"></span>' +
		    '<span class="aiLinkedIn"></span>' +
		    '<span class="aiYouTube"></span>' +
			'</div></div>');
			
			this._onLoad();
			$(this.element).fadeIn(2000);	//fancy and probably unnecessary effects :D
        },
        _onLoad: function () {
	
		//Display Agent Photo Url if supplied
		if (this.options.AgentPhotoUrl == "") {
		    $(this.element).find(".aiPhoto").hide();
		}
		else {
		    $(this.element).find(".aiPhoto").html('<img src="' + this.options.AgentPhotoUrl + '" />');  
		}

		//Display Agent Name if supplied
		if (this.options.AgentName == "") {
		    $(this.element).find(".aiAgentName").hide();
		}
		else {
		    $(this.element).find(".aiAgentName").text(this.options.AgentName);  
		}

		//Display Agent Cell Phone if supplied
		if (this.options.AgentCellPhone == "") {
		    $(this.element).find(".aiCellPhone").hide();
		    $(this.element).find(".aiCellPhoneLabel").hide();
		}
		else {
		    $(this.element).find(".aiCellPhone").text(this.options.AgentCellPhone);  
		}

		//Display Agent Office Phone if supplied
		if (this.options.AgentOfficePhone == "") {
		    $(this.element).find(".aiOfficePhone").hide();
		    $(this.element).find(".aiOfficePhoneLabel").hide();
		}
		else {
		    $(this.element).find(".aiOfficePhone").text(this.options.AgentOfficePhone);  
		}

		//Display Agent Email Clickable Link if supplied
		if (this.options.AgentEmail == "") {
		    $(this.element).find(".aiAgentEmail").hide();
		}
		else {
		    $(this.element).find(".aiAgentEmail").html(
		    '<a href="mailto:' + this.options.AgentEmail +
		    '">' + this.options.AgentEmail + '</a>'
		    );  
		}

		//Display Facebook Link if provided
		if (this.options.FacebookLink == "") {
		    $(this.element).find(".aiFacebook").hide();
		}
		else {
		     $(this.element).find(".aiFacebook").html(
		     '<a href="' + this.options.FacebookLink + '" target="_blank">' +
		     '<img src="' + this.options.FacebookIconUrl + '" /></a>'
		     );
		}

		//Display Twiter Link if provided
		if (this.options.TwitterLink == "") {
		    $(this.element).find(".aiTwitter").hide();
		}
		else {
		    $(this.element).find(".aiTwitter").html(
			'<a href="' + this.options.TwitterLink + '" target="_blank">' +
			'<img src="' + this.options.TwitterIconUrl + '" /></a>'
		    );
		}

		//Display LinkedIn Link if provided
		if (this.options.LinkedInLink == "") {
		    $(this.element).find(".aiLinkedIn").hide();
		}
		else {
		    $(this.element).find(".aiLinkedIn").html(
			'<a href="' + this.options.LinkedInLink + '" target="_blank">' +
			'<img src="' + this.options.LinkedInIconUrl + '" /></a>'
		    );
		}

	       //Display YouTube Link if provided
		if (this.options.YouTubeLink == "") {
		    $(this.element).find(".aiYouTube").hide();
		}
		else {
		    $(this.element).find(".aiYouTube").html(
			'<a href="' + this.options.YouTubeLink + '"target="_blank">' +
			'<img src="' + this.options.YouTubeIconUrl + '" /></a>'
		    );
		}


            //We only want to provide a style sheet link if they are not using a Custom Layout
            if (this.options.Layout.toLowerCase() == "default") {
                $("head").append("<link rel='Stylesheet' type='text/css' id='qsCss' href='http://tools.1parkplace.com/Widgets/AgentInfo/AgentInfoDefault.css' />");
            }

            //Display the header if specified.
            $(this.options.Header != "") ?
            $(this.element).find(".aiHeader").text(this.options.Header)
            : $(this.element).find(".aiHeader").hide();
         }
    });
})(jQuery);

