// Loadpictures onclick
$(document).ready(function() {
jQuery.easing.def = "easeOutQuad";
$('a.toggle-info').click(function() {
$('li .info').slideToggle(200);
return false;
});
$("#thumbnail li a").click(function(){
if ($(this).attr("href") != "/images/no-photo.gif")
{
var altext = $("> img", this).attr("alt");
var imagename = $(this).attr("href");
var origimage = '/photos'+imagename.slice(imagename.lastIndexOf('/'));
$("#bigimg").fadeTo(0,0).attr({"src": imagename, "alt": altext});
$("#pict-cap").html(altext);
$("#largea").attr("href", origimage);
}
return false;
});
$("#bigimg").load(function()
 {
 $("#bigimg").fadeTo(600,1);
 });
function SendEmailMessage( modalWind)
 {
 var dialobj = $('<div></div>');
 $(dialobj).load( modalWind.targetUrl + ' ' + modalWind.TargetContainer,{ idn: buildid}, function(){
     $(dialobj).dialog({
        autoOpen: true,
        title: modalWind.title,
        height: 460,
        width: 470,
        modal: true,
        buttons: {
            "Odustani": function() {
              $( this ).dialog( "destroy" );
              $(dialobj).remove();
            },
            "Pošalji": function() {
              var datas = $( '#friend-form').serializeArray();
              $('div.error-box').remove();
              $.getJSON( modalWind.submitUrl , datas, function(retval){
                var err_flag = false;
                for(x in retval)
                {
                  var errnot = '<div class="error-box">' + retval[x] + '</div>';
                  $('#friend-form input#' + x).parent('li').prepend(errnot);
                  err_flag = true;
                }
                if(err_flag)
                {
                  $('#friend-form input#cptext').val('');
                  $('li img#captcha').attr('src', $('li img#captcha').attr('src') + 'x');
                }
                else
                {
                  $(dialobj).dialog('destroy');
                  $(dialobj).remove();

                  var dialmes = '<div title="Poruka"><div class="error-box info-box">Vaša poruka je uspešno poslata.</div></div>';
                  var dnote = $(dialmes).dialog({
                    autoOpen: false,
                    show: 'fade',
                    width: 500
                    });
                  $(dnote).dialog("open").fadeTo(1500, 1, function() {$(dnote).dialog("destroy")});
                }
              });
            }
          },
        close: function() { $(this).dialog('destroy'); $(dialobj).remove();}
        });
        
 });
};
    
  $('ul.contact a').click(function(){
    var sw_class = $(this).attr('class');
    switch(sw_class)
    {
      case 'to_friend':
        var mWind = {
          title: 'Obavestite prijatelja',
          targetUrl: 'form-note-friend.php',
          TargetContainer: '#friend-form',
          idn: buildid,
          submitUrl: 'php/sendmessage.php' 
        };
        SendEmailMessage(mWind);
        return false;
      case 'to_owner':
        var mWind = {
          title: 'Kontaktirajte vlasnika',
          targetUrl: 'form-contact-owner.php',
          TargetContainer: '#friend-form',
          idn: buildid,
          submitUrl: 'php/sendmessage.php'
        };
        SendEmailMessage(mWind);
        return false;
      default:
         return; 
    }
  });
    
}); 

