﻿
// Cufon text replacememnt, add more elements to replace text with cufon generated text.
Cufon.replace('h2, .cufon, .banner', { hover: true });

$(document).ready(function () {
    //Main navigation dropdowns    
    if ($(document).superfish) {
        $('ul.sf-menu').superfish({
            delay: 300,                             // one second 0 delay on mouseout 
            animation: { height: 'show' },          // fade-in and slide-down animation 
            speed: 'fast',                          // faster animation speed 
            autoArrows: false,                      // disable generation of arrow mark-up 
            dropShadows: false                      // disable drop shadows 
        });
    }

    if ($.browser.safari) {
        $('ul.sf-menu li a').css('display', 'table-cell');
    };

    // Add watermarks
    $("[watermark]").each(function (num, el) {
        $(el).watermark($(el).attr("watermark"));
    });

    //IE6 compatibility
    if ($.browser.msie && $.browser.version == "6.0") {
        $('input[type=text]').addClass('typetext');
        $('input[type=checkbox]').addClass('checkbox');
        $('input[type=checkbox] + label').addClass('checkbox');
        $('textarea').addClass('textarea');

        //compatibility for Superfish
        if (document.getElementById) {
            getSuperFishForIE6($('.sf-menu')[0]);
        }
    }
});

function getSuperFishForIE6(list) {
    for (i = 0; i < list.childNodes.length; i++) {
        node = list.childNodes[i];
        if (node.nodeName == "LI") {
            node.onmouseover = function () {
                this.className += " over";
            }
            node.onmouseout = function () {
                this.className = this.className.replace(" over", "");
            }
        }
        if (node.childNodes) {
            for (j = 0; j < node.childNodes.length; j++) {
                subnode = node.childNodes[j];
                if (subnode.nodeName == "UL") {
                    getSuperFishForIE6(subnode);
                }
            }
        }
    }
}

/* Google Maps */
$.googleMap = {
    maps: {},
    marker: function (m) {
        if (!m) {
            return null;
        } else if (m.lat == null && m.lng == null) {
            return $.googleMap.marker($.googleMap.readFromGeo(m));
        } else {
            var marker = new GMarker(new GLatLng(m.lat, m.lng), m.opts);
            if (m.txt) { GEvent.addListener(marker, "click", function () { marker.openInfoWindowHtml(m.txt, m.windowOpts); }); }
            return marker;
        }
    },
    readFromGeo: function (elem) {
        var latElem = $(".latitude", elem)[0];
        var lngElem = $(".longitude", elem)[0];
        if (latElem && lngElem) { return { lat: parseFloat($(latElem).attr("title")), lng: parseFloat($(lngElem).attr("title")), txt: $(elem).attr("title")} } else { return null; }
    },
    mapNum: 1
};

$.fn.googleMap = function (lat, lng, zoom, options) {
    // If we aren't supported, we're done    
    if (!window.GBrowserIsCompatible || !GBrowserIsCompatible()) return this;

    // Default values make for easy debugging
    if (lat == null) lat = 37.4419;
    if (lng == null) lng = -122.1419;
    if (!zoom) zoom = 13;
    // Sanitize options
    if (!options || typeof options != 'object') options = {};
    options.mapOptions = options.mapOptions || {};
    options.markers = options.markers || [];
    options.controls = options.controls || {};

    // Map all our elements
    return this.each(function () {
        // Make sure we have a valid id
        if (!this.id) this.id = "gMap" + $.googleMap.mapNum++;

        // Create a map and a shortcut to it at the same time
        var map = $.googleMap.maps[this.id] = new GMap2(this, options.mapOptions);

        // Center and zoom the map
        map.setCenter(new GLatLng(lat, lng), zoom);

        // Add controls to our map
        for (var i = 0; i < options.controls.length; i++) {
            var c = options.controls[i];
            eval("map.addControl(new " + c + "());");
        }

        // If we have markers, put them on the map
        var marker = null;
        for (var i = 0; i < options.markers.length; i++) {
            if (marker = $.googleMap.marker(options.markers[i]))
                map.addOverlay(marker);
        }
    });
};
