var curNode = 0;

function copyAddressDeliv(){
	$('deliv_name').value = $('name').value;
	$('deliv_surname').value = $('surname').value;
	$('deliv_street').value = $('street').value;
	$('deliv_street_n1').value = $('street_n1').value;
	$('deliv_street_n2').value = $('street_n2').value;
	$('deliv_post_code').value = $('post_code').value;
	$('deliv_city').value = $('city').value;
	$('deliv_country_id').value = $('country_id').value;
}
	
function copyAddressInv(){
	$('inv_name').value = $('name').value;
	$('inv_surname').value = $('surname').value;
	$('inv_street').value = $('street').value;
	$('inv_street_n1').value = $('street_n1').value;
	$('inv_street_n2').value = $('street_n2').value;
	$('inv_post_code').value = $('post_code').value;
	$('inv_city').value = $('city').value;
	$('inv_country_id').value = $('country_id').value;
}


window.addEvent('domready', function(){
	/*new Swiff(site_url+'img/anpn.jpg',{
		container: $('flashTop'),
		width: 930,
		height: 285,
		vars: {site_url: 'http://www.anpn.pl'}
	});
*/
	
	if(!$defined(Cookie.read('visitid'))){
		var visitid = $random(100000,999999);
		Cookie.write('visitid',visitid,{
			duration: 0
		});
		new Request({
			url: site_url+'counter',
			data: 'visitid='+visitid
		}).send();
	}
	
	$$('a[rel^=treeOpen:]').each(function(el) {
		el.addEvent('click', function(e){
			new Event(e).stop();
			var tmp = this.getProperty('rel').split(':');
			$('node'+tmp[1]).toggleClass('hide');
			if(tmp[2] == '1') {
				if($('node'+tmp[1]).get('class') == '') {
					if(curNode > 0) {
						$('node'+curNode).toggleClass('hide');
					}
					curNode = parseInt(tmp[1]);
				} else {
					curNode = 0;
				}
			}
		});
	});
	
	$$('a[rel^=loadPic]').each(function(el, i){
		el.addEvent('click', function(e){
			new Event(e).stop();
			var a = this.getProperty('rel').split('|');
			var params = a[2].split(':');
			$(a[1]+'_img').setProperties({
				src: 'img/invis.gif',
				alt: 'trwa ładowanie zdjęcia...',
				width: params[1],
				height: params[2]
			});
			(function(){
				$(a[1]+'_img').setProperties({
					src: params[0],
					width: params[1],
					height: params[2],
					alt: params[3]
				});
				$(a[1]+'_img').getParent().setProperty('href', a[3]);
				}
			).delay(250);
		});
	});
	
	$$('a[rel^=confirm]').each(function(el) {
		switch(el.getProperty('rel')) {
			case 'confirmCancelReserv':
			el.addEvent("click", function(e) {
				var c=confirm('Czy na pewno chcesz anulować rezerwację?');
				if(!c) {
					new Event(e).stop();
				}
			});
			break;
		}
	});
	
	$$('a[rel^=show]').each(function(id) {
		var par = id.getProperty('rel').split(':');
		id.s = 0;
		id.txt = id.get('text');
		id.addEvent('click', function(e){
			new Event(e).stop();
			$(par[1]).toggleClass('hide');
			this.s = 1 - this.s;
			if(this.s == 1) {
				this.set('text', par[2]);
			} else {
				this.set('text', this.txt);
			}
		});
	});
	
	if($('fb_widget')){
		var fbx = new Fx.Tween($('fb_widget'), {fps:60, duration:400});
		$('fb_widget').addEvents({
			'mouseenter': function(){
				fbx.start('left', '0');
			},
			'mouseleave': function(){
				fbx.start('left', '-205px');
			}
		});
	}
	
});

/* banner */
/*
window.addEvent('load',function(){
	//-- jezeli zalogowany to baner animowany
	//-- powinien zjezdzac nizej niz normalnie
	if (isLogged) pozY = 85;
	else pozY = 35;
	
	$('cont').setStyle('position', 'relative');
	new Element('div',{
		'id': 'top-banner',
		'styles': {
			'position': 'absolute',
			'z-index': '200',
			'top': '35px',
			'left': '0'
		}
	}).inject($('cont'),'top');
	new Swiff(site_url+'img/winieta_banner_06.swf',{
		container: $('top-banner'),
		width: 930,
		height: 276,
		callBacks:{
			onLoad: function(){
				new Fx.Tween($('top-banner'), {fps:200,duration:1,transition:'sine:out'}).start('top',pozY+'px');
			},
			onUnload: function(){
				$('top-banner').destroy();
			}
		}
	});
});
*/

function MM_swapImgRestore(){var i,x,a=document.MM_sr;for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++)x.src=x.oSrc}function MM_preloadImages(){var d=document;if(d.images){if(!d.MM_p)d.MM_p=new Array();var i,j=d.MM_p.length,a=MM_preloadImages.arguments;for(i=0;i<a.length;i++)if(a[i].indexOf("#")!=0){d.MM_p[j]=new Image;d.MM_p[j++].src=a[i]}}}function MM_findObj(n,d){var p,i,x;if(!d)d=document;if((p=n.indexOf("?"))>0&&parent.frames.length){d=parent.frames[n.substring(p+1)].document;n=n.substring(0,p)}if(!(x=d[n])&&d.all)x=d.all[n];for(i=0;!x&&i<d.forms.length;i++)x=d.forms[i][n];for(i=0;!x&&d.layers&&i<d.layers.length;i++)x=MM_findObj(n,d.layers[i].document);if(!x&&d.getElementById)x=d.getElementById(n);return x}function MM_swapImage(){var i,j=0,x,a=MM_swapImage.arguments;document.MM_sr=new Array;for(i=0;i<(a.length-2);i+=3)if((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x;if(!x.oSrc)x.oSrc=x.src;x.src=a[i+2]}}

