
$(function() {
	$('.slide-out-div').tabSlideOut({
		tabHandle: '.handle',                              //class of the element that will be your tab
		pathToTabImage: '/img/slide_slo.png',              //path to the image for the tab *required*
		imageHeight: '145px',                              //height of tab image *required*
		imageWidth: '50px',                                //width of tab image *required*
		tabLocation: 'left',                               //side of screen where tab lives, top, right, bottom, or left
		speed: 300,                                        //speed of animation
		action: 'click',                                   //options: 'click' or 'hover', action to trigger animation
		topPos: '110px',                                   //position from the top
		fixedPosition: false                                //options: true makes it stick(fixed position) on scroll
	});


	// Začetek projektor OMARE
		var blnstop = false;

	$('img#visual-2').hide();
	$('img#button-visual-1').attr('src','/img/button-1.png');

	function projektodin1() {
		$('img#visual-2').removeClass('adselect');
		$('img#visual-1').addClass('adselect');
		$('img#visual-2').delay(100).fadeOut(400);
		$('img#visual-1').fadeIn(200);
		$('img#button-visual-1').attr('src','/img/button-1.png').delay(500);
		$('img#button-visual-2').attr('src','/img/button-2.png');
	}

	function projektodin2() {
		$('img#visual-1').removeClass('adselect');
		$('img#visual-2').addClass('adselect');
		$('img#visual-1').delay(100).fadeOut(400);
		$('img#visual-2').fadeIn(200);
		$("img#button-visual-1").attr('src','/img/button-2.png');
		$("img#button-visual-2").attr('src','/img/button-1.png').delay(500);
	}

	$("img#button-visual-1").click(function() {
		projektodin1();
		blnstop = true;
		return false;
	});

	$("img#button-visual-2").click(function() {
		projektodin2();
		blnstop = true;
		return false;
	});

	function changeprojectodin() {
		if (blnstop==false)
		{
			if($('img#visual-2').attr('class')=='adselect')
			{
				projektodin1();
			}
			else
			{
				projektodin2();
			}
		}
		else
		{return;}
	}

	setInterval(function(){changeprojectodin()}, 6000);

	//Konec projektor ODIN

	//Form obnašanje

	$('[placeholder]').focus(function() {
		var input = $(this);
		if (input.val() == input.attr('placeholder')) {
			input.val('');
			input.removeClass('placeholder');
			$(this).addClass('selected')
		}
		}).blur(function() {
		var input = $(this);
		if (input.val() == '' || input.val() == input.attr('placeholder')) {
			input.addClass('placeholder');
			input.val(input.attr('placeholder'));
			$(this).removeClass('selected')
		}
	}).blur();

	//Konec Form obnašanje
	
	//Začetek funkcija za pošiljanje
	$('#name').focus(function () {
		$('.opozoriloIme').hide('1000');
		$(this).removeClass('error')
	});
	$('#email').focus(function () {
		$('.opozoriloEmail').hide('1000');
		$(this).removeClass('error')
	});
	$('#sporocilo').focus(function () {
		$('.opozoriloSporocilo').hide('1000');
		$(this).removeClass('error')
	});

	$('#poslji').click(function () {
		$('div.message').hide();
		
		var inputs = [];
		$(':input').each(function () {
			inputs.push(this.name + '=' + encodeURIComponent(this.value));
		});

		$.ajax({
			data: inputs.join('&'),
			type: 'POST',
			url: '/inc/ajax_poslji_sporocilo.inc.php',
			cache: false,
			timeout: 2000,
			error: function () {
				alert("Error");
		},
			success: function (r) {
				if (r == 'sucess')
				{
					$('#poslji').attr("disabled", "true");
					$('#poslji').removeClass('hover');
					$('#poslji').after($('<div class="message">Vaše sporočilo je bilo poslano.</div>').fadeIn('slow'));
					$('#poslji').hide();
					$(':input','#obrazec').not(':button, :submit, :reset, :hidden').val('')
				}
				else
				{
					var response = r.split(' | ');
					if (response[1] == 1)
					{
						$('.opozoriloIme').show('1000');
						$('#name').addClass('error');
					}

					if (response[2] == 1)
					{
						$('.opozoriloEmail').show('1000');
						$('#email').addClass('error');
					}

					if (response[3] == 1)
					{
						$('.opozoriloSporocilo').show('1000');
						$('#sporocilo').addClass('error');
					}
					
					/*$('#poslji').after($('<div class="message">' + response[0] + '</div>'));*/
				}
			}
		});
		return false;
	});
});
