function startTime()	{
	var JSclock=document.getElementById('JSclock');
	if (JSclock) {
		var today=new Date();
		var h=today.getHours();
		var m=today.getMinutes();
		var s=today.getSeconds();
		m=addZero(m);
		s=addZero(s);
		JSclock.innerHTML=h+":"+m+":"+s;
		setTimeout('startTime()',1000);
	}
}

function addZero(i)	{ 
	if (i<10) i="0" + i; 
	return i; 
}

function getCookie(c_name)	{
	if (document.cookie.length>0)	{
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1)	{ 
			c_start=c_start + c_name.length+1 ;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length
			return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
	return ""
}

function setCookie(c_name,value,expiredays)	{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : "; expires="+exdate.toGMTString())+"; path=/";
}

Slimbox.scanPage = function() {
	var links = $$("a").filter(function(el) {
		return el.rel && el.rel.test(/^lightbox/i);
	});
	$$(links).slimbox({
			counterText: "{x}/{y}"
		}
		, null
		, function(el) {
/**			return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));	/**/
			return (this == el) || (this.rel.length > 8);
	});
};


window.addEvent("domready", function () {
	Slimbox.scanPage();
	
	document.body.className = document.body.className.replace(/jsOFF/gi, "jsON");

	(function () {
		var acord = $('acord');
		if (acord) var myAccordion = new Accordion(acord, 'h3.togler', 'div.toglie', {
			  opacity: false
			, show: 0
			, onActive: function(toggler, element){ $$(toggler, element).addClass('target');}
			, onBackground: function(toggler, element){	$$(toggler, element).removeClass('target');}
		})

		var SNh = $('sub_nav').getSize().y;
		
		if (SNh>0) {
			var crc = $('crc');
			if (crc && SNh>crc.getSize().y) {
				new Fx.Tween(crc).start('height', SNh );
			}
		}
		
		var cntr = $('content_top');
		var hdings = cntr.getChildren();

		var h1 = hdings[0];
		var h2 = hdings[1];
		var h1h = h1.getSize().y;
		var h2h = h2.getSize().y;
		var cntr_hght = h2h + h1h;
		cntr.style.height = (cntr_hght+8) + 'px';
		h1.style.position="absolute";
		h2.style.position="absolute";
		
		// Anpassung IE6
		if(window.ie6) var heightValue='100%';
		else var heightValue='';
	
		// Selektoren der Container fur Schalter und Inhalt
		var togglerName='.h_togler_';
		var contentName='div.h_toglie_';
	
		// Selektoren setzen
		var counter=1;	
		var toggler=$$(togglerName+counter);
		var content=$$(contentName+counter);
	
		while(toggler.length>0)	{
		
			// Accordion anwenden
			new Accordion(toggler, content, {
				opacity: false,
				display: -1,
				onComplete: function() { 
					var element=$(this.elements[this.previous]);
					if(element && element.offsetHeight>0) element.setStyle('height', heightValue);			
				},
				onActive: function(toggler, content) {
					toggler.addClass('opened');
				},
				onBackground: function(toggler, content) {
					toggler.removeClass('opened');
				}   
			});
		
			// Selektoren fur nachstes Level setzen
			counter++;
			toggler=$$(togglerName+counter);
			content=$$(contentName+counter);
		}
		// Accordion mit der ID open_accordion_entry offnen
		var open_accordion_entry = $('open_accordion_entry');
		if (open_accordion_entry) open_accordion_entry.fireEvent('click');		
		
	}).delay(10);
	
	(function () {
		var flash_FX = new Fx.Morph('flash_container', {duration: 'long', transition: Fx.Transitions.Circ.easeOut});
		var posit_FX = new Fx.Morph('content_top', {duration: 'long', transition: Fx.Transitions.Circ.easeOut});
		var FX_v = {
			min_max: getCookie('flash_on_off') || 'max'
			, min:{'height':0,  'opacity':0,'margin-top':160}
			, max:{'height':300,'opacity':1,'margin-top':460}
		}
		flash_FX.set({'height': FX_v[FX_v.min_max]['height'] , 'opacity': FX_v[FX_v.min_max]['opacity'] });
		posit_FX.set({'margin-top': FX_v[FX_v.min_max]['margin-top'] });
		if (FX_v.min_max == 'max') $('hide_flash').removeClass('target');  else $('hide_flash').addClass('target');
		$('hide_flash').addEvent("click", function() {
			if (FX_v.min_max == 'min') {
				FX_v.min_max = 'max';
				this.removeClass('target');
			} else {
				FX_v.min_max = 'min';
				this.addClass('target');
			}
			setCookie('flash_on_off',FX_v.min_max,1);
			flash_FX.cancel();
			flash_FX.start({'height': FX_v[FX_v.min_max]['height'] , 'opacity': FX_v[FX_v.min_max]['opacity'] });
			posit_FX.cancel();
			posit_FX.start({'margin-top': FX_v[FX_v.min_max]['margin-top'] });
		});
	})();
	
	(function () {
		var foot_nav = $('foot_nav');
		var hide_fnav = $('hide_fnav');
		var foot_nav_FX = new Fx.Morph(foot_nav, {duration: 'long', transition: Fx.Transitions.Circ.easeOut});
		var FX_v = {
			min_max: getCookie('fnav_on_off') || 'max'
			, min:0
			, max: (function () {foot_nav.getSize()['y']})
		}
		foot_nav_FX.set({'height': FX_v[FX_v.min_max]  });
		if (FX_v.min_max == 'max') hide_fnav.removeClass('target');  else hide_fnav.addClass('target');
		hide_fnav.addEvent("click", function() {
			if (FX_v.min_max == 'min') {
				FX_v.min_max = 'max';
				this.removeClass('target');
			} else {
				FX_v.min_max = 'min';
				this.addClass('target');
			}
			setCookie('fnav_on_off',FX_v.min_max,1);
			foot_nav_FX.cancel();
			foot_nav_FX.start({'height': FX_v[FX_v.min_max]  });
		})
	})();
	
	(function () {
		var search_city = $('search_city');
		if (search_city) {
		  search_city.addEvent('change',function(){
			this.form.submit();
		  });
		}
		
		var pLinks = $$('#partners-links a');
		var pLink = $('partners-links');
		if (pLinks) {
			var MyFx=new Array();
			pLinks.each(function(elem, i){
				MyFx[i] = new Fx.Morph(elem, {duration: 400, transition: Fx.Transitions.Sine.easeOut});
				elem.addEvent('mouseover', function() {
					MyFx[i].cancel();
					MyFx[i].start({'opacity':'1'});
				})
				if (!elem.hasClass('cur_page')) {
					MyFx[i].set({'opacity':'0.1'});
					elem.addEvent('mouseleave', function() {
						MyFx[i].cancel();
						MyFx[i].start({'opacity':'0.1'});
					})
				}
			})
		}
		
	})();
	
	(function(){
		if (!$('InsCalc')) return false;
		
		var CheckAllIsrrs = $('CheckAllIsrrs');
		if (CheckAllIsrrs) {
			var IsrrsChBoxS = $$('#IsrrsChBox input');
			function checkAll (){
				IsrrsChBoxS.each(function (el){
					el.checked = CheckAllIsrrs.checked;					
				});
			}
			CheckAllIsrrs.addEvents({
				  'change': checkAll
				, 'click': checkAll
				, 'focus': checkAll
			});
		}
		
		var described = new Hash({});
		
		function ShowDescFields (DescName, selVal) {
			described[DescName]['all'].each(function(el){
				el.morph({'height': 0, 'opacity':0});
				//el.style.display="none";
			});
			if (described[DescName][selVal]) described[DescName][selVal].each(function(selValData){
				//selValData.el.style.display="inline-block";
				selValData.el.morph({'height': selValData['y'], 'opacity':1});
			});              
		}

		$$('#InsCalc .described').each(function(el) {
			var el_described = el.getProperty('data-described');
			if (el_described) {
				if (!described[el_described]) described[el_described] = {'all':[]};

				if (el.checked !== false) {
					described[el_described]['slc'] = el.value;
				}

				el.addEvents({
					  'change': function(){ShowDescFields(el_described, el.value);}
//					, 'click': function(){ShowDescFields(el_described, el.value);}
//					, 'focus': function(){ShowDescFields(el_described, el.value);}
				});
			};
		});
		
		$$('#InsCalc label').each(function(el) {
			var describes = el.getProperty('data-describes');
			if (describes) {
				var tmp = describes.split(':');
				var name = tmp[0];
				described[name]['all'].push(el);
				var OnVals = tmp[1].split(',');
				OnVals.each(function (SelName){ 
					if (!described[name][SelName]) described[name][SelName] = [];
					described[name][SelName].push({'el':el, 'y': el.getSize()['y'] });
				});
				el.style.height='0';
				el.set('opacity', 0);
			};
		});
		
		described.each(function (ObData,SelName) {
			ShowDescFields (SelName, ObData['slc']);
		});
		return true;
	})();

	if (Browser.Engine.trident4 && false) {
		$$('li').each(function(liItem)  {
			liItem.addEvent("mouseover", function() {this.className += ' IEover';})
			liItem.addEvent("mouseout", function() {this.className = this.className.replace(/ IEover/g, "");})
		})
	}
	
});

function copyFormDetails()
{
$("recipient_name").value 					= $("owner_name").value;
$("recipient_email").value 					= $("owner_email").value;
$("recipient_address_region").value			= $("owner_address_region").value;
$("recipient_address_municipality").value 	= $("owner_address_municipality").value;
$("recipient_address_city").value 			= $("owner_address_city").value;
$("recipient_address_code").value 			= $("owner_address_code").value;
$("recipient_address_street").value 		= $("owner_address_street").value;
$("recipient_tel").value 					= $("owner_tel").value;
}
