window.addEvent( 'domready', function() {
	/* marking that jQuery works */
	$$( 'body' ).addClass( "mooTools" );
	
	labelToInput( 'f_s_query' );
	labelToInput( 'f_l_login' );
	labelToInput( 'f_l_pass' );
	labelToInput( 'f_r_mail' );
	
	textToInput( 'f_order_coupon', '9 cyfrowy kod' );
	
	menuClick ('#navigation > #submenu > ul > li > a');
});

function menuClick ( id )
{

	i = $$( id );
	
	i.addEvent( "click", function() {
	
		/* list item and its class */
		p = $( this ).getParent();
		c = p.get( "class" );
		
		/* class manipulation */
		if ( p.hasClass( "collapsed" ) ) {
			p.removeClass( "collapsed" );
			p.addClass( "expanded" );
			
			return false;
		}
		else if ( p.hasClass( "expanded" ) ) {
			p.removeClass( "expanded" );
			p.addClass( "collapsed" );
					
			return false;
		}
		else {
			p.addClass( "expanded" );
			
			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 a.pic');
	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++;
}

function showPrev(){
	var images=$$('.itemDetails .info a.pic');
	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--;
}

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');	
}
