window.addEvent( 'domready', function() {
	
	/* marking that jQuery works */
	$$( 'body' ).addClass( "mooTools" );
	
	$each( $$( ".itemsOverview .oddItem" ), function( el ) {
	
		c = new Element( 'li', {
						'class': 'clear'
						});
	
		c.inject( el, 'before' );
	
	});
	
	labelToInput( 'f_s_query' );
	
	pics=$$('.pics ul a');
	if ( pics.length ) {
		
		pics.addEvent( 'click', function() {
			var a=$('photo');
			a.href=$(this).href;
			a.getElement('img').src=$(this).rel;
			return false;
		});
		
	}
	
});

function labelToInput ( id )
{
	/* input */
	i = $( id );
	
	if( i ) {	
		/* setting default value */
		i.setProperty( 'originalValue', i.getPrevious( 'label[for='+id+']' ).get( 'text' ).toLowerCase() );
		i.set( 'value', i.getProperty( 'originalValue' ) );
		
		/* click on input events */
		i.addEvent( 'focus', function() {
			if ( $( this ).get( 'value' ).toLowerCase() == $( this ).getProperty( 'originalValue' ) ) {
				$( this ).set( 'value', '' );
			}		
		});	
		i.addEvent( 'blur', function() {		
			if ( $( this ).get( 'value' ) == '' ) {
				$( this ).set( 'value', $( this ).getProperty( 'originalValue' ) );
			}		
		});
	}
}

function textToInput ( id, text )
{
	/* input */
	i = $( id );
	
	if ( i ) {
		/* setting default value */
		i.setProperty( 'originalValue', text );
		i.set( 'value', i.getProperty( 'originalValue' ) );
		
		/* click on input events */
		i.addEvent( 'focus', function() {
			if ( $( this ).get( 'value' ).toLowerCase() == $( this ).getProperty( 'originalValue' ) ) {
				$( this ).set( 'value', '' );
			}		
		});	
		i.addEvent( 'blur', function() {		
			if ( $( this ).get( 'value' ) == '' ) {
				$( this ).set( 'value', $( this ).getProperty( 'originalValue' ) );
			}		
		});
	}
}

var curPhoto=0;

function display_loading () {Loading();}

function hide_loading() {
    destroyLoading();
}

function zaznacz_wszystkie(obiekt) {
	ile=obiekt.length;
	i=0;
	while (i < ile) {
		obiekt.options[i].selected=1;
		i=i+1;
	}

}
function odznacz_wszystkie(obiekt) {
	ile=obiekt.length;
	i=0;
	while (i < ile) {
		obiekt.options[i].selected=0;
		i=i+1;
	}
}

function showNext(){
	var images=$$('.itemDetails .info .pic a');
	var ilosc=images.length;
	if(ilosc <= (curPhoto+1)) return false;
	for(i=0; i < ilosc; i++){
		if(i==(curPhoto+1))	images[i].setStyle('display', 'block');
		else images[i].setStyle('display', 'none');
	}
	curPhoto++;
	refreshButtons(ilosc);
}

function showPrev(){
	var images=$$('.itemDetails .info .pic a');
	var ilosc=images.length;
	if(curPhoto==0) return false;
	for(i=0; i < ilosc; i++){
		if(i==(curPhoto - 1))	images[i].setStyle('display', 'block');
		else images[i].setStyle('display', 'none');
	}
	curPhoto--;
	refreshButtons(ilosc);	
}

function refreshButtons(ilosc){
	if(curPhoto==(ilosc - 1)) $('next-photo').setProperty('src', odnosnik+'system/application/views/img/ikony/arrow_right_off.gif');
	else $('next-photo').setProperty('src', odnosnik+'system/application/views/img/ikony/arrow_right.gif');
	
	if(curPhoto==0) $('prev-photo').setProperty('src', odnosnik+'system/application/views/img/ikony/arrow_left_off.gif');
	else $('prev-photo').setProperty('src', odnosnik+'system/application/views/img/ikony/arrow_left.gif');	
}
