// JavaScript Document
var SiteEngine = new Class ({
	
	initialize : function(basehref){
		
		this.basehref = basehref;
		this.myMask = new Mask(document.body,{'hideOnClick': false});
		
		this.createModalWindow();
		
		this.modalWindow = $('fb-modal');
		this.ajaxResponseTarget = $('modal_ajax_request_response');	
		
		if($defined(this.modalWindow)) {
			this.modalWindow.setStyles({
					opacity:0,
					display:'block'
				});	
			}
		
		this.prepareBuyBtns();
		this.prepareSwitchTopBox();
		this.prepareHeaderTabs();
		this.prepareIndexTabs();
		this.prepareCatalougeTabs();
		this.prepareAuthorTabs();
		this.prepareAuthor2Tabs();
		this.prepareMostInfoTabs();
		this.prepareTitlesTabs();
		this.gotoTop();
		this.prepareOvertext();
		this.preparePagination();
		this.productCartMp3Player();
		this.rightMenu();
		this.prepareKeysTips();
		this.prepareInfoTips();
		this.prepareListenNow();
		
		this.prepareAddToFav();
		this.prepareReferUs();
		
		this.prepareOrderForms();
		this.prepareForceShow();
		this.userModalsShow();
		this.prepareForceShow();
		this.prepareShipmentsActions();
		
		this.bindConfirmation();
		this.preventFromSubmitViaEnter();		
		this.bindLoggedUserAddressForm();
		this.bindShowToChooseWindows();
		this.prepareListHovers();
		this.chooseListsAddresses();
		this.changeAddressFromList();
		this.chooseListsInvoices();
		this.changeInvoiceFromList();	
		this.prepareOrderLogin();
		this.prepareDownloadCountdown();
		this.prepareCoupons();
		this.preparePopup();
		this.preparePaymentInfo();
//		this.prepareSearch();
	},
	
	prepareSearch: function() {
		$('search_submit').setStyle('display','none');
		$('search_btn').setStyle('cursor','pointer').addEvent('click',function(){$('search_submit').fireEvent('click');});
	},
	
	preparePaymentInfo: function () {
		if($defined($('payment_types_c')) && $defined($('payment_info_box'))) {
			
			$('payment_info_box').setStyle('display','none');
			$('payment_info_box').set('reveal', {duration: 1000, transition: 'bounce:out'});
			
			$('payment_types_c').getElements('input').each(function(item){
			
				if(item.hasClass('radio_hide')){
					item.addEvent('click',function(){
					$('payment_info_box').get('reveal').dissolve();	
												   });
				} else {
					item.addEvent('click',function(){
					$('payment_info_box').get('reveal').reveal();
				   });
				}
			
			});
			
		}
	},
	
	prepareOrderLogin: function() {
		if($defined($('has_account_no')) && $defined($('has_account_yes'))) {
			
			form = $('has_account_no').getParent('form');
			
			$('has_account_no').addEvent('click',function() {
				if(this.checked) {
					form.getElement('label[for=has_account_yes]').removeClass('str_choice');
					form.getElement('label[for=has_account_no]').addClass('str_choice');
					form.getElements('.hsac input').each(function(input,index){input.disabled = true});
					form.getElements('.hsnoac input').each(function(input,index){input.disabled = false});
				}
			});
			
			$('has_account_yes').addEvent('click',function() {
				if(this.checked) {
					form.getElement('label[for=has_account_no]').removeClass('str_choice');
					form.getElement('label[for=has_account_yes]').addClass('str_choice');
					form.getElements('.hsac input').each(function(input,index){input.disabled = false});
					form.getElements('.hsnoac input').each(function(input,index){input.disabled = true});					
				}
			});
			
			if($('has_account_no').checked) {
				form.getElements('.hsac input').each(function(input,index){input.disabled = true});
				form.getElements('.hsnoac input').each(function(input,index){input.disabled = false});
				
			} else {
				form.getElements('.hsac input').each(function(input,index){input.disabled = false});
				form.getElements('.hsnoac input').each(function(input,index){input.disabled = true});	
			}

			
		}
	},
	
	prepareShipmentsActions: function() {
	if($defined($('shipment_types'))) {
		$('order_cost').store('cost',$('order_cost').getAttribute('alt').toFloat());
		
		$$('#shipment_types input[type=radio]').each(function(item){
		item.store('additional_cost',item.getAttribute('alt').toFloat()).removeAttribute('alt');													  
		item.addEvent('change',function(){
			if(item.checked==true) {
				$('current_shipment_cost').set('text',(item.retrieve('additional_cost')==0)?'gratis':item.retrieve('additional_cost').toFixed(2).replace('.',',') + ' zł').getParent('li').highlight('#FFF7C0');
				$('current_order_total').set('text',(item.retrieve('additional_cost')+$('order_cost').retrieve('cost')).toFixed(2).replace('.',',') + ' zł').getParent('li').highlight('#FFF7C0');
			}
			});
		});
		
		}	
	},
	
		prepareCompanySwitch: function() {
		if($$('.company_switch_name').length) {
			$$('.company_switch_name').each(function(item) {
			
			form = item.getParent('form');
													 
			var switch_cn = item;
			var switch_content = form.getElement('.switchable_company_name');
			
			switch_cn.addEvent('click', function(){
			
			if(this.checked === true) {
			switch_content.setStyle('display','block');
			switch_content.highlight('#FFF7C0');
			} else {
			switch_content.setStyle('display','none')
			}
			});
			});
		}
	
	},
	
	prepareInvoiceSwitch: function() {
		if($$('.switch_invoice').length) {
			$$('.switch_invoice').each(function(item) {
			
			form = item.getParent('form');
													 
			var switch_cn = item;
			var switch_content = form.getElements('.switchable_invoice');
			
			if(switch_cn.checked === true) {
			switch_content.setStyle('display','block');
			switch_content.highlight('#FFF7C0');
			}
			
			switch_cn.addEvent('click', function(){
		
			if(this.checked === true) {
			switch_content.setStyle('display','block');
			switch_content.highlight('#FFF7C0');
			} else {
			switch_content.setStyle('display','none')
			}
			});
			});
		}
	},
	
	prepareForceShow: function() {
		if($$('.force_show').length){
		
		$$('.force_show').each(function(item){
		
		var rel = item.getAttribute('id');
		
		$('content').getElements('.modal_show[rel='+rel+']').fireEvent('click');
		});
		}
	},
	
	prepareAddToFav: function() {
		if($defined($('add2fav')))
		{
			var aURL ='http://www.karaokedzieciom.com';
			var aTitle ='www.KaraokeDzieciom.com';
			
			$('add2fav').addEvents({
			
			 'click': function(event) {
			 var event = new Event(event); event.preventDefault();
			 if (document.all)
			 {
			 window.external.AddFavorite(aURL,aTitle);
			 }
			 else
			 {
			 if(window.sidebar)
			 {
			 window.sidebar.addPanel(aTitle,aURL,"");
			 } /* else call bookmark for NS&FF */
			 }
			 return false;
			 }
			});
		}	
	},
	
	prepareIndexTabs: function() {
		if($defined($('index_content_tabs')))
		this.prepareRegularTabs($('index_content_tabs'));
	
	},
	
	prepareCatalougeTabs: function() {
		if($defined($('catalouge_tabs')))
		this.prepareRegularTabs($('catalouge_tabs'));
	
	},
	
	prepareAuthorTabs: function() {
		if($defined($('author_tabs')))
		this.prepareRegularTabs($('author_tabs'));
	
	},
	
	prepareAuthor2Tabs: function() {
		if($defined($('author_2_tabs')))
		this.prepareRegularTabs($('author_2_tabs'));
	
	},
	
	prepareTitlesTabs: function() {
		if($defined($('titles_tabs')))
		this.prepareRegularTabs($('titles_tabs'));
	
	},
	
	prepareMostInfoTabs: function() {
	if($defined($('most_info_tabs')))
		this.prepareRegularTabs($('most_info_tabs'));
	
	},
	
	prepareReferUs: function() {
	
	var slf= this;	
	
		if($defined($('referus_form_container'))) {
			
			var cform =	$('referus_form_container').getElement('form');
			

			$('referus_form_container').getElement('.btn_anuluj').addEvent('click',function(event) {
			event.preventDefault();
			
			slf.myMask.hide();
			slf.modalWindow.fade('out');
			
			});
			
			
			
			$$('.show_referus_form').addEvent('click',function(event) {
			
			event.preventDefault();
			
			cform.setAttribute('id', 'cfold');

			
			slf.myMask.show();
			slf.modalWindow.getElement('.dialog_summary').set('html','Poleć nas znajomym');
			slf.ajaxResponseTarget.empty();
			slf.modalWindow.fade('in');
			
			var clonedform = $('referus_form_container').getElement('form').clone();
			
			clonedform.setAttribute('id','referus_form_q');
			
			clonedform.inject(slf.ajaxResponseTarget);																						  
			});
		}
	
	},
	
	referusFormSubmit: function(event) {
		
	var slf= this;	
		
	new Event(event).preventDefault();

	
	$('referus_form_q').set('send', {
			 onRequest: function() {
				slf.ajaxResponseTarget.set('spinner', {msg: 'proszę czekać...'});
				slf.modalWindow.getElement('.dialog_summary').set('text','Trwa przetwarzanie... proszę czekać...');
				slf.ajaxResponseTarget.get('spinner').show(true);
				self.positionAbs();
			},
			
			onSuccess: function(resp){
					
					if(resp) {
					var responseJSON = JSON.decode(resp);
					}
					
					slf.modalWindow.getElement('.dialog_summary').set('text',responseJSON.box_title);
					slf.ajaxResponseTarget.set('html',responseJSON.box_info);
					
					if(responseJSON.auto_hide == 1) {
					(function(){
					slf.ajaxResponseTarget.empty();
					slf.modalWindow.fade('out');
					slf.myMask.hide();
					}).delay(1800);
					}
				},
				
				onFailure: function(){
					slf.modalWindow.getElement('.dialog_summary').set('text','Wystąpił błąd...');
					slf.myMask.hide();
					slf.modalWindow.fade('out');
				},
		
			onComplete: function(response) {
				slf.ajaxResponseTarget.get('spinner').hide(true);	
				}
		}); 
		
		$('referus_form_q').send();
},
	
	userModalsShow: function() {
		
		var slf= this;
		
		if($$('.modal_show').length) {
			
			
			$$('.modal_show').each(function(item){
											   
			item.addEvent('click',function(){
			slf.myMask.show();
			slf.modalWindow.getElement('.dialog_summary').set('text','Zmiana danych');		
			slf.ajaxResponseTarget.empty();
			slf.modalWindow.fade('in');
			slf.ajaxResponseTarget.adopt($(item.getAttribute('rel')).getElement('form'));
			slf.modalWindow.getElement('.anuluj_btn').addEvent('click',function(){
							slf.modalWindow.fade('out');
							$(item.getAttribute('rel')).adopt(slf.ajaxResponseTarget.getElement('form'));
							slf.myMask.hide(); 
						});
			});
			
			});
		}	
	},
	
	prepareRegularTabs: function(obj) {
	
		var tabs_links = obj;
		var links = tabs_links.getElements('a.tab_switch_regular');
		var box = tabs_links.getParent('div.box');
		
		
		links.each(function(item){
		
			item.addEvent('click', function(event){
				event.preventDefault();
				
				var tab_id = this.getAttribute('rel');
				box.getElements('.inside').addClass('hidden_tab');
				
				$(tab_id).removeClass('hidden_tab');
				tabs_links.removeProperty('class');
				tabs_links.addClass(tab_id);
				OverText.update();
			});
		
		});
	
	},
	
	prepareOrderForms: function() {
		this.prepareCompanySwitch();
		this.prepareInvoiceSwitch();
		
		if($defined($('receiver_name'))) {
			//$('receiver_name').addEvent('keyup',function(){$('contact_name').set('value',this.value)});
			if($defined($('contact_name'))) {
			$('contact_name').addEvent('keyup',function(){$('receiver_name').set('value',this.value)});
			}
		}
		
		if($defined($('receiver_company'))) {
			$('receiver_company').addEvent('keyup',function(){$('invoice_company_name').set('value',this.value)});
		}
		
		if($defined($('receiver_phone'))) {
			if($defined($('contact_phone'))) {
			$('contact_phone').addEvent('keyup',function(){$('receiver_phone').set('value',this.value)});
			}
		}
	},
	
	
	prepareHeaderTabs: function() {
	
		var tabs_links = $('header_tabs');
		var links = tabs_links.getElements('a.tab_switch_regular');
		var box = tabs_links.getParent('div.box');
		var hidable_parent = $('hidable').getParent();
		
		links.each(function(item){
		
			item.addEvent('click', function(event){
				event.preventDefault();
				
				var tab_id = this.getAttribute('rel');
				box.getElements('.inside').addClass('hidden_tab');
				
				$(tab_id).removeClass('hidden_tab');
				
				if($defined($('zwin_rozwin'))) {
					$('hidable').get('slide').show();
				}
				
				
				if(hidable_parent.getStyle('height') != '0px') {
					hidable_parent.setStyle('height',$(tab_id).getSize.y);	
				}
				tabs_links.removeProperty('class');
				tabs_links.addClass(tab_id);
				OverText.update();
			});
		
		});
	
	},
	
	gotoTop: function() {
		new SmoothScroll('#go_to_top');
		new SmoothScroll('#buy_it_btm');
	},
	
	prepareOvertext: function() {
	
		if($defined($('right_search_input'))) {
			new OverText($('right_search_input'));
		}
		
		if($defined($('right_newsletter_email'))) {
			new OverText($('right_newsletter_email'));	
		}
		
		if($defined($('top_username'))) {
			new OverText($('top_username'));
		}
		
		if($defined($('top_password'))) {
			new OverText($('top_password'));
		}
		
		if($defined($('logowanie_Form'))) {
			var tmp = $('logowanie_Form').getElement('#email');
			if(tmp) new OverText(tmp);
		}
		
		if($defined($('resetowanie_Form'))) {
			var tmp = $('resetowanie_Form').getElement('#email')
			if(tmp) new OverText(tmp);
		}
		
		
		if($defined($('logowanie_Form'))) {
			new OverText($('logowanie_Form').getElement('#password'));
		}
		
		if($defined($('resetowanie_Form'))) {
			var tmp = $('resetowanie_Form').getElement('#password')
			if(tmp) new OverText(tmp);
		}
		
		if($defined($('resetowanie_Form'))) {
			var tmp = $('resetowanie_Form').getElement('#password_confirm')
			if(tmp)	new OverText(tmp);
		}
		
		if($defined($('prestep_form')) && $defined($('username_no_account')) && $defined($('username_has_account')) && $defined($('pre_password'))) {
			new OverText($('username_no_account'));
			new OverText($('username_has_account'));
			new OverText($('pre_password'));
		}
		
		
		window.addEvent('load',function(){
			OverText.update();
		});
	
	},
	
	prepareSwitchTopBox: function() {
		if($defined($('hidable')))	{
	
		
		if($defined($('zwin_rozwin')))	{
		var myFx = new Fx.Slide($('hidable'), {duration: 'normal'});
		myFx.hide();					
		

			$('zwin_rozwin').addEvent('click', function() {
				myFx.toggle();	
			});
		
		}
		
		}
	},
	
	preparePagination: function() {
	var self = this;
	
	 $$('.pagination').each(function(pagination){
		if(pagination.getParent('div').hasClass('pagination'))
		self.preparePaginationLinksEvent(pagination);
		
		});
	
	},
	
	preparePaginationLinksEvent: function(pgnt) {
		
		var self = this;
		
		pagination = pgnt;
		
		pagination.getElements('a').addEvent('click',function(event){
			event.preventDefault();
			
			thelink = event.target;
			response_object = thelink.getParent('div.inside');
			mask_object = thelink.getParent('div.box');
			
	

			myHTMLRequest = new Request({method: 'get', url: thelink.href,
				onRequest: function(){
					mask_object.spin({message:'Proszę czekać',fxOptions:null});
					},					
				onSuccess: function(responseHTML) {	
					mask_object.unspin();
					response_object.set('html',responseHTML);
					self.preparePaginationLinksEvent(response_object.getElement('div.pagination'));
					self.prepareListenNow(response_object);
					self.prepareKeysTips(response_object);
					self.prepareInfoTips(response_object);
					self.prepareBuyBtns(response_object);
					}
								 
			});
			
			myHTMLRequest.send();


			
			
		}.bind(this));
	},
	
	prepareCoupons: function() {
		if($defined($('coupon_slides'))) {
		
		var cs = new noobSlide({
			box: $('coupon_slides'),
			items: $$('#coupon_slides div.slide'),
			size: 690,
			handles: $$('#coupon_handles span'),
			onWalk: function(currentItem,currentHandle){
				$$('#coupon_handles span').removeClass('active');
				currentHandle.addClass('active');
			}
		});
		
		}
		
		if($defined($('place_kuponem'))) {
			
			var content = $('place_kuponem').get('title').split('::');
			
			$('place_kuponem').store('tip:title', content[0]);
			$('place_kuponem').store('tip:text', content[1]);
			
			
			
			var myTips2 = new Tips($('place_kuponem'),
				{fixed: false,
				hideDelay: 50,
				showDelay: 50
				});
			
		}
	},
	
	productCartMp3Player: function() {
		
		var self = this;
		
		if($defined($('product_player'))) {
			
		//	Playlist = new Playlist();			
			
			
				var i = 0;
				Poptions = {
						'onRegister': function() {
						i++;
						this.el = new Element('div', {'class':'song'});
						this.title        = new Element('h3', {'class':'title', text:this.url}).inject(this.el);
						this.controls     = new Element('div', {'class':'controls'}).inject(this.el);
						
						this.volume_c	  = new Element('div', {'class': 'volume_c'}).inject(this.el);
						this.volume_n      = new Element('div', {'class': 'volume'}).inject(this.volume_c);
						
						
						this.seekbar_c	  = new Element('div', {'class': 'seekbar_c'}).inject(this.el);
						this.seekbar      = new Element('div', {'class': 'seekbar'}).inject(this.seekbar_c);
						this.position     = new Element('div', {'class':'position'}).inject(this.seekbar);
						this.seekbar.set('tween', {duration:this.options.progressInterval, unit:'%', link: 'cancel'});
						this.position.set('tween', {duration:this.options.positionInterval, unit:'%', link: 'cancel'});
						this.volume_n.set('tween', {duration:this.options.positionInterval, unit:'%', link: 'cancel'});
						this.playEl       = new Element('img', {'class':'play',  src:self.basehref + 'images/play.gif',id:'play'+i }).inject(this.controls);
					//	this.stopEl       = new Element('img', {'class':'stop',  src:'images/stop.gif',id:'stop'+i }).inject(this.controls);
						this.pauseEl      = new Element('img', {'class':'pause', src:self.basehref + 'images/pause.gif',id:'pause'+i}).inject(this.controls);
					//	this.stopEl.addEvent('click', function() { this.stop(); }.bind(this));
						this.playEl.addEvent('click', function() { this.start(); }.bind(this));
						this.pauseEl.addEvent('click', function() { this.pause(); }.bind(this));
						this.seekbar.addEvent('click', function(e) {
							var coords = this.seekbar.getCoordinates();
							var ms = ((e.page.x - coords.left)/coords.width)*this.duration;
							this.jumpTo(ms);
						}.bind(this));
						
						this.volume_c.addEvent('click', function(e) {
							var coords = this.volume_c.getCoordinates();
							var value = ((e.page.x - coords.left)/coords.width)*100;
							this.volume_n.get('tween').start('width', value );
							this.setVolume(value);
						}.bind(this));
						
						this.el.inject($('playlist'));
						this.el.addClass('paused')
						
					},
					'onLoad': function() {
						var percent = this.getVolume();
						this.volume_n.get('tween').start('width', percent );
						},
					'onPause': function() { 
							 this.el.removeClass('playing').addClass('paused');
							var pauseposition = this.pausedAt;
							},
					'onPlay': function() { this.el.addClass('playing').removeClass('paused'); 

					},
					'onStop': function() { this.el.removeClass('playing').addClass('paused'); },
					'onProgress': function(loaded, total) {
						var percent = (loaded / total*100).round(2);
						this.seekbar.get('tween').start('width', percent);
					},
					'onPosition': function(position,duration) {
						var percent = (position/duration*100).round(2);
						this.position.get('tween').start('left', percent);
					},
					'onID3': function(key, value) {
						if (key == "TIT2") { this.title.set('text', value); }
					},
					'onComplete': $empty
				};
			
					var songs = [self.basehref + "music/demo/" + _current_mp3_demo]; 
					Playlist.loadSounds(songs, Poptions);
		}
	
	},
	rightMenu: function() {
		if($defined($('accordion'))) {
			
			var aco_show = 1;
			
			$('accordion').getElements('h4.toggler').each(function(item,index){
				if(item.id == 'current_toggler_open') {aco_show = index;}												   
			});
			
			var myAccordion = new Accordion($('accordion'), 'h4.toggler', 'div.element', {
		opacity: true, display: aco_show

	});
		}
	},
	prepareKeysTips: function(object) {
		
		if(object!=null) {
			var keytips = object.getElements('a.keyTip');
		} else {
			var keytips = $$('a.keyTip');	
		}
		
		keytips.each(function(element,index) {
		var content = element.get('title').split('::');
		element.store('tip:title', content[0]);
		element.store('tip:text', content[1]);
	});
		
		var myTips = new Tips('.keyTip',
				{fixed: false,
				hideDelay: 50,
				showDelay: 50
				});
	
	},
	prepareInfoTips: function(object) {
		
		if(object!=null) {
			var infotips = object.getElements('a.infoTip');
		} else {
			var infotips = $$('a.infoTip');	
		}
		
		infotips.each(function(element,index) {
		var content = element.get('title').split('::');
		element.store('tip:title', content[0]);
		element.store('tip:text', content[1]);
	});
		
		var myTips = new Tips('.infoTip',
				{className:'infoSpecial',
				fixed: false,
				hideDelay: 50,
				showDelay: 50
				});
	
	},
	prepareDownloadCountdown: function() {
		
		if($defined($('downloads_holder'))) {
		$$('.download-link-item').each(function(item, index){
			now = new Date();	
			
			count_container_id = 'cont_'+ now.getTime()  + '_' + index;
			
			item.getParent().adopt(new Element('div',{'id':count_container_id, 'class':'countdown_container'}));		
			
			item.store('container',count_container_id);
			
			if(item.hasClass('download-yet-active')) {
				$(item.retrieve('container')).setStyle('display','none');
				item.addEvent('click',function(event){
					var now = new Date();
						this.setStyle('display','none');
						$(this.retrieve('container')).setStyle('display','block');
						new MooCountdown({futureDate: now.getTime() + 86400000,
					container: this.retrieve('container'),											
					 startFont : '10px',
					finishFont : '10px',
					dayText:'dni',
					  hourText:'h',
					  minuteText:'min'
					});
				});			 
							 
			} else {
				item.setStyle('display','none');
				$(item.retrieve('container')).setStyle('display','block');
				new MooCountdown({futureDate: item.getAttribute('alt'),
					container: item.retrieve('container'),											
					 startFont : '10px',
					finishFont : '10px',
					dayText:'dni',
					  hourText:'h',
					  minuteText:'min',
					  onComplete: function() { 
					  		item.setStyle('display','inline');
							item.retrieve('container').setStyle('display','none');
							item.addEvent('click',function(event){
								$(this.retrieve('container')).setStyle('display','block');
								var now = new Date();
									this.setStyle('display','none');
									new MooCountdown({futureDate: now.getTime() + 86400000,
								container: this.retrieve('container'),											
								 startFont : '10px',
								finishFont : '10px',
								dayText:'dni',
								  hourText:'h',
								  minuteText:'min'
								});
							});	
          				}
					});
				
			}
		});
		
		new Tips('.countdown_container');
		
		$$('.countdown_container').each(function(el) {  
			el.store('tip:title', 'Informacja');  
			el.store('tip:text', 'Plik będzie ponownie dostępny po upływie tego czasu.');  
		});
		}
	},
	
	prepareListenNow: function(object) {
		var self = this;
		
		if(object != null) {
			var listen_btns = object.getElements('a.sluchaj_btn');
		} else {
		var listen_btns = $$('a.sluchaj_btn');
		}
		
		listen_btns.each(function(ahref){
			ahref.store('status',0);
			ahref.store('song',ahref.getAttribute('alt'));
			
			ahref.addEvent('click', function(event){
				 event.preventDefault();

					
				 
				 
				 var i=0;
				 
				 Soptions = {
					'onPlay': function() {ahref.addClass('show_stop small_loading_ico'); ahref.store('status',1);},
					'onStop': function() {ahref.removeClass('show_stop'); ahref.store('status',0);},
					'onProgress': function(loaded, total) {ahref.store('status',3); if(loaded == total) {ahref.removeClass('small_loading_ico'); }}
				};
			

	
					var song2 = self.basehref + "music/demo/" + ahref.retrieve('song'); 
					Playlist.loadSound(song2, Soptions);
					
					if(ahref.retrieve('status') == '0') {
					Playlist.stopSounds();
					var mySound = Playlist.getSound(song2).start();
					}
					else {
					 Playlist.stopSounds();	
					 ahref.removeClass('show_stop');
					 ahref.removeClass('small_loading_ico');
					}

				 

			 });
		});
	
	},
	
	createModalWindow: function() {
		
		var modal_box = new Element('div',{'class':'generic_dialog', 'id':'fb-modal'});
		var gdp = new Element('div',{'class':'generic_dialog_popup', 'styles' : {'top':'125px'}});
		var tbl = new Element('table',{'class':'pop_dialog_table', 'id':'pop_dialog_table'});
	
	//tr1
		new Element('tr').adopt(new Element('td',{'class':'pop_topleft'}), new Element('td',{'class':'pop_border pop_top'}), new Element('td',{'class':'pop_topright'})).inject(tbl);
	//tr2	
		var pop_content_td =  new Element('td',{'id':'pop_content', 'class':'pop_content'});
		var dialog_content = new Element('div', {'class':'dialog_content'}).inject(pop_content_td);
		
		new Element('div',{'class':'dialog_summary'}).inject(dialog_content);
		new Element('div',{'class':'dialog_body', 'id':'modal_ajax_request_response'}).inject(dialog_content);
	
		new Element('tr').adopt(new Element('td',{'class':'pop_border pop_side'}),pop_content_td, new Element('td',{'class':'pop_border pop_side'})).inject(tbl);
		
	//tr3
		new Element('tr').adopt(new Element('td',{'class':'pop_bottomleft'}), new Element('td',{'class':'pop_border pop_bottom'}), new Element('td',{'class':'pop_bottomright'})).inject(tbl);	
		tbl.inject(gdp);
		gdp.inject(modal_box);
		
		modal_box.inject(document.body);
		},
		
		prepareBuyBtns: function(object) {

			var self = this;


			if(object!=null) {
				var add_to_basket = object.getElements('.do_koszyka_btn');
			} else {
				var add_to_basket = $$('.do_koszyka_btn');	
			}
		
			add_to_basket.each(function(btn){
			
		
			btn.addEvent('click', function(event){
										   
										   
				event.preventDefault();
				
				var pInfoR = new Request({	url: btn.getAttribute('href'),
											method: 'get',
											
											onRequest: function() {
													self.myMask.show();
													self.ajaxResponseTarget.set('html', '<div class="regular_response_info"></div>').set('spinner');
													self.modalWindow.getElement('.dialog_summary').set('text','Trwa przetwarzanie... proszę czekać...');
													self.ajaxResponseTarget.get('spinner').show(true);
													self.modalWindow.fade('in');
													self.positionAbs();
												},
											onSuccess: function(responseText, responseXML) {
													if(responseText) {
														var responseJSON = JSON.decode(responseText);
													}
													
													//self.modalWindow.getElement('.dialog_summary').set('text',responseJSON.box_title);
													
													
													self.modalWindow.getElement('.dialog_summary').empty().adopt(new Element('img',{src: self.basehref + '/images/twoje_zamowienie_koszyk.gif'}));
													self.ajaxResponseTarget.set('html',responseJSON.box_info);
													
													var checkboxes = document.body.getElement('.basket_choice').getElements('input[type:checkbox]');
													if(self.ajaxResponseTarget.getElements('.kit_choice').length == 0) {
													FancyForm.f_reset();
													FancyForm.start(checkboxes,{onSelect: function(){self.updateChosenStatus()}, onDeselect: function() { self.updateChosenStatus()}});
													}
													self.closeModalBoxBtn();
												},
											onComplete: function(response) {
													self.ajaxResponseTarget.get('spinner').hide(true);
												}
											});

				pInfoR.send();
				
			});
			

			});
		},
		
		closeModalBoxBtn: function() {
			var self = this;
			
			$('fb-close').addEvent('click', function() {
			
				self.modalWindow.fade('out');
				self.myMask.hide();			
			});
		
		},
		updateChosenStatus: function() {
			var self = this;
			if($defined($('with_line'))) {
			var with_line_checkboxes = $('with_line').getElements('label.checked');
			
			var with_line = $('with_line_info_box');
			var text_tone = with_line.getElement('span');
			var text_info = '';
			if(with_line_checkboxes.length > 0) {
				
				with_line.removeClass('hidden');
				
				with_line_checkboxes.each(function(label){
					text_info += 'tonacja ' + label.get('text') + ', ';							   
				})
			
			text_tone.set('text', text_info);
			
			} else {
			text_tone.set('text', text_info);				
				with_line.addClass('hidden');
			}
			
			
			}
			
			if($defined($('without_line'))) {
			var without_line_checkboxes = $('without_line').getElements('label.checked');
			
			var without_line = $('without_line_info_box');
			var text_tone2 = without_line.getElement('span');
			var text_info2 = '';
			
			if(without_line_checkboxes.length > 0) {
				
							without_line.removeClass('hidden');
				
				without_line_checkboxes.each(function(label){
					text_info2 += 'tonacja ' + label.get('text') + ', ';							   
				})

			text_tone2.set('text', text_info2);
			
			} else {
				text_tone2.set('text', '');
				without_line.addClass('hidden');
			}
			
			}
			
			$('chosen_count').set('html',$('choice_basket_options').getElements('label.checked').length);

		},
	
	bindConfirmation: function() {
		$$('.remove_confirm').addEvent('click',function(event){  
		 var msg=this.title?this.title:'Czy na pewno...';  
		 if(!confirm(msg)) event.stop();  
	 });	
	},
	
	bindLoggedUserAddressForm: function() {
		if($defined($('basic_data'))){
		
		var form = $('basic_data');
		var submit_btn = form.getElement('.buttons');
		submit_btn.setStyle('display','none');
		
		submit_btn.set('reveal', {duration: 1000, transition: 'bounce:out'});
				
		form.store('contact_name', $('contact_name').get('value'));
		form.store('contact_phone', $('contact_phone').get('value'));
		
		$('contact_name').addEvents({
			'keyup':this.loggedUserAddressFromChange,
			'blur':this.loggedUserAddressFromChange
		});
		
		$('contact_phone').addEvents({
			'keyup':this.loggedUserAddressFromChange,
			'blur':this.loggedUserAddressFromChange
		});
		}	
	},
	
	loggedUserAddressFromChange: function(form, submit_btn){
			if($('contact_name').get('value')!=$('basic_data').retrieve('contact_name') || $('contact_phone').get('value')!=$('basic_data').retrieve('contact_phone')){
					$('basic_data').getElement('.buttons').get('reveal').reveal();
				} else {
					$('basic_data').getElement('.buttons').get('reveal').dissolve();
				}
	},
	
	bindShowToChooseWindows: function() {
		if($$('.show_to_choose').length) {
			var show_btns = $$('.show_to_choose');
			
			var self = this;
			
			show_btns.each(function(item){
			
			item.addEvent('click', function(){
				self.myMask.show();
			
				if(item.getAttribute('rel') == 'addresses') {
					self.modalWindow.getElement('.dialog_summary').set('text','Twoje adresy...');		
				} else {
					self.modalWindow.getElement('.dialog_summary').set('text','Twoje dane do rachunków');
				}
				
				self.ajaxResponseTarget.empty();
				
				self.modalWindow.fade('in');
				
				self.positionAbs();
				
				self.ajaxResponseTarget.adopt($(item.getAttribute('rel')));
				
					if($defined(self.modalWindow.getElement('.anuluj_btn')))
					self.modalWindow.getElement('.anuluj_btn').addEvent('click',function(){
					self.modalWindow.fade('out');
					$('hidden').adopt(self.ajaxResponseTarget.getElement('.choisable_entity_list'));
					self.myMask.hide(); 
					});
				});
			});
		}	
	},
	
	preventFromSubmitViaEnter: function() {
	var inputs = $$('input');
		
		$each(inputs,function(el,i) {
			if(el.getAttribute('type')!='image' && el.getAttribute('type')!='submit' && el.getAttribute('type')!='button' && el.getAttribute('id')!='right_search_input' && el.getAttribute('id')!='top_login_btn')
			el.addEvent('keypress',function(e) {
				if(e.key == 'enter') { 
					e.stop(); 
					if(inputs[i+1]) { inputs[i+1].focus(); }
					//last one?
				}
			});
		});		
	},
	
chooseListsAddresses: function() {
		
		var self = this;
		if($defined($('addresses'))) {
		$('addresses').getElements('.choisable_entity').each(function(item){

	var choose_link = item.getElement('.choose');
				
		if(choose_link != null) {
		self.chooseAddressBind(choose_link);
		}
		
		});
	}
},

chooseAddressBind: function(choose_link) {
	
	var self = this;
	
					
				choose_link.store('item_id', choose_link.getAttribute('rel'));
				choose_link.removeAttribute('rel');	
				choose_link.addEvent('click',function(event) {
				event.preventDefault();
				
				if(!this.getParent('.choisable_entity').hasClass('chosen_entity')) {
				
				var id = this.retrieve('item_id');
				
				var req = new Request({
				url: this.getAttribute('href'),
				data: { 'id' : ''+id+'' },
				method: 'post',
				
				onRequest: function() {
					self.ajaxResponseTarget.set('spinner', {msg: 'proszę czekać...'});
					self.modalWindow.getElement('.dialog_summary').set('text','Twoje adresy... proszę czekać...');
					self.ajaxResponseTarget.get('spinner').show(true);
					self.positionAbs();
			
					//this.modalWindow.getElement('.anuluj_btn').hide();
				},
			
				onSuccess: function(resp){
					
					if(resp) {
					var responseJSON = JSON.decode(resp);
			
					$('addresses').getElements('.choisable_entity').removeClass('chosen_entity');
					choose_link.getParent('div').addClass('chosen_entity');
					$('current_address_id').set('value', responseJSON.address_id);
					$('current_address_text').set('html',responseJSON.address_info);
					}
					self.ajaxResponseTarget.get('spinner').hide(true);
					self.modalWindow.getElement('.dialog_summary').set('text',responseJSON.box_title);
					$('hidden').adopt(self.ajaxResponseTarget.getElement('.choisable_entity_list'));
					self.ajaxResponseTarget.set('html',responseJSON.box_info);
					
					if(responseJSON.auto_hide == '1') {
					(function(){
						self.myMask.hide();
						self.modalWindow.fade('out');
					}).delay(1000);
					}
				},
			
				// Our request will most likely succeed, but just in case, we'll add an
				// onFailure method which will let the user know what happened.
				onFailure: function(){
					self.modalWindow.getElement('.dialog_summary').set('text','Wystąpił błąd...');
					self.myMask.hide();
					self.modalWindow.fade('out');
				}
				});
				
				req.send();
				} else {
				self.modalWindow.fade('hide');
					self.myMask.hide();	
					self.modalWindow.getElement('.anuluj_btn').show()
					$('hidden').adopt(self.ajaxResponseTarget.getElement('.choisable_entity_list'));
				}
			
			});							  
},

changeAddressFromList: function() {

		var self = this;
	if($defined($('addresses'))) {
	$('addresses').getElements('.choisable_entity').each(function(item){
			
		var change_link = item.getElement('.change');
			
		if(change_link != null) {
			self.changeAddressBind(change_link);
		}

		});
	}
},

changeAddressBind: function(change_link) {
			var self = this;
			
						
		change_link.store('item_id', change_link.getAttribute('rel'));
		change_link.removeAttribute('rel');	
		change_link.addEvent('click',function(event) {
	
		event.preventDefault();
		
		$('hidden').adopt(self.ajaxResponseTarget.getElement('.choisable_entity_list'));
		self.ajaxResponseTarget.set('html','<div style="padding:10px;">Ładowanie adresu</div>');
	
			
		var req = new Request({
		url: this.getAttribute('href'),
		method: 'get',
		
		onRequest: function() {
			self.ajaxResponseTarget.set('spinner', {msg: 'proszę czekać...'});
			self.modalWindow.getElement('.dialog_summary').set('text','Edycja adresu... proszę czekać...');
			self.ajaxResponseTarget.get('spinner').show(true);
			self.positionAbs();
		},
	
		onSuccess: function(resp){
			
			if(resp) {
			var responseJSON = JSON.decode(resp);
			}
			
			self.ajaxResponseTarget.get('spinner').hide(true);
			self.modalWindow.getElement('.dialog_summary').set('text',responseJSON.box_title);
			self.ajaxResponseTarget.set('html',responseJSON.box_info);
			
			if(responseJSON.status != 2) {
				self.switch_address_checkbox();
				self.preventFromSubmitViaEnter();
			}	
		},
	
		// Our request will most likely succeed, but just in case, we'll add an
		// onFailure method which will let the user know what happened.
		onFailure: function(){
			self.modalWindow.getElement('.dialog_summary').set('text','Wystąpił błąd...');
			self.myMask.hide();
			self.modalWindow.fade('out');
		}
		});
		
		req.send();	
			
		});
		
	
},

prepareListHovers: function() {
	if($$('.choisable_entity').length) {
		
		var boxes = $$('.choisable_entity');
		
		boxes.each(function(item){
			
			item.addEvents({	
			'mouseover': function(){this.addClass('hover_entity');},
			'mouseleave': function(){this.removeClass('hover_entity');}			
			});
							
		});
		}
	},

chooseListsInvoices: function() {
		
		var self = this;

	if($defined($('invoices'))) {		
		$('invoices').getElements('.choisable_entity').each(function(item){
				
				var choose_link = item.getElement('.choose');
				
				if(choose_link != null) {
				self.chooseInvoiceBind(choose_link);
				}
		});
	}
},

chooseInvoiceBind: function(choose_link) {
	
	var self = this;
	
	choose_link.store('item_id', choose_link.getAttribute('rel'));
	choose_link.removeAttribute('rel');	
	
	choose_link.addEvent('click',function(event) {
	event.preventDefault();
	
	if(!this.getParent('.choisable_entity').hasClass('chosen_entity')) {
	
	var id = this.retrieve('item_id');
	
	var req = new Request({
	url: this.getAttribute('href'),
	data: { 'id' : ''+id+'' },
	method: 'post',
	
	onRequest: function() {
		self.ajaxResponseTarget.set('spinner', {msg: 'proszę czekać...'});
		self.modalWindow.getElement('.dialog_summary').set('text','Twoje dane do rachunku... proszę czekać...');
		self.ajaxResponseTarget.get('spinner').show(true);
		self.positionAbs();

		//this.modalWindow.getElement('.anuluj_btn').hide();
	},

	onSuccess: function(resp){
		
		if(resp) {
		var responseJSON = JSON.decode(resp);

		$('invoices').getElements('.choisable_entity').removeClass('chosen_entity');
		choose_link.getParent('div').addClass('chosen_entity');
		$('current_invoice_id').set('value', responseJSON.invoice_id);
		$('current_invoice_text').set('html',responseJSON.invoice_info);
		}
		self.ajaxResponseTarget.get('spinner').hide(true);
		self.modalWindow.getElement('.dialog_summary').set('text',responseJSON.box_title);
		$('hidden').adopt(self.ajaxResponseTarget.getElement('.choisable_entity_list'));
		self.ajaxResponseTarget.set('html',responseJSON.box_info);
		
		if(responseJSON.auto_hide == 1) {
		(function(){
			self.myMask.hide();
			self.modalWindow.fade('out');
		}).delay(1000);
		}
	},

	// Our request will most likely succeed, but just in case, we'll add an
	// onFailure method which will let the user know what happened.
	onFailure: function(){
		self.modalWindow.getElement('.dialog_summary').set('text','Wystąpił błąd...');
		self.myMask.hide();
		self.modalWindow.fade('out');
	}
	});
	
	req.send();
	} else {
	self.modalWindow.fade('hide');
		self.myMask.hide();	
		self.modalWindow.getElement('.anuluj_btn').show()
		$('hidden').adopt(self.ajaxResponseTarget.getElement('.choisable_entity_list'));
	}

});							  

	
},
changeInvoiceFromList: function() {

	var self = this;
	if($defined($('invoices'))) {
	$('invoices').getElements('.choisable_entity').each(function(item){
			
		var change_link = item.getElement('.change');
			
		if(change_link != null) {
			self.changeInvoiceBind(change_link);
		}

		});
	}
},

changeInvoiceBind: function(change_link) {
			var self = this;
			
						
		change_link.store('item_id', change_link.getAttribute('rel'));
		change_link.removeAttribute('rel');	
		change_link.addEvent('click',function(event) {
	
		event.preventDefault();
		
		$('hidden').adopt(self.ajaxResponseTarget.getElement('.choisable_entity_list'));
		self.ajaxResponseTarget.set('html','<div style="padding:10px;">Ładowanie informacji do rachunków</div>');
	
			
		var req = new Request({
		url: this.getAttribute('href'),
		method: 'get',
		
		onRequest: function() {
			self.ajaxResponseTarget.set('spinner', {msg: 'proszę czekać...'});
			self.modalWindow.getElement('.dialog_summary').set('text','Edycja informacji do rachunku... proszę czekać...');
			self.ajaxResponseTarget.get('spinner').show(true);
			self.positionAbs();
		},
	
		onSuccess: function(resp){
			
			if(resp) {
			var responseJSON = JSON.decode(resp);
			}
			
			self.ajaxResponseTarget.get('spinner').hide(true);
			self.modalWindow.getElement('.dialog_summary').set('text',responseJSON.box_title);
			self.ajaxResponseTarget.set('html',responseJSON.box_info);
		},
	
		// Our request will most likely succeed, but just in case, we'll add an
		// onFailure method which will let the user know what happened.
		onFailure: function(){
			self.modalWindow.getElement('.dialog_summary').set('text','Wystąpił błąd...');
			self.myMask.hide();
			self.modalWindow.fade('out');
		}
		});
		
		req.send();	
			
		});
		
	
},

switch_address_checkbox : function() {
if($$('.company_switch_name').length) {
	$$('.company_switch_name').each(function(item) {
	
	form = item.getParent('form');
											 
	var switch_cn = item;
	var switch_content = form.getElement('.switchable_company_name');
	
	switch_cn.addEvent('click', function(){

	if(this.checked === true) {
	switch_content.setStyle('display','block');
	switch_content.highlight('#FFF7C0');
	} else {
	switch_content.setStyle('display','none')
	}
	});
	});
}	
},

form_address_cancel : function() {
	var self = this;
	$('fb-modal').getElement('.dialog_summary').set('text','Twoje adresy...');
	$('modal_ajax_request_response').empty();
	$('modal_ajax_request_response').adopt($('addresses'));

},

form_invoice_cancel : function() {
	var self = this;
	$('fb-modal').getElement('.dialog_summary').set('text','Twoje dane do rachunków...');
	$('modal_ajax_request_response').empty();
	$('modal_ajax_request_response').adopt($('invoices'));

},

ajax_address_submit : function(event)  {

		new Event(event).preventDefault();


		var self= this;
		
		$('ajax_form_address').set('send', {
			 onRequest: function() {
				$('modal_ajax_request_response').set('spinner', {msg: 'proszę czekać...'});
				$('fb-modal').getElement('.dialog_summary').set('text','Edycja adresu... proszę czekać...');
				$('modal_ajax_request_response').get('spinner').show(true);
				self.positionAbs();
				//$('fb-modal').getElement('.anuluj_btn').hide();
			},
			
			onSuccess: function(resp){
					
					if(resp) {
					var responseJSON = JSON.decode(resp);
					}
					$('fb-modal').getElement('.dialog_summary').set('text',responseJSON.box_title);
					$('modal_ajax_request_response').set('html',responseJSON.box_info);
					
					self.switch_address_checkbox();
					
					if(responseJSON.status == 4) {
			
					var newaddress = new Element('div',{'class':'address_entity choisable_entity', 'html':responseJSON.html});
					var newchange = new Element('a',{'href':responseJSON.hrefchange, 'html':'Edytuj', 'class':'change', 'rel':responseJSON.id});
					var newchoose = new Element('a',{'href':responseJSON.hrefchoose, 'html':'Wybierz', 'class':'choose', 'rel':responseJSON.id});
					
					
					newchoose.inject(newaddress);
					newchange.inject(newaddress);
					
					newaddress.inject($('addresses'),'top');
					
					self.changeAddressBind(newchange);
					self.chooseAddressBind(newchoose);
					
					}
					
					if(responseJSON.status == 3) {
						$('current_address_text').set('html',responseJSON.html);
					}

					if(responseJSON.status == 1) {
					$('addresses').getElement('.address_entity[rel='+responseJSON.toupdate+']').getElement('p').set('html', responseJSON.html);
					}
					
					if(responseJSON.auto_hide == 1) {
					(function(){
					self.ajaxResponseTarget.empty();
				
					self.modalWindow.fade('in');
				
					self.modalWindow.getElement('.dialog_summary').set('text','Twoje adresy...');				  
					self.ajaxResponseTarget.adopt($('addresses'));

					}).delay(1000);
					}
				},
				
				onFailure: function(){
					$('fb-modal').getElement('.dialog_summary').set('text','Wystąpił błąd...');
					self.myMask.hide();
					$('fb-modal').fade('out');
				},
		
			onComplete: function(response) {
				$('modal_ajax_request_response').get('spinner').hide(true);	
				self.preventFromSubmitViaEnter();
				}
		}); 
		
		$('ajax_form_address').send();

},

	form_referus_cancel : function() {
	var slf = this;
	$('fb-modal').getElement('.dialog_summary').set('text','');
	$('modal_ajax_request_response').empty();
	$('fb-modal').fade('out');
	slf.myMask.hide();

},

ajax_invoice_submit : function(event)  {

		new Event(event).preventDefault();


		var self= this;
		
		$('ajax_form_invoice').set('send', {
			 onRequest: function() {
				$('modal_ajax_request_response').set('spinner', {msg: 'proszę czekać...'});
				$('fb-modal').getElement('.dialog_summary').set('text','Edycja danych do rachunku... proszę czekać...');
				$('modal_ajax_request_response').get('spinner').show(true);
				self.positionAbs();
			},
			
			onSuccess: function(resp){
					
					if(resp) {
					var responseJSON = JSON.decode(resp);
					}
					
					$('fb-modal').getElement('.dialog_summary').set('text',responseJSON.box_title);
					$('modal_ajax_request_response').set('html',responseJSON.box_info);
					
					$('fb-modal').getElement('.dialog_summary').set('text',responseJSON.box_title);
					$('modal_ajax_request_response').set('html',responseJSON.box_info);
					
	
					if(responseJSON.status == 4) {
			
					var newinvoice = new Element('div',{'class':'invoice_entity choisable_entity', 'html':responseJSON.html});
					var newchange = new Element('a',{'href':responseJSON.hrefchange, 'html':'Edytuj', 'class':'change', 'rel':responseJSON.id});
					var newchoose = new Element('a',{'href':responseJSON.hrefchoose, 'html':'Wybierz', 'class':'choose', 'rel':responseJSON.id});
					
					
					newchoose.inject(newinvoice);
					newchange.inject(newinvoice);
					
					newinvoice.inject($('invoices'),'top');
					
					self.changeInvoiceBind(newchange);
					self.chooseInvoiceBind(newchoose);
					
					}
					
					if(responseJSON.status == 3) {
						$('current_invoice_text').set('html',responseJSON.html);
					}
					
					if(responseJSON.status == 1) {
					$('invoices').getElement('.invoice_entity[rel='+responseJSON.toupdate+']').getElement('p').set('html', responseJSON.html);
					}
					
					if(responseJSON.auto_hide == 1) {
					(function(){
					self.ajaxResponseTarget.empty();
				
					self.modalWindow.fade('in');
					//self.myMask.hide();
				
					self.modalWindow.getElement('.dialog_summary').set('text','Twoje dane do rachunku...');				  
					self.ajaxResponseTarget.adopt($('invoices'));

					}).delay(1000);
					}
				},
				
				onFailure: function(){
					$('fb-modal').getElement('.dialog_summary').set('text','Wystąpił błąd...');
					self.myMask.hide();
					$('fb-modal').fade('out');
				},
		
			onComplete: function(response) {
				$('modal_ajax_request_response').get('spinner').hide(true);	
				self.preventFromSubmitViaEnter();
				}
		}); 
		
		$('ajax_form_invoice').send();

},

ajax_hit_submit: function(event) {
	
	var self = this;
	
	new Event(event).preventDefault();

		
$('hits_form').set('send', {
			onRequest: function() {
				
			},
			
			onSuccess: function(resp){
					
					if(resp) {
					$('hit_response').empty().set('html',resp);
					}
					
					
				},
				
				onFailure: function(){
					
				},
		
			onComplete: function(response) {

				self.preventFromSubmitViaEnter();
				}
		}); 
		
		$('hits_form').send();
},


positionAbs: function() {
	window.getScroll().y;
	$('fb-modal').getElement('.generic_dialog_popup').setStyle('top',window.getScroll().y + 125 + 'px');
	$('fb-modal').setStyle('position','absolute');	
},

positionFixed: function() {
	$('fb-modal').getElement('.generic_dialog_popup').setStyle('top','125px');
	$('fb-modal').setStyle('position','fixed');	
},

preparePopup: function() {
if($defined($('popup')))
{
$('popup').set('opacity',0);	
$('popup').set('tween', {duration: 'normal'});

$('popup').getElement('.close').addEvent('click',function()
 {
	$('popup').get('tween').start('opacity', 1, 0);
 });
}
	
},

popupLoad: function() {
if($defined($('popup'))) {
 var win_size = window.getSize();
 var sizes = $('popup').getSize();

 var newLeft = ((win_size.x - sizes.x)/2).round();
 var newTop = ((win_size.y - sizes.y)/2).round();

 $('popup').setStyles({
 left: newLeft+'px',
 top: newTop +'px'});
(function(){$('popup').get('tween').start('opacity', 0, 1);


 }).delay(1000);
}	
}
	
});

window.addEvent('domready',function(){
	//Playlist = new Playlist({'swfLocation': _basehref + 'MooSound.swf'});
	site = new SiteEngine(_basehref);
	site.popupLoad();



window.addEvent('load',function(){



if($defined($('user_message'))) {
	
		new Fx.Reveal($('user_message')).reveal();
	}

	if($defined($('addresses'))) {
		var boxes = $('addresses').getElements('.choisable_entity');
		var height = 0;
		boxes.each(function(item){
		if(item.getSize().y - item.getStyle('padding-top').toInt() - item.getStyle('padding-bottom').toInt() > height) {
		 height = item.getSize().y - item.getStyle('padding-top').toInt() - item.getStyle('padding-bottom').toInt();	
		}
	});
		boxes.setStyle('height',height + 'px');
		
	}
	
	if($defined($('invoices'))) {
		var boxes = $('invoices').getElements('.choisable_entity');
		var height = 0;
		boxes.each(function(item){
		if(item.getSize().y - item.getStyle('padding-top').toInt() - item.getStyle('padding-bottom').toInt() > height) {
		 height = item.getSize().y - item.getStyle('padding-top').toInt() - item.getStyle('padding-bottom').toInt();	
		}
	});
	boxes.setStyle('height',height + 'px');
		
	}


});
});

var form_address_cancel = function() {
	site.form_address_cancel();	
}

var form_invoice_cancel = function() {
	site.form_invoice_cancel();	
}

var ajax_address_submit = function(event) {
	site.ajax_address_submit(event);	
}

var ajax_invoice_submit = function(event) {
	site.ajax_invoice_submit(event);	
}

var referusFormSubmit = function(event) {
		site.referusFormSubmit(event);
	};
	
var form_referus_cancel = function() {
		site.form_referus_cancel();	
}

var ajax_hit_submit = function(event) {
	site.ajax_hit_submit(event);	
}
