// JavaScript Document
var SiteEngine = new Class ({
Implements: Class.Binds,							
initialize : function(basehref){
	this.basehref = basehref;
	this.top_menu();
	this.header_news_slider();
	this.bottom_gallery();
	this.back_to_top();
	this.calendar();
	this.rightmenu();
	this.bluebuttons();
	this.newslistindex();
	this.right_partners();
	this.firm_list();
	this.tools_bars();
	this.section_multimedia();
	this.gallery_subpage();
	this.company_details();
	this.library_list();
	this.project_list();
	this.layout_extend();
	this.cfe_init();
	this.contact_form();	
	this.hideTitles();
	this.skin_handle();
	this.newsletter();
	this.newsletter_form();
	this.searchbox();
	this.cferepair();
	},
	
cferepair: function() {

	var elem = $(document.body).getElement('.tools_bar .category .jsSelectorCategory_select .jsSelectorContentSlide1');
	
	if(elem) {
		if(elem.getElement('.jsSelectorScrollerWrapper .scrollTop')) {
		elem.setStyle('width',(elem.getDimensions().width + 20) + 'px');	
		}
	}

},
	
searchbox: function() {
	var search_box_form = $('search_box_form');
	
	if(search_box_form != null) {
		
		new OverText($('search_box_fraza'));
		
		search_box_form.addEvent('submit', function(event){
			event.preventDefault();
			$('search_box_fraza').value = $('search_box_fraza').value.trim();
			var txt = $('search_box_fraza').value;
			var error = $('search_box_fraza').getAttribute('rel');
			
			if(txt.length < 3 ) {
				alert(error);	
			} else {
				search_box_form.submit();
			}
		
		});	
	}
},
	
newsletter: function() {
	var newsletter = $('newsletter');
	
	if(newsletter) {
		
		newsletter.addEvent('submit',function(event){
			event.preventDefault();
		});
		
		new OverText($('newsletter_email'));
		
		
		$('newsletter_add').addEvent('click',function(event){
		event.preventDefault();

		Mediabox.open($('newsletter_add').getAttribute('rel') + '?email='+$('newsletter_email').value, 'Newsletter', '400 200');
		
		});
	
		$('newsletter_remove').addEvent('click',function(event){
		event.preventDefault();

		Mediabox.open($('newsletter_remove').getAttribute('rel') + '?email='+$('newsletter_email').value, 'Newsletter', '400 200');
		
		});
	}
	
	var mb_newsletter_dialog = $('mb_newsletter_dialog');
	if(mb_newsletter_dialog != null) {
		Mediabox.open('#mb_newsletter_dialog', 'Newsletter', '400 100');
	}
	
},

newsletter_form: function() {
	
	form = $('newsletter_regular_form');
	

	if(form != null) {
			
		cfe.spacer = this.basehref + "gfx/spacer.gif";

							   var myCfe = new cfe.replace();
						
							   myCfe.setModuleOptions("select",{
											scrolling: true,
											scollSteps: 2,
											size: 10
											});
							myCfe.init({
								   scope: $('contact_form')
							   });
	}
},


skin_handle: function() {
	if($(document.body).hasClass('skin_z') && $(document.body).hasClass('index')) {
	var myScript = Asset.javascript(this.basehref + 'js/grayscale.js', {
		id: 'myScript'
	});		
		window.addEvent('load',function(){
			grayscale($$('#header_news_slide img'));
			grayscale($$('#newslist_index img'));
			grayscale($$('#right_partners img'));
			grayscale($$('#panel_galleries img'));
			grayscale($$('#right_menu .submenu'));
		});
	}
},

hideTitles:function() {
	$$('a[rel^=lightbox]').each(function(el,i){
	el.store('title',el.title);
	el.title = '';
	});
},

contact_form: function() {

	var form = $('contact_form');
	var bindsth = this;
	
	if(form!=null) {
		
		form.getElements('[type=text], textarea').each(function(el, index){
			new OverText(el);
		});
		
		send_btn = form.getElement('[type=image]');
		reset_btn = form.getElement('[type=reset]');
		
		reset_btn.addEvent('click', function() {
			form.reset();
			OverText.update();
		});
        
        var tips = new Tips('#contact_form .error_ico',{'className':'error-tips'});
        
        form.getElements('[type=text], textarea').each(function(item,index){item.disabled = 0;});
        
		var bindsth = this;
		
        form.addEvent('submit', function(event){
        new Event(event).preventDefault();
		
		
		form.set('send', { method: 'post', 
                onRequest: function() {
                        form.getElement('.btns').dispose();
                        form.getElements('[type=text], textarea').each(function(item,index){item.disabled = 1;});
                        $('ajax_contact_response').set('opacity',0.6);
                        },

                onComplete: function(response){
                        $('ajax_contact_response').set('html',response);
                        $('ajax_contact_response').set('opacity',1);  
							cfe.spacer = this.basehref + "gfx/spacer.gif";

							   var myCfe = new cfe.replace();
						
							   myCfe.setModuleOptions("select",{
											scrolling: true,
											scollSteps: 2,
											size: 10
											});
						
							myCfe.init({
								   scope: $('contact_form')
							   });
                        	bindsth.contact_form();
							
							$$('#contact_form .overText').each(function(el){
								new OverText(el);
							});	
                        }
                });
                        form.send();
                });
        
        }
		
},

cfe_init: function() {
	if($$('.cfe').length) {
	cfe.spacer = this.basehref + "gfx/spacer.gif";

       var myCfe = new cfe.replace();

	   myCfe.setModuleOptions("select",{
					scrolling: true,
					scollSteps: 2,
					size: 10
					});

	myCfe.init({
           scope: document.body.getElement('.cfe form')
       });
	}
},

layout_extend: function() {
	
	$$('.article_text').each(function(article, index){
		var children = article.getChildren();
		
		if(children) {
			var last = children.getLast();	
			if(last)
			last.setStyle('padding-bottom',0).setStyle('margin-bottom',0);
		}
	});
	
},

project_list: function(){
	
	var project_list_el = $('project_list');
	
	if(project_list_el != null) {
		
	project_list_el.getElements('.logo').each(function(logo, index){
			logo.adopt(new Element('span'));
		});		
		
	project_list_el.getElements('.email, .www').setStyle('opacity',0.85).addEvents({
				 'mouseover':function() { this.setStyle('opacity',1);},
				 'mouseleave': function() {this.setStyle('opacity',0.85);}			   
			});
	}
	
	
},

library_list: function() {
	
	var library_list_el = $('library_list');
	
	if(library_list_el == null) {
		if($('content'))
		library_list_el = $('content').getElement('.cover_and_download_desc');
	}
	
	if(library_list_el != null) {
		library_list_el.getElements('.cover').each(function(cover, index){
		
			if(cover.getElement('img') != null) cover.adopt(new Element('span'));
														 
		});	
		
		library_list_el.getElements('.download').setStyle('opacity',0.85).addEvents({
					 'mouseover':function() { this.setStyle('opacity',1);},
					 'mouseleave': function() {this.setStyle('opacity',0.85);}			   
				});
	}
	
},

company_details: function() {
	
	var comp_det = $('company_details');
	
	if(comp_det != null) {
		
		comp_det.getElements('.www, .email').each(function(elem, index2){
				elem.setStyle('opacity',0.85);
				
				elem.addEvents({
					 'mouseover':function() { this.setStyle('opacity',1);},
					 'mouseleave': function() {this.setStyle('opacity',0.85);}			   
				});
			});
		
	}
	
},

firm_list: function() {

	var firm_list = $('firm_list');
	
	if(firm_list != null ) {
		
		firm_list.getElements('.logo').each(function(logo, index){
		
			if(logo.getElement('img') != null) logo.adopt(new Element('span'));
														 
		});	
		
		firm_list.getElements('.email_and_www').each(function(item,index){
		
			item.getElements('.www , .email').each(function(elem, index2){
				elem.setStyle('opacity',0.85);
				
				elem.addEvents({
					 'mouseover':function() { this.setStyle('opacity',1);},
					 'mouseleave': function() {this.setStyle('opacity',0.85);}			   
				});
			});
		
		});
	}

},

gallery_subpage: function() {
	
	var gallery_view  = $('gallery_view');
	
	if(gallery_view != null) {
		
		var column_right_height = $('main_column_right').getSize().y + 100;
		var left_column = $('main_column_left');
		var newsitems_pagination = $('gallery_pagination');
		var items_per_page = 0;
		var pages_number = 0;
		
		var photos = gallery_view.getElements('.photo');
	
		photos.set('tween',{'duration':500, 'link':'chain',
				  onStart: function() {
					if(this.element.hasClass('toShow')) {
						this.element.setStyle('display','block');	
					}
				  },
  				  onComplete: function() {
					if(!this.element.hasClass('toShow')) {
						this.element.setStyle('display','none');	
					}
				  }
				  }).setStyle('display','none');	
	
		photos.each(function(photo, index){
			
			photo.getElement('a').adopt(new Element('div', {'class':'zoom_ico', 'styles': {'display':'none'}}));
			photo.addEvents({
							'mouseenter': function() {this.getElement('.zoom_ico').setStyle('display','block');},
							'mouseleave': function() {this.getElement('.zoom_ico').setStyle('display','none');}							
							});
		
		});
	
		
	for(i = 0;  i < photos.length ; i++) {
		
		photos[i].setStyle('display','block').addClass('toShow');
	
		if(left_column.getSize().y > column_right_height)	 {
			photos[i].setStyle('display','none');
		} else {
			items_per_page = items_per_page + 1; 
			photos[i].setStyle('display','block');
		}
	}

	pages_number = (photos.length / items_per_page).ceil();
	
	for(z = 0; z < pages_number; z++) {
		
		var number_span = new Element('span');
		newsitems_pagination.adopt(number_span);
		
		if(z == 0) number_span.addClass('chosen');


		number_span.store('page',z).addClass(z);
		
		
		number_span.addEvent(
			'click', function() {
				
				newsitems_pagination.getChildren().removeClass('chosen');
				
				var e = this.retrieve('page');
				var start =  e * items_per_page;
				var end = start + items_per_page;
				
				this.addClass('chosen');
			
				//newsitems.setStyle('display','none').removeClass('toShow');
					for (i = 0; i < photos.length; i++) {
						photos[i].setStyle('display','none');
						
						if(i >= start && i < end) {
							photos[i].setStyle('display','block');
						} 
					}
						
			new Fx.Scroll(window,{ duration:500 }).toElement($('gallery_top'));
			
			}
		);
		
		
	}
	}
	
},


section_multimedia: function() {
	
	var slideshow = new Array();
	
	$$('.section_gallery').each(function(gallery,index) {
	
	if(gallery.getElement('.type_film') != null) {
		gallery.getElement('.box').getElements('a').each(function(aelem, i){
			aelem.adopt(new Element('div',{'class': 'play_btn'}));		
			
			aelem.addEvents({
				'mouseenter': function(){this.getElement('.play_btn').setStyle('opacity',1);},
				'mouseleave': function(){this.getElement('.play_btn').setStyle('opacity',0.8);}
			});
			
			aelem.getElement('.play_btn').setStyle('opacity',0.8);
		});
	}
	
	gallery.adopt(new Element('div',{'class':'slide_prev'}), new Element('div',{'class':'slide_next'}))
	
		slideshow[index] = new noobSlide({
			box: gallery.getElement('.box'),
			items: gallery.getElement('.box').getElements('a'),
			size: 74,
			fxOptions: {duration:300,wait:false},
			addButtons: {
				previous: gallery.getElement('.slide_prev'),
				next: gallery.getElement('.slide_next')
			}
		});
	
	});
	
	
	$$('.section_sound_player').each(function(player, index){
		
		var Poptions = {
						'onRegister': function() {
						
						this.el = new Element('div', {'class':'song'});
						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/player_play.png',id:'play'+index}).inject(this.controls);
						this.pauseEl      = new Element('img', {'class':'pause', src:self.basehref + 'images//player_pause.png',id:'pause'+index}).inject(this.controls);
						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(player.getElement('.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': null
				};
			
					var songs = [this.basehref + "media/sounds/"+ player.getElement('h3').getAttribute('rel') +".mp3"];// + _current_mp3_demo]; 
					Playlist.loadSounds(songs, Poptions);
	
	});
	
},

prints: function() {
	$$('.print').addEvent('click',function(){
											   
	window.print();
	
	});	
},


tellafriend: function() {
	var tlf = $$('.tools_bar .tell_friend');
	bindsth = this;
	if(tlf.length) {
		
		
		
			$('mb_tellafriend').store('initial',$('mb_tellafriend').get('html'));
		
			tlf.each(function(tlf_item, index){
			tlf_item.addEvent('click', function(){
				$('mb_tellafriend').set('html',$('mb_tellafriend').retrieve('initial'));
				bindsth.tellafriendform();
												
				Mediabox.open('#mb_tellafriend', '', '350 300');	
			});
		
		});	
	}
		
},

tellafriendform: function() {
	var form = $(document.body).getElement('.tellafriend_form');
			
			if(form != null) {
			
			bindsth = this;
				
				cfe.spacer = this.basehref + "gfx/spacer.gif";
		
									   var myCfe = new cfe.replace();
								
									   myCfe.setModuleOptions("select",{
													scrolling: true,
													scollSteps: 2,
													size: 10
													});
								
									myCfe.init({
										   scope: form
									   });
				
			
				send_btn = form.getElement('[type=image]');

			
				form.getElements('[type=text], textarea').each(function(item,index){item.disabled = 0;});
				
				var bindsth = this;
				var response_div = form.getParent('.tellafriend_response');
				
				form.addEvent('submit', function(event){
				new Event(event).preventDefault();
				
				
				form.set('send', { method: 'post', 
						onRequest: function() {
								form.getElement('.btns').dispose();
								form.getElements('[type=text]').each(function(item,index){item.disabled = 1;});
								response_div.set('opacity',0.6);
								},
		
						onComplete: function(response){
								response_div.set('html',response);
								response_div.set('opacity',1);  
									cfe.spacer = this.basehref + "gfx/spacer.gif";
		
									   var myCfe = new cfe.replace();
								
									   myCfe.setModuleOptions("select",{
													scrolling: true,
													scollSteps: 2,
													size: 10
													});
								
									myCfe.init({
										   scope: form
									   });
									bindsth.tellafriendform();
									
									
								}
						});
								form.send();
						});
			
			}
},

tools_bars: function() {
	this.fontsizer();
	this.go_to_selects();
	this.prints();
	this.tellafriend();
},

go_to_selects: function() {
	var quasi_selects = $$('.tools_bar .go_on_change');
	
	if(quasi_selects.length) {
	
		quasi_selects.each(function(elem, index){
			
			elem.store('curval',elem.get('value'));
									
			elem.addEvent('change', function(){
				var cur_val = elem.get('value');
				if(cur_val != elem.retrieve('curval')) window.location.href = cur_val;
											 
			});			
		});
			
	}
},

fontsizer: function() {
	
	var uparrows = $$('.tools_bar .font .up');
	var downarrows = $$('.tools_bar .font .down');	
	var font_icos = $$('.tools_bar .font .font-size');	
	
	if(uparrows.length && downarrows.length && font_icos.length) {
		
		if($('content').hasClass('font-medium')) {
			font_icos.set('html','14');					 
		} else if($('content').hasClass('font-big')) {
			font_icos.set('html','16');	
			uparrows.setStyle('opacity',0.5);
		} else {
			font_icos.set('html','12');	
			downarrows.setStyle('opacity',0.5);
		}
		
		
		uparrows.addEvent('click', function(){
			
			var classtoadd = '';
			
			if($('content').hasClass('font-medium')) {
				classtoadd = 'font-big';
				font_icos.set('html','16');
				uparrows.setStyle('opacity',0.5);
				downarrows.setStyle('opacity',1);
			} else if($('content').hasClass('font-big')) {
				downarrows.setStyle('opacity',1);
				return;	
			} else {
				classtoadd = 'font-medium';
				font_icos.set('html','14');
				downarrows.setStyle('opacity',1);
			}
			
			$('content').removeClass('font-medium').removeClass('font-big');
			if(classtoadd) $('content').addClass(classtoadd);
		});
		
		downarrows.addEvent('click', function(){
			
			var classtoadd2 = '';
			
			if($('content').hasClass('font-big')) {
				uparrows.setStyle('opacity',1);
				font_icos.set('html','14');
				classtoadd2 = 'font-medium';
			} else if($('content').hasClass('font-medium')) {
				uparrows.setStyle('opacity',1);
				font_icos.set('html','12');
				downarrows.setStyle('opacity',0.5);
			} else {
				uparrows.setStyle('opacity',1);
				downarrows.setStyle('opacity',0.5);
			}
			
			$('content').removeClass('font-medium').removeClass('font-big');
			if(classtoadd2) $('content').addClass(classtoadd2);
		});
		
	}
},
	
right_partners: function() {
	
	var partners = $('right_partners');
	
	if(partners != null) {

	if($$('#partners_right_slide a').length) {
	$('right_partners_bottom').getElement('.title').empty().set('text',$('partners_right_slide').getElement('a').getElement('img').getAttribute('alt'));
	$('right_partners_bottom').getElement('.link a').href = $('partners_right_slide').getElement('a').href;
	
	var slideshow = new viewer($$('#partners_right_slide a)'),{
	mode: 'alpha',
	sizes: {w:140,h:102},
	interval: 8000,
	transparent: true,
	onWalk: function(current_item) {
					$('right_partners_bottom').getElement('.title').empty().set('text',this.items[current_item].getElement('img').getAttribute('alt'));
					$('right_partners_bottom').getElement('.link a').href = this.items[current_item].href;
				}
});
	slideshow.play();
	}
	}
	
},
	
newslistindex: function() {

	var newslist = $('newslist_index');

	if(newslist != null) {

	var r_banner_height = 0;

	if($('banner_right')) {
		r_banner_height =  $('banner_right').getSize().y;
	}

	column_right_height = r_banner_height + $('main_column_right').getSize().y  ;
	column_left = $('main_column_left');

	var newsitems = newslist.getElements('.news_item');
	var newsitems_pagination = $('index_news_pagination');
	var items_per_page = 10;
	var pages_number = 0;
	var lft_baner_height = 0;
	
	if($('left_billboard_banner')) {
		lft_baner_height = $('left_billboard_banner').getSize().y - 80;
	}
	
	newsitems.set('tween',{'duration':500, 'link':'chain',
				  onStart: function() {
					if(this.element.hasClass('toShow')) {
						this.element.setStyle('display','block');	
					}
				  },
  				  onComplete: function() {
					if(!this.element.hasClass('toShow')) {
						this.element.setStyle('display','none');	
					}
				  }
				  }).setStyle('display','none').setStyle('opacity',0);
	
	if($(document.body).hasClass('swes')) {
		items_per_page = 6;			

			for(i = 0;  i < newsitems.length ; i++) {
			if(i < 6) {
			newsitems[i].setStyle('display','block').addClass('toShow').tween('opacity',1);

			}

		}				
	} else {
		
	for(i = 0;  i < newsitems.length ; i++) {
		
		newsitems[i].setStyle('display','block').addClass('toShow');
		if((column_left.getSize().y + lft_baner_height) > column_right_height)	 {
			//items_per_page = items_per_page - 2;
			newsitems[i].tween('opacity',0).removeClass('toShow');
		} else {
				items_per_page = i+1; 	
		}
	}
	
	}


	pages_number = (newsitems.length / items_per_page).ceil();
	
	for(z = 0; z < pages_number; z++) {
		
		var number_span = new Element('span');
		newsitems_pagination.adopt(number_span);
		
		if(z == 0) number_span.addClass('chosen');


		number_span.store('page',z).addClass(z);
		
		
		number_span.addEvent(
			'click', function() {
				
				newsitems_pagination.getChildren().removeClass('chosen');
				
				var e = this.retrieve('page');
				var start =  e * items_per_page;
				var end = start + items_per_page;
				
				this.addClass('chosen');
	
					for (i = 0; i < newsitems.length; i++) {
						newsitems[i].tween('opacity',0).removeClass('toShow');
						
						if(i >= start && i < end) {
							newsitems[i].addClass('toShow');
						} 
					}
			
			newslist.getElements('.toShow').tween('opacity',1);
			
			if($(document.body).hasClass('swes')) {
				new Fx.Scroll(window,{ duration:500 }).toElement($('swes_intro_short'));					
			} else {
				new Fx.Scroll(window,{ duration:500 }).toElement($('newslist_index'));
			}
			
			}
		);
		 
 
	}
	newslist.getElements('.toShow').each(function(item, index){item.tween('opacity',1);});
}

	
},
	
bluebuttons: function() {
	
	$$('.blue_btn, .green_btn').each(function(btn, i) {
	
		btn.addEvents({
					  'mouseover':function() { this.setStyle('opacity',1);},
					  'mouseleave': function() {this.setStyle('opacity',0.85);}
					  }).setStyle('opacity',0.85);
								  
	});
	
},

rightmenu: function() {
	var rightmenu = $('right_menu');
	
	if(rightmenu != null) {
		rightmenu.getElements('li.leaf').each(function(el, index){

		var submenu = el.getElement('ul.submenu');

		if( submenu != null) {
			
				//submenu.set('opacity',0.9);
				
				var chli = submenu.getChildren();
				
				submenu.empty();
				submenu.adopt(new Element('li',{'class':'first'}));
				submenu.adopt(chli);
				submenu.adopt(new Element('li',{'class':'last'}));
				submenu.setStyle('z-index', el.getElement('.btn').getStyle('z-index')-1)	;				
			}
			
			el.addEvents({
						 'mouseenter': function() {
							el.addClass('hover'); 
						 },
						 
						 'mouseleave': function() {
							 el.removeClass('hover');
						 }
						 
						 
						 });
													   
		});		
	}
},

calendar: function() {
	var calendar = $('calendar');
	
	if(calendar != null) {
	var slf = this;	
		
		var calendar_ico = $('calendar_switch');
		
		calendar_ico.store('status','closed');
		
		var calendar_container = $('calendar_container').setStyle('display','none').setStyle('opacity',0);
		var calendar_bottom = $('calendar_container_bottom');
		calendar_bottom.store('init_top', calendar_bottom.getStyle('top')).setStyle('top',222);
		
		
		calendar_bottom.set('tween');
		
		
		cc_tween = new Fx.Tween(calendar_container, 
			{duration: 500,
				onStart: function() {
					if(calendar_ico.retrieve('status') == 'closed') {
						calendar_container.setStyle('display','block');
					} 
				},
				onComplete: function() {
					if(calendar_ico.retrieve('status') == 'opened') {
						calendar_ico.store('status','closed');	
						calendar_container.setStyle('display','none');
					} else {
						calendar_ico.store('status','opened');	
					}
				}
			
			}
			
			);
		
		calendar_ico.addEvent('click', function(){
			if(this.retrieve('status') == 'opened') {									
				cc_tween.start('opacity',0);
				this.getElement('div').removeClass('opened');
			}
			else {
				if(calendar_container.retrieve('ajax_status') != 'loaded')
				{
				
				slf.calendar_request(calendar.getAttribute("rel"));
				
				$$('.calendar_widget_reload').addEvent('click', function(event){
					event.preventDefault();													 
					slf.calendar_request(this.getAttribute("rel"));														 
				});
				
				}
				cc_tween.start('opacity',1);				
				this.getElement('div').addClass('opened');
			}
		});
		
	}
},

calendar_request: function(url_to_fetch) {
	
	var slf = this;
	
	var calendar = $('calendar');
	var calendar_container = $('calendar_container')
	var calendar_bottom = $('calendar_container_bottom');
	$('calendar_container').set('spinner', {message: 'proszę czekać...'});
	
	var myRequest = new Request.JSON({
					url: url_to_fetch,
					onRequest:function() {
						calendar_bottom.tween('top',222);
						$('calendar_container').spin();
					},
					onSuccess: function(responseJSON, responseText) {
						calendar_container.store('ajax_status','loaded');	
						$('calendar_response').set('html',responseJSON.table);
						$('calendar_year').set('html',responseJSON.year);
						$('calendar_month').set('html',responseJSON.month);
						
						$('calendar_prev_year').set('rel',responseJSON.prev_year);
						$('calendar_next_year').set('rel',responseJSON.next_year);						
						
						$('calendar_prev_month').set('rel',responseJSON.prev_month);
						$('calendar_next_month').set('rel',responseJSON.next_month);	
						
						
						calendar_bottom.empty();
						
						if(Object.getLength(responseJSON.events)) {
							calendar_bottom.tween('top',calendar_bottom.retrieve('init_top'));
							
							var mask = new Element('div',{'class':'mask'});
							var slider = new Element('div',{'id':'event_right_slider'});
							var previous = new Element('div',{'id':'event_previous','html':'&#8249;'});
							var next = new Element('div',{'id':'event_next','html':'&#8250;'});							
							
							calendar_bottom.adopt(previous,next);
							
							Object.each(responseJSON.events,function(ev, index) {
								var ev_el = new Element('div',{'class':'event_item'})
								.adopt(new Element('span',{'html':ev.date,'class':'date'}))
								.adopt(new Element('h5',{'html':ev.title}))
								.adopt(new Element('a',{'html':ev.category_title,'href':ev.category_url, 'class':'category'}))
								.adopt(new Element('a',{'href':ev.url,'html':'<span></span>','class':'green_btn read_more'}))								
								;
															  
								slider.adopt(ev_el);								  
							});
							
							calendar_bottom.adopt(mask.adopt(slider));
							
							var slider1 = new viewer(slider.getElements('.event_item'), {
							mode: 'alpha',
							interval: 8000,
							transparent: true
							});
							
							$$('.view-events').each(function(el, ind){
								var i = (el.getAttribute("rel")-1).toInt();	
								
								el.addEvent('click',function(event){event.preventDefault();});
								
								
								el.addEvent('click',slider1.walk.pass([i,true], slider1));								 
								
								});							 
															 
							
							previous.addEvent('click',slider1.previous.bind(slider1));
							next.addEvent('click',slider1.next.bind(slider1));
							
						}
						$('calendar_container').unspin();
					}
				});
				 
				myRequest.send();
	
},

top_menu: function() {
	
	$$('.tooltips').each(function(ite,ind){ite.store('tip:text', ite.getAttribute('alt'))});
	
	var myTips = new Tips('.tooltips');
	
	if($('nav')!= null) {
	var myMenu = new MenuMatic({'tweakInitial':{ x:-5, y:20}, 'hideDelay': 500, 
							   'onInit_complete': function(){
								   	$$('a.nc').addEvent('click',function(event)
									 {
									 event.preventDefault();
									 })
									}
								});

	}
	
},


back_to_top: function() {
	var mySmoothScroll = new Fx.SmoothScroll({
    links: '#back_to_top',
    wheelStops: false
});
},

bottom_gallery: function() {
	
	gallery_test = $('bottom_gallery_outer');
	
	if(gallery_test != null) {
		
		if($$('#panel_galleries .gallery').length) {	
		
		var elem1 = $('gallery_bottom_panel');
		var elem2 = $('content_outer');
		
		var gallery_inner = $('bottom_gallery_inner');
		
		var gallery_title = $('gallery_text_closed');
		var galleries_panel = $('panel_galleries');		
		
		if(gallery_inner.hasClass('opened')) {
			gallery_inner.store('status','opened');
		}
		

		
		galleries_panel.setStyle('opacity',0);
		gallery_title.setStyle('opacity',0);
		
		var galleries = galleries_panel.getChildren();
		
		var btn_holder = $('bottom_gallery_switch');
		var btn = btn_holder.getElement('span');

		
		btn.store('initial_elem1',elem1.getStyle('margin-top'));
		btn.store('initial_elem2',elem2.getStyle('margin-bottom'));		

		elem1.set('morph', {
			duration: 500,
			link: 'cancel'
		  });

		elem2.set('morph', {
			duration: 500,
			link: 'cancel',
			onComplete: function(){if(!gallery_inner.hasClass('opened')) {galleries_panel.setStyle('display','none');}},
			onStart: function(){if(!gallery_inner.hasClass('opened')) {galleries_panel.setStyle('display','block');} }
		  });
		
		gallery_title.set('morph', {
			duration: 500,
			link: 'cancel'
		  });
		
		galleries_panel.set('morph', {
			duration: 500,
			link: 'cancel'
		  });
		

		btn.addEvent('click',function(){
					
					var elem1_val;
					var elem2_val;					
					var gallery_panel_opacity;
					var gallery_t1_opacity;
					
					if(btn.retrieve('status') == 'completed') {
						
						elem1_val = btn.retrieve('initial_elem1');
						elem2_val =  btn.retrieve('initial_elem2');		
						btn.store('status','begin')
						btn_holder.removeClass('open');
						gallery_panel_opacity = 0;
						gallery_t1_opacity = 1;
					} else {

						elem1_val = '0px';
						elem2_val = '295px';		
						btn.store('status','completed')
						btn_holder.addClass('open');
						gallery_panel_opacity = 1;
						gallery_t1_opacity = 0;
					}
					
		
					var myChain = new Chain();
					
					myChain.chain(
					 function(){ 
						elem1.morph({
					  'margin-top': elem1_val
					});
					
					elem2.morph({
					  'margin-bottom': elem2_val
						});		
					},
					
					function(){ 
						galleries_panel.morph({
							'opacity': gallery_panel_opacity					  
						});
					},
					
					function(){ 
						gallery_title.morph({
							'opacity': gallery_t1_opacity					  
						});
						},
						
					function() {
						if(btn_holder.hasClass('open')) {
							gallery_inner.addClass('opened');				   
						} else {
							gallery_inner.removeClass('opened');	
						}
						
					}
					);
					
					myChain.callChain();
					myChain.callChain();
					myChain.callChain();
					myChain.callChain();
					
		});
		
		if(gallery_inner.hasClass('opened'))  {
			galleries_panel.show();	
			elem1.setStyle('margin-top','0px');
			elem2.setStyle('margin-bottom','295px');
			btn.store('status','completed');
			btn_holder.addClass('open');
			galleries_panel.setStyle('opacity',1);
		} else {
			gallery_title.setStyle('opacity',1);
		}
		
		galleries.each(function(gallery,i){
			var btng = gallery.getElement('.button');
			
			var temp = gallery.getElement('.button')
			var img = new Element('span',{'class':'img_mask'});
			img.inject(temp, 'before');
			
			btng.addEvents({
						  'mouseenter':function(){this.addClass('chosen');},
						  'mouseleave':function(){this.removeClass('chosen')}
						  });
			
								
		}) ;
		} else {
		
			$('bottom_gallery_outer').dispose();
			$('content_outer').setStyle('margin-bottom','16px');
		
		}
	}
	
	
},

	
header_news_slider: function() {
	
	if(header_news_elem = $('header_news_slide')) {
		
		slide_elems = header_news_elem.getElements('.slide_elems img');
		
		
	
		if(slide_elems.length > 1) {
			
			var slider1 = new viewer(slide_elems, {
			mode: 'alpha',
			interval: 8000
			});
		
		slider1.play(true);
		
		}
		var handles = $$('#header_news_items .item');
		var slider_holder = $('header_news_slide');
		
		handles.each(function(el,index){
							  var image = el.getElement('img');
							  if(image != null) {
									 image.addClass('additional_news_photo').setProperty('id','additional_news_photo_' + index).setStyle('opacity',0).set('tween',{}); 
									 slider_holder.adopt(image);
									 el.store('additional_photo','additional_news_photo_' + index);
							  }
							  
							  el.addEvents({
							  				'mouseover': function(){
												this.addClass('current');
												var has_photo = this.retrieve('additional_photo');
												if(has_photo != null) {
														$(has_photo).setStyle('z-index',4).tween('opacity',1);
												}
												
											},
											'mouseleave': function() {
												this.removeClass('current');
												var has_photo = this.retrieve('additional_photo');
												if(has_photo != null) {
														$(has_photo).setStyle('z-index',3).tween('opacity',0);
												}

											}
											
										   });
							  
							  });
		
		
	
	}
	
}
	

	
});


window.addEvent('domready',function(){
   thesite = new SiteEngine(basehref);
});
