/* DOCUMENT READY
----------------------------------------------------------- */


$(function(){

    $('.debug').each(function(){
       console.log($(this).attr('rel') + ': ' + $(this).text());
       $(this).hide(); 
    });
    $("a[rel='colorbox']").colorbox();
    
    $('img[data-src2]').hover(
        function(){
            
            var src = $(this).attr('src');
            $(this).attr('src', $(this).attr('data-src2'));
            $(this).attr('data-src2', src);
        },
        function(){
            var src = $(this).attr('src');
            $(this).attr('src', $(this).attr('data-src2'));
            $(this).attr('data-src2', src);
        }
    ).each(function(){
        
        $('<img/>')[0].src = $(this).attr('data-src2');
        
    });
    
    /*
  $("a[rel='colorbox']").colorbox({onOpen:function(){ $("#header object").hide(); },
				                  onClosed:function(){ $("#header object").show(); }});*/

});


var geocoder;
var map;
var lokace;
function gMapInitialize() {
    geocoder = new google.maps.Geocoder();
    var latlng = new google.maps.LatLng(-34.397, 150.644);
    var myOptions = {
      zoom: 8,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}

function gMapFindAddress(address) {
    if(!address && lokace){
        map.setCenter(lokace);
        map.setZoom(16);
        var marker = new google.maps.Marker({
            map: map,
            position: lokace
        });

    }
    else{
        geocoder.geocode( { 'address': address}, function(results, status) {
          if (status == google.maps.GeocoderStatus.OK) {
            lokace = results[0].geometry.location;
            map.setCenter(results[0].geometry.location);
            map.setZoom(16);
            var marker = new google.maps.Marker({
                map: map,
                position: results[0].geometry.location
            });
          } else {
            alert("Geocode was not successful for the following reason: " + status);
          }
        });
    }
}




function addToBasket(btn) {

    var form = $(btn).closest('form');

    var $link = $(form).attr('action');
    $.ajax({
      url: $link,
      data: $(form).serialize(),
      type: 'GET',
      success: function(data) {
           $('#jquery-basket').html(data);
        alert('Zboží přidáno do košíku!'); }
    });

}


