
                document.appPath='http://www.collective-minds.com/';
                document.loadScript = function(src) {
                    if( src.substring(0,1) == '#') 
                        src = 'ScriptCompress.'+src.replace('#','!')+'.axd';   
                    var e = document.createElement('script');
                    e.src = src.replace('~/', document.appPath);
                    e.type = 'text/javascript';
                    document.getElementsByTagName('head')[0].appendChild(e);
                };

                document.toAbsoluteUri = function(appUrl) {
                    return appUrl.replace('~/', document.appPath);
                };

                document.loadCSS = function(src, media) {
                    var e = document.createElement('link');
                    e.href = src.replace('~/', document.appPath);
                    e.type = 'text/css';
                    e.rel = 'stylesheet';
                    if(media)
                        e.media = media;
                    document.getElementsByTagName('head')[0].appendChild(e);
                }; 
                
                document.loadCSSLast = function(src, media) {
                    jQuery('head').ready(function() {
                        var e = document.createElement('link');
                        e.href = src.replace('~/', document.appPath);
                        e.type = 'text/css';
                        e.rel = 'stylesheet';
                        if (media)
                            e.media = media;
                        document.getElementsByTagName('head')[0].appendChild(e);
                    });
                };

                

(function($) {
    document.loadScript("#ePath.Ajax.epath.js");
    document.loadScript("~/_includes/jQuery/ui/ui.core.js");
    document.loadScript("~/_includes/jQuery/ui/ui.draggable.js");
    document.loadScript("~/_includes/jQuery/ui/ui.resizable.js");
    document.loadScript("~/_includes/jQuery/ui/ui.dialog.js");
    document.loadScript("~/_includes/jQuery/ui/ui.tabs.js");

    document.loadCSSLast("~/_includes/jQuery/themes/theme/ui.all.css");

    $(window).load(function() {

        // Default Buttons
        //$ePath.addDefaultButton("#searchBar input[name=search]", "#searchBar input[name=submit]");



        //Contact Form validation
        (function(contactForm) {
            contactForm.addValidator({ submitButtons: ".submit", invalidCss: { border: "solid 1px red" }, validCss: { border: "solid 1px green" },
                fields: {
                    name: { selector: ".name", required: true, minLength: 2, required: true /*infoText:"Your email address",*/ },
                    email: { selector: ".email", required: true, email: true, required: true },
                    message: { selector: ".message", required: true, minLength: 2, required: true }
                }
            });

        })($("#contactForm"));

        //Signups
        (function() {
            var updateBar = jQuery("#signupForm");
            var upEmail = updateBar.find("input.email");


            updateBar.find(".submitSmall").click(function() {
                $("#signupError").text("");

                if ($ePath.validation.isEmail(upEmail.val())) {
                    CollectiveMinds.AddUpdateSignup("", upEmail.val(), function(results) {
                        if (results == "OK")
                            updateBar.html('<span>Thank you, you will now receive updates</span>');
                        else
                            $("#signupError").html('<label for="signup_email" generated="true" class="error">' + results + '</label>');
                    }, function(err) {
                        $("#signupError").html('<label for="signup_email" generated="true" class="error">' + err.get_message() + '</label>');
                        alert(err.get_message());

                    });
                } else {
                    $("#signupError").html('<label for="signup_email" generated="true" class="error">Please enter a valid email address.</label>');
                }
                return false;
            });
        })();



        //Map stuff
        (function() {
            //****************************************************************************************************
            //****************************  CAN BE TWEAKED TO RECALABRATE DOTS  **********************************
            //****************************************************************************************************
            var top = 51.610426653170714;
            var bottom = 51.42404561602712;
            var left = -0.3732791137695371;
            var right = 0.19749786376954185;
            var mapWidthPx = 861;  // map image width
            var mapHeightPx = 480;  //Map image height
            var mapTopMargin = 10;  //pixels of unused map space at the top of image.
            //****************************************************************************************************
            //****************************************************************************************************

            var dottyM = jQuery("#mapWithDots");
            var floatImage = jQuery('<div><img src="" /><span></span></div>');
            jQuery(document.body).append(floatImage);
            floatImage.css({ display: "block", position: "absolute", border: "solid 1px #888888", backgroundColor: "#666666", width: "118px", cursor: "pointer" });
            floatImage.find("span").css({ display: "block", color: "white", padding: "2px", textAlign: "center", fontWeight: "bold", fontFamily: "Verdana" });
            floatImage.hide();
            floatImage.click(function() { location.href = "venue.aspx?vid=" + this.venue.VenueID });

            if (dottyM.length > 0) {
                CollectiveMinds.GetVenues(function(results) {
                    jQuery(results).each(function(index) {
                        if (this.Latitude != 0 || this.Longitude != 0) {
                            fadeInDot(this, index);
                        }
                    });
                    //onDotsPlaced();
                });
            }

            function fadeInDot(venue, index) {
                var dot = jQuery('<a class="hotDot_' + venue.VenueID + '" title="' + venue.Name + '" href="venue.aspx?vid=' + venue.VenueID + '"></a>');




                var xPos = (venue.Latitude - left) * (mapWidthPx / (right - left));
                var yPos = (top - venue.Longitude) * ((mapHeightPx - mapTopMargin) / (top - bottom));
                yPos += mapTopMargin;

                if (xPos > 0 && xPos < mapWidthPx && yPos > 0 && yPos < mapHeightPx) {
                    dot.css({ marginTop: Math.round(yPos) + "px",
                        marginLeft: Math.round(xPos) + "px",
                        opacity: "0"
                    });
                    dottyM.append(dot);
                }
                dot.hover(function() {
                    var offset = jQuery(this).offset();
                    floatImage.find("img").attr("src", document.toAbsoluteUri("~/Resources/Venues/" + venue.VenueID + "_thumb.jpg"));
                    floatImage.find("span").text(venue.Name);
                    floatImage.css({ top: (offset.top - 105) + "px", left: (offset.left - 110) + "px" });

                    floatImage.show();
                    floatImage.noHide = true;
                    clearTimeout(floatImage.hideTimeout);
                    floatImage.get(0).venue = venue;
                    floatImage.stop();
                    floatImage.animate({ opacity: "1" }, { queue: false });
                }, function() {
                    floatImage.noHide = false;

                    floatImage.hideTimeout = setTimeout(function() {
                        floatImage.animate({ opacity: "0" }, { duration: 1000, queue: false, complete: function() { if (!floatImage.noHide) floatImage.hide(); } });
                    }, 2000);
                });
                setTimeout(function() {
                    dot.animate({ opacity: 1 });


                }, 50 * index);
            }
        })();


    }); // End on load
})(jQuery);




jQuery(function($) {
    // assign error div for signup form
//    $("form").validate({
//        errorLabelContainer: $("#signupError")
//    });
//    // remove outlines from clicked links
    $('a').bind("focus", function(e) { $(this).blur(); });
});
