﻿// This function converts the specified control into a Google Map.
function initGoogleMap(mapControlID, initialLongitude, initialLatitude, initialZoomLevel, infoText) {
    try {
        // Use jQuery to get the map control from the ID.
        mapControl = jQuery("#" + mapControlID)[0];

        // Check if Google Maps is supported in this browser.
        if (GBrowserIsCompatible()) {
            // Create GMap2 object for the map control.
            map = new GMap2(mapControl);

            // Enable zooming using the mouse scroll wheel.
            // map.enableScrollWheelZoom();

            // Hide map types that are not needed (Hybrid, Satellite, Physical).
            // map.removeMapType(G_HYBRID_MAP);
            // map.removeMapType(G_SATELLITE_MAP);
            // map.removeMapType(G_PHYSICAL_MAP);

            // Create the point from the initial coordinates.
            var point = new GLatLng(initialLatitude, initialLongitude);

            // Center the map to the initial point, using the initial zoom level.
            map.setCenter(point, initialZoomLevel);

            // Show the default UI.
            map.setUIToDefault();

            // Create a marker for that point.
            var marker = new GMarker(point);

            // Add the marker to the map.
            map.addOverlay(marker);

            if (infoText != null && infoText != '') {
                // Register event listener for this marker.
                GEvent.addListener(marker,
                               'mouseover',
                               function () {
                                   // On mouse over, open the info window, displaying the given HTML.
                                   marker.openInfoWindowHtml(infoText);
                               });
                GEvent.addListener(marker,
                               'click',
                               function ()
                               {
                                   // On mouse over, open the info window, displaying the given HTML.
                                   marker.openInfoWindowHtml(infoText);
                               });
            }
        }
        else {
            // If Google Maps is not supported in this browser, display error.
            alert('Google Maps not supported in this browser.');
        }
    }
    catch (error) {
        // If something goes wrong, display error.
        alert(error.message)
    }
}

// This function cycles between the child elements of the specified control.
function cycleElements(cycleControlID, transitionSpeed)
{
    jQuery("#" + cycleControlID).cycle({
        speed: 1000,
        timeout: transitionSpeed
    });
}

function addPeopleSearchBoxWatermark() {
    var searchbox = jQuery('#c5-ap-pswp-keywords');

    if (searchbox.val() == null || searchbox.val() == '') {
        searchbox.val("Search for a person...");
        searchbox.addClass("c5-ap-pswp-queryprompt");
    }

    searchbox.blur(function () {
        if (jQuery(this).val() == null || jQuery(this).val() == '') {
            jQuery(this).val("Search for a person...");
            if (!jQuery(this).hasClass("c5-ap-pswp-queryprompt"))
                jQuery(this).addClass("c5-ap-pswp-queryprompt");
        }
    }
	);

    searchbox.focus(function () {
        if (jQuery(this).hasClass("c5-ap-pswp-queryprompt")) {
            jQuery(this).removeClass("c5-ap-pswp-queryprompt");
            jQuery(this).val("");
        }
    }
	);

}


function addSearchBoxWatermark() {
    var searchcheck = jQuery('div.c5-ap-topsearch').find('#SRSB').children('div').children('input:last-child');
    var searchbox = jQuery('div.c5-ap-topsearch td.ms-sbcell > input.ms-sbplain');
    searchbox.attr('value', 'I\'m looking for...');
    if (!searchbox.hasClass('s4-searchbox-QueryPrompt')) {
        searchbox.addClass('s4-searchbox-QueryPrompt');
    }


    searchbox.removeAttr('onblur');
    searchbox.removeAttr('onfocus');

    searchbox.blur(function () {
        if (jQuery(this).attr('value') == null || jQuery(this).attr('value') == '') {
            jQuery(this).attr('value', 'I\'m looking for...');
            if (!jQuery(this).hasClass('s4-searchbox-QueryPrompt'))
                jQuery(this).addClass('s4-searchbox-QueryPrompt');
            searchcheck.attr('value', '0');
        }
        else {
            searchcheck.attr('value', '1');
        }
    });

    searchbox.focus(function () {
        if (searchcheck.attr('value') == '0') {
            jQuery(this).attr('value', '');
            if (jQuery(this).hasClass('s4-searchbox-QueryPrompt')) {
                jQuery(this).removeClass('s4-searchbox-QueryPrompt');
            }
            searchcheck.attr('value', '1');
        }
    });
}

function removeTopBarFromTop() {
    var isiPad = navigator.userAgent.match(/iPad/i) != null;
    if ((jQuery('a.s4-signInLink').length > 0) || (isiPad)) {
        jQuery('#s4-ribbonrow').css('display', 'none');
    }
}


var currenthover = '';


