var Site = {
  rootPath: '/',

  init: function() {
    Site.handleNewWinOpen();
    // Site.handleLightbox();
    // Site.handleLyrics();
    // Site.sfHover();
    // Site.handlePoll();
    var spinner = new Image();
    spinner.src = Site.rootPath +'client/css/images/spinner.gif';
  },
  
  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();})});
  },
  
  handleLightbox: function() {
    var imgs = $ES('div.static-text a img', 'content');
    if(imgs.length>0) imgs.each(function(img) {img.getParent().setProperty('rel', 'lightbox[galleries]');});
    // alert($('content').innerHTML);
  }, 
  
  sfHover: function() {
    var isIE = !window.opera && navigator.userAgent.indexOf('MSIE') != -1;
    if(!isIE) return;
    if(!document.getElementById("main-nav")) return;
    var sfEls = document.getElementById("main-nav").getElementsByTagName("LI");
    for (var i=0; i<sfEls.length; i++) {
      sfEls[i].onmouseover=function() {
        this.className+=" sfhover";
      }
      sfEls[i].onmouseout=function() {
        this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
      }
    }
  }, 
  
  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();
      });
    }
  }

}

// Otvara sliku u popup-u velicine slike
function popup(path, width, height) {
	var win = window.open('', 'popup_win', 'width='+width+',height='+height+',top='+(screen.height/2-(height/2))+',left='+(screen.width/2-(width/2)));
	win.document.write('<html>\n<head>\n<title>Preglednik slika</title>\n</head>\n');
	win.document.write('<body marginwidth=0 marginheight=0 topmargin=0 leftmargin=0 onblur="window.close()">\n');

	if( path.substring( (path.length-3),path.length )=='swf' ) {
		win.document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" WIDTH='+width+' HEIGHT='+height+'><PARAM NAME=movie VALUE="'+path+'"> <PARAM NAME=quality VALUE=high> <EMBED src="'+path+'" quality=high WIDTH='+width+' HEIGHT='+height+' TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=Shockwav eFlash"></EMBED> </OBJECT>');
	} else {
		win.document.write('<a href="javascript:void(0);" onclick="window.close()" title="Klik za zatvaranje prozora"><img src="'+path+'" width="'+width+'" height="'+height+'" border="0" /></a>');
	}

	win.document.write('</body>\n');
	win.document.write('</html>\n');
	win.document.close();
}

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

jQuery(document).ready(function() {
  if(jQuery('body.top_cat_6 img[src=http://www.project6.hr/repository/Preuzmi.gif]').size()) {
    jQuery('body.top_cat_6 img[src=http://www.project6.hr/repository/Preuzmi.gif]').each(function(idx) {
      var current_parent = jQuery(this).parent();
      var mp3 = jQuery(current_parent).attr('href').split('/')[4].replace('.mp3', '');
      jQuery(current_parent).attr('href', Site.rootPath + 'download_mp3.php?file=' + mp3 + '.mp3');
    });
  }
  
  var preload1 = jQuery('<img src="http://www.project6.hr/repository/spikeri_mouseover_glasovi.jpg" alt="" />');
  var preload2 = jQuery('<img src="http://www.project6.hr/repository/spikeri_mouseover_radionica.jpg" alt="" />');
  
});

