window.addEvent('domready',function() {logo();time();if($$('a[rel=NaMoo]') != null){new NaMooBox();}});

//logo
function logo(){
$('logo').set('html','<a href='+$('he1').getElement('a')+'><img src='+path+'pic/logo.png width=168 height=40></a>');
}
//logo
//NaMooBox NaMooBox NaMooBox NaMooBox NaMooBox NaMooBox NaMooBox NaMooBox NaMooBox NaMooBox 
var NaMooBox = new Class({

	initialize: function(){
		
		this.anchors = $$('a[rel=NaMoo]');
			
		this.anchors.each(function(a){
			a.store("caption", a.get("title") || a.getElement("img").get("alt"));
			a.addEvent("click", this.open.bind(this,a));
			
		},this);
		
		
		
		this.body = $(document.body);
		
		this.overlay = new Element("div", {
			id:'NaMoo_overlay',
			styles: {
				background:'#000',
				position: "absolute",
				index:9999,
				opacity:0.5,
				left:0,
				top:0
			},
			events: {
				click: this.close.bind(this)
			}
		}).inject(this.body,'bottom');
		
			
		this.quickBox = new Element("div", {
			id:'NaMoo_quickBox',
			styles: {			
				width:10,
				height:10,
				background:'#fff',
				position: "absolute",
				index:9999,
				//border:'10px solid #fff',
				//'border-top':'50px solid #fff',
				opacity:0,
				display:'block',
				marginTop:-5,
				marginLeft:-5,
				top: window.getScrollTop() + (window.getHeight()/2), 
				left: window.getScrollLeft() + (window.getWidth()/2)
			}
		}).inject(this.body);
		
		

		this.top = new Element("div", {
		styles: {			
				'position': 'absolute',
				'index': 9999,
				'width': '100%',
				'height': 30,
				'display': 'block',
				'color':'#0033C4',
				'font-size':'12px',
				'font-family':'Arial',
				'top':-30,
				'left':0,
				'background':'#fff',
				'cursor':'pointer'
			},
			events: {
				click:this.close.bind(this)
			}
		}).inject(this.quickBox);
		
		
		this.prevLink = new Element("div", {
			styles: {			
				'position': 'absolute',
				'index': 9999,
				'width': '50%',
				'height': '100%',
				'display': 'block',
				'color':'#fff',
				'font-size':'40px',
				'text-decoration':'none',
				'font-weight':700,
				'cursor':'pointer',
				'font-family':'Arial'
			}
			
		}).inject(this.quickBox);
		
		this.prevLink.addEvent("click", this.changeImage.bind(this, -1));
		
		this.nextLink = this.prevLink.clone().setProperty("id", "qbNext").inject(this.quickBox);
		this.nextLink.setStyles({'left':'50%'});
		
		this.nextLink.addEvent("click", this.changeImage.bind(this, 1));
			
		this.stage = new Element("div", {id: "qbStage"}).inject(this.quickBox);
		
		var nextEffect = this.nextEffect.bind(this);
		var nextEffect2 = this.nextEffect2.bind(this);
		
		this.fx = {
			overlay: new Fx.Tween(this.overlay, {
				property: "opacity"
			}),
			quickBox: new Fx.Tween(this.quickBox, {
				property: "opacity"
			}),
			resize: new Fx.Morph(this.quickBox, {
				duration: 600,
				transition: Fx.Transitions.Circ.easeOut,
				onComplete: nextEffect2
			}),
			show: new Fx.Tween(this.stage, {
				property: "opacity"
			})
		};
	},
	
	open: function(link){
		this.active = true;
				
		this.overlay.setStyles({
			width:window.getScrollSize().x,
			height:window.getScrollSize().y,
			display: "block"
		}); 
		
		this.quickBox.setStyles({
			display: "block"
		});

		this.fx.overlay.start(0.9);
		this.fx.quickBox.start(1);
		this.startLoad(link);
		return false;
	},
	
	startLoad: function(link,preload){

		if(!link) return;
		
		var image = new Asset.image(link.get("href"), {
			onload: function(){
				if(!preload && this.currentLink == link) this.nextEffect();
			}.bind(this)
		});
		if(!preload){
			this.stage.empty();
			this.top.set("html", '<div style="position:absolute;top:8px;left:10px;">Nalaganje...</div>');
			this.currentLink = link;
			this.currentImage = image;
			this.currentIndex = this.anchors.indexOf(link);
			this.currentCaption = link.retrieve("caption");
		}
	},
		
	changeImage: function(step,event){
		event.preventDefault();
		var link = this.anchors[this.currentIndex+step];
		if(!link) return false;
		this.startLoad(link);
	},
	
	nextEffect: function(){
	
				var w = this.currentImage.width;
				var h = this.currentImage.height;
				
				var ratio = w/h;
	
				var wi = window.getSize().x;
				var hi = window.getSize().y;
				var ratio_w = wi/hi;
						
				if(w > wi && ratio > ratio_w){
				w = wi-20;
				h = w/ratio;
				this.currentImage.width = w;
				this.currentImage.height = h;				
				} 
				
				if(h > hi && ratio < ratio_w){
				h = hi-80;
				w = h*ratio;
				this.currentImage.width = w;
				this.currentImage.height = h;
				}
				

				this.fx.resize.start({
					width: w,
					height: h,
					marginTop:-((h/2)-15),
					marginLeft:-(w/2),
					opacity:1,
					top: window.getScrollTop() + (window.getHeight()/2), 
					left: window.getScrollLeft() + (window.getWidth()/2)
				});
				
				
				var total = this.anchors.length;
				var num = this.currentIndex + 1;
				if(total != 1){
				this.prevLink.set('html','<div style="position:absolute;top:45%;left:0;padding:10px 2px;display:block;color:#000;background:#fff">&lt;</div>');
				this.nextLink.set('html','<div style="position:absolute;top:45%;right:0;padding:10px 2px;display:block;color:#000;background:#fff">&gt;</div>');
				}
				var bottom_text1 = "<div style='position:absolute;top:6px;left:10px;'><b>"+this.currentCaption+"</b> &nbsp; &nbsp; ("+num+"/"+total+")</div>";
				var bottom_text2 = "<div style='color:#000;position:absolute;display:block;font-weight:700;font-size:25px;padding:5px 5px 8px 5px;top:0px;right:0px;'><b>X</b></div>";
				this.top.set("html", bottom_text1+bottom_text2);
				
				//alert(w+'-'+h);
				
	},
	
	nextEffect2: function(){
				//alert('ne2');
				this.stage.empty();
				this.currentImage.inject(this.stage);
				this.fx.show.start(1);
	},

	close: function(){
		this.quickBox.setStyle("display", "none");
		this.overlay.fade("out");
		this.active = false;
	}
});
//NaMooBox NaMooBox NaMooBox NaMooBox NaMooBox NaMooBox NaMooBox NaMooBox NaMooBox NaMooBox
//---------------TIME
function time() 
{
var Digital=new Date();
var date = Digital.getDate();
var month = (Digital.getMonth());
var year = Digital.getFullYear();
var montharr=new Array("januar","februar","marec","april","maj","junij","julij","avgust","september","oktober","november","december");
var fulldate = date+"."+montharr[month]+" "+year;
var hours=Digital.getHours();
var minutes=Digital.getMinutes();
var seconds=Digital.getSeconds();
if (minutes<=9){minutes="0"+minutes;}
if (seconds<=9){seconds="0"+seconds;}
var fulltime = hours+":"+minutes+":"+seconds;
$$('.timer').set('text',fulldate+" "+fulltime);
time.delay(1000);
}
//---------------TIME
