window.addEvent( 'domready', function() {
									  
	bodyEl = $$( 'body' )[0];
	
	/* marking that jQuery works */
	bodyEl.addClass( "mooTools" );
	
	if( bodyEl.hasClass( 'showPopUp' ) ) {	
		showPopUp();	
	}
	else {
		myLytebox = new LyteBox(); 
	}
	
	/* "tree" submenu */
	$$( "#navigation .submenu li a.moo" ).addEvent( "click", function() {
	
		/* list item and its class */
		p = $( this ).getParent();
		c = p.get( "class" );
		
		/* class manipulation */
		if ( c == "collapsed"  )
			p.set( "class", "expanded" );
		else if ( c == "expanded" )
			p.set( "class", "collapsed" );					
		
		/* avoiding relocating to "#" */
		if(p.getElement('ul')) return false;
		
	});
	
	$$( "#navigation .submenu .acc li a.moo" ).addEvent( "click", function() {
		
		/* list item and its class */
		p = $( this ).getParent();
		c = p.get( "class" );
		
		/* class manipulation */
		if ( c == "collapsed"  )
			p.set( "class", "expanded" );
		else if ( c == "expanded" )
			p.set( "class", "collapsed" );				
		window.location.href=$(this).href;
		/* avoiding relocating to "#" */
		/*if(p.getElement('ul')) return false;*/
		
	});
	
	$$( "#navigation .submenu li a.moo2" ).addEvent( "click", function() {
	
		/* list item and its class */
		p = $( this ).getParent();
		c = p.get( "class" );
		
		/* class manipulation */
		if ( c == "collapsed"  )
			p.set( "class", "expanded" );
		else if ( c == "expanded" )
			p.set( "class", "collapsed" );					
		
		/* avoiding relocating to "#" */
		if(p.getElement('ul')) return false;
		
	});
	
	
	/* inputs' labels put in value attribute */
	labelToInput( "f_s_query" );
	labelToInput( "f_l_login" );
	labelToInput( "f_l_pass" );	
	
	
	/* clear value on focus */
	$$( "#f_r_mail, #f_order_coupon" ).addEvent( "focus", function() {
		$( this ).set( "value", "" );
	});
	
	/* button change */
	$each( $$( "input.button-change[type=submit]" ), function( b ) {
		l = new Element( 'a', {
						'href': '#',
						'class': 'button'+b.get( 'class' ).replace( /button-change/, ' ' ),
						'events': {
							'click': function(){
								$( this ).getNext( 'input[type=submit]' ).click();
								return false;
							}
						}
						});
		
		s = new Element( 'span' );
		
		s.set( 'text', b.get( 'value' ) );
		
		s.inject( l );		
		l.inject( b, 'before' );
	
	});
	
	$each( $$( ".newsOverview .oddItem, .itemsOverview .oddItem" ), function( el ) {
	
		c = new Element( 'li', {
						'class': 'clear'
						});
	
		c.inject( el, 'before' );
	
	});
	
});

function labelToInput ( id )
{
	if(!$(id) ) return;
	/* input */
	i = $( id );
	
	/* setting start value */
	i.set( "value", i.getParent().getElement( "label[for="+id+"]" ).get( 'text' ).toLowerCase() );
	
	/* click on input events */
	i.addEvent( "focus", function() {
		if ( $( this ).get( "value" ) == $( this ).getParent().getElement( "label[for="+$( this ).get( "id" )+"]" ).get( 'text' ).toLowerCase() ) {
			$( this ).set( "value", "" );
		}		
	});	
	i.addEvent( "blur", function() {		
		if ( $( this ).get( "value" ) == "" ) {
			$( this ).set( "value", $( this ).getParent().getElement( "label[for="+$( this ).get( "id" )+"]" ).get( 'text' ).toLowerCase() );
		}		
	});
}

function display_loading () {Loading();}
var curPhoto=0;
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=$('photos').getElements('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++;
}

function showPrev(){
	var images=$('photos').getElements('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--;
}

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