if (!UserVoice) {
  var UserVoice = {}
}

UserVoice.Util = {
//	sslAssetHost: "https://uservoice.com",
//	assetHost: "http://cdn.uservoice.com",
    sslAssetHost: "/",
	assetHost: "/",
  getAssetHost: function() {
    return ("https:" == document.location.protocol) ? this.sslAssetHost : this.assetHost
  },
  requireCss: function(path) {
	  document.write('<style type="text/css" media="screen">@import url(\'' + this.getAssetHost() + '' + path + '\');</style>')
  },
  requireJs: function(path) {
		document.write('<script type="text/javascript" src=\'' + this.getAssetHost() + '' + path  + '\'></script>')
  },
  render: function(template, params) {
    return template.replace(/\#{([^{}]*)}/g,
      function (a, b) {
          var r = params[b]
          return typeof r === 'string' || typeof r === 'number' ? r : a
      }
    )
  }
}

UserVoice.Tab = {
	id: "uservoice-feedback-tab",
	css_template: "a##{id} { #{alignment}: 0; background-color: #{background_color}; background-image: url(#{text_url}); border: outset 1px #{background_color}; border-#{alignment}: none; -moz-border-radius: 1em; -moz-border-radius-top#{alignment}: 0; -moz-border-radius-bottom#{alignment}: 0; -webkit-border-radius: 1em; -webkit-border-top-#{alignment}-radius: 0; -webkit-border-bottom-#{alignment}-radius: 0;}" +
     "a##{id}:hover { background-color: #{hover_color}; border: outset 1px #{hover_color}; border-#{alignment}: none; }" +
     "* html a##{id} { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='#{text_url}');",
  content_template: '<iframe src="#{url}" frameborder="0" scrolling="no" allowtransparency="true" width="#{width}" height="#{height}" style="height: #{height}; width: #{width};"></iframe>',
///widgets/#{dialog}.html?referer=#{referer}
  show: function(options) {
  options.counter++;
    this.setupOptions(options || {})
		UserVoice.Util.requireCss('App_Themes/Default/css/tab.css')
		UserVoice.Util.requireJs('App_Themes/Default/script/dialog.js')
    document.write('<a id="' + this.id + '" onclick="UserVoice.Tab.onClick(); return false;" href="' + this.url() + '" style="top: '+ this.options.setTop +'"></a>')		
	  document.write('<style type="text/css">' + UserVoice.Util.render(this.css_template, this.options) + '</style>')
  },
  setupOptions: function(options) {
	  this.options = {
		  alignment: 'left',
		  background_color:'#f00', 
		  text_color: 'white',
		  hover_color:'#06C',
		  dialog: 'popin',
		  width: '350px',
		  height: '400px',
		  setTop: '50% !important',
		  setImg: 'pagamenti_tab_white.png'
	  }
    for (attr in options) { this.options[attr] = options[attr] }
	  this.options.text_url = UserVoice.Util.getAssetHost() + 'App_Themes/Default/images/' + this.options.setImg
	  this.options.id = this.id	
	  this.options.referer = this.getReferer()
	  this.options.url = this.url()
  },
  onClick: function() {
	  UserVoice.Dialog.show(UserVoice.Util.render(this.content_template, this.options))
  },
  getReferer: function() {
		var referer = window.location.href
	  if (referer.indexOf('?') != -1) { referer = referer.substring(0, referer.indexOf('?')) } // strip params
	  return referer
	},
  url: function() {
	  return this.options.host;//document.location.protocol + '//' + this.options.host + '/pages/' + this.options.forum
  }
}