window.addEvent('domready',function() {popmenu();logo();if($$('a[rel=NaMoo]') != null){new NaMooBox();}if($('form1') != null){new NaMooForm();}});
window.addEvent('load', function() {if($('news_ticker') != null){new NewsTicker();}if($('NaMooSlideC') != null){new NaMooSlideC();}});
//logo
function logo(){
$('logo').set('html','<a href='+$('he1').getElement('a')+'><img src='+path+'pic/logo.png width=283 height=56></a>');
}
//logo

//popmenu popmenu popmenu popmenu popmenu popmenu popmenu
function popmenu(){
$('na2').getElements('li a').each(function(el){
	el.addEvent('mouseover', function(event){
	if(el.get('title') == 'O nas'){show('na3p');}else {hide('na3p');}
	if(el.get('title') == 'Zaposlitev'){show('na7p');}else {hide('na7p');}
	if(el.get('title') == 'Informacije'){show('na8p');}else {hide('na8p');}
	});
	$('na3p').addEvent('mouseleave', function(event){hide('na3p')});
	$('na7p').addEvent('mouseleave', function(event){hide('na7p')});
	$('na8p').addEvent('mouseleave', function(event){hide('na8p')});
});
function show(a){$(a).setStyles({'display':'block','z-index':9999});$(a).fade('in');}
function hide(a){$(a).fade('out');}
}
//popmenu popmenu popmenu popmenu popmenu popmenu popmenu

//NewsTicker NewsTicker NewsTicker NewsTicker NewsTicker NewsTicker
NewsTicker = new Class({

	showDuration1: 7000,
	showDuration2: 500,

	initialize: function() {
	
		this.slideshow = $('news_ticker');
		this.slideshow.setStyle('display','block');
		this.ul = this.slideshow.getElement('ul');
		this.li = this.slideshow.getElements('li');
	
		this.x = 0;
		this.li.each(function(li,i){li.setStyle('opacity',[i<1?1:0]);},this);
		this.start();	
		
		this.ul.addEvents({
			mouseenter: function() {this.stop(); }.bind(this),
			mouseleave: function() {this.start(); }.bind(this)
		});
	},  

	show: function() {
		this.effect(this.x,0);
		this.x=this.x<this.li.length-1?this.x+1:0;
		this.effect(this.x,1);
	},

	start:function() {this.interval = this.show.bind(this,'').periodical(this.showDuration1);},
	stop: function() {clearInterval(this.interval);},
	
	effect: function(x,t) {
		this.li[x].set('morph', {duration:this.showDuration2, transition: 'linear'});
		this.li[x].morph({opacity: t});
	}
});
//NewsTicker NewsTicker NewsTicker NewsTicker NewsTicker NewsTicker
//NaMooSlideC   NaMooSlideC   NaMooSlideC   NaMooSlideC   NaMooSlideC   NaMooSlideC   NaMooSlide   
var NaMooSlideC = new Class({
	showDuration: 5000,
	effectDuration:1500,
	count:0,
	
	initialize: function(){
		this.slideshow = $('NaMooSlideC');
		this.ul = this.slideshow.getElement('ul');
		this.li = this.slideshow.getElements('li');
		
		var liSize = this.li[0].getSize();
		this.ul.setStyles({'width':(liSize.x*this.li.length),height:liSize.y});
		
		/*this.li.each(function(el,e) {
			var imgLink = 'pic/'+el.getElement('b').get('text');
			new Element('img',{'src':imgLink}).inject(el,'top');
			
			slidesText = el.getElement('p').get('html').split('::');
			slideTextSum1 = '<p style="background:#fff;color:#000;padding:10px;font-family:Ubuntu,sans-serif;font-size:28px;font-weight:700;float:left">'+slidesText[0]+'</p><br>';
			slideTextSum2 = '<p style="background:#000;color:#fff;padding:5px;float:left">'+slidesText[1]+'</p>';
			new Element("div", {
				html:slideTextSum1+slideTextSum2,
				styles: {			
					'position': 'absolute',
					'index': 104,
					'bottom':20,
					'right':15,
					'padding':0,
					'color':'#fff',
					'font-size':'12px',
					'font-family':'Arial',
					'opacity':0.9
				}
				
			}).inject(el);
	
		}, this);*/
		
/* 		this.ul.addEvents({
			mouseenter: function() {this.stop(); }.bind(this),
			mouseleave: function() {this.start(); }.bind(this)
		}); */
		
		//--------
		/* this.prevLink = new Element("div", {
			styles: {			
				'position': 'absolute',
				'index': 104,
				'width': 100,
				'height': 100,
				'background-image':'url(pic/prev_next.png)',
				'cursor':'pointer',
				'top':120,
				'left':0
			}
			
		}).inject(this.slideshow);
		
		this.nextLink = this.prevLink.clone().inject(this.slideshow);
		this.nextLink.setStyles({'left':880,'background-position':'100px 0'});

		this.nextLink.addEvents({
			click: function() {this.show(); }.bind(this)
		});
		
		this.prevLink.addEvents({
			click: function() {this.back(); }.bind(this)
		}); */
		
		//--------
		this.start();
	}, //
	
	show:function() {
		if(this.count > this.li.length-1){this.count=0;}
		this.effectNext(this.count);
		this.count = this.count+1;	
	},
	
	back:function(){
		if(this.count == 0){this.count=this.li.length;}
		this.count = this.count-1;
		this.effectBack(this.count);
	},
	
	effectNext: function(a) {
		new Fx.Tween(this.li[a],{
		property: 'margin-left',
		duration:this.effectDuration, 
		transition: Fx.Transitions.Quart.easeInOut,
		onComplete: function() {
			this.li[a].inject(this.ul);
			this.li[a].setStyle('margin-left',0);
		 }.bind(this)
		}).start(-this.li[a].getSize().x);
	},
	
	effectBack: function(a) {
		this.li[a].inject(this.ul,'top');
		this.li[a].setStyle('margin-left',-this.li[a].getSize().x);
		new Fx.Tween(this.li[a],{
		property: 'margin-left',
		duration: this.effectDuration, 
		transition: Fx.Transitions.Quart.easeInOut
		}).start(0);
	},	
	
	start:function() {this.interval = this.back.bind(this,'').periodical(this.showDuration);},
	stop: function() {clearInterval(this.interval);}
	

});
//NaMooSlideC   NaMooSlideC   NaMooSlideC   NaMooSlideC   NaMooSlideC   NaMooSlideC   NaMooSlide   
//NaMooBox NaMooBox NaMooBox NaMooBox NaMooBox NaMooBox NaMooBox NaMooBox NaMooBox 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));
			
			//a.setStyles({'color':'red'});
			//alert(a);
		},this);
		
		this.body = $(document.body);
		
		this.overlay = new Element("div", {
			styles: {
				background:'#000',
				position: "absolute",
				index:100,
				opacity:0,
				left:0,
				top:0
			},
			events: {
				click: this.close.bind(this)
			}
		}).inject(this.body);
		
			
		this.quickBox = new Element("div", {
			styles: {			
				width:10,
				height:10,
				background:'#fff',
				position: "absolute",
				index:101,
				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': 104,
				'width': '100%',
				'height': 30,
				'display': 'block',
				'color':'#000',
				'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': 104,
				'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.8);
		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;">Nalagam...</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:#666;background:#fff">&lt;</div>');
				this.nextLink.set('html','<div style="position:absolute;top:45%;right:0;padding:10px 2px;display:block;color:#666;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:#666;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.setStyles({'display':'none'});
		this.overlay.fade("out");
		this.active = false;
	}
});	
//NaMooBox NaMooBox NaMooBox NaMooBox NaMooBox NaMooBox NaMooBox NaMooBox NaMooBox NaMooBox 
//Form Form Form Form Form Form Form Form Form Form Form Form Form Form Form 
var NaMooForm = new Class({
	initialize: function(){
		this.submitB = $$('.sub');
		this.form = $('form1');
		this.formInput = this.form.getElements('input');
		this.ch = true;
		this.submitB.addEvent("click", this.checkID.bind(this));
	},
	
	checkID: function(){
		this.active = true;
		
		this.ch = 0;
		this.formInput.each(function(el,e) {
			
			if(el.get('id') != null){
				if(el.get('id') == 'xmail'){ /* email check */
					var regEmail = /^[A-Z0-9._%-]+@[A-Z0-9.-]+.[A-Z]{2,4}$/;
					(el.get('value').toUpperCase().match(regEmail))? this.style1(el):this.style2(el);
				} 
				else{
					(el.get('value') == '')? this.style2(el):this.style1(el);
				}
			}

		}, this);

		if(this.ch == 0){this.formSend(this);}

		return false;
	},
	
	formSend: function(){
		this.active = true;
		//console.log('out = ' + this.ch);
				
			this.form.set('send', {
				url: 'pic/izracun1.php',
				method: 'post',
				onRequest: function() {$('form1_on').empty().addClass('form1_loading');}.bind(this),
				onSuccess: function() {$('form1_on').removeClass('form1_loading');$('form1_off').setStyle('display', 'block');}.bind(this)
			});
				
			this.form.send();
						
			return false;
	},
	
	style1: function(b){b.setStyles({'border':'1px solid #ccc'});},
	style2: function(b){b.setStyles({'border':'2px solid #FF6604'});this.ch = 1;}
	
});
//Form Form Form Form Form Form Form Form Form Form Form Form Form Form Form
