$(document).ready( function(){
	
	// okienko wyszukiwarki
	if( $('input[name=szukaj]').get(0) ){
		$('input[name=szukaj]').click( function(){
			var wartosc = $( this ).val();
			if( wartosc == 'wpisz szukaną frazę' ){
				$( this ).val('');
			}
			if( ! wartosc ){
				$( this ).val('wpisz szukaną frazę');
			}
		}).blur( function() {
			var wartosc = $( this ).val();
			if( ! wartosc ){
				$( this ).val('wpisz szukaną frazę');
			}
		});
	}
	
	// slider sg
	if( $('#s').get(0) ){
		$('#s .r').click(function(){
			var pierwszy = $('#s ul li:first');
			$(pierwszy.clone()).appendTo($('#s ul'));
			pierwszy.remove();
		});
		
		$('#s .l').click(function(){
			var ostatni = $('#s ul li:last');
			$('#s ul li:first').before( ostatni.clone() );
			ostatni.remove();
		});
	}
	
	// projekty sg
	if( $('#b').get(0) ){
		
		if( typeof(_projekty) != 'undefined' ){
			
			var ile_projektow = _projekty.length;
			
			if( ile_projektow == 0 ){
				$('#b').remove();
			}
			else{
				var kpax;
				var lista = '<ul>';
				
				for( k=0; k < ile_projektow; k+=1 ){
					if( k == 0 ){
						lista = lista + '<li class="s">' + (k+1) + '</li>';
					}
					else{
						lista = lista + '<li>' + (k+1) + '</li>';
					}
				}
				lista = lista + '</ul>';
				
				$(lista).appendTo($('#b div:first'))
				
				$('#b').css('background','url('+_projekty[0][0]+')');
				$('#b div ins p:first').html('klient: '+_projekty[0][1]);
				$('#b div ins p:last').html('rodzaj projektu: '+_projekty[0][2]);
				$('#b div ins a').html(_projekty[0][3]).attr('href','http://'+_projekty[0][3]);
				$('#b a.erl').attr('href', _projekty[0][4] );
	
				$('#b ul li').click( function(){
					var obecny = $(this);
					
					if( obecny.hasClass('s') ){
						return false;
					}
					else{
						
						clearInterval( kpax );
						
						$('#b ul li').removeClass('s');
						
						var index = obecny.html();
						index = index - 1;
						
						if( _projekty[index] ){
							$('#b').css('background','url('+_projekty[index][0]+')');
							$('#b div ins p:first').html('klient: '+_projekty[index][1]);
							$('#b div ins p:last').html('rodzaj projektu: '+_projekty[index][2]);
							$('#b div ins a').html(_projekty[index][3]).attr('href','http://'+_projekty[index][3]);
							
							$('#b a.erl').attr('href', _projekty[index][4] );
							
							obecny.addClass('s');
						}
												
						if( $('#b ul li.s + li' ).get(0) ){
							var nastepny = $('#b ul li.s + li' ).html();
							nastepny = nastepny - 1;
							$('#b img:first').attr('src',_projekty[nastepny][0]);
						}
						
						karuzela( );
						return false;
					}
				});
				
				function karuzela( ){
					kpax = setInterval(function(){
						
						if( $('#b ul li:last').hasClass('s') ){
							$('#b ul li:first').trigger('click');
						}
						else{
							$('#b ul li.s + li' ).trigger('click');
						}
					}, 8000);
				}
				
				karuzela( );
				
			}
		}
		
	}
	
	
	function getInnerDimensions() {
		var x,y;
		if (self.innerHeight) // all except Explorer
		{
			x = self.innerWidth;
			y = self.innerHeight;
		}
		else if (document.documentElement && document.documentElement.clientHeight)
			// Explorer 6 Strict Mode
		{
			x = document.documentElement.clientWidth;
			y = document.documentElement.clientHeight;
		}
		else if (document.body) // other Explorers
		{
			x = document.body.clientWidth;
			y = document.body.clientHeight;
		}
		
		return [x,y];
	}
	
	function getScrollingOffset() {
		var x,y;
		if (self.pageYOffset) // all except Explorer
		{
			x = self.pageXOffset;
			y = self.pageYOffset;
		}
		else if (document.documentElement && document.documentElement.scrollTop)
			// Explorer 6 Strict
		{
			x = document.documentElement.scrollLeft;
			y = document.documentElement.scrollTop;
		}
		else if (document.body) // all other Explorers
		{
			x = document.body.scrollLeft;
			y = document.body.scrollTop;
		}
		
		return [x,y];
	}
	
	
	
});	
