﻿$(document).ready(function() {
    $(".divDestaqueHome").mouseover(function() {
        $(this).prev().children().first().show();
    });
    $(".divDestaqueHome").mouseout(function() {
        $(this).prev().children().first().hide();
    });

    $('.aMenuImagens').click(function() {
        $('.divImagens').css('display', 'none');
        $('div[option="' + $(this).attr('option') + '"]').css('display', 'block');
    });

    try {
        $("a[rel^='prettyPhoto[product]']").prettyPhoto({ theme: 'facebook' });
    } catch (ex) { }

    try {
        changeImagemDestaque('#divBackgroundCenterHomeTopImage', 0, 5000);
    }
    catch (ex) { }
});

var timeoutControl2;
function changeImagemDestaque(featuresWrapperID, featureID, time, bypassImageChange) {

    clearTimeout(timeoutControl2);

    var children = $('.divBackCenterHomeImagem').length-1;

    //alert(children);

    for (i = 0; i <= children; i++) {
        $(featuresWrapperID + i).stop(true, true)
        $(featuresWrapperID + i).fadeOut();
    }

    if (!bypassImageChange) {
        $(featuresWrapperID + featureID).fadeIn("slow");
    }
    else {
        $(featuresWrapperID + featureID).show(2000);
    }

    if (children > 1) {
        var nextFeature = (featureID < children) ? featureID + 1 : 0;
        if (time > 0) { timeoutControl2 = setTimeout(function () { changeImagemDestaque(featuresWrapperID, nextFeature, time) }, time); }
    }
}

function googleMap(decLat, decLong, strTitle) {
    var myLatlng = new google.maps.LatLng(decLat, decLong);
    var myOptions = {
        zoom: 15,
        center: myLatlng,
        mapTypeId: google.maps.MapTypeId.HYBRID
    }
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

    var marker = new google.maps.Marker({
        position: myLatlng,
        map: map,
        title: strTitle
    });
}

// Google Maps
//var map;
var GoogleMaps = {
    Map: Object,
    DirectionsDisplay: Object,
    DirectionsService: Object,

    Init: function (lat, long, zoom, container, textbox, button, strTitle) {
        var position = new google.maps.LatLng(lat, long);
        var myOptions = {
            zoom: zoom,
            center: position,
            mapTypeId: google.maps.MapTypeId.HYBRID
            //mapTypeId: google.maps.MapTypeId.ROADMAP
        }
        GoogleMaps.Map = new google.maps.Map($(container)[0], myOptions);

        //key press para a caixa de texto
        if (textbox && button) {
            $(textbox).keypress(function (e) {
                if (e.which == 13) {
                    $(button).click();
                    return false;
                }
            });
        }

        var marker = new google.maps.Marker({
            position: position,
            map: GoogleMaps.Map
        });

        GoogleMaps.DirectionsService = new google.maps.DirectionsService();
        GoogleMaps.DirectionsDisplay = new google.maps.DirectionsRenderer();

    },

    GetDirections: function (textBox, location, to, from, directionsPanel) {
        if ($(textBox).val() != '') {

            // inicializa
            GoogleMaps.DirectionsDisplay.setMap(GoogleMaps.Map);
            GoogleMaps.DirectionsDisplay.setPanel(document.getElementById(directionsPanel))

            // efectua o cálculo e mostra no mapa
            var start = ($('#' + to).attr('checked')) ? $('#' + location).val() : $('#' + textBox).val();
            var end = ($('#' + to).attr('checked')) ? $('#' + textBox).val() : $('#' + location).val();
            var request = {
                origin: start,
                destination: end,
                travelMode: google.maps.DirectionsTravelMode.DRIVING
            };
            GoogleMaps.DirectionsService.route(request, function (result, status) {
                if (status == google.maps.DirectionsStatus.OK) {
                    GoogleMaps.DirectionsDisplay.setDirections(result);
                }
            });

        }
    }
}

// /Google Maps
