var Site = {
  rootPath: '/',

  init: function() {
		Site.fixHomepageBoxes();
    Site.handleNewWinOpen();
    Site.handlePoll();
    var spinner = new Image();
    spinner.src = Site.rootPath +'client/css/images/spinner.gif';
  },
  
	fixHomepageBoxes: function() {
		var arrNewsLi = $$('ul.fresh-news li');
		if(arrNewsLi.length>0) {
			var heightSize = 0;
			arrNewsLi.each(function(link) {
				if(link.offsetHeight>heightSize) heightSize = link.offsetHeight;
			});
			arrNewsLi.each(function(link) {
				link.style.height = heightSize +'px';
			});
		}
	},
	
  handleNewWinOpen: function() {
    var links = $$('a.newWin');
    if(links.length>0) links.each(function(link) {link.addEvent('click', function(e) {window.open(this, '');e = new Event(e).stop();})});
  }, 
  
  handlePoll: function() {
    if($('frmPoll')) {
      $('frmPoll').addEvent('submit', function(e) {
        e = new Event(e).stop();
        var spinner = new Element('img').setProperties({id:'spinner', src:Site.rootPath +'client/css/images/spinner.gif', width:'16', height:'16', alt:'Učitavam...'});
        spinner.inject($('poll'));
        var ajaxOptions = {postBody:$('frmPoll'), update:'poll'};
        new Ajax(Site.rootPath +'homepage/poll/', ajaxOptions).request();
      });
    }
  }

}

window.addEvent('domready', Site.init);

