window.onload = function(){

jQuery.noConflict();

	/* event : print offer */
	if ($('printOffer')) {
		$('printOffer').onclick = function(){
		
			window.print();
			return false;
			
		}
	}
	
	/* event : send question form in offer */
	
	if ($('askForm')) {
	
		$('askForm').addEvent('submit', function(e){
		
			new Event(e).stop();
			var ajaxResult = $('ajaxResult');
			var bodyOldValue = $('bodySend').value;
			

			ajaxResult.setStyle("opacity", "1.0");
			
			var log = $('ajaxResult').empty().addClass('ajax-loader').appendText('Wysyłam...');
			
			this.send({
				update: log,
				onComplete: function(){
				
					var delFx = new Fx.Styles(ajaxResult, {
						duration: 4000,
						wait: 1500
					});
					
					log.removeClass('ajax-loader');
					
					delFx.start({
						'opacity': '0.0'
					}).chain(function(){
					
						ajaxResult.empty();
						
					});
				}
			});
			
			$('submitSend').setStyle("visibility", "hidden");
		
			bodySend = $('bodySend');
			
			bodySend.onkeypress = function(){
			
				if (bodySend.value != bodyOldValue) {
				
					$('submitSend').setStyle("visibility", "visible");
					
				}
				
			}
			
			
			
		});
		
	}
	
/*	if ($('addBriefcase')) {
	
		$('addToBriefcaseBtn').addEvent('click', function(e){
		
			new Event(e).stop();
			var ajaxResult = $('ajaxResult');
			
			ajaxResult.setStyle("opacity", "1.0");
			
			var log = $('ajaxResult').empty().addClass('ajax-loader').appendText('Wysyłam...');
			
			
			$('addBriefcase').send({
				update: log,
				onComplete: function(){
					var delFx = new Fx.Styles(ajaxResult, {
						duration: 4000,
						wait: 1500
					});
					
					log.removeClass('ajax-loader');
					delFx.start({
						'opacity': '0.0'
					}).chain(function(){
					
						ajaxResult.empty();
						
					});
				}
				
			});
			
		});
		
	}*/
	
/*	if ($$('.delBriefcase')) {
	
		$$('.delFromBriefcase').addEvent('click', function(e){
		

			new Event(e).stop();
			
			this.parentNode.send({
				update: this.parentNode.parentNode
			});
			

			var box = this.parentNode.parentNode.parentNode;
			var delFx = new Fx.Styles(box, {
				duration: 800,
				wait: false
			});
			
			delFx.start({
				'opacity': '0.0'
			}).chain(function(){
				box.remove();
			});
			
		});
		
	}*/
	
	if ($('bodySend')) {
	
		$('bodySend').onfocus = function(){
		
			if ((this.value == 'Treść pytania') || (this.value == 'Text of message')) {
			
				this.value = '';
				
			}
			
		}
		
	}
	
	if ($('emailSend')) {
	
	
		$('emailSend').onfocus = function(){
		
			if ((this.value == 'Twój adres e-mail') || (this.value == 'your e-mail')) {
			
				this.value = '';
				
			}
			
		}
		
	}
	
	if ($('query')) {
	
	
		$('query').onfocus = function(){
		
			if ((this.value == 'Katowice, działka, sprzedaż lub numer oferty') || (this.value == 'Katowice, plot, sell or offer number')) {
			
				this.value = '';
				
			}
			
		}
		
	}
	
	if ($('username')) {
	
	
		$('username').onfocus = function(){
		
			if ((this.value == 'adres e-mail') || (this.value == 'e-mail address')) {
			
				this.value = '';
				
			}
			
		}
		
	}
	
	if ($('password')) {
	
	
		$('password').onfocus = function(){
		
			if ((this.value == 'hasło') || (this.value == 'password')) {
			
				this.value = '';
				
			}
			
		}
		
	}
	
	
	
	/* sortable briefcase 
	 
	 if ($('briefcaseResult')) {
	 new Sortables($('briefcaseResult'), {
	 
	 initialize: function(){
	 var step = 0;
	 this.elements.each(function(element, i){
	 step = step + 15;
	 });
	 }
	 
	 });
	 
	 }
	 
	 */
	if ($$('.delOffer')) {
	
		$$('.delOffer').each(function(element){
		
			element.onclick = function(){
			
				var conf = confirm("Czy na pewno chcesz usunąć ofertę?");
				
				if (!conf) {
					return false;
				}
				
			}
			
		});
		
	}
	
	
	
	/* event : send question form in contact */
	
	if ($('contactFormForm')) {
	
		$('yourMail').onfocus = function(){
		
			if ((this.value == 'Twój adres e-mail') || (this.value == 'your e-mail')) {
			
				this.value = '';
				
			}
			
		}
		
		$('yourPhoneNum').onfocus = function(){
		
			if ((this.value == 'Twój numer telefonu') || (this.value == 'your phone number')) {
			
				this.value = '';
				
			}
			
		}
		
		$('body').onfocus = function(){
		
			if ((this.value == 'treść wiadomości') || (this.value == 'message text...')) {
			
				this.value = '';
				
			}
			
		}
		
		$('contactFormForm').addEvent('submit', function(e){
		
			new Event(e).stop();
			var ajaxResult = $('ajaxResult');
			var bodyOldValue = $('body').value;
			
			ajaxResult.setStyle("opacity", "1.0");
			
			var log = $('ajaxResult').empty().addClass('ajax-loader').appendText('Wysyłam...');
			
			this.send({
				update: log,
				onComplete: function(){
				
					var delFx = new Fx.Styles(ajaxResult, {
						duration: 4000,
						wait: 1500
					});
					
					log.removeClass('ajax-loader');
					
					delFx.start({
						'opacity': '0.0'
					}).chain(function(){
					
						ajaxResult.empty();
						
					});
				}
			});
			
			$('submitSend').setStyle("visibility", "hidden");
			
			bodySend = $('body');
			
			bodySend.onkeypress = function(){
			
				if (bodySend.value != bodyOldValue) {
				
					$('submitSend').setStyle("visibility", "visible");
					
				}
				
			}
			
			
			
		});
		
	}



/*jQuery('.boxOffer').mouseup(function() {

    document.location = jQuery(this).attr('href');

});

jQuery('.boxOfferPromo').mouseup(function() {

    document.location = jQuery(this).attr('href');

});*/

if(jQuery('#offer').length>0) {
    
    jQuery('html').animate({ scrollTop: 420 }, 550);
    
}

jQuery('#categoryBar').hover(function() {

    jQuery('#categoryBar .add a').css('display', 'block');

}, function() {

    jQuery('#categoryBar .add a').css('display', 'none');

});

if(jQuery('#frmSubmit').length>0) {

    jQuery('#frmSubmit').click(function(ev) {

	jQuery('#formToSubmit').submit();

    });

}

Shadowbox.init();

jQuery('#good').val('1');
		
}


