var glowne_foty = new Array();

//troche stalych
var initial_menu_pos_y = (document.viewport.getHeight()/2) - 180;
var is_menu_down = false;
var menu_animates = false;
var webroot = '';

//obrazki na stronie glownej
var main_images_url = new Array();
main_images_url[0] = webroot + 'img/image1.jpg';
main_images_url[1] = webroot + 'img/image2.jpg';
main_images_url[2] = webroot + 'img/image3.jpg';
main_images_url[3] = webroot + 'img/image4.jpg';
main_images_url[4] = webroot + 'img/image5.jpg';
main_images_url[5] = webroot + 'img/image6.jpg';
main_images_url[6] = webroot + 'img/image7.jpg';
 
var main_images = new Array();

var main_images_loaded = 0;

var the_category_we_are_in = 0;

//slidery
var slider1 = null;

///////////////

function makeHidden(id)
{
	document.getElementById(id).style.visibility = 'hidden';
	//document.getElementById(id).style.zIndex = -100;
}

function makeVisible(id)
{
	document.getElementById(id).style.visibility = 'visible';
	//document.getElementById(id).style.zIndex = 1;
}

///////////////

function show_main_image(id)
{
	//$('main_image_'+id).appear();
	new Effect.Appear('main_image_'+id);
	if (id < (main_images_url.length - 1)) {
		setTimeout('show_main_image('+parseInt(id-(-1))+')', 50); 
	}
	else {
		switch_main_image();
		//switch_main_image.image_id = 0;
		//put_back_main_image();
	}
}

var initial_content_pos = new Object();

// scroll the element vertically based on its width and the slider maximum value
function scrollVertical(value, element, slider) {
	element.scrollTop = Math.round(value/slider.maximum*(element.scrollHeight-element.offsetHeight));
}

function initializeContent(hard)
{
	//jezlei wszystkie obrazki sie juz zaladowaly
	if (main_images_loaded == main_images_url.length || hard)
	{		
		//wysokosc i szerokosc viewportu
		var viewport_height = document.viewport.getHeight();
		var viewport_width = document.viewport.getWidth();

		var menu_handle = $('menu_container');

		//ustawiamy pozycje kontentu (na srodku pod menu)
		var content_handle = $('content_container');
		var blindfold_handle = $('content_blindfold');
		var category_handle = $('category_container');
		
		//zapamietujemy poczatkowo pozycje :<
		initial_content_pos.x = content_handle.positionedOffset().left;
		initial_content_pos.y = content_handle.positionedOffset().top;

		content_handle.style.left = ((viewport_width - content_handle.getWidth()) / 2) + 'px';
		content_handle.style.top = (parseInt(eval(menu_handle.style.top.replace(/px,*\)*/g,"") - (-menu_handle.getHeight())))) + 'px';
		
		//teraz ustawiamy pozycje jezyka
		$('language_select').style.top = (content_handle.style.top.replace(/px,*\)*/g,"") - 110) + "px";
		$('language_select').style.left = (content_handle.style.top.replace(/px,*\)*/g,"") - (-590)) + "px";
		$('language_select').appear();

		blindfold_handle.style.left = ((viewport_width - content_handle.getWidth()) / 2) + 'px';
		blindfold_handle.style.top = (parseInt(eval(menu_handle.style.top.replace(/px,*\)*/g,"") - (-menu_handle.getHeight())))) + 'px';
		
		category_handle.style.left = ((viewport_width - category_handle.getWidth()) / 2) + 'px';
		category_handle.style.top = (parseInt(eval(menu_handle.style.top.replace(/px,*\)*/g,"") - (-menu_handle.getHeight())))) + 'px';

		blindfold_handle.show();
		content_handle.show();
		
		//teraz czas na slidery
		// vertical slider control
		slider1 = new Control.Slider('handle1', 'track1', {
			axis: 'vertical',
			onSlide: function(v) { scrollVertical(v, $('scrollable1'), slider1);  },
			onChange: function(v) { scrollVertical(v, $('scrollable1'), slider1); }
		});
		
		// disable vertical scrolling if text doesn't overflow the div
		if ($('scrollable1').scrollHeight <= $('scrollable1').offsetHeight) {
			slider1.setDisabled();
			$('handle1').hide();
		}
		
		//ustawiamy czerwone cos
		set_red_thing('link_1');

		$('content_blindfold').morph('height: 0px;', { duration: 0.5, afterFinish: function() { $('content_blindfold').hide(); document.body.style.overflow = 'visible'; } });
	
		//robimy fale przy pokazywaniu obrazkow
		show_main_image(0);	
	}
	else
	{
		setTimeout('initializeContent(1)', 2000);	
	}
}

function initializePage()
{
	//wysokosc i szerokosc viewportu
	var viewport_height = document.viewport.getHeight();
	var viewport_width = document.viewport.getWidth();
	
	var menu_handle = $('menu_container');
	
	document.body.style.overflow = 'hidden';
	
	menu_handle.style.top = (viewport_height) + 'px';
	
	menu_handle.show();
	
	//najpierw robimy zeby menu wyjechalo z dolu
	new Effect.Move('menu_container', { x: 0, y: initial_menu_pos_y, mode: 'absolute', afterFinish: function() { initializeContent(); } });
	
	//tworzymy obrazki na strone glowna
	for (i = 0 ; i < main_images_url.length ; i++) {
		main_images[i] = document.createElement("img");
		main_images[i].setAttribute('id', 'main_image_'+i);
		document.getElementById('content_container').appendChild(main_images[i]);
		main_images[i].className = 'main_photo';
		main_images[i].style.display = 'none'; //nie wiem czy to dziala pod ie
		Event.observe(main_images[i], 'load', function() { 
				main_images_loaded++;
			});
			
		main_images[i].src = main_images_url[i];
			
		//ustawiamy obrazki (odpowiednie pozycje)
		if (i == 0) {
			main_images[i].style.left = $('content_container').positionedOffset().left + 'px';
			main_images[i].style.top = (($('content_container').positionedOffset().top) - (-219)) + 'px';
		}
		else {
			main_images[i].style.left = ( (document.getElementById('main_image_'+(i-1)).style.left.replace(/px,*\)*/g,""))  - (-105)) + 'px';
			main_images[i].style.top = $('main_image_0').style.top;//(($('content_container').positionedOffset().top) - (-219)) + 'px';
		}	
	}
	
	//ustaiwamy ramke na 1 foto
	$('main_frame').style.left = ($('main_image_0').style.left.replace(/px,*\)*/g,"") - 2) + 'px';
	$('main_frame').style.top = ($('main_image_0').style.top.replace(/px,*\)*/g,"") - 2) + 'px';
	
}

//funkcja do ustawiania tego czerwonego czegos pod menu
var old_red_thing_id = '';

function set_red_thing(element)
{
	if (element == old_red_thing_id) { return; }
	
	old_red_thing_id = element;
	
	var pos = $(element).positionedOffset();
	//alert(pos.left);
	
	var offset = 0;
	
	//wyliczamy offset
	if ( ($('red_thing').positionedOffset().left) > (pos.left)) {
		offset = 30; } else { offset = -30; }
	
	
	$('red_thing').morph('left: '+(pos.left - (offset))+'px; width: '+$(element).getWidth()+'px;', { duration: 0.1, afterFinish: function() {
		$('red_thing').morph('left: '+(pos.left)+'px; width: '+$(element).getWidth()+'px;', { duration: 0.1	}); } } );
		
}

//spuszcza menu na dol
function slide_content_down(offset, execute)
{
	if (!is_menu_down) {
		is_menu_down = true;
		var menu_handle = $('menu_container');
		
		//ustawiamy canvas troche nizej zeby nie bylo rpzerw miedzy nim a menu
		var canvas_handle = $('white_canvas_above_the_sky');
		canvas_handle.style.height = ($('content_container').getHeight()) + 'px';
		canvas_handle.style.top = (menu_handle.style.top.replace(/px,*\)*/g,"") - (canvas_handle.getHeight()) - (-menu_handle.getHeight())) + 'px';
		canvas_handle.show();
	
		menu_animates = true;
		
		new Effect.Move('menu_container', { x: 0, y: ($('content_container').getHeight() - offset), mode: 'relative', afterFinish: function() { menu_animates = false; eval(execute); } } );
		new Effect.Move('white_canvas_above_the_sky', { x: 0, y: ($('content_container').getHeight() - offset), mode: 'relative' } );
	
		//setTimeout('slide_content_up()', 2000);
	}
}

//podjezdzamy do gory
function slide_content_up(offset, execute)
{
	if ((is_menu_down) && (!menu_animates)) {
		menu_animates = true;
		var canvas_handle = $('white_canvas_above_the_sky');
		new Effect.Move('menu_container', { x: 0, y: -($('content_container').getHeight() - offset), mode: 'relative', afterFinish: function() { is_menu_down = false; menu_animates = false; canvas_handle.hide(); eval(execute); } } );
		new Effect.Move('white_canvas_above_the_sky', { x: 0, y: -($('content_container').getHeight() - offset), mode: 'relative' } );
	}
		
}

var old_pos = new Object;
var initial_pos = new Object;

function reset_main_photos_z_index()
{
	for (i = 0 ; i < main_images.length ; i++) {
		main_images[i].style.zIndex = 1;
	}
}

function switch_main_image()
{
	if ( typeof switch_main_image.image_id == 'undefined' ) {
        //inicjalizujemy zmienna statyczna ; p
        switch_main_image.image_id = 0;
    }
    
	var con_pos = $('content_container').positionedOffset();
	var img_pos = $('main_image_'+switch_main_image.image_id).positionedOffset();
	
	//zapamietujemy stara pozycje
	//old_pos.x = img_pos.left;
	//old_pos.y = img_pos.top;
	
	if (switch_main_image.image_id == 0) {
		
		old_pos.x = img_pos.left;
		old_pos.y = img_pos.top;
		
		initial_pos.x = old_pos.x;
		initial_pos.y = old_pos.y;
	}
	
	//liczymy wektorek
	var vec2i = new Object;
	vec2i.x = ((img_pos.left - (-con_pos.left)) - con_pos.left);
	vec2i.y = ((img_pos.top - (-con_pos.top)) - con_pos.top - (43));
	
	//przesuwamy obrazek
    new Effect.Move('main_image_'+switch_main_image.image_id, { x: -vec2i.x, y: -vec2i.y, mode: 'relative', duration: 0.3 } );
    $('main_image_'+switch_main_image.image_id).morph('width: 240px; height: 159px; border-bottom: 6px solid #CCCCCC;', { duration: 0.3 });
    
    //oraz ramke
    new Effect.Move('main_frame', { x: -vec2i.x-2, y: -vec2i.y-2, mode: 'relative', duration: 0.3 } );
    $('main_frame').morph('width: 248px; height: 174px;', { duration: 0.3 });
    
    //wywolujemy kolejna funkcje ktora teraz odlozy obrazek na miejsce
	setTimeout('put_back_main_image('+switch_main_image.image_id+')', 2000);

}

function put_back_main_image()
{
	//resetujemy wszystkim z indexy
	reset_main_photos_z_index();
	
	//owracamy obrazek	
	Effect.Fade('main_image_'+switch_main_image.image_id, { duration: 0.2, afterFinish: function () {
			$('main_image_'+switch_main_image.image_id).style.left = old_pos.x + 'px';
			$('main_image_'+switch_main_image.image_id).style.top = old_pos.y + 'px';
			$('main_image_'+switch_main_image.image_id).style.width = '95px';
			$('main_image_'+switch_main_image.image_id).style.height = '63px';
			$('main_image_'+switch_main_image.image_id).style.borderBottom = '3px solid #CCCCCC';
			Effect.Appear('main_image_'+switch_main_image.image_id, { duration: 0.2 } );
			
			//ramka wraca na oryginalna pozycje	 //'top: '+(initial_pos.y - 2)+'px; left: '+(initial_pos_x - 2)+'px; 
			new Effect.Move('main_frame', { x: (initial_pos.x -4), y: (initial_pos.y -4), mode: 'absolute', duration: 0.5 } );
    		$('main_frame').morph('width: 103px; height: 75px;', { duration: 0.5, afterFinish: function () {
    				switch_main_image.image_id++;
    				
    				if (switch_main_image.image_id > (main_images.length - 1)) {
    					switch_main_image.image_id = 0;
    				}
    				
    				var img_pos = $('main_image_'+switch_main_image.image_id).positionedOffset();
					old_pos.x = img_pos.left;
					old_pos.y = img_pos.top;
    				
    				//setTimeout('switch_main_image()', 1000); 
    				
    				//przesuwamy ramke na nowa fotke
    				new Effect.Move('main_frame', { x: ($('main_image_'+switch_main_image.image_id).positionedOffset().left), y: 0, mode: "relative",
    					afterFinish: function () {
    						//teraz suniemy obrazkiem na initial pos razem z ramka
    						$('main_image_'+switch_main_image.image_id).style.zIndex = 4;
    						new Effect.Move('main_image_'+switch_main_image.image_id, { x: (initial_pos.x), y:  (initial_pos.y), mode: 'absolute', duration: 0.3 });
    						new Effect.Move('main_frame', { x: (initial_pos.x -2), y: (initial_pos.y -2), mode: 'absolute', duration: 0.3, afterFinish: function () { switch_main_image(); } } );
    					}
    				 });
    			} 
    		} );
		}
	 });	
}

function change_text_on_main_page(id)
{
	if (id==1) {
		$('scrollable1').innerHTML = $('text_main').innerHTML;
	}
	if (id==2) {
		$('scrollable1').innerHTML = $('text_about').innerHTML;
	}
	if (id==3) {
		$('scrollable1').innerHTML = $('text_contact').innerHTML;
	}
	if (id==4) {
		$('scrollable1').innerHTML = $('text_news').innerHTML;
	}
	
	if (id==5) {
		$('scrollable1').innerHTML = $('text_news_archive').innerHTML;
	}
	//alert('dupa');
	
	$('handle1').show();
	
	//aktualizujemy scrollbar
	slider1 = new Control.Slider('handle1', 'track1', {
		axis: 'vertical',
		onSlide: function(v) { scrollVertical(v, $('scrollable1'), slider1);  },
		onChange: function(v) { scrollVertical(v, $('scrollable1'), slider1); }
	});
	
	// disable vertical scrolling if text doesn't overflow the div
	if ($('scrollable1').scrollHeight <= $('scrollable1').offsetHeight) {
		slider1.setDisabled();
		$('handle1').hide();
	}
}

function go_back_to_main_page(id)
{
	remove_actual_category();
	$('content_header').innerHTML=podstrony_headery[id];
	slide_content_down(0, '$(\'category_container\').hide(); $(\'paginator_container\').hide(); makeVisible(\'content_container\'); change_text_on_main_page('+id+'); slide_content_up(0, \'\');');
}

////////////////////////////////////
//	ladowanie i obsluga kategorii
////////////////////////////////////

var category_urls = new Array();

category_urls[0] = "img/category1.jpg";
category_urls[1] = "img/category1.jpg";
category_urls[2] = "img/category1.jpg";
category_urls[3] = "img/category1.jpg";

var category_desc = new Array();

category_desc[0] = "OBRAZEK1";
category_desc[1] = "SIŁOWNIA SIALALA";
category_desc[2] = "LUBIE KLOPSIKI";
category_desc[3] = "WSZYSCY LUBIĄ KLOPSY!";

var category_ids = new Array();

var category_loaded = 0;
var category_blur = new Array();
var category_images = new Array();
var category_divs = new Array();
var category_page = 0;
var category_pages_count = 0;
var category_descriptions = new Array();

var blur_timer;

function show_category(id) {
	//po kliknieciu w glowny link - laduje glowna kategorie
	$('category_container').fade( {duration: 0.2} );
	$('paginator_container').hide();
	$('category_header').innerHTML=projekty_headery[id];
	slide_content_down(0, '$(\'project_description\').hide(); $(\'paginator_content\').appear();');
	//zapelniamy tablice sialala
	the_category_we_are_in = id;
	category_urls = new Array();
	category_desc = new Array();
	
	for (var i = 0 ; i < projekty_foty[id].length ; i++) {

		category_urls[i] = projekty_foty[id][i];
		category_desc[i] = projekty_podpisy[id][i];
	}
	
	setTimeout('load_categories()', 800);
}

function control_blur() {
	for (i = 0 ; i < category_images.length ; i++) {
		if (category_blur[i] == true) {
			if ($(category_images[i].id).getStyle('opacity') == 1) {
				blur_image(category_images[i]);
			}
		}
		else {
			if ($(category_images[i].id).getStyle('opacity') < 0.12) {
				unblur_image(category_images[i]);
			}
		}
		
		//alert($(category_images[i].id).getStyle('opacity'));
	}
	
	blur_timer = setTimeout('control_blur()', 100);
}



function unblur_image(element) {
//alert("yoo");
	//var cc = document.getElementById('category_container');
	/*
	for (i = 0 ; i < 4 ; i++) {
		id = element.id + '_clone_' + i;
		var el = document.getElementById(id);
		if (el) cc.removeChild(id);
	} 
	*/
	
	new Effect.Opacity(element.id, { from: 0.2, to: 1.0, duration: 0.2 });
	
	
}

function blur_image(element) {
	//unblur_all_images();	
	//alert(element.cumulativeOffset().left);
	//robimy efekt blura - kopiujemy obrazek 2 razy i przemieszczamy, simple as hell
	var img_copies = new Array();
	/*
	for (i = 0 ; i < 4 ; i++) {
		img_copies[i] = element.cloneNode(true);
		img_copies[i].id = element.id + '_clone_'+i;
		img_copies[i].style.zIndex = img_copies[i].style.zIndex++;
		img_copies[i].setOpacity(0.0);
		//document.body.appendChild(img_copies[i]);
		document.getElementById('category_container').appendChild(img_copies[i]);
		
		img_copies[i].onmouseout = function () { unset_blur(element.id); };
	}
	
	img_copies[0].style.left = ($(img_copies[0].id).positionedOffset().left - (-2)) + 'px';
	img_copies[1].style.left = ($(img_copies[0].id).positionedOffset().left - 2) + 'px';
	img_copies[2].style.top = ($(img_copies[0].id).positionedOffset().top - (-2)) + 'px';
	img_copies[3].style.top = ($(img_copies[0].id).positionedOffset().top - 2) + 'px';
	*/
	new Effect.Opacity(element.id, { from: 1.0, to: 0.1, duration: 0.3 });
	/*
	for (i = 0 ; i < 4 ; i++) {
		new Effect.Opacity(img_copies[i].id, { from: 0.2, to: 0.2, duration: 0.2 });
	}*/
}

function set_blur(id) {
	var true_id = id.substring(13, id.length);
	//alert(true_id);
	category_blur[true_id] = true;
	//alert("omg");
}

function unset_blur(id) {
	var true_id = id.substring(13, id.length);
	//alert(true_id);
	category_blur[true_id] = false;
	//alert("kurde" + category_blur[true_id]);
}

function load_categories() {

	//usuwamy costam jak bylo ;p
	remove_actual_category();

	//inicjalizacja zmiennych
	category_loaded = 0;
	category_blur = new Array();
	category_images = new Array();
	category_page = 0;
	category_pages_count = 0;
	category_descriptions = new Array();
	
	if (blur_timer) {
		clearTimeout(blur_timer);
	}
	

	//usuwamy poprzednie shitesy
	var old_categories = $$('.category_photo');
	var old_categories_div = $$('.category_div');
	var old_categories_desc = $$('.category_description');
	for (i = 0 ; i < old_categories.length ; i++) {
		document.getElementById('category_container').removeChild(old_categories[i]);
		document.getElementById('category_container').removeChild(old_categories_div[i]);
		document.getElementById('category_container').removeChild(old_categories_desc[i]);
	}
			

	//ukrywamy content
	$('category_container').show();
	$('content_container').fade( { afterFinish : function (effect) { makeHidden(effect.element.id); effect.element.show(); } } ); //fading jest yo

	//robimy ten paginator na dole
	var paginator = $('paginator_container');//document.createElement("div");
	//paginator.setAttribute('id', 'paginator_container');
	//document.body.appendChild(paginator);
	paginator.style.top = ((0) - (-227)) + 'px'; //($('category_container').positionedOffset().top - (227)) + 'px';
	paginator.style.left = (-$('category_container').positionedOffset().left) + 'px';
	paginator.style.width = document.viewport.getWidth() + 'px';
	
	$('arrow_right').style.marginLeft = '70px';
	$('arrow_left').style.marginRight = '70px';
	
	category_images = new Array();
	
	var iteration = 0;
	for (i = 0 ; i < category_urls.length ; i++) {


		//obrazki
		category_images[i] = document.createElement("img");
		category_images[i].setAttribute('id', 'category_image_'+i);
		category_images[i].className = 'category_photo';
		category_images[i].style.display = 'none';
		category_blur[i] = false;
		//category_images[i].onmouseover = function () { set_blur(this.id); };
		//category_images[i].onmouseout = function () { unset_blur(this.id); };
		//category_images[i].onload = function () { category_loaded++; };
		
		//divy do lapania onmouseover
		category_divs[i] = document.createElement("div");
		category_divs[i].setAttribute('id', 'category_div_'+i);
		category_divs[i].onmouseover = function () { set_blur(this.id); };
		category_divs[i].onmouseout = function () { unset_blur(this.id); };
		category_divs[i].style.display = 'none';
		category_divs[i].className = 'category_div';
		category_divs[i].innerHTML = '&nbsp;';
		category_divs[i].onclick = function () { display_actual_category(this); }
		
		//podpisy pod obrazkami
		category_descriptions[i] = document.createElement('div');
		category_descriptions[i].innerHTML = category_desc[i];
		category_descriptions[i].className = 'category_description';
		category_descriptions[i].style.display = 'none';
		category_descriptions[i].setAttribute('id', 'category_desc_'+i);
		
		//document.body.appendChild(category_images[i]);
		
		document.getElementById('category_container').appendChild(category_images[i]);
		document.getElementById('category_container').appendChild(category_divs[i]);
		document.getElementById('category_container').appendChild(category_descriptions[i]);
		
		Event.observe(category_images[i], 'load', function() { 
				category_loaded++;
				//alert(category_loaded);
		});
		
		category_images[i].src = category_urls[i];
		
		//ustawiamy po 3
		category_images[i].style.left = ( initial_content_pos.x - (-(category_images[i].getWidth() * iteration)) -(-10*iteration)) + 'px';
		category_images[i].style.top = (initial_content_pos.y - (-42)) + 'px';
		category_divs[i].style.left = category_images[i].style.left;
		category_divs[i].style.top = category_images[i].style.top;
		category_descriptions[i].style.left = category_images[i].style.left;
		category_descriptions[i].style.top = (category_images[i].style.top.replace(/px,*\)*/g,"") - (-category_images[i].getHeight())) + 'px';
		
		iteration++;
		
		if (iteration == 3) { iteration = 0; }	
	}
	

	//pierwsze 3 pokazujemy
	//for (i = 0 ; i < 3 ; i++) { category_images[i].appear(); }
	
	category_images_onload();
}

function hide_all_images() {
	for (var i = 0 ; i < category_images.length ; i++) {
		category_images[i].style.display = 'none';
		category_divs[i].style.display = 'none';
		category_descriptions[i].style.display = 'none';
	}
}

function appear_first_three(ide) {
	if ((ide < category_images.length) && (ide > -1))
	{
		category_images[ide].appear();
		//$(category_descriptions[id].id).appear();
		Effect.Appear(category_descriptions[ide].id);
		category_divs[ide].style.display = 'block';
		$(category_divs[ide].id).setOpacity(0.0); //layer niewidzialny nad do kontrolowania zdarzen!
		if (ide < (2 - ((-3)*category_page))) {
			setTimeout('appear_first_three('+(ide-(-1))+')', 250);
		} else { blur_timer = setTimeout('control_blur()', 500); }
	}
}

function set_up_paginator() {
	set_page_label();
	$('paginator_container').appear();
	$('arrow_right').morph('margin-left: 0px;', {duration: 1.0});
	$('arrow_left').morph('margin-right: 0px;', {duration: 1.0});
}

//kontrola onloadu obrazkow z kategorii
function category_images_onload() {
				//alert("Apacad"+category_images.length);

	for(var i = 0 ; i < category_images.length ; i++) {

		if (!category_images[i].complete) {
			setTimeout('category_images_onload()', 100); return;
		}

	}

	//setTimeout('control_blur();
	setTimeout('appear_first_three(0)', 1600);
	setTimeout('slide_content_up(0, "")', 1000);
	setTimeout('set_up_paginator(0)', 1000);
}

//obsluga strzaleczek //////////////////////
////////////////////////////////////////////

function set_page_label()
{
	var max_pages = Math.ceil(category_images.length/3);
	
	$('pages').innerHTML = "STRONA "+Math.ceil(category_page+1)+" Z "+max_pages;
}

function left_arrow(out) {
	if (out) {
		$('arrow_left').morph('margin-right: 0px;', {duration: 0.1});
		new Effect.Opacity('arrow_left', { to: 1.0, duration: 0.1 });

	} else {
		$('arrow_left').morph('margin-right: 5px;', {duration: 0.1});
		new Effect.Opacity('arrow_left', { to: 0.2, duration: 0.1 });
	}
}

function right_arrow(out) {
	if (out) {
		$('arrow_right').morph('margin-left: 0px;', {duration: 0.1});
		new Effect.Opacity('arrow_right', { to: 1.0, duration: 0.1 });

	} else {
		$('arrow_right').morph('margin-left: 5px;', {duration: 0.1});
		new Effect.Opacity('arrow_right', { to: 0.2, duration: 0.1 });
	}
}


//onclicki

var page_changing = false;

function right_arrow_onclick() {
	
	if (page_changing) { return; }
	
	page_changing = true;
	
	if ( ((category_page+1)*3) < category_images.length)
	{
		category_page++;
		clearTimeout(blur_timer);
		//slide_content_down(54, 'slide_content_up(54, "control_blur()");');
		slide_content_down(54, 'setTimeout(\'appear_first_three('+((category_page*3))+');\', 300); hide_all_images(); slide_content_up(54, \'control_blur(); page_changing = false;\');');
	}
	
	set_page_label();
}

function left_arrow_onclick() {
	
	if (page_changing) { return; }
	
	page_changing = true;
	
	if ((category_page-1) > -1)
	{
		category_page--;
		clearTimeout(blur_timer);
		//slide_content_down(54, 'slide_content_up(54, "control_blur()");');
		slide_content_down(54, 'setTimeout(\'appear_first_three('+((category_page*3))+');\', 300); hide_all_images(); slide_content_up(54, \'control_blur(); page_changing = false;\');');
	}
	
	set_page_label();
}

////////////////////////////////////////////////////////
//otwarcie konkretnej kategorii

var categories_that_were_visible = new Array();
var single_category_photos = new Array();
var single_category_containers = new Array();
var single_category_anchors = new Array();

var single_category_loaded = 0;

var single_category_urls = new Array();
single_category_urls[0] = 'img/thumb1.jpg';
single_category_urls[1] = 'img/thumb1.jpg';
single_category_urls[2] = 'img/thumb1.jpg';
single_category_urls[3] = 'img/thumb1.jpg';
single_category_urls[4] = 'img/thumb1.jpg';
single_category_urls[5] = 'img/thumb1.jpg';
single_category_urls[6] = 'img/thumb1.jpg';
single_category_urls[7] = 'img/thumb1.jpg';
single_category_urls[8] = 'img/thumb1.jpg';

var single_category_urls_big = new Array();
single_category_urls_big[0] = 'img/big1.png';
single_category_urls_big[1] = 'img/big1.png';
single_category_urls_big[2] = 'img/big1.png';
single_category_urls_big[3] = 'img/big1.png';
single_category_urls_big[4] = 'img/big1.png';
single_category_urls_big[5] = 'img/big1.png';
single_category_urls_big[6] = 'img/big1.png';
single_category_urls_big[7] = 'img/big1.png';
single_category_urls_big[8] = 'img/big1.png';

//kaskadowa animacja pojawiania sie fotek
function cascade_single_photos_animation(id)
{
	new Effect.Grow('single_container_'+id);
	setTimeout('$(\'single_photo_'+id+'\').appear()', 50);
	
	if (id < (single_category_urls.length - 1)) {
		setTimeout('cascade_single_photos_animation('+parseInt(id-(-1))+')', 100); 
	}
}

//sprawdzamy cyz wszystko sie zaladowalo - jesli tka odpalamy sekwencje animacji
function wait_for_single_photos()
{
	if (single_category_loaded == single_category_photos.length) {
		cascade_single_photos_animation(0);
		//new Lightbox();
		Lightbox.prototype.updateImageList();
	}
	else {
		setTimeout('wait_for_single_photos()', 100);
	}
}

function remove_actual_category()
{
	$('loader').hide();
	
	//if (Lightbox) { delete Lightbox; }
	
	//usuwamy poprzednie obrazki
	var elements_to_remove = $$('.single_photo');
	for (var i = 0 ; i < elements_to_remove.length ; i++) {
		elements_to_remove[i].remove();
	}
	
	elements_to_remove = $$('.single_photo_container');
	for (var i = 0 ; i < elements_to_remove.length ; i++) {
		elements_to_remove[i].remove();
	}
	
	elements_to_remove = $$('.single_photo_anchor');
	for (var i = 0 ; i < elements_to_remove.length ; i++) {
		elements_to_remove[i].remove();
	}
}

function display_actual_category(element)
{
	//pobieramy id
	var this_id = parseInt(element.id.substr(13, element.id.length));
	
	//zapelniamy tablice miniaturek
	single_category_urls = new Array();
	single_category_urls_big = new Array();
	
	if (projekty_miniatury[the_category_we_are_in][this_id].length < 1) { return; }
	
	for (var i = 0 ; i < projekty_miniatury[the_category_we_are_in][this_id].length ; i++)
	{
		single_category_urls[i] = projekty_miniatury[the_category_we_are_in][this_id][i];
		single_category_urls_big[i] = projekty_powiekszenia[the_category_we_are_in][this_id][i];
	}
	
	remove_actual_category();
	
	$('category_return').show();
	
	//resetujemy zmienne
	categories_that_were_visible = new Array();
	single_category_photos = new Array();
	single_category_containers = new Array();
	single_category_loaded = 0;

	//var categories_that_were_visible = new Array();
	var iteration = 0;
	var loader_pos = false;
	
	//zapamietujemy ktore kategorie byly widoczne
	for (var i = 0 ; i < category_images.length ; i++) {
		if (category_images[i].style.display != 'none') {
		
			if (loader_pos == false)
			{
				loader_pos = new Object();
				loader_pos.x = category_images[i].cumulativeOffset().left;
				loader_pos.y = category_images[i].cumulativeOffset().top;
			}
			
			//alert('siema');
		
			categories_that_were_visible[iteration] = i;
			iteration++;
			category_images[i].hide();
			category_divs[i].hide();
			category_descriptions[i].hide();
		}
	}	
	
	$('paginator_content').fade( { duration: 0.1 });
	
	//pokazujemy gdziestam loader
	$('loader').style.top = (loader_pos.y - (-50)) + 'px';
	$('loader').style.left = (loader_pos.x - (-17)) + 'px';
	$('loader').style.visibility = 'visible';
	
	var x = 0;
	var y = 0;
	
	//ladujemy male obrazki
	for (var i = 0 ; i < single_category_urls.length ; i++) {
		single_category_containers[i] = document.createElement('div');
		single_category_containers[i].className = 'single_photo_container';
		single_category_containers[i].setAttribute('id', 'single_container_'+i);
		
		single_category_containers[i].onmouseover = function () { 
			var sialala = parseInt(this.id.substr(17, this.id.length)); 
			//new Effect.Opacity('single_photo_'+sialala, { from: 1.0, to: 0.5, duration: 0.1 } ); 
			$('single_photo_'+sialala).setOpacity(0.8);
		}
		
		single_category_containers[i].onmouseout = function () { 
			var sialala = parseInt(this.id.substr(17, this.id.length)); 
			//new Effect.Opacity('single_photo_'+sialala, { from: 0.5, to: 1.0, duration: 0.1 } ); 
			$('single_photo_'+sialala).setOpacity(1.0);
		}
		
		//teraz robimy obrazki
		single_category_photos[i] = document.createElement('img');
		single_category_photos[i].className = 'single_photo';
		single_category_photos[i].setAttribute('id', 'single_photo_'+i);
		
		single_category_photos[i].onload = function () { single_category_loaded++; }
		
		//a teraz linkacze
		single_category_anchors[i] = document.createElement('a');
		single_category_anchors[i].className = 'single_photo_anchor';
		single_category_anchors[i].setAttribute('id', 'single_photo_anchor_'+i);
		single_category_anchors[i].href = single_category_urls_big[i];
		single_category_anchors[i].rel = 'lightbox[photos]';
		
		//single_category_photos[i].onmouseover = function () { alert('jo'); }
		
		single_category_photos[i].src = single_category_urls[i];
		
		//na wstepie wszystko ukrywamy skrzetnie :p
		//single_category_containers[i].hide();
		single_category_containers[i].style.display = 'none';
		single_category_photos[i].style.display = 'none';
		
		//teraz numerek w srodku
		var number_inside = document.createElement('div');
		number_inside.innerHTML = "<span style=\"font-size: 9px;\">"+(i-(-1))+"</span>";
		
		document.body.appendChild(single_category_containers[i]);
		single_category_anchors[i].appendChild(single_category_photos[i]);
		
		single_category_containers[i].appendChild(single_category_anchors[i]);
		single_category_containers[i].appendChild(number_inside);
		
		
		
		single_category_containers[i].style.left = ( (loader_pos.x) - (-(x * $(single_category_containers[i].id).getWidth())) - (-(x* 2)) ) + 'px';
		single_category_containers[i].style.top = ( (loader_pos.y) - (-(y * $(single_category_containers[i].id).getHeight())) - (-(y * 5)) ) + 'px';
		
		x = x + 1;
		if (x > 6) { x = 0; y++; }
		
		//single_category_containers[i].grow();
		//single_category_photos[i].appear();
		
	}
	
	wait_for_single_photos();
	
	//mozemy juz pokazac scroll i wszysto
	$('scrollable2').innerHTML = projekty_teksty[the_category_we_are_in][this_id];
	$('project_description').show();
	
	// vertical slider control
	/*
	var slider2 = new Control.Slider('handle2', 'track2', {
		axis: 'vertical',
		onSlide: function(v) { scrollVertical(v, $('scrollable2'), slider2);  },
		onChange: function(v) { scrollVertical(v, $('scrollable2'), slider2); }
	});
	
	// disable vertical scrolling if text doesn't overflow the div
	if ($('scrollable2').scrollHeight <= $('scrollable2').offsetHeight) {
		slider2.setDisabled();
		$('handle2').hide();
	}
	*/

}

function return_to_categories_view()
{
	remove_actual_category();
	for (var i = 0 ; i < categories_that_were_visible.length ; i++) {
		category_images[categories_that_were_visible[i]].show();
		category_divs[categories_that_were_visible[i]].show();
		category_descriptions[categories_that_were_visible[i]].show();
	}
	
	$('paginator_content').appear( { duration: 0.1 });
	$('category_return').hide();
	$('project_description').hide();
	

}




