window.addEvent('domready',function() {
pop();logo();if($$('a[rel=NaMoo]') != null){new NaMooBox();}if($('form1') != null){new NaMooForm();}

if($('disc') != null){disc();} 
});
window.addEvent('load', function() {resize();if($$('.swf') != null){NewSwf();} if($('NaMooNewsH') != null){new NaMooNewsH();}  if($('NaMooSlideC') != null){new NaMooSlideC();}});
window.addEvent('resize',function(){resize();});

function disc(){
		win= window.getSize();
		var he1 = $('he1').getStyle('height').toInt();
		var se1 = $('se1').getStyle('height').toInt();
		var fo1 = $('fo1').getStyle('height').toInt();
		console.log(he1+'...'+se1+'...'+fo1);
		var wr1H =he1+se1+fo1;
		var wr1HmarginT=(win.y-wr1H)/2;
		if(wr1HmarginT>20){$('disc').setStyles({'height':wr1HmarginT-20});}
}

function NewSwf(){
	$$('.swf').each(function(el,e) {
	var SwfT = el.get('text').split('::');
	var SwfID = el.get('id');
		var obj = new Swiff(SwfT[0], {
		width:SwfT[1], 
		height:SwfT[2],
		params: {wMode:'opaque'},	
		container: $(SwfID)
		});
	});
}

//logo
function logo(){
$('logo').set('html','<a href='+$('he1').getElement('a')+'><img src='+path+'pic/logo.png width=236 height=39></a>');
}
//logo
//resize resize resize resize resize resize resize resize resize resize resize 
function resize(){
	win= window.getSize();
	if($('bg') !=null){$('bg').dispose();}
	if($('bg2') !=null){$('bg2').dispose();}
	
	
	
	var bg2 = new Element('div',{id:'bg2'}).inject(document.body,'top');
	bg2.setStyles({'background':'url('+path+'pic/2.png)','overflow':'hidden','top':0,'left':0,'width':win.x,'height':win.y,'display':'block'});
	
	var bg = new Element('div',{id:'bg'}).inject(document.body,'top');
	bg.setStyles({'overflow':'hidden','top':0,'left':0,'width':win.x,'height':win.y,'display':'block'});
	var image = path+'pic/bg2.jpg';
	var loader = new Asset.images(image, {
		onComplete: function() {
			var imgL = new Element('img',{src:image});
			imgL.setStyles({'opacity':0});
			imgL.inject(bg);
			imgW = imgL.getSize().x;
			imgH = imgL.getSize().y;
			if(imgW/imgH>win.x/win.y){n_imgH = win.y; n_imgW = (win.y/imgH)*imgW;}
			else {n_imgH = (win.x/imgW)*imgH; n_imgW = win.x;}
			imgL.setStyles({'width':n_imgW ,'height':n_imgH,'display':'block','opacity':1});
			imgL.inject(bg);
		}
	});
};
//resize resize resize resize resize resize resize resize resize resize resize 
//NaMooSlideC   NaMooSlideC   NaMooSlideC   NaMooSlideC   NaMooSlideC   NaMooSlideC   NaMooSlide   
var NaMooSlideC = new Class({
	showDuration: 5000,
	effectDuration:1500,
	count:0,
	
	initialize: function(){
		this.slideshow = $('NaMooSlideC');
		
		this.slideshow.setStyles({'display':'block','opacity':0});
		this.slideshow.fade('in');
		
		this.ul = this.slideshow.getElement('ul');
		this.li = this.slideshow.getElements('li');
		
		this.lip = this.slideshow.getElements('li p');
		
		this.lip.setStyles({'opacity':0.8});
		
		var liSize = this.li[0].getSize();
		this.ul.setStyles({'width':(liSize.x*this.li.length),height:liSize.y});
		
		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.show.bind(this,'').periodical(this.showDuration);},
	stop: function() {clearInterval(this.interval);}
	

});
//NaMooSlideC   NaMooSlideC   NaMooSlideC   NaMooSlideC   NaMooSlideC   NaMooSlideC   NaMooSlide   
//NaMooNewsH   NaMooNewsH   NaMooNewsH   NaMooNewsH   NaMooNewsH   NaMooNewsH   NaMooNewsH   
var NaMooNewsH = new Class({
	showDuration: 80,
	count:0,
	xPad:0,
	pad:5,

	initialize: function(){
		this.slideshow = $('NaMooNewsH');
		this.ul = this.slideshow.getElement('ul');
		this.li = this.slideshow.getElements('li');
		this.ul.addEvents({
			mouseenter: function() {this.stop(); }.bind(this),
			mouseleave: function() {this.start(); }.bind(this)
		});

		this.start();
	}, //
	
	show:function() {
		if(this.xPad > (this.li[this.count].getSize().x)-1){
			this.xPad=0;
			this.effectIn(this.count);
			this.count = this.count+1;
			if(this.count > this.li.length-1){this.count=0;}
		}
		this.xPad = this.xPad+this.pad;
		this.effectNe(this.count,this.xPad);
	},
	
	effectIn: function(c) {
		this.li[c].inject(this.ul);
		this.li[c].setStyle('margin-left',0);
	},	
	
	effectNe: function(a,b) {
		this.li[a].setStyles({'margin-left':-b});
	},
	
	start:function() {this.interval = this.show.bind(this,'').periodical(this.showDuration);},
	stop: function() {clearInterval(this.interval);}
	

});
//NaMooNewsH   NaMooNewsH   NaMooNewsH   NaMooNewsH   NaMooNewsH   NaMooNewsH   NaMooNewsH   
//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 
//NaMooForm NaMooForm NaMooForm NaMooForm NaMooForm NaMooForm NaMooForm NaMooForm NaMooForm
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/form1.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':'1px solid #F00'});this.ch = 1;}
	
});
//NaMooForm NaMooForm NaMooForm NaMooForm NaMooForm NaMooForm NaMooForm NaMooForm NaMooForm

//pop pop pop pop pop pop pop pop pop pop pop pop pop pop pop pop pop pop pop 
function pop(){
$$('.pop').addEvents({'click': function(e){
	new DOMEvent(e).stop();
	
	var pop_max1 = new Element('div').inject(document.body);
	pop_max1.setStyles({width:'100%',height: window.getScrollSize().y,opacity: 0.80,background: "#000",position:'absolute',top:0,left:0,'z-index':5});
	
	var pop_max2 = new Element('div').inject(document.body);
	pop_max2.setStyles({width:'100%',height: window.getScrollSize().y,position:'absolute',top:0,left:0,'z-index':6});
	
	var pop_box1 = new Element('div').inject(pop_max2,'top');
	pop_box1.setStyles({width: 940,height:450,background:"#fff",position:'relative',marginLeft:'auto',marginRight:'auto',marginTop:(window.getScrollTop()+120),'z-index':7});
	
	var pop_text = new Element('div').inject(pop_box1 ,'inside');
	pop_text.setStyles({padding:10});
	
	pop_text.set('html','<div id="map_canvas2" style="width:920px; height:430px"></div>');
	//$('map_canvas2').setStyles({margin:10});
		//map google
			  if (GBrowserIsCompatible()) {
				var map = new GMap2($('map_canvas2'));
				map.setCenter(new GLatLng(46.60572022768446,15.248980522155762), 16);
				GEvent.addListener(map, "moveend", function() {
				var center = map.getCenter();
				});
				var latlng = new GLatLng(46.60572022768446,15.248980522155762);
				map.addOverlay(new GMarker(latlng));
			  }
			map.addControl(new GSmallMapControl());
			map.addControl(new GMapTypeControl());
		//map google	
	
	var log_close  = new Element('div').inject(pop_box1,'inside');
	log_close.setStyles({padding:'2px 5px 8px 5px',background:"#FFC81C",position:'absolute',top:-30,right:0,cursor:'pointer','font-weight':700,'font-size':'30px',color:'#000'});
	
	log_close.set('text','x');
	log_close.addEvent('click', function(e) { //zapri
	pop_max1.destroy();
	pop_max2.destroy();
	});	
	
}});
}
//pop pop pop pop pop pop pop pop pop pop pop pop pop pop pop pop pop pop pop
