function slideSwitch() {
    var $active = $('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

function bannerSlider() {
	var $selected = $('#changer #buttons div.selected');
    if ($selected.length == 0) {
		$selected = $('#changer #buttons div:last');
		$selected.click();
	}
	var $next =  $selected.next().length ? $selected.next() : $('#changer #buttons div:first');
	$next.click();
	
	
}
function zamk() {
	if(document.getElementById('popup'))
		document.getElementById('popup').style.display = "none";

	if(document.getElementById('kamera'))
		document.getElementById('kamera').style.display = "none";
}
$(document).ready(function(){
	
	$('select[name="kategoria"]').change(function() {
		if ($(this).val() != '0') {
			$.ajax({
				url: '/index.php?module=tekst&akcja=get_sub&ajax=1',
				data: 'id_a='+$(this).val(),
				type: 'get',
				success: function(response) {
					if (response != '') {
						$('#podkategorie_f .field').empty().append(response);
						$('#podkategorie_f').show();
					} else {
						$('#podkategorie_f').hide();
					}
				}
			});
		}
	});
	 
  	$('select[name="SortMiasta"]').change(
		function() {
			$('table.Pok tr').show();
			if (this.value=='') $('table.Pok tr').fadeIn();
			else $('table.Pok tr[class!="'+this.value+'"]').hide();
			$('table.Pok tr.Head').show();
			}
		);
	
	$('a.link_gorny').click(function() {
			
			rel = this.rel;
			
			$('div[class^=podmenu_]').hide();
			$('div.podmenu_'+rel).fadeIn('fast');
			
		});
		
	$('#changer #buttons div').each(function(index, value) {
		$(this).click(function() {
			$('#changer #buttons div.selected img:eq(1)').removeClass('button_hidden');
			$('#changer #buttons div.selected img:eq(0)').addClass('button_hidden');
			$('#changer #buttons div.selected').removeClass('selected');
			$(this).addClass('selected');
			$(this).find('img:eq(0)').removeClass('button_hidden');
			$(this).find('img:eq(1)').addClass('button_hidden');
			$('#current_img img').hide();
			$('#current_img img:eq('+index+')').css('display', 'block');
		});
	});
	
	$('.location_select').change(function() {
		$('#location_form').submit();
	});
	
	$('.harmonogramy_form #print_btn').click(function() {
		var myWindow = window.open(
			'/index.php?module=drukuj&ajax=1&row='+$('select[name="location_select"]').val(), 
			'myWindow', 
			'width=620,height=600'
		);
	});
});

$(function() {
	$('#changer #current_img img:gt(0)').hide();
    setInterval( "slideSwitch()", 7000 );
	setInterval("bannerSlider()", 5000);
	
	var i = 0;
	$('div#jAn div.Item').hide();
	$('div#jAn div.Item:first').show();
	$('div#jAn').everyTime(7000, function(i) {
		showNext(i);
	});
	$('a[name^="Item_"]').click(function() {
		var oBj = $('div#jAn div.Item');
		for (i = 0; i<oBj.length; i++) {
			if (i==this.name.split('_')[1]) $(oBj[i]).fadeIn('slow'); 
			else $(oBj[i]).hide();
			}
		$('div#jAn').stopTime();
		$('div#jAn').everyTime(7000, function(i) {
			showNext(i);
		});
	});


var i = 0;
	$('div#haslo p.Itemp').hide();
	$('div#haslo p.Itemp:first').show();
	$('div#haslo').everyTime(7000, function(i) {
		showNextp(i);
	});
	$('a[name^="Item_"]').click(function() {
		var oBj = $('div#haslo p.Itemp');
		for (i = 0; i<oBj.length; i++) {
			if (i==this.name.split('_')[1]) $(oBj[i]).fadeIn('slow'); 
			else $(oBj[i]).hide();
			}
		$('div#haslo').stopTime();
		$('div#haslo').everyTime(7000, function(i) {
			showNextp(i);
		});
	});


	
	$('a.lightbox').lightBox(); // Select all links with lightbox class

});

function zatrzymaj() {
	$('div#jAn').stopTime();
	$('div#haslo').stopTime();
}
function showNext(a) { 
	var oBj = $('div#jAn div.Item');
	var z = 0;
	for (i = 0; i<oBj.length; i++) {
		if ($(oBj[i]).is(":visible")) z = i;
		$(oBj[i]).hide();
	}
	z++;
	if (z>=oBj.length) z = 0;
	$(oBj[z]).fadeIn();
}

function showNextp(a) { 
	var oBj = $('div#haslo p.Itemp');
	var z = 0;
	for (i = 0; i<oBj.length; i++) {
		if ($(oBj[i]).is(":visible")) z = i;
		$(oBj[i]).hide();
	}
	z++;
	if (z>=oBj.length) z = 0;
	$(oBj[z]).fadeIn();
}


function showDiv(id) {
	$('div.GPW ul.Gray').hide();
	$('div.GPW ul.Orange').hide();
	$('div.GPW div.Gray').attr('class','Orange');
	$('div.GPW div#DIV_'+id).attr('class','Gray');
	$('div.GPW ul#UL_'+id).fadeIn();
}

function FAQ(id) {
	$('div.Faq p.FAQ').hide();
	$('div.Faq p.FAQ_'+id).fadeIn();

}

function load() {
    var a=12;
    var b=new GLatLng(50.703123, 16.737642);
    var c=new GMarker(b);
    if(GBrowserIsCompatible()) {
        var d=new GMap2(document.getElementById("map"));
        GEvent.addListener(c,"click",function() {
            alert("DSS")
        }
        );
        d.addControl(new GSmallZoomControl());
        d.setCenter(new GLatLng(50.703123, 16.737642),a);
        d.addOverlay(c)
    }
}
