﻿(function () {

    // Localize jQuery variable
    var jQuery;

    /******** Load jQuery if not present *********/
    if (window.jQuery === undefined || window.jQuery.fn.jquery !== '1.7.1') {
        var script_tag = document.createElement('script');
        script_tag.setAttribute("type", "text/javascript");
        script_tag.setAttribute("src",
        "http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js");
        if (script_tag.readyState) {
            script_tag.onreadystatechange = function () { // For old versions of IE
                if (this.readyState == 'complete' || this.readyState == 'loaded') {
                    scriptLoadHandler();
                }
            };
        } else {
            script_tag.onload = scriptLoadHandler;
        }
        // Try to find the head, otherwise default to the documentElement
        (document.getElementsByTagName("head")[0] || document.documentElement).appendChild(script_tag);
    } else {
        // The jQuery version on the window is the one we want to use
        jQuery = window.jQuery;
        main();
    }



    /******** Called once jQuery has loaded ******/
    function scriptLoadHandler() {
        // Restore $ and window.jQuery to their previous values and store the
        // new jQuery in our local jQuery variable
        jQuery = window.jQuery.noConflict(true);
        // Call our main function
        main();
    }



    /******** Our main function ********/
    function main() {
        jQuery(document).ready(function ($) {
            var css_link = $("<link>", {
                rel: "stylesheet",
                type: "text/css",
                href: "http://www.awakening360.com/content/new360.css"
            });
            css_link.appendTo('head');
            $("#a360widget").text();

            /******* Load HTML *******/
            var jsonp_url = "http://www.awakening360.com/test/widad?id=" + apar + "&jsoncallback=?";
            $.getJSON(jsonp_url, function (data) {
                var dirname = data.dirname;
                var dirimage = data.dirimage;
                $("#a360widget").append("<div id='a360cont' class='fabox' style='width:290px;height:130px;'></div>");
                $("#a360cont").append("<div id='a360image' style='float:left;width:80px;height:80px;padding:5px;border:1px solid #cacaca;'></div>");
                $("#a360cont").append("<div class='boxheader3602' id='a360data' style='float:left;width:185px;height:130px;margin-left:10px;'></div>");
                $("#a360data").append("<div style='margin-bottom:5px;'><b class='tbheader'>Awakening360 Professional Member</b></div>");

                $("#a360data").append("<a href='http://www.awakening360.com/business/" + data.dirurl + "'><b style='font-weight:normal;'>" + data.dirdesc + "</b></a>");
                $("#a360image").append("<a href='http://www.awakening360.com/business/" + data.dirurl + "'><img id='theImg' style='width:80px;' src='http://www.awakening360.com/content/images/directories/" + dirimage + "'/></a>");
            });






        });
    }

})();
