$(document).ready(function()
{
    $(".clearInput").focus(function(srcc)
    {
        if ($(this).val() == this.defaultValue)
        {
            $(this).val("");
            $(this).css('color', '#000');
        }
    });
    
    $(".clearInput").blur(function()
    {
        if ($(this).val() == "")
        {
            $(this).val(this.defaultValue);
            $(this).css('color', '#888');
        }
    });
    
    $(".clearInput").blur();
    
    
	$("a[rel='lightbox']").colorbox();
    
    $('.innerfade').innerfade({
		speed: 750,
		timeout: 5000,
		type: 'random'
	});
    
    $(".validateForm").validate({
        errorPlacement: function(error, element) {
			error.prependTo( element.parent().next() );
		},
		// set this class to error-labels to indicate valid fields
		success: function(label) {
			// set &nbsp; as text for IE
			label.html("&nbsp;").addClass("checked");
		}
    });
    
    $('#aanbodSearchTabs > ul > li > span').click(function() {
        // Change the active class
        $('#aanbodSearchTabs > ul > li > span').removeClass('active');
        $(this).addClass('active');
        
        // Set new type
        $.post(root + '12/Aanbod.html', { switchTab: true, type: $(this).parent().attr('id') }, function(data) {
             location.reload(true);
        });
        return false;
    });
    
    $('.enqueteRadio').change(function()
    {
        if ($(this).val() == '1')
        {
            $(this).parent('td').siblings('.reden').show();
        }
        else
        {
            $(this).parent('td').siblings('.reden').hide();
        }
    });
    
    /*
    $('#aanbodSearchTabs > ul > li > a').click(function() {
        // Change active tab
        $('#aanbodSearchTabs > ul > li > a').removeClass('active');
        $(this).addClass('active');
        
        // Hide all tabs
        $('.pageTab').hide();
        $($(this).attr('href')).show();
        return false;    
    });
    */
    
    $('.smallPicture').click(function() {
        $('#bigPicture').attr('src', $(this).attr('id'));
        return false; 
    });
    
    $('select[name=plaats]').change(function() {
        $('input[name=selectedPlaats]').val($(this).val());
    })
    
    $('input[name=straatnaam]').autocomplete({
        source: function(request, response) {
            $.post(root + '2/Home.html', {'straten': 'true', 'nameContains': request.term, 'city': $('input[name=selectedPlaats]').val(), 'type': $('input[name=selectedType]').val()}, function(data) {
                 response($.map(data, function(item) {
                    return {
                        label: item.street
                    }
                 }));
            }, 'json');
        }
    });
    
    $('.carousel').jcarousel({
        auto: 3,
        scroll: 1,
        buttonPrevHTML: null,
        buttonNextHTML: null,
    	wrap: 'circular'
    });
});

function openTab(tab)
{
    $('#aanbodSearchTabs > ul > li > a').removeClass('active');
    $('a[class=' + tab + ']').addClass('active');
    $('.pageTab').hide();
    $('#' + tab).show();
    
    if (tab == 'map')
	{
        $('#map2').css('top', '-602px');
        $('#map2').css('left', '1px');
	} else {
	   $('#map2').css('top', '-10000px');
	}
    return false;
}

function openHomeTab(tab)
{
    $('#homeSearchTab > li > a').removeClass('active');
    $('a[class=' + tab + ']').addClass('active');
    $('.homeSearchTable').hide();
    $('#' + tab).show();
    $('input[name=selectedType]').val(tab)
    return false;
}

function handleNoFlash(errorCode) {
  if (errorCode == 603) {
    alert("Error: Flash doesn't appear to be supported by your browser");
    return;
  }
} 

function showAddress(map,geocoder,address,html, postalcode, i) {
	geocoder.getLatLng(
	address,
	function(point) {
		if (!point && i < 1) {
			showAddress(map, geocoder, postalcode, html, postalcode, 1);
		} else {
		    var icon = [];
            icon[0] = new GIcon();
            icon[0].image = "http://www.goethvastgoed.nl/images/markerGoeth.png";
            icon[0].shadow = "http://www.goethvastgoed.nl/images/shadowGoeth.png";
            icon[0].shadowSize = new GSize(37,34);
            icon[0].iconSize = new GSize(20,34);
            icon[0].iconAnchor = new GPoint(10,17);
            icon[0].infoWindowAnchor = new GPoint(10,17);
			map.setCenter(point, 15);
			var marker = new GMarker(point,{'icon': icon[0]});		
			map.addOverlay(marker);
			map.addControl(new GMapTypeControl());
			map.addControl(new GLargeMapControl());
		}
	});
}

function react($id)
{
	window.open('/reageer.php?id=' + $id,'React','width=450,height=500,scrollbars=no,toolbar=no');
}
