window.addEvent('load', function(){resize();});
window.addEvent('resize', function(){bg.empty();resize();});

window.addEvent('domready', function(){
round();
intro_tabs1();
intro_tabs2();
news_ticker();
intro_images();
form();
popup();
});
//resize resize resize resize resize resize resize resize resize resize resize 
function resize(){
	width = window.getSize().x;
	height = window.getSize().y;
	
	bg = new Element('div').inject(document.body,'top');
	bg.setStyles({'position':'fixed','width':width,'height':height,'display':'block'});
	
	img_bg = new Element('img',{src:path+'pic/bg'+Math.floor(Math.random()*3)+'.jpg'}).inject(bg); 
	
	image_width = 1000;
	image_height = 665;
		
	if(image_width/image_height>width/height){new_image_height = height; new_image_width = (height/image_height)*image_width;}
	else {new_image_height = (width/image_width)*image_height; new_image_width = width;}
		
	img_bg.setStyles({'width':new_image_width ,'height':new_image_height,'display':'block'});
};
//resize resize resize resize resize resize resize resize resize resize resize 
//round border round border round border round border round border round border round border round border round border round border
function round(){
    $$('.imgr').each(function(imgr){
        new Element('span', {
            'class': 'round',
            styles: {
                'background-image': 'url(' + imgr.getProperty('src') + ')',
                height: imgr.getProperty('height') + 'px',
                width: imgr.getProperty('width') + 'px'	
            }
        }).wraps(imgr);
		
	$$('.round img').setStyle('opacity','0');
    });
};
//round border round border round border round border round border round border round border round border round border round border
//news ticker news ticker news ticker news ticker news ticker news ticker news ticker news ticker
function news_ticker(){
	if($chk($('news_ticker'))){ 
		var x=0;
		var li=$('news_ticker').getElements('li');
		li.each(function(el,i){el.setStyle('top',[i<1?0:40]);});
		function action() {
			li[x].get('tween', {property: 'top', duration: 'long'}).start(40);
			li[x=x<li.length-1?x+1:0].get('tween', {property: 'top', duration: 'long'}).start(0);
		}
		action.periodical(4000);
	}
}
//news ticker news ticker news ticker news ticker news ticker news ticker news ticker news ticker 
//intro tabs intro tabs intro tabs intro tabs intro tabs intro tabs intro tabs intro tabs 
function intro_tabs1(){
	if($chk($('ar4'))){ 
	var li=$('ar4').getElements('li');
	li.each(function(el,i){
		el.addEvents({
		'mouseover': function(e){ 
			el.setStyles({'background-color':'#E81C00'});
			var ela = el.getElements('a');
			ela.setStyles({'color':'#fff'});
			var elp = el.getElements('p');
			elp.setStyles({'margin':'8px 0 8px 0'});
		},
		'mouseleave': function(e){ 
			el.setStyles({'background-color':'#eee'});
			var ela = el.getElements('a');
			ela.setStyles({'color':'#333'});
			var elp = el.getElements('p');
			elp.setStyles({'margin':'8px 0 8px 0'});
		}
		}); 
	
	});
	}
}
//intro tabs intro tabs intro tabs intro tabs intro tabs intro tabs intro tabs intro tabs
//intro tabs intro tabs intro tabs intro tabs intro tabs intro tabs intro tabs intro tabs 
function intro_tabs2(){
	if($chk($('ar5'))){ 
	var li=$('ar5').getElements('li');
	li.each(function(el,i){
		el.addEvents({
		'mouseover': function(e){ 
			el.setStyles({'background-color':'#E81C00'});
			var ela = el.getElements('a');
			ela.setStyles({'color':'#fff'});
			var elp = el.getElements('p');
			elp.setStyles({'margin':'8px 0 8px 0'});
		},
		'mouseleave': function(e){ 
			el.setStyles({'background-color':'#eee'});
			var ela = el.getElements('a');
			ela.setStyles({'color':'#333'});
			var elp = el.getElements('p');
			elp.setStyles({'margin':'8px 0 8px 0'});
		}
		}); 
	
	});
	}
}
//intro tabs intro tabs intro tabs intro tabs intro tabs intro tabs intro tabs intro tabs 
//intro images intro images intro images intro images intro images intro images intro images 
function intro_images(){
	if($chk($('slideshow-container'))){ 
	var showDuration = 3000;
	var container = $('slideshow-container');
	var images = container.getElements('li');
	var currentIndex = 0;
	var interval;
	var toc = [];
	var tocWidth = 15;
	var tocActive = 'toc-active';
	var tocActive2 = 'link_toc-active';
	
	var start = function() { interval = show.periodical(showDuration);};
	var stop = function() { $clear(interval); };
	var show = function(to) {
		images[currentIndex].fade('out');
		toc[currentIndex].removeClass(tocActive);
		images[currentIndex = ($defined(to) ? to : (currentIndex < images.length - 1 ? currentIndex+1 : 0))].fade('in');
		toc[currentIndex].addClass(tocActive);
	};
	
	images.each(function(img,i){
		if(i > 0) { img.set('opacity',0); }
	});

	images.each(function(img,i){
		toc.push(new Element('a',{
			//text: i+1,
			href: '#',
			'class': 'toc' + (i == 0 ? ' ' + tocActive : ''),
			events: {
				click: function(e) {
					if(e) e.stop();
					stop();
					show(i);
				}
			},
			styles: {left: ((i + 1) * (tocWidth))}
		}).inject(container));
		if(i > 0) { img.set('opacity',0); }
	});

	
	var next = new Element('img',{ 
		src:'pic/intro_a2.png',
		id: 'next',
		events: {
			click: function(e) {
				if(e) e.stop();
				stop(); show();
			}
		}
	}).inject(container); 
	
	var previous = new Element('img',{ 
		src:'pic/intro_a1.png',
		id: 'previous',
		events: {
			click: function(e) {
				if(e) e.stop();
				stop(); show(currentIndex != 0 ? currentIndex -1 : images.length-1);
			}
		}
	}).inject(container); 
	

	container.addEvents({
		mouseenter: function() { stop(); },
		mouseleave: function() { start(); }
	});
	
	window.addEvent('load',function(){
		start();
	});
}
}
//intro images intro images intro images intro images intro images intro images intro images 
//---------------form
function form(){
if($chk($('form1'))){

var tel = $('tel');
var xmail = $('xmail');
var kontakt = $('kontakt');
	
$('form1').addEvent('submit', function(e) {	
new Event(e).stop();	 var regEmail = /^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/;

function yellow(var1){var1.style.background = '#FFF79C'; var1.style.border = '1px solid #f00';}
function white(var2) {var2.style.background = '#fff'; var2.style.border = '1px solid #ccc';}

if(tel.get('value') == '') {yellow(tel);} else {white(tel); var telOK=1;}
if(xmail.get('value').toUpperCase().match(regEmail)){white(xmail); var xmailOK='1';} else {yellow(xmail);}
if(kontakt.get('value') == '') {yellow(kontakt);} else {white(kontakt); var kontaktOK=1;}

		if(kontaktOK==1 && xmailOK==1 && telOK==1)
		{
			this.set('send', {
				url: 'js/form1.php',
				method: 'post',
				onRequest: function() {$('show').empty().addClass('ajax-loading');},
				onSuccess: function() {
				$('hide').setStyle('display', 'block');
				$('show').removeClass('ajax-loading');
				}
				});
				this.send();
			$('show').setStyle('display', 'none');
			$('hide').setStyle('display', 'block');
		} 
		//---
		});
	}
}
//---------------form

function popup(){
var popbox1 = '';
if($chk($$('.popup1'))){
	$$('.popup1').addEvents({
		'mouseenter': function(e){
			tx1 = this.get('rel');
			var tx2 = $(tx1).get('html');
				popbox1 = new Element('div',{'class': 'popbox1'}).inject(document.body,'top');;
				popbox1.setStyles({
					'opacity':0,
					'padding':10,
					'position':'absolute',
					'background':'#fff',
					'border':'2px solid #ccc',
					'left':0,
					'width':430,
					'top':0,
					'z-index':1000
				});
			popbox1.set('html',tx2);
			var pos2 = this.getCoordinates();
			var popbox1_h = popbox1.getStyle('height').toInt();
			popbox1.setStyles({top:(pos2.top-popbox1_h-28),left:(pos2.left),height:popbox1_h});
			popbox1.fade('in');
		},
		'mouseleave': function(){
		popbox1.fade('out');
	}
	});
	} 
}




