var admin = false;
var splits = 1;

$(function(){

	admin = $("#amina-panel").length == 0 ? false : true;

	$(".fancy").fancybox({modal: true});





// VIZUAL
	$("#vizual li").hover(
		function(){
			$(this).find('ul').show(100);
		},
		function(){
			$(this).find('ul').hide(100);
		}
	);




	
// ROTATOR
	if(admin == false && $('.rotator').length != 0) {

		if($('.rotator li').length > 1) {

			$('.rotator').addClass('slidator');

			var _root = $('.slidator');
			var _vec = $('.slidator').find('ul');
			var _min = 0;
			var _max = ( _root.find('li').length - 1 ) * -650;

			_vec.width( ( _root.find('li').length * 650 ) + 'px' );
			
			$('<span class="next" />').appendTo('.slidator').click(function(){
				left = parseInt(_vec.css('left'));
				if($(this).hasClass('disable') || left == _max) {
					return false;
				}
				else {
					_root.find('.prev').removeClass('disable');
					_anim = left - 650;
					_vec.animate({left: _anim + 'px'}, 300);
					if(_anim == _max) {
						$(this).addClass('disable');
					}
				} 
				
			});

			$('<span class="prev disable" />').appendTo('.slidator').click(function(){
				left = parseInt(_vec.css('left'));
				if($(this).hasClass('disable') || left == _min) {
					return false;
				}
				else {
					_root.find('.next').removeClass('disable');
					_anim = left + 650;
					_vec.animate({left: _anim + 'px'}, 300);
					if(_anim == _min) {
						$(this).addClass('disable');
					}
				} 
				
			});

		}
		
	}



	$('table tbody tr:odd').addClass('odd');
	$('tr').each(function(){
		$(this).children(':first').addClass('first');
	});






// SOLUTION
	$('.more-split a').click(function(){
		splits = splits + 1;
		$('.split:last').after( $('.split:last').clone() );
		$('.split:last label').attr('for', 'split-' + splits);
		$('.split:last select').attr('id', 'split-' + splits);
		resplit();		
		return false;
		
	});
	$('.remove_split').live('click', function(){
		$(this).parent().remove();
		resplit();
		return false;
	});
	$('#solution-form input[type=number]').live('change', function(){
		$(this).val( Math.abs( $(this).val() ) );
	});
	$('#solution-form input[type=number]').live('blur', function(){
		$(this).val( Math.abs( $(this).val() ) );
	});
	
	

	if($(".homepage").length == 0) {
		$("#aside").height( $("#main").height() );
		$('img').load(function(){
			$("#aside").height( $("#main").height() );
		});
	}
	
	
	$(".reply").click(function(){
		if($('#name').length)
			$('#name').focus();
		else if($('#post').length)
			$('#post').focus();
	});
	
});


function resplit() {
	i = 1;
	$('.split').removeClass('first');
	$('.split:first').addClass('first');
	$('.split').each(function(){
		$(this).find('label').text('Split ' + i);
		$(this).find('[type=hidden]').val('Split ' + i);
		i++;
	});
}
