var tlo = "banner_przemyslowe";

    $(document).ready(function() {
        
		$('.gallery').lightBox();
		
		$('#kat_back').click(function(){
			pozycja = $('#slider_slide').position();
			if(pozycja.left == 45)
			{
			}
			else if(pozycja.left == 295)
			{
				$('#slider_slide').animate({left: '-=250'});
				wczytajSlider(1);
				$('#wyciagarki_font').animate({color: 'white'});
				$('#sprezarki_font').animate({color: '#454545'});
				$('#akcesoria_font').animate({color: '#454545'});
				$('#plugi_font').animate({color: '#454545'});
			}
			else if(pozycja.left == 545)
			{
				$('#slider_slide').animate({left: '-=250'});
				wczytajSlider(2);
				$('#wyciagarki_font').animate({color: '#454545'});
				$('#sprezarki_font').animate({color: 'white'});
				$('#akcesoria_font').animate({color: '#454545'});
				$('#plugi_font').animate({color: '#454545'});
			}
			else if(pozycja.left == 795)
			{
				$('#slider_slide').animate({left: '-=250'});
				wczytajSlider(3);
				$('#wyciagarki_font').animate({color: '#454545'});
				$('#sprezarki_font').animate({color: '#454545'});
				$('#akcesoria_font').animate({color: 'white'});
				$('#plugi_font').animate({color: '#454545'});
			}
		});
		
		$('#kat_forward').click(function(){
			pozycja = $('#slider_slide').position();
			if(pozycja.left == 45)
			{
				$('#slider_slide').animate({left: '+=250'});
				wczytajSlider(2);
				$('#wyciagarki_font').animate({color: '#454545'});
				$('#sprezarki_font').animate({color: 'white'});
				$('#akcesoria_font').animate({color: '#454545'});
				$('#plugi_font').animate({color: '#454545'});
			}
			else if(pozycja.left == 295)
			{
				$('#slider_slide').animate({left: '+=250'});
				wczytajSlider(3);
				$('#wyciagarki_font').animate({color: '#454545'});
				$('#sprezarki_font').animate({color: '#454545'});
				$('#akcesoria_font').animate({color: 'white'});
				$('#plugi_font').animate({color: '#454545'});
			}
			else if(pozycja.left == 545)
			{
				$('#slider_slide').animate({left: '+=250'});
				wczytajSlider(4);
				$('#wyciagarki_font').animate({color: '#454545'});
				$('#sprezarki_font').animate({color: '#454545'});
				$('#akcesoria_font').animate({color: '#454545'});
				$('#plugi_font').animate({color: 'white'});
			}
		});
		
		var galleries = $('.ad-gallery').adGallery({
	
		width: 357, // Width of the image, set to false and it will read the CSS width
  		height: 314
	
		});
		
		$("#wydarzenia").easySlider({
				auto: true, 
				continuous: true,
				pause:			10000,
				prevText: 		'',
				nextText: 		''
			});
		
		$('.opacity').each(function() {
            $(this).hover(function() {
                $(this).stop().animate({ opacity: 0.7 }, 500);
            },
           function() {
               $(this).stop().animate({ opacity: 1.0 }, 500);
           });
        });
		
		$('.grafiki_thumb').each(function() {
            $(this).hover(function() {
                $(this).stop().animate({ opacity: 1.0 }, 500);
            },
           function() {
               $(this).stop().animate({ opacity: 0.7 }, 500);
           });
        });
		
		$('.produkt_thumb').each(function() {
            $(this).hover(function() {
                $(this).stop().animate({ opacity: 0.6 }, 500);
            },
           function() {
               $(this).stop().animate({ opacity: 1.0 }, 500);
           });
        });
		
		$('.wydarzenia_nawigacja').each(function() {
            $(this).hover(function() {
                $(this).stop().animate({ opacity: 0.7 }, 500);
            },
           function() {
               $(this).stop().animate({ opacity: 1.0 }, 500);
           });
        });
		
		$('#slider_slide').each(function() {
            $(this).hover(function() {
                $(this).stop().animate({ opacity: 1.0 }, 500);
            },
           function() {
               $(this).stop().animate({ opacity: 0.5 }, 500);
           });
        });
		
		$('.grafiki_thumb').click(function(){
			if(tlo == "banner_przemyslowe")
			{
				$('#banner_glowny_przemyslowe').slideUp(500);
				$('#banner_glowny_wyciagarki').slideDown(500);
				
				$('#3_przemyslowe').fadeOut(500);
				$('#3_wyciagarki').fadeIn(500);
				
				tlo = "banner_wyciagarki";
			}
			else if(tlo == "banner_wyciagarki")
			{
				$('#banner_glowny_wyciagarki').slideUp(500);
				$('#banner_glowny_sprezarki').slideDown(500);
				
				$('#3_wyciagarki').fadeOut(500);
				$('#3_sprezarki').fadeIn(500);
				
				tlo = "banner_sprezarki";
			}
			else if(tlo == "banner_sprezarki")
			{
				$('#banner_glowny_sprezarki').slideUp(500);
				$('#banner_glowny_plugi').slideDown(500);
				
				$('#3_sprezarki').fadeOut(500);
				$('#3_plugi').fadeIn(500);
				
				tlo = "banner_plugi";
			}
			else if(tlo == "banner_plugi")
			{
				$('#banner_glowny_plugi').slideUp(500);
				$('#banner_glowny_akcesoria').slideDown(500);
				
				$('#3_plugi').fadeOut(500);
				$('#3_akcesoria').fadeIn(500);
				
				tlo = "banner_akcesoria";
			}
			else if(tlo == "banner_akcesoria")
			{
				$('#banner_glowny_akcesoria').slideUp(500);
				$('#banner_glowny_przemyslowe').slideDown(500);
				
				$('#3_akcesoria').fadeOut(500);
				$('#3_przemyslowe').fadeIn(500);
				
				tlo = "banner_przemyslowe";
			}
    	});
		
		var slajder;
		var pozycja;
		
		$("#slider_slide").draggable({ 
			axis: "x", 
			containment: "#slider", 
			scroll: true, 
			grid: [250, 0],
			start: function() {
				document.getElementById("slider_content").innerHTML = '<p align="center"><br /><br /><img src="img/loading_animation.gif" alt="wczytuje" /></p>';
			},
			stop: function() {
				pozycja = $('#slider_slide').position();
				
				if(pozycja.left == 45)
				{
					wczytajSlider(1);
					$('#wyciagarki_font').animate({color: 'white'});
					$('#sprezarki_font').animate({color: '#454545'});
					$('#akcesoria_font').animate({color: '#454545'});
					$('#plugi_font').animate({color: '#454545'});
				}
				else if(pozycja.left == 295)
				{
					wczytajSlider(2);
					$('#wyciagarki_font').animate({color: '#454545'});
					$('#sprezarki_font').animate({color: 'white'});
					$('#akcesoria_font').animate({color: '#454545'});
					$('#plugi_font').animate({color: '#454545'});
				}
				else if(pozycja.left == 545)
				{
					wczytajSlider(3);
					$('#wyciagarki_font').animate({color: '#454545'});
					$('#sprezarki_font').animate({color: '#454545'});
					$('#akcesoria_font').animate({color: 'white'});
					$('#plugi_font').animate({color: '#454545'});
				}
				else if(pozycja.left == 795)
				{
					wczytajSlider(4);
					$('#wyciagarki_font').animate({color: '#454545'});
					$('#sprezarki_font').animate({color: '#454545'});
					$('#akcesoria_font').animate({color: '#454545'});
					$('#plugi_font').animate({color: 'white'});
				}
			}
		});
    });
	
	
function wczytajSlider(id_kategorii)
{
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			$('#slider_content').fadeOut(300);
			setTimeout('zmienZawartosc(xmlhttp.responseText)', 400);
			
		}
	}
	
	var url = "ajax/wczytajslider.php?kid="+id_kategorii+"&key="+Math.random();
	//alert(url);
	xmlhttp.open("GET",url,true);
	xmlhttp.send();	
}

function zmienZawartosc(zawartosc)
{
	document.getElementById("slider_content").innerHTML = zawartosc;
	$('#slider_content').fadeIn(1000);
	$('.opacity').each(function() {
            $(this).hover(function() {
                $(this).stop().animate({ opacity: 0.7 }, 500);
            },
           function() {
               $(this).stop().animate({ opacity: 1.0 }, 500);
           });
        });
}


function pokazKategorie(nazwa)
{
	window.location = "?kategoria/"+nazwa;	
}
