var Site = new Class({

	initialize: function(){
		
		hs.registerOverlay(
			{
				thumbnailId: null,
				overlayId: 'controlbar',
				position: 'top right',
				hideOnMouseOut: true
			}
		);

        if($('facebookComments')) $('facebookComments').innerHTML('<fb:comments href=\"' + window.location.href + '\" num_posts=\"5\" width=\"800\"></fb:comments>');

		hs.graphicsDir = 'public/images/highslide/';
		hs.outlineType = 'rounded-white';
		hs.align = 'center';
		hs.captionEval = 'this.thumb.title';
		
		hs.addSlideshow({
			//slideshowGroup: 'group1',
			interval: 5000,
			repeat: false,
			useControls: true,
			fixedControls: 'fit',
			overlayOptions: {
				opacity: .75,
				position: 'bottom center',
				hideOnMouseOut: true
			}
		});

		
	}, // initialize
	
	domReady: function() {

		Cufon.replace('h2.caption');
		Cufon.now();

		this.activatePartnersBanners();
		this.activateTips();
		this.activateGoToTop();
		this.overflowBox();
		this.orderMail();
	}, // domReady
	
	showMail: function(user, domain, contry, attr) {
		var start = "<a href=\"mailto:" + user + "@" + domain + "." + contry + "\"" + attr + ">";
		var end = "</a>";
		document.write(start + user + "@" + domain + "." + contry + end);
		return false;
	}, // showMail
	
	// activatePartnersBanners
	activatePartnersBanners: function ()
	{
		$$('div#bottom-banners img').each(function(img){
			img.addEvent('mouseover', function(){
                newsrc = img.src.replace("bannergray", "bannercolor");
                img.src = newsrc;
			});
            img.addEvent('mouseout', function(){
                newsrc = img.src.replace("bannercolor", "bannergray");
                img.src = newsrc;
			});
		});
	},
	
	// openWindow
	openWindow: function (theURL,winName,w,h,scrollbars)
	{
		
		  LeftPosition=(screen.width)?(screen.width-w)/2:100;
		  TopPosition=(screen.height)?(screen.height-h)/2:100;
		  
		  settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scrollbars+',location=no,directories=no,status=0,menubar=no,toolbar=no,resizable=no';
		  URL = theURL;
		  window.open(URL,winName,settings);
		
	}, // openWindow

	// centeringPager
	centeringPager: function ()
	{
		var totalWidth = 0;
		$$('ul.pager li').each(function(li){
			totalWidth = totalWidth + parseInt( li.getStyle('width') ) + 5; // margin-right:5px
		});
		
		$$('ul.pager').setStyle('width', totalWidth + 'px');
		
	}, // centeringPager

	// contactForm
	contactForm: function ()
	{
		if ($('contact-form')) {
			if ($('companyname').value == '') { $('companyname').value = 'nazwa firmy'; }
			if ($('name').value == '') { $('name').value = 'imię i nazwisko'; }
			if ($('email').value == '') { $('email').value = 'adres e-mail'; }
			if ($('phone').value == '') { $('phone').value = 'telefon kontaktowy'; }
			if ($('message').value == '') { $('message').value = 'treść wiadomości'; }

	 		$('companyname').addEvent("focus",function(){			
	 			if ($('companyname').getProperty('value') == "nazwa firmy") $('companyname').value = '';
			});
	 		$('companyname').addEvent("blur",function(){			
	 			if ($('companyname').getProperty('value') == "") $('companyname').value = 'nazwa firmy';
			});
	 		
	 		$('name').addEvent("focus",function(){			
	 			if ($('name').getProperty('value') == "imię i nazwisko") $('name').value = '';
			});
	 		$('name').addEvent("blur",function(){			
	 			if ($('name').getProperty('value') == "") $('name').value = 'imię i nazwisko';
			});
	 		
	 		$('email').addEvent("focus",function(){			
	 			if ($('email').getProperty('value') == "adres e-mail") $('email').value = '';
			});
	 		$('email').addEvent("blur",function(){			
	 			if ($('email').getProperty('value') == "") $('email').value = 'adres e-mail';
			});
	 		
	 		$('phone').addEvent("focus",function(){			
	 			if ($('phone').getProperty('value') == "telefon kontaktowy") $('phone').value = '';
			});
	 		$('phone').addEvent("blur",function(){			
	 			if ($('phone').getProperty('value') == "") $('phone').value = 'telefon kontaktowy';
			});
	 		
	 		$('message').addEvent("focus",function(){			
	 			if ($('message').getProperty('value') == "treść wiadomości") $('message').value = '';
			});
	 		$('message').addEvent("blur",function(){			
	 			if ($('message').getProperty('value') == "") $('message').value = 'treść wiadomości';
			});
	 		
	 		$('contact-form').addEvent("submit",function(){
	 			
	 			$('ajax_loader').setStyle('display', 'block');
	 			$('button_send').setStyle('display', 'none');
	 			
				if ($('companyname').value == 'nazwa firmy') { $('companyname').value = ''; }
				if ($('name').value == 'imię i nazwisko') { $('name').value = ''; }
				if ($('email').value == 'adres e-mail') { $('email').value = ''; }
				if ($('phone').value == 'telefon kontaktowy') { $('phone').value = ''; }
				if ($('message').value == 'treść wiadomości') { $('message').value = ''; }
				
			    $('contact-form').set('send',{ url: '/kontakt/formularz',
		          	  onSuccess: function(response) {
		          	      	$('ajax_loader').setStyle('display', 'none');
		          	        if ($('button_send')) $('button_send').setStyle('display', 'block');
		  	              	$('ajax_contact_form').innerHTML = response;
			    			Site.contactForm();
		          	  }
			    	 
				});
		  
				$('contact-form').send();
				
				return false;
				
			});
	 		
		}
		
	}, // contactForm
	

	getCalendar: function(month, year) {

        var path = 'kalendarz/' + month + '/' + year;
        
        var req = new Request({ 
        	headers: {'X-Requested-With': 'XMLHttpRequest'},
            method: 'get',
            url: path,
            onSuccess: function(response) {
                $('main-calendar').innerHTML = response;
        		Cufon.replace('h2.caption');
        		Cufon.now();
        		Site.activateTips();
            }  
        }).send();
	}, // getCalendar
	
	activateTips: function() {
		var Tips1 = new Tips($$('.day1'), {
			className: 'tooltip'
		});
	}, // activateTips
	
	activateGoToTop: function() { 
		 $('gotop').addEvent('click', function() { 
			 var scrollFx = new Fx.Scroll(window, { 
				 transition: Fx.Transitions.Quad.easeInOut 
			 }); 
			 scrollFx.toTop(); 
		 }); 
	}, //activateGoToTop 

	orderMail: function() {
		$$('.faktura-mail-get').each(function(item) {
			item.addEvent('click', function(){
				var a = this.get('value');
				if(a == 'tak') {
					$('faktura-mail-container').setStyle('display','block'); 
				} else {
					$('faktura-mail-container').setStyle('display','none');
				}
			});
		});
	},
	
	overflowBox: function() {
	    $$('#main-left div.box-type2').each(function(item){
			if(item.getSize().y > 400) {
				var or_height = item.getSize().y;
			    item.setStyle('overflow','hidden');
			    item.setStyle('height','293px');
			    item.setStyle('position','relative');
			    
			    var btn = document.createElement('a');
			    btn.set('text','czytaj więcej');
			    btn.addClass('box-read-more');
			    btn.addEvent('click', function(){
			    	item.setStyle('height',or_height + 'px');
			    	this.setStyle('display','none');
			    });
			    item.appendChild(btn);
			}
	    });
	}
});

var Site = new Site();
window.addEvent('domready', function(){ Site.domReady(); });
