var  newPos = 0, newLI, SF, newHor = 0, newVert = 0, maximus, theslide, firsLide, showFirst, thisPos, thisHor;

var colors = ["a2abff", "ff8282", "ffc000", "aae1e9", "a2abff", "ff8282", "ffc000", "aae1e9"];

function minmax(min, max) {
	maximus = (max - min) + 1;
	return (Math.floor(Math.random() * maximus) + min);
}		

function showFirst(slide) {

	firsLide = typeof (slide) !== 'undefined' ? slide : $('.jobs li').eq(0);
	
	$('.content').hide();
			
	$('.jobs li').stop(true);
	
	$('.jobs li').each(function () {
		newPos = $(this).position();
		newHor = newPos.left;
		newVert = newPos.top;
			
		$(this).css({'top' : newVert, 'left' : newHor});
	
	});	

	
	$('.jobs li').css('position', 'absolute').animate({left: 0, top: 60}, 1000);


	firsLide.addClass('selected');
	
	if ($.browser.msie && parseInt($.browser.version, 1) <= 8) {
		$('.title').removeClass('title').addClass('title-mini');
	} else {
		$('.title').switchClass('title', 'title-mini', 1000);
	}
	
	firsLide.animate({left: 0, top: 60, width: "100%", height: "100%"}, 1000, function () {
	
		$('.jobs li').removeClass('firz').addClass('not');

		$(this).removeClass('not').find('.content').fadeIn().find('.innerSpace').fadeIn();
		$('.jobsNav').fadeIn();
		$('.jobs li.not').removeAttr('style');
			
	});

}


$('.next').click(function (event) {
	event.preventDefault();
	$('.jobs li').stop(true);
	
	$('.content').hide();
	$('.innerSpace').hide();

	$('.selected').animate({left: '69%', top: 5, height: 40, width: '8.3%'}, 1000, function () {
		$(this).appendTo('.jobs').removeAttr('style');
		
		$(this).removeClass('selected').addClass('not');

	});
	
	$('.jobs li.not').eq(0).css({position: 'absolute', top: 5, left: '0'}).animate({left: 0, top: 60, width: "100%", height: "100%"}, 1000, function () {
		$(this).addClass('selected').removeClass('not');		 
		$(this).find('div.content').fadeIn().find('.innerSpace').fadeIn(1000);
	});

});

$('.prev').click(function (event) {
	event.preventDefault();
	$('.jobs li').stop(true);
	
	$('.content').hide();
	$('.innerSpace').hide();		

	$('.selected').animate({left: '0', top: 5, width: "8.3%", height: "40px"}, 1000, function () {
		$(this).prependTo('.jobs').removeAttr('style');
		
		$('.jobs li').removeClass('selected').addClass('not');

	});
	
	$('.jobs li.not:last').css({position: 'absolute', top: 5, left: 'auto', right: 0}).animate({height: "100%", width: '100%', top: '60'}, 1000, function () {
		$(this).addClass('selected').removeClass('not');		 
		$(this).find('div.content').fadeIn().find('.innerSpace').fadeIn(1000);
	});
});

$('.jobs li.not').live('click', function (event) {
	event.preventDefault();
	$('.jobs li').stop(true);
	
	$('.content').hide();
	$('.innerSpace').hide();

	$('.selected').animate({left: '79%', top: 5, height: 40, width: '8.3%'}, 1000, function () {
		$(this).appendTo('.jobs').removeAttr('style');
		
		$(this).removeClass('selected').addClass('not');

	});
	
	thisPos = $(this).position();
	thisHor = thisPos.left;
			
	$(this).css({position: 'absolute', top: 5, left: thisHor}).animate({left: 0, top: 60, width: "100%", height: "100%"}, 1000, function () {
		$(this).addClass('selected').removeClass('not');
		$(this).find('div.content').fadeIn().find('.innerSpace').fadeIn(1000);
	});
});

$('.jobs li.firz').live('click', function (event) {
	event.preventDefault();

	theslide = $(this);
	showFirst(theslide);
});	
	
$('.SeeAll').click(function (event) {
	event.preventDefault();
	if ($.browser.msie && parseInt($.browser.version, 1) <= 8) {
		$('.title-mini').removeClass('title-mini').addClass('title');
	} else {
		$('.title-mini').switchClass('title-mini', 'title', 500);
	}
		
	$('.jobs li').removeAttr('style').removeClass('not').removeClass('selected').each(function () {
		newPos = $(this).position();
		newHor = newPos.left;
		newVert = newPos.top;
			
		$(this).css({'top': newVert, 'left': newHor});
	
	});

	
	$('.jobs li').addClass('firz').css('position', 'absolute').animate({left: 0, top: '70%'}, 1500);
	
	var countR = 0, LefP, TopP;

	if (document.documentElement.clientWidth >= 780) {
	
		$('.jobs li').each(function () {
			LefP = (countR % 3) * 33;
			TopP = 0;
			
			if (countR > 2 && countR <= 5) { TopP = 35; }
			if (countR > 5) { TopP = 70; }
			
			$(this).animate({left: LefP + '%', top: TopP + '%'}, 1000);
			
			countR = countR + 1;
		});
		
	} else if (document.documentElement.clientWidth < 780 && document.documentElement.clientWidth >= 481) {
	
		$('.jobs li').each(function () {
			LefP = (countR % 2) * 48;
			TopP = 0;
			
			if (countR > 2 && countR <= 4) { TopP = 35; }
			if (countR > 4 && countR <= 6) { TopP = 70; }
			if (countR > 6 && countR <= 8) { TopP = 105; }
					
			$(this).animate({left: LefP + '%', top: TopP + '%'}, 1000);
			
			countR = countR + 1;
		});
	
	}else{
		$('.jobs li').removeAttr('style');
	}	

	$('.content').fadeIn();

	$('.content .innerSpace').hide();

	$('.jobsNav').hide();
	

});

$('.conDrop').click(function () {
	$('.contact').slideToggle();
});

