window.addEvent('domready', function () {
	//zmiana obrazkow w topie na głównej stronie 
	var top_fotos = $$('.sloganHead');
	if (top_fotos[0]) {
		var timer = 0;
		var active_foto = top_fotos.length - 1;
		var switchFotos = function () {
			var new_active_foto = active_foto + 1;
			if (new_active_foto == top_fotos.length) {
				new_active_foto = 0;
			} 
			var fotos_to_switch = [top_fotos[active_foto], top_fotos[new_active_foto]];
			top_fotos[active_foto].setStyle('display', 'block');
			top_fotos[active_foto].setStyle('opacity', '1');
			top_fotos[new_active_foto].setStyle('display', 'block');
			top_fotos[new_active_foto].setStyle('opacity', '0');
			
			new Fx.Elements(fotos_to_switch, {'link': 'cancel', duration: 600, transition: Fx.Transitions.linear, onComplete: function () {
				active_foto = new_active_foto;
			}}).start({
				'0': {
       			'opacity': [1,0]
    			},
    			'1': {
		      	'opacity': [0,1]
    			}
			}); 
			
		}

		timer = switchFotos.periodical(4000);
	}
	
	//podświetlanie/zmiana kolorów w górnym menu po najechaniu myszą
	var top_menu = $$('#menuBox a img, #subMenuBody a img, #subMenuBody2 a img');
	if (top_menu[0]) {
		$each(top_menu, function (el, key) {
			$(el).parentNode.addEvents({
				'mouseover' : function () {
					if ($(el).parentNode.hasClass('selected')) {
						return false;
					} else {
						zrodlo = el.src;
						zrodlo = zrodlo.replace('e=_s', 'e=_n');
						zrodlo = zrodlo.replace('c=221c19', 'c=cc0606');
						zrodlo = zrodlo.replace('c=ffffff', 'c=cc0606');
						el.src = zrodlo;
					}
				},
				'mouseout' : function () {
					if (el.parentNode.hasClass('selected')) {
						return false;
					} else {
						zrodlo = el.src;
						zrodlo = zrodlo.replace('e=_n', 'e=_s');
						if (el.parentNode.parentNode.parentNode.id == 'subMenuBody' || el.parentNode.parentNode.parentNode.parentNode.id == 'subMenuBody') {
							zrodlo = zrodlo.replace('c=cc0606', 'c=ffffff');
						} else {
							zrodlo = zrodlo.replace('c=cc0606', 'c=221c19');
						}
						el.src = zrodlo;
					}
				}
			});
		});
	}
	
	//skroll

    var scroll;
    var postfix;
    var temp;

    if($('scrollBox')) {
        scroll = $('scrollBox');
        postfix = '';
        temp = 230;
    } else if($('scrollBox_powi')) {
        scroll = $('scrollBox_powi');
        postfix = '_powi';
        temp = 440;
    } else if($('scrollBox_powi2')) {
        scroll = $('scrollBox_powi2');
        postfix = '_powi2';
        temp = 1213;
    } else if($('scrollBox_powi3')) {
        scroll = $('scrollBox_powi3');
        postfix = '_powi3';
        temp = 1453;
    }
/*,,,,,,,,,,,,,,,,,,*/
	if (scroll && ($('scrollBody') || $('scrollBody_powi'))) {
		var scrollContent = $('scrollBody');
		var text_length = scrollContent.offsetHeight - temp;
		var position = 0;
		var up_S = 0;
		var down_S = 0;

		if (text_length <= 0) {
			text_length = 0;
		} else {
			scroll.setStyle('display', 'block');

			var scrollBar = $('scrollDrag' + postfix);

			var scrollKnot = new Element('div', { 'id': 'scrollKnot'	});
			scrollKnot.inject(scrollBar, 'top');

			mySlide = new Slider(scrollBar, scrollKnot, {
				'steps': text_length,
				'mode': 'vertical',
				onChange: function (step) {
					position = step;
					//alert(step);
					scrollContent.scrollTo(0, step);
					scrollContent.setStyle('top', -1*step);
				}
			}).set(0);

			//przesuniecie w gore
			var downClick = function (pos) {
				if (!pos) {	pos = 1;	}

				position += (5*pos);
				if (position > text_length) {	position = text_length; }

				mySlide.set(position);
			}

			//przesuniecie w dol
			var upClick = function (pos) {
				if (!pos) {	pos = 1;	}

				position -= (5*pos);
				if (position < 0) {	position = 0; }

				mySlide.set(position);
			}

			function scrollItDown() {
				downClick(3);
				down_S = setTimeout(scrollItDown, 100);
			}

			function scrollItUp() {
				upClick(3);
				up_S = setTimeout(scrollItUp, 100);
			}

			//dodanie zdarzen
			scrollContent.addEvent('mousewheel', function(event){
				event = new Event(event);

				if(event.wheel > 0) {
					upClick(2*event.wheel);
				}
				else {
					if (event.wheel < 0){
						downClick(2*event.wheel * -1);
					}
				}
				return false;
			});

			$('scrollUp').addEvents({
				'mousedown': function(event) {
					up_S = setTimeout(scrollItUp, 100);
				},
				'mouseup': function(event) {
					clearTimeout(up_S);
					this.blur;
				}
			});

			$('scrollDown').addEvents({
				'mousedown': function(event) {
					down_S = setTimeout(scrollItDown, 100);
				},
				'mouseup': function(event) {
					clearTimeout(down_S);
					this.blur;
				}
			});
		}
	}

/* fgddgggggggggggggggggg*/
    $$('#subColumnsBox .columns_off img, #subColumnsBox2 .columns_off img').each(function(el) {
        
        if(el.nextSibling.tagName == 'H2') {
            $(el).set('opacity', 0.2);
        }
        
    });
    
    $$('#subColumnsBox .columns img, #subColumnsBox .columns_off img, #subColumnsBox2 .columns img, #subColumnsBox2 .columns_off img').each(function(el) {
         $(el).addEvents({
            'click': function() {
                var loc = $(this).getParent().getElements('a.moreBtn').get('href');
                document.location = loc;
            }
        });
    });

    var subTops = new Array('subTop1.jpg', 'subTop2.jpg', 'subTop3.jpg');
    var num = 0;

    num = Math.floor(Math.random() * 3);
    
    $$('#subPageTopBox').setStyles({
        background: 'url(/gfx/' + subTops[num] + ')'
    });

    $$('div[id^=nav__]').each(function(el) {
        var id = $(el).get('id');

        if(id.indexOf('__', id.indexOf('__') + 1) > -1) {
            $(el).setStyle('display', 'none');
        }
    });

    $$('a.parent').each(function(el) {
       var submenu = $(el).get('rel');

       $(submenu).getElements('a').addClass('submenuelem');
    });

    $$('#nav_lewe a.selected').each(function(el) {
        var id = $(el).getParent().get('id');
        $(id).setStyle('display', 'block');
        $$('a[rel='+id+']').addClass('selected').setStyle('color', '#ffffff');

        id = $(id).getParent().get('id');
        $(id).setStyle('display', 'block');
        $$('a[rel='+id+']').addClass('selected').setStyle('color', '#ffffff');
        
        id = $(id).getParent().get('id');
        $(id).setStyle('display', 'block');
        $$('a[rel='+id+']').addClass('selected').setStyle('color', '#ffffff');
        
        id = $(id).getParent().get('id');
        $(id).setStyle('display', 'block');
        $$('a[rel='+id+']').addClass('selected').setStyle('color', '#ffffff');

    });
    
    $$('#nav_green a.selected').each(function(el) {
        var id = $(el).getParent().get('id');
        $(id).setStyle('display', 'block');
        $$('a[rel='+id+']').addClass('selected').setStyle('color', '#1F1A17');
        
        id = $(id).getParent().get('id');
        $(id).setStyle('display', 'block');
        $$('a[rel='+id+']').addClass('selected').setStyle('color', '#1F1A17');
        
        id = $(id).getParent().get('id');
        $(id).setStyle('display', 'block');
        $$('a[rel='+id+']').addClass('selected').setStyle('color', '#1F1A17');
    });

    $$('#scrollBody table tr:odd').setStyle('background-color', '#DADADA');
    $$('#scrollBody table tr:even').setStyle('background-color', '#E8E8E8');
});
