﻿var $stock;

$(function() {
    $('.PersonPopupDetail').hover(function() {
        var self = this;
        $('.FullName', this).fadeIn(200);
    }, function() {
        $('.FullName', this).fadeOut(200);
    });
    var $persona = $('.PersonPopupDetail a');
    if ($persona.length > 0) $('.PersonPopupDetail a').fancybox();
    
    $('#loginpopups a').fancybox({
        overlayShow: true,
        hideOnOverlayClick: false,
        hideOnContentClick: false,
        frameWidth: 700,
        frameHeight: 600
    });

    $('#cmdFind').click(addrSearch);
    $('#txtFind').keydown(function(e) {
        if (e.keyCode == 13) { e.preventDefault(); e.stopPropagation(); addrSearch(); return false; }
    });
    
    if (typeof Cms=='undefined') {
        $stock = $('#stock .ContentItemGalleryImage');
        if ($stock.length > 0) {
            window.setTimeout(function() {
                fadeItem(Math.floor(($stock.length) * Math.random()));
            }, 1000);
        }
    }
});

function fadeItem(item) {
    $stock.eq(item).fadeIn(500, function() {
        window.setTimeout(function() {
            $stock.eq(item).fadeOut(500, function() {
                item += 1; if (item > ($stock.length - 1)) item = 0;
                fadeItem(item);
            });
        }, 5000);
    });
}

function addrSearch(map, address) {
    var map = subgurim_;
    var address = $('#txtFind').val();
    var geocoder = new GClientGeocoder();
    geocoder.getLatLng(
        address,
        function(point) {
            if (!point) {
                alert(address + " niet gevonden.");
            } else {
                map.setCenter(point, 13);
//        var marker = new GMarker(point);
//        map.addOverlay(marker);
//        marker.openInfoWindowHtml(address);
            }
        }
    );
}
