
$(document)
	.ready(function()
	{
		$("#menu > a")
			.click(function()
			{
				$("#second_menu")
					.queue(function()
					{
						$("#second_menu div")
							.animate({ top : -30 }, 300, function() { $("#second_menu").dequeue(); });
					});
		
				if (!$(this).attr("href")) {
				uu = this;
				$("#second_menu")
					.queue(function()
					{	
						$("."+$(uu).attr("id"))
							.animate({ top : 0}, 300, function() { $("#second_menu").dequeue(); });
					});
							
					return false;
				}
			})
			.hover(function()
			{
				var span = $(this).children("span");
				span
					.animate({marginTop : "50"}, 125)
					.queue(function()
					{ 
						$(this)
							.css('marginTop', -50);
						$(this)
							.dequeue();
					})
					.animate({marginTop : "0"}, 125);
					
				var img = $(this).children("img");
					img
						.animate({ marginTop : "-50" }, 125)
						.queue(function()
						{ 
							$(this)
								.css('marginTop', 50);
							$(this)
								.dequeue();
						})
						.animate({ marginTop : "0" }, 125);
					
					
			}, function() {});
			
		$("#right_arrow")
			.click(slide_right);
			
		$("#left_arrow")
			.click(slide_left);
			
		$("#test")
			.click(function()
			{
				window.open(
						$(this).attr("href"),
						"testy",
						"width=750,height=550,scrollbars=no,status=0,resizable=0,left=" + (screen.width*0.5-325) + ",top=" + (screen.height*0.5-275)
						);
				
				return false;
				
			});

		$("#game, #symulator")
			.click(function()
			{
				window.open(
						$(this).attr("href"),
						"testy",
						"width=640,height=480,scrollbars=no,status=0,resizable=0,left=" + (screen.width*0.5-320) + ",top=" + (screen.height*0.5-240)
						);
				
				return false;
				
			});
			
		$("a[rel^='prettyPhoto']")
			.prettyPhoto({
						 animation_speed: 'fast',
						 counter_separator_label: ' z ',
						 theme: 'facebook',
						 callback: function() {},
						 gallery_markup: ''
			
			});
			
		$("a[rel=external]")
			.click(function()
			{
				this.target = "_blank";
			});
		$("#wystaw")
			.click(function()
			{	
  				window.open($(this).attr("href"),"Opinie","width=600,height=600,left=" + (screen.width*0.5-300) + ",top=50,resizable=1,scrollbars=yes,menubar=no");
				return false;
				
			});
			
		$(".fade")
			.css('opacity', 0.6)
			.hover(function()
			{
				$(this)
					.animate({ opacity : 1 }, 250);
					
			}, function()
			{
				$(this)
					.animate({ opacity : 0.6 }, 250);
					
			});
			
			
		if ($("#PrawoTermin").length > 0 || $("#SzkoleniumTermin").length > 0 ) {
			$("#lista_terminow")
				.addClass("lista_terminow");
			
			$(".lista_terminow li")
				.click(function()
				{
					if ( $("#PrawoTermin").length > 0 )
					{
						$("#PrawoTermin")
							.attr("value", $(this).html()+" "+$(this).parent().parent().parent().attr("title")+" r.");
					} else {
						$("#SzkoleniumTermin")
							.attr("value", $(this).html()+" "+$(this).parent().parent().parent().attr("title")+" r.");	
					}
				});	
		}
		if ($("#reloadCaptcha"))
			$("#reloadCaptcha")
				.click(function() 
				{
					$("#captcha")
						.attr('src', $(this).attr("href") + Math.random());
					return false;
				});
			
	});
	
	function slide_left()
	{
		if (inProgress) {
			return false;
		}
		inProgress = true;
		
		if (vehicles_on + 1 < vehicles.length) 
		{
			vehicles_on = vehicles_on + 1;
		}
		else if (vehicles_on + 1 == vehicles.length)
		{
			vehicles_on = 0;
		}
		
		left_image = vehicles_on - 2;
				
		if (left_image < 0)
			left_image = vehicles.length + left_image;
				
		img = $("<img>");
		img.attr("src", "/images/"+vehicles[left_image][0]);
		img.css("width", 0);
				
		$("#vehicles img:last-child")
			.remove();
					
		$("#vehicles")
			.prepend(img);
					
		images = $("#vehicles").children();
		
		$("#vehicles_conteiner").css("backgroundImage", "");
		
		$(images[0])
			.animate({
					 	"width"		: 230,
						"height"	: 230
					 }, 500);	
			
		$(images[2])
			.animate({
					 	"marginTop"	: 0,
						"width"		: 460,
						"height" 	: 460
					 }, 500);	
			
		$(images[3])
			.animate({
					 	"marginTop"	: 120,
						"width"		: 230,
						"height"	: 230
					 }, 500, function() 
					 {
						$("#vehicles_conteiner").css("backgroundImage", "url(/images/vcimages/"+vehicles_on+".png)");
						inProgress = false;
					 });
			
			clearTimeout(TimeOut);
			TimeOut = setTimeout(slide_right, 5000)	
	}
	
	function slide_right()
	{
		if (inProgress) {
			return false;
		}
		inProgress = true;
		
		if (vehicles_on - 1 >= 0) 
		{
			vehicles_on = vehicles_on - 1;
		} 
		else if (vehicles_on - 1 < 0) 
		{
			vehicles_on = vehicles.length - 1;
		}
				
		
		right_image = vehicles_on + 2;
				
		if (right_image >= vehicles.length)
			right_image = right_image - vehicles.length;
				
		$("#vehicles_conteiner").css("backgroundImage", "");
				
		img = $("<img>");
		img.attr("src", "/images/"+vehicles[right_image][0]);
					
		$("#vehicles")
			.append(img);
					
		images = $("#vehicles").children();
		
		$(images[0])
			.animate({
					 	"width"		: 0,
						"height"	: 230
					 }, 500, function()
					 {
						 $(images[0]).remove();
					 });	
			
		$(images[3])
			.animate({
					 	"marginTop"	: 0, 
						"width" : 460,
						"height": 460
					 }, 500);
		
		$(images[2])
			.animate({ 
					 	"marginTop"	: 120,
						"width"		: 230,
						"height"	: 230
					 }, 500, function() 
					 {
						$("#vehicles_conteiner").css("backgroundImage", "url(/images/vcimages/"+vehicles_on+".png)");
						inProgress = false;
					 });
			
			clearTimeout(TimeOut);
			TimeOut = setTimeout(slide_right, 5000);
	}
	
	var TimeOut = setTimeout(slide_right, 5000);
	
	vehicles = new Array();
			
			vehicles[3] = new Array("moto.png");
			vehicles[2]= new Array("tir.png");
			vehicles[1] = new Array("car.png");
			vehicles[0]= new Array("bus.png");
			
			vehicles_on = 1;
			
	var inProgress = false;
