$(document).ready( function(){

	/* slide tła w banerze*/
	if( $('.slider').get(0) ){
		$('.slider').nivoSlider({
			effect:'fade',
			directionNav:false,
			pauseTime:7000,
			pauseOnHover:false,
			captionOpacity:1
		});
	}


	/*baner flash*/
	
	if( $('#flash2').get(0) ){
		var flashvars = {};
		var params = {
			'wmode': 'transparent',
			'menu': false
		};
		var attributes = {};

		swfobject.embedSWF(
			_BASEURL+"www/client/swf/opineo_maly.swf",
			"flash2",
			"766",
			"183",
			"9.0.0",
			_BASEURL+"www/client/swf/expressInstall.swf",
			flashvars,
			params,
			attributes
		);
	}
	
	
	if( $('#flash_txt').get(0) ){
		var flashvars = {};
		var params = {
			'wmode': 'transparent',
			'menu': false
		};
		var attributes = {};

		swfobject.embedSWF(
			_BASEURL+"www/client/swf/tekst.swf",
			"flash_txt",
			"765",
			"65",
			"9.0.0",
			_BASEURL+"www/client/swf/expressInstall.swf",
			flashvars,
			params,
			attributes
		);
	}
	
		
	if( $('#flash').get(0) ){
		var flashvars = {};
		var params = {
			'wmode': 'transparent',
			'menu': false
		};
		var attributes = {};

		swfobject.embedSWF(
			_BASEURL+"www/client/swf/opineo_duzy.swf",
			"flash",
			"772",
			"284",
			"9.0.0",
			_BASEURL+"www/client/swf/expressInstall.swf",
			flashvars,
			params,
			attributes
		);
	}
	
	/* szczegoly produktu plus - minus */
	if($('.plus_minus').get(0)){
		$('.plus_minus .minus').click( function(){
			var ile = $(this).parents('div:first').find('input').val();
			ile = ile * 1;
			
			if( ile > 1 ){
				ile = ile - 1;
			}
			$(this).parents('div:first').find('input').val(ile);
			$(this).parents('div:first').find('i:first').html(ile);
			return false;
		});
		
		$('.plus_minus .plus').click( function(){
			var ile = $(this).parents('div:first').find('input').val();
			ile = ile * 1;
			ile = ile + 1;
			$(this).parents('div:first').find('input').val(ile);
			$(this).parents('div:first').find('i:first').html(ile);
			return false;
		});
	}
	
	
	/* strona z logowaniem - przechwycenie klikniecia w button zaloz konto */
	if( $('.zaloz').get(0) ){
		$('.zaloz').bind('click', function(){
			location.href= _BASEURL+"uzytkownicy/rejestracja/";
			return false;
		});
	}
			
	/* ustawienie overlaya */
	var document_height = $(document).height();
	var document_width = $(document).width();
	var divTag = document.createElement("div");
	divTag.id = "overlay";
	divTag.style.position = "absolute";
	divTag.style.width = document_width+"px";
	divTag.style.height = document_height+"px";
	divTag.style.backgroundColor ="#000";
	divTag.style.zIndex ="50";
	divTag.style.opacity ="0.3";
	divTag.style.top ="0px";
	divTag.style.left ="0px";
	divTag.style.display ="none";
	document.body.appendChild(divTag);
	$('#overlay').css( { filter:"alpha(opacity=30)" });

	
	if( $('#komunikat').get(0) ){
		
		error();
		
		/* zamkniecie komunikatu */
		$('#komunikat button').click( function(){
			$('#overlay').hide();
			$('#komunikat').hide().css({'top':'-1400px'});
			return false;
		});
	}
	
	
	/* wyszukiwarka - slowo kluczowe */
	if( $('#frmSzukaj').get(0) ){
	
		$('#frmSzukaj 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ę ...');
			}
		});
	}
	
	/* zapis do newslettera */
	if( $('#newsletter').get(0) ){

		$('#newsletter input[name="email"]').click( function(){
			
			var wartosc = $( this ).val();
			
			if( wartosc == 'e-mail' ){
				$( this ).val('');
			}
			if( ! wartosc ){
				$( this ).val('e-mail');
			}
		
		}).blur( function() {
			
			var wartosc = $( this ).val();
					
			if( ! wartosc ){
				$( this ).val('e-mail');
			}
		});
	}
	
	/* funkcja odpalajaca komunikat o bledzie */
	function error(){
	
		var offset = getScrollingOffset();
		var window_size = getInnerDimensions();
		var wysokosc_okna = window_size[1];
		var wysokosc_komunikatu = $('#komunikat').height();
		var top = (wysokosc_okna - wysokosc_komunikatu) /2;
		top = top + offset[1];
		
		$('#overlay').show();
		$('#komunikat').css({'top':top+'px'}).show();
		return false;
		
	}
	
	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];
	}
	
	
	
});	
