var Site = new Class({

	initialize: function(){
		
		hs.registerOverlay(
			{
				thumbnailId: null,
				overlayId: 'controlbar',
				position: 'top right',
				hideOnMouseOut: true
			}
		);
		
		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.newsSlider();
		this.searchBox();
		this.centeringPager();
		this.contactForm();
	}, // 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
	
	// opencloseDetails
	opencloseDetails: function (el, div)
	{
 		if($(div).getStyle('display') == 'none'){
 			$(div).setStyle('display','block');
 			el.innerHTML = 'ukryj detale';
 		}else{
 			$(div).setStyle('display','none');
 			el.innerHTML = 'rozwiń detale';
 		}
	}, // opencloseDetails
	
	// searchBox
	searchBox: function ()
	{
 		$('search_text').addEvent("focus",function(){			
 			if ($('search_text').getProperty('value') == "wpisz szukaną frazę") {
 				$('search_text').value = '';
 			}

		});
 		$('search_text').addEvent("blur",function(){			
 			if ($('search_text').getProperty('value') == "") {
 				$('search_text').value = 'wpisz szukaną frazę';
 			}
		});

	}, // searchBox
	
	// News slider
	newsSlider: function ()
	{
		
		$$('div#left_box_nav a').each(function(a){
			a.addEvent('click', function(){
				new Fx.Morph($('main-news-list'), {
					duration: 500, 
					transition: Fx.Transitions.Cubic.easeInOut
				}).start({
					'margin-left': -(this.get('rel')-1)*344
				});
				
				$$('div#left_box_nav a').each(function(b){
					b.removeClass('active');
				});
				
				this.addClass('active');
			
			});
		});

	},
	
	// 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
	
});

var Site = new Site();
window.addEvent('domready', function(){ Site.domReady(); });
