// Simple JQuery Collapsing menu. web: http://www.i-marco.nl/weblog/ 
function initMenu() {
  $('#menu ul').hide();
  $('#menu li a').click(
    function() {
        $(this).next().slideToggle('normal');	
      }
    );
  }
$(document).ready(function() {initMenu();});


function Setclasslimenu(id)
{
	var element = document.getElementById(id);
	if(element.className == '')
	{
	element.className = 'on_li_menu';
	}
	else
	element.className = '';
}

$(document).ready(function() {
// Добавлено декабрь 09
function opa()
{
$(".opa").hover(function () {$(this).fadeTo("fast", 0.7);},
  function() {$(this).fadeTo("fast", 1);});
}
opa();
// Для поиска						   
$('#search_ex_, #ex_hide').click(function(){
$('#search_ex_, #search_ex').toggle();
										  });
$('#search_ex p').click(function(){
$('#search_ex p').addClass("decor");
$(this).removeClass("decor");
$('#search_ex input').val($("#search_ex p").index(this));
								 });
// надписи в полях инпут
$('input.q').focus(function(){
ds_value = $(this).val();
$(this).val('');
							});

$('input.q').blur(function(){
if ($.trim($(this).val()) == "") $(this).val(ds_value);
							});


$('span.password').click(function(){
$(this).next().focus();
})

$('input.password').focus(function(){
if($(this).val() == ' ') $(this).val(''); // для хрома, чтоб лишние символы убрать
$(this).prev().hide();								   
								  });
$('input.password').blur(function(){
if($.trim($(this).val()) == '') {
	
	$(this).val('');
	$(this).prev().show(); 		}
								  });

$('.sfull span').click(function(){
$('.sfull span').addClass("decor");
$(this).removeClass("decor");								
$('.sfull input').val($(".sfull span").index(this));								
								});
$('.stype span').click(function(){
$('.stype span').addClass("decor");
$(this).removeClass("decor");
$('.stype input').val($(".stype span").index(this));								
								});
// при загрузке назначаем отметки в поисковой форме
var s_full = $('.sfull input').val();
var s_type = $('.stype input').val();
$('.sfull span, .stype span').addClass("decor");
$('.sfull span').eq(s_full).removeClass("decor");
$('.stype span').eq(s_type).removeClass("decor");
// Добавлено янв. 10
// Для добавления уроков в закладки
$('#favorite').click(function(){
$(this).addClass('sendf');
$(this).children('img').show();
$(this).children('span').html('&nbsp;Работаю...');

$.post(
"add_favorite.php",
{lesUrl:encodeURI(location)}, 
function(data){
	$('#favorite').removeClass('sendf');
	$('#favorite img').hide();
	$('#favorite span').html(data);
	$('#favorite').unbind();
	}
	   )
							  });

//  в комментах
	$("#add_userjob, #add_screen").live('click', function(){
	addfilefield('to_add', $(this).attr('id'));
	return false
	});	

// * регистрация с сайта * // 

// Опросы
$('.form_poll button').click(function(){
var id_form = $(this).parents('form').attr('id');
$('#'+id_form).next().children('.loader').show();
$(this).hide();
info1 = $('#'+id_form).serialize()+"&id_form="+id_form;
$.post(
"update_poll.php",
info1,
function(data){
$('#'+id_form).next().children('.loader').hide();
json = eval("(" + data + ")");
if(json.error) 
{
	$('#'+id_form + ' button').show();
	alert(json.error);
}
else 
{
	 $('#'+id_form).next().children('.loader').remove();
 	 $('#'+id_form).prev().html(json.good);
	 $('#'+id_form).remove();
}

	}
	   )
return false
									  });

$('.erase_comment').live('click',function(){
$(this).hide();
$(this).prev().show();
var user_id = $(this).next().children().children().attr('href');
var comm_id = $(this).attr('id');

$.post(
"del_mycomment.php",
{user_id:user_id, comm_id:comm_id},
function(data){
	if(data) alert(data);
	else  $('#'+comm_id).parents('.Comment').remove();
})
								   });

// colorbox
function ColorboxCallback(){
opa();
// user_ball
var this_height = $('#content_view_job').height() + 40;
$('#cboxLoadedContent').height(this_height);
$("img.opa").click(function(){
var ball = $(this).attr('alt');
$(this).parent().prev().show();			
$(this).parent().hide();
$.get(
"ajax_block/update_view_job.php",
{id: $('img#user_job').attr('alt'), ball: ball}, 
function(data){
json = eval("(" + data + ")");	
if(json.error) alert(json.error); 
else { $("#content_ball_job").html('<p>'+json.TotalBall+'</p><p>'+json.ContentBall+'</p>');
delta = parseInt($("#limitball li strong").eq(1).text()) - 1; $("#limitball li strong").eq(1).text(delta);
$('#total_ball_for'+json.CommId).html('<h5>'+json.CommBall+'<small>'+json.CommVoice+'</small></h5>');
}
               }
	   )
							});
                              };
$("a[rel='lightbox[roadtrip]'], a[rel='lightbox']").colorbox();
$("a.view_user_job").colorbox({width:850}, ColorboxCallback);	

						   });

// Прокрутка реламных блоков курсов 

    function mt_rand (min, max) { 
        var argc = arguments.length; if (argc === 0) {
            min = 0; max = 2147483647;
        } else if (argc === 1) { throw new Error('Ошибка: mt_rand передан 1 параметр, а нужно 2 ');
        } return Math.floor(Math.random() * (max - min + 1)) + min;
    }

                          
$(document).ready(function() { 
      var contents = $('#rotator_conteiner li');
      var countContent  = contents.length;
      var IntervalStart = 40;
      var randFlag = false;
      function getCurrentIndex(){
            if(!randFlag) {
              currentIndex = mt_rand(0,countContent-1);
              randFlag = true; 
            }
            else{
                currentIndex = currentIndex+1;
                if(currentIndex == 3) currentIndex = 0;
            }
            return currentIndex;
    }
      function viewContent(elemantIndex){
        contents.eq(elemantIndex).siblings().animate({top:400},
        {   duration: 500,
            queue: false
        })
        contents.eq(elemantIndex).animate({ 
            top:0 
        },{
            duration: 500,
            queue : false
        });
       }
        var currentIndex = getCurrentIndex();
        viewContent(currentIndex);       
      setInterval(function(){
         var currentIndex = getCurrentIndex();
         viewContent(currentIndex);
      },IntervalStart*1000)
        
})                           