$(function () {
	
  /*	Tražilica projekata
	*/	
  
	var switchLokalno = function () {
		if ($('#searchHome').attr('action') === "/lokalno-volontiranje/pretrazivanje-projekata/") {
			$('#searchHome').attr('action', "/medjunarodno-volontiranje/pretrazivanje-projekata/");
		}
	}
	var switchMedunarodno = function () {
		if ($('#searchHome').attr('action') === "/medjunarodno-volontiranje/pretrazivanje-projekata/") {
			$('#searchHome').attr('action', "/lokalno-volontiranje/pretrazivanje-projekata/");
		}
	}
	
	$('#radioLokalno').click(switchMedunarodno);
	$('#radioMedunarodno').click(switchLokalno);
  
  /*$('li.col3 form fieldset input.button').submit(function() {
    if ($('#radioMedunarodno').attr('checked') === "checked") {
      $('#searchHome').attr('action', "/medjunarodno-volontiranje/pretrazivanje-projekata/");
      return true;
    }
  });*/
  
	/*  Tabovi na naslovnici; animacija u trecem tab-u
	 */
	var _slideRunning = false;
	var paused = false;
	var mouseOff = false;
	
	/*
	*	showTab# FUNCTIONS
	*/
	var showTab1 = function () {
		$("#tabCont1").removeClass ("inactive");
		$("#tab1").addClass ("active");
		$("#tabCont2, #tabCont3").addClass ("inactive");
		$("#tab2,  #tab3").removeClass ("active");
		
		if (_slideRunning) {
			_slideRunning = false;
			
			$('ul#tabCont3 .col3 a:first')
			.addClass('original')
			.clone()
				.insertBefore($('ul#tabCont3 .col3 a.original'))
				.addClass('clone')
				.removeClass('original');
				
			$('ul#tabCont3 .col3 a.original:first')
				.removeClass('original')
				.addClass('old')
				.css({display: 'none'});
		}
	};
	
	var showTab2 = function () {
		$("#tabCont2").removeClass ("inactive");
		$("#tab2").addClass ("active");
		$("#tabCont1, #tabCont3").addClass ("inactive");
		$("#tab1,  #tab3").removeClass ("active");
		
		if (_slideRunning) {
			_slideRunning = false;
			
			$('ul#tabCont3 .col3 a:first')
			.addClass('original')
			.clone()
				.insertBefore($('ul#tabCont3 .col3 a.original'))
				.addClass('clone')
				.removeClass('original');
				
			$('ul#tabCont3 .col3 a.original:first')
				.removeClass('original')
				.addClass('old')
				.css({display: 'none'});
		}
	};
	
	var showTab3 = function () {
		$("#tabCont3").removeClass ("inactive");
		$("#tab3").addClass ("active");
		$("#tabCont1, #tabCont2").addClass ("inactive");
		$("#tab1,  #tab2").removeClass ("active");
		
		_slideRunning = true;
		
		if (!isIE6) { $('ul#tabCont3 .col3 a.old').remove(); }
		
		$('ul#tabCont3 .col3 a:first').cycle({ 
			//fx: 'fade',  
			fx: 'scrollRight',
			speed: 1000,
			timeout: 2000,
			sync: 0
			
		});
	};
	
	var _mainPause = 5000;
	var _afterPause = 100;
	var _pause = 0;
	
	/*
	*	animateTab FUNCTION
	*/
	/*var animateTabs = function () {
		//provjeri o kojem se tabu radi i prikaži ga
		if ($(this).is('#tab1')) {
			if (!paused) {
				$(this)
					.animate (
						{bottom: '0'},
						0,
						showTab1
					);
			}
			else {
				paused = false;
				mouseOff = true;
				$(this)
					.animate (
						{bottom: '0'},
						0
					);
			}
		}
		else if ($(this).is('#tab2')) {
			if (!paused) {
				$(this)
					.animate (
						{bottom: '0'},
						0,
						showTab2
					);
			}
			else {
				paused = false;
				mouseOff = true;
				$(this)
					.animate (
						{bottom: '0'},
						0
					);
			}
		}
		else if ($(this).is('#tab3')) {
			if (!paused) {
				$(this)
					.animate (
						{bottom: '0'},
						0,
						showTab3
					);
			}
			else {
				paused = false;
				mouseOff = true;
				$(this)
					.animate (
						{bottom: '0'},
						0
					);
			}
		}
		
		//prikazuj tab "_mainPause" sekundi i zatim zakaci animateTab funkciju na slijedeći tab
		if (mouseOff) { _pause = _afterPause; mouseOff = false; }
		else { _pause = _mainPause; }
		$(this).animate (
			{bottom: '0'},
			_pause,
			function () {
			
				if ($(this).next().is('#tab2') || $(this).next().is('#tab3')) {
					$(this).next().animate (
						{bottom: '0'},
						0,
						animateTabs
					);
				}
				else {
					$('#tab1').animate (
						{bottom: '0'},
						0,
						animateTabs
					);
				}
			}
		);
	}
	
	$("#tab1, #tabCont1").hover (
		function () {
			$('#tab1, #tab2, #tab3').stop();
			paused = true;
		}
		, 
		function () {
			$('#tab1').animate (
				{bottom: '0'},
				0,
				animateTabs
			);
		}
	);
	
	$("#tab2, #tabCont2").hover (
		function () {
			$('#tab1, #tab2, #tab3').stop();
			paused = true;
		}
		, 
		function () {
			$('#tab2').animate (
				{bottom: '0'},
				0,
				animateTabs
			);
		}
	);
	
	$("#tab3, #tabCont3").hover (
		function () {
			$('#tab1, #tab2, #tab3').stop();
			paused = true;
		}
		, 
		function () {
			$('#tab3').animate (
				{bottom: '0'},
				0,
				animateTabs
			);
		}
	);
	
	$('#tab1').animate (
		{bottom: '0'}, 
		0, 
		animateTabs
	);*/
	
	$("#tab1").hover (showTab1, function () {});
	$("#tab2").hover (showTab2, function () {});
	$("#tab3").hover (showTab3, function () {});
});
