$(document).ready(function() { 

	$('#drukarnia').click(function() {$('#subm1').slideToggle('fast'); $('#subm2').slideUp('fast')})
	$('#technologie').click(function() {$('#subm2').slideToggle('fast')})


/* **************************************** kolory - wydarzenia - domyslnie ****************************** */
	if (location.pathname=="/kolory.html") {
		var active = 5;
		$('.page').hide();
		$('.right_column #e').show();
		$('#bottom_menu .stripe').removeClass("stripe_color");
		$('#bottom_menu #5 .stripe').addClass("stripe_color");
		$('#bottom_menu div').removeClass("still_background");
		$('#bottom_menu .e').addClass("still_background");
	} else {
		var active = 1;
		$('#bottom_menu #1 .stripe').addClass("stripe_color");
		$('#bottom_menu .a').addClass("still_background");
	}

/* ****************************************** dolne menu ************************************************ */
	$('#bottom_menu .a').hover( function() { $('#bottom_menu #1 .stripe').addClass("stripe_color"); },
						function() { if (active!=1) $('#bottom_menu #1 .stripe').removeClass("stripe_color"); }
	)
	$('#bottom_menu .b').hover( function() { $('#bottom_menu #2 .stripe').addClass("stripe_color"); },
						function() { if (active!=2) $('#bottom_menu #2 .stripe').removeClass("stripe_color"); }
	)
	$('#bottom_menu .c').hover( function() { $('#bottom_menu #3 .stripe').addClass("stripe_color"); },
						function() { if (active!=3) $('#bottom_menu #3 .stripe').removeClass("stripe_color"); }
	)
	$('#bottom_menu .d').hover( function() { $('#bottom_menu #4 .stripe').addClass("stripe_color"); },
						function() { if (active!=4) $('#bottom_menu #4 .stripe').removeClass("stripe_color"); }
	)
	$('#bottom_menu .e').hover( function() { $('#bottom_menu #5 .stripe').addClass("stripe_color"); },
						function() { if (active!=5) $('#bottom_menu #5 .stripe').removeClass("stripe_color"); }
	)

	$('#bottom_menu .a').click( function() {
												$('.page').hide();
												$('.right_column #a').show();
												$('#bottom_menu .stripe').removeClass("stripe_color");
												$('#bottom_menu #1 .stripe').addClass("stripe_color");
												$('#bottom_menu div').removeClass("still_background");
												$('#bottom_menu .a').addClass("still_background");
												active=1
											} )
	$('#bottom_menu .b').click( function() {
												$('.page').hide();
												$('.right_column #b').show();
												$('#bottom_menu .stripe').removeClass("stripe_color");
												$('#bottom_menu #2 .stripe').addClass("stripe_color");
												$('#bottom_menu div').removeClass("still_background");
												$('#bottom_menu .b').addClass("still_background");
												active=2
											} )
	$('#bottom_menu .c').click( function() {
												$('.page').hide();
												$('.right_column #c').show();
												$('#bottom_menu .stripe').removeClass("stripe_color");
												$('#bottom_menu #3 .stripe').addClass("stripe_color");
												$('#bottom_menu div').removeClass("still_background");
												$('#bottom_menu .c').addClass("still_background");
												$('#bottom_menu #zastosowanie_intro').addClass("still_background_2");
												active=3
											} )
	$('#bottom_menu .d').click( function() {
												$('.page').hide();
												$('.right_column #d').show();
												$('#bottom_menu .stripe').removeClass("stripe_color");
												$('#bottom_menu #4 .stripe').addClass("stripe_color");
												$('#bottom_menu div').removeClass("still_background");
												$('#bottom_menu .d').addClass("still_background");
												active=4
											} )
	$('#bottom_menu .e').click( function() {
												$('.page').hide();
												$('.right_column #e').show();
												$('#bottom_menu .stripe').removeClass("stripe_color");
												$('#bottom_menu #5 .stripe').addClass("stripe_color");
												$('#bottom_menu div').removeClass("still_background");
												$('#bottom_menu .e').addClass("still_background");
												active=5
											} )

/* ********************************************** roll mapy ******************************************** */

	$('#map_down').click( function() {
										$('#map').slideDown('fast');
										$('#map_down').hide();
										$('#map_up').show();
									}
						)

	$('#map_up').click( function() {
										$('#map').slideUp('fast');
										$('#map_up').hide();
										$('#map_down').show();
									}
						)

/* ******************************************* dzialy w kontakt.html ******************************************************* */

	var dd=0;

	$('#headline_roll_1').click( function() {
												$('.roll').slideUp('fast');
												if (dd==1) {
													dd=0;
												} else {
													$('#roll_1').slideDown('fast');
													dd=1;
												}
											})

	$('#headline_roll_2').click( function() {
												$('.roll').slideUp('fast');
												if (dd==2) {
													dd=0;
												} else {
													$('#roll_2').slideDown('fast');
													dd=2;
												}
											})

	$('#headline_roll_3').click( function() {
												$('.roll').slideUp('fast');
												if (dd==3) {
													dd=0;
												} else {
													$('#roll_3').slideDown('fast');
													dd=3;
												}
											})

	$('#headline_roll_4').click( function() {
												$('.roll').slideUp('fast');
												if (dd==4) {
													dd=0;
												} else {
													$('#roll_4').slideDown('fast');
													dd=4;
												}
											})
	$('#headline_roll_5').click( function() {
												$('.roll').slideUp('fast');
												if (dd==5) {
													dd=0;
												} else {
													$('#roll_5').slideDown('fast');
													dd=5;
												}
											})

/* ************************************************* zmiana obrazków w index.html ******************************** */

/*
	var i = Math.floor(Math.random()*2)+1;
	var p;


	$('.header').hide();
	if (i==1) {
		p=1;
		$('#header_1').show();
		$('#number_1').show();
	}
	if (i==2) {
		p=2;
		$('#header_2').show();
		$('#number_2').show();
	}
	if (i==3) {
		p=3;
		$('#header_3').show();
		$('#number_3').show();
	}

*/

	var infLoopStop=false;
	var infLoop=null;
	var t;
	var p=2;
	var s=1000; //czas fade
	var tm=7000; //interwał między zmianą obrazków

	infLoop=function(){

//		var j = Math.floor(Math.random()*3)+1;

		if (p==2) {
			$('.header').fadeOut(s);
			$('#header_1').fadeIn(s);
			p=1;
			$('.numbers').hide();
			$('#number_1').show();
		} else

		if (p==1) {
			$('.header').fadeOut(s);
			$('#header_2').fadeIn(s);
			p=2;
			$('.numbers').hide();
			$('#number_2').show();
		} /*else

		if (p==2) {
			$('.header').fadeOut(s);
			$('#header_3').fadeIn(s);
			p=3;
			$('.numbers').hide();
			$('#number_3').show();
		}*/

		if(!infLoopStop) t=setTimeout(infLoop,tm);

	};

	infLoop();

	$('.number_c1').click( function() {
										clearTimeout(t);
										$('.header').fadeOut(s);
										$('#header_1').fadeIn(s);
										p=1;
										$('.numbers').hide();
										$('#number_1').show();
										t=setTimeout(infLoop,tm);
									})

	$('.number_c2').click( function() {
										clearTimeout(t);
										$('.header').fadeOut(s);
										$('#header_2').fadeIn(s);
										p=2;
										$('.numbers').hide();
										$('#number_2').show();
										t=setTimeout(infLoop,tm);
									})

	$('.number_c3').click( function() {
										clearTimeout(t);
										$('.header').fadeOut(s);
										$('#header_3').fadeIn(s);
										p=3;
										$('.numbers').hide();
										$('#number_3').show();
										t=setTimeout(infLoop,tm);
									})



/* ***************************** galeria ************************************************************* */

// lightbox
	$('#th_1 a').lightBox({txtImage: 'Zdjecie', txtOf: 'z'}); //oznaczanie poszczególnych galerii
	$('#th_2 a').lightBox({txtImage: 'Zdjecie', txtOf: 'z'});
	$('#th_3 a').lightBox({txtImage: 'Zdjecie', txtOf: 'z'});
	$('#th_4 a').lightBox({txtImage: 'Zdjecie', txtOf: 'z'});


	var ff=0; //aktywna galeria

	function event_show(n) {
		$('.event_roll').slideUp('fast');
		if(ff==n)
			n=0
		else {
			if(!$('#th_'+n+' img')[0]) {
				var g=$('#th_'+n+' a'), t=g[0].title, s=g[0].href.replace(/event-[0-9]+\.jpg/,'')+'thumbnail-'
				g.each(function(i,a) {
					var e=$('<img width=120 height=120>'), t2=a.title
					if(t2) t=t2; else a.title=t
					e.attr('src',s+(i+1)+'.jpg')
					$(a).append(e)
				})
			}

			$('#event_roll_'+n).slideDown('fast')
		}
		ff=n;
	}

	$('#event_headline_1').click(function() {event_show(1)})
	$('#event_headline_2').click(function() {event_show(2)})
	$('#event_headline_3').click(function() {event_show(3)})
	$('#event_headline_4').click(function() {event_show(4)});

	(onhashchange = function() {
		switch(location.hash) {
		case '#lado': event_show(1); break
		case '#anisland': event_show(2); break
		case '#singsingpenelope': event_show(3); break
		case '#bukkake': event_show(4); break
		}
	})()
})
