var imgPath = '';
$(document).ready(function () {
  setTimeout(function () {

    imgPath = themedir + '/images/';
  }, 400);
});

var callRestorant = function (id) {
  subDialog.overlay = true;
  subDialog.buttons.splice(subDialog.buttons.indexOf('close'), 1);
  subDialog.init();
  subDialog.open(600, 500, 'Google Maps');
  postAjax(sitedir + '/maps?id=' + id + '&onlyAction=true&cid=' + cid, 'ajaxData', '');
  setTimeout(function () {
    subDialog.changeData($("#ajaxData").html(), 'assign');
  }, 1000);
}
var pollSelectVote = function (id) {
  var theForm = document.getElementById('pollform');
  var opts = theForm.getElementsByTagName('img');
  var imgs = Array('optcheckon.png', 'optcheckoff.png');
  if (document.getElementById('option_id') != null)
    document.getElementById('option_id').value = id;

  for (var i = 0; i <= opts.length - 1; i++) {
    if (opts.item(i).className == 'polloption') {
      if (opts.item(i).id == id)
        opts.item(i).src = imgPath + imgs[0];
      else
        opts.item(i).src = imgPath + imgs[1];
    }
  }


}
var adressGetted = false;
var adressForms = '';
var selectAdress = function () {

  subDialog.overlay = true;
  subDialog.buttons.splice(subDialog.buttons.indexOf('close'), 1);
  subDialog.init();
  subDialog.open(600, 350, 'ADRES');
  if (adressGetted == false) {
    setTimeout(function () {
      adressForms = $("#selectaddres").html();
      subDialog.changeData($("#selectaddres").html(), 'assign');
      $("#selectaddres").html('');
      adressGetted = true;
    }, 1000);
  } else {
    subDialog.changeData(adressForms, 'assign');
  }
}

// JavaScript Document
var sitedir;
var themedir;
var ajaxhash;
var tH = 0;


var appendFacebox = function (links) {
  var links;
  var sss = '<div id="favoriteCount" style="margin:0px; padding:2px 0px 5px 2px; height:20px; width:450px"><div id="fb-root"><fb:like href="' + links + '" show_faces="false" width="450" height="20"></fb:like></div></div>';
  $(".ui-dialog[aria-labelledby=ui-dialog-title-productBox] .ui-dialog-buttonpane").append(sss);
  setTimeout(function () {
    FB.init({ appId: '355315023712', status: true, cookie: true,
      xfbml: true });
  }, 1000);
}

var scrollToContent = function (id) {
  $("#detail_" + id).animate({
    scrollTop: "+=50"
  });
}

var ratio;
var scrollMax;
var scrollSize;
var scrollInterval;

function scrollBasket(y, target) {
  var y;
  if (0 - (y * ratio) < 0) {
    var pos = y * ratio;
    clearInterval(scrollInterval);
    scrollInterval = setInterval(function () {
      $("#" + target).stop();
      $("#" + target).animate({ top: (0 - (y * ratio)) }, "fast", function () {
        clearInterval(scrollInterval);
      });

    }, 20);
  }

}

var postChangeMenu = function (target, item_id, obj) {
  var val = $(obj).val();
  postAjax(sitedir + '/buy?a=postSubItemChanges&cid=' + ajaxhash + '&onlyAction=true&menu=' + target + '&item_id=' + item_id + '&value=' + val, 'ajaxData', '');
}

var postPoll = function (url) {
  var url;
  postAjax(url, 'pollform', 'pollform');
  var html = '<div style="margin-top:10px" align=center><img src="' + themedir + '/images/ajax-loader.gif"></div>';
  $("#homepoll").html('');
}

var printWarn = function(obj, title, message, interval) {
  var title;
  var message;
  if (!isNaN(interval)) {
    setTimeout(function () {
      $(obj).html('');
    }, interval);
  }
  var htm = '<div class="ui-corner-all ui-state-highlight" style="margin-bottom:5px; padding:5px">' +
          '<p>' +
          '<span class="ui-icon ui-icon-info"></span><strong style="display:inline">' + title + '</strong>' + message +
          '</p>' +
          '</div>';
  $(obj).html(htm);

};

var printError = function(obj, title, message, interval) {
  var title;
  var message;
  if (!isNaN(interval)) {
    setTimeout(function () {
      $(obj).html('');
    }, interval);
  }
  var htm = '<div class="ui-corner-all ui-state-error" style="margin-bottom:5px; padding:5px">' +
          '<p>' +
          '<span class="ui-icon ui-icon-alert"></span>' +
          '<strong style="display:inline">' + title + '! </strong>'
          + message +
          '</p>' +
          '</div>';
  $(obj).html(htm);
};

function postForm(formName, url, target) {
  var formName
  var url
  // window.open(url);
  url = url + '&' + ($("#" + formName).serialize());
  ajaxPost(url, target, '');

}


