$(document).ready(function(){
	$('#header ul li a').hover(function(){
		$('#header ul li').removeClass('active');
		$(this).parent().parent().addClass('active');
	}, function() {
		$(this).parent().parent().removeClass('active');
	})
	
	if($('#main .scrollable .items div').length == 1)
	{
		$('#main .nav').hide();
	}

	$('#main .back').hover(function(){
		$('a.more', this).css('text-decoration', 'underline');
	}, function(){
		$('a.more', this).css('text-decoration', 'none');
	});
	
	$("#main .scrollable").scrollable({
		next: 'a.right',
		prev: 'a.left'
	}).navigator("#navi");
	
	$('#navi').css('margin-left', -$('#navi').width()/2);

//var $groups = $('#index-scrollable div.group'),
//     groupsLength = $groups.length,
//     randNum = Math.floor ( Math.random ( ) * groupsLength + 1 );
     // show image that is nth child of image array
//     $groups.eq(randNum-1).css('z-index', 20);

	setInterval( "slideSwitch()", 10000 );
		
	$('.weight .easy_open_text a').click(function(){
		var unpack = $('#unpack');
		if(unpack.hasClass('hidden')) {
			unpack.removeClass('hidden');
			$(this).parent().css('position', 'absolute');
			$(this).css({
				'border-bottom': '1px dashed #fff'
			});
		} else {
			unpack.addClass('hidden');
			$(this).parent().css('position', 'static');
			$(this).css({
				'border-bottom': '1px solid #fff'
			});
		}
		
		return false;
	});
	
	$('#vacancy-list li span').click(function(){
		var $index = $('#vacancy-list li').index($(this).parent());
		var $vacancy = $('#vacancies-description .vacancy').eq($index);

		$('#main').css({overflow: 'visible'});
		$vacancy.show(10, function(){
			$('body').click(function(){
				$vacancy.hide();
				$('#main').css({overflow: 'hidden'})
			});
		});
		
		$('body').unbind('click');
	});

     	
//	$('#hand_made .scrollable .column').hover(function(){
//		$('a', this).css({
//			'text-decoration': 'underline'
//		});
//		$(this).css('cursor', 'pointer');
//	}, function(){
//		$('a', this).css({
//			'text-decoration': 'none'
//		});
//		$(this).css('cursor', 'default');
//	}).click(function(){
//		var href = $('a', this).attr('href');		
//		window.location = href;
//		return false;
//	})

$("#fields .box").hover( 
      function () {
            var id = $(this).attr('id');
            $('span#a'+id).show();
      }, 
      function () {
           var id = $(this).attr('id');
            $('span#a'+id).hide();
      }
    );

$("#fieldss .box").hover( 
      function () {
            var id = $(this).attr('id');
            $('span#a'+id).show();
      }, 
      function () {
           var id = $(this).attr('id');
            $('span#a'+id).hide();
      }
    );

});






function slideSwitch() {
	var groups = $('#index-scrollable div.group');
    var $active = $('#index-scrollable div.group.active');

    if ( $active.length == 0 ) 
		$active = $('#index-scrollable div.group:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length 
		? $active.next()
        : $('#index-scrollable div.group:first');
		
	groups
		.removeClass('next');

	$next.addClass('next');

    $active.addClass('last-active');

	$active.animate({opacity: 0.0}, 1000);
    $next.css({opacity: 0.0, 'z-index': 10})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active
				.removeClass('active last-active')
				.css({'z-index': 5, opacity: 0.0});
        });
}


