$(document).ready(function() {
	
  // show and hide block
  $('.slick-toggle').click(function() {
   $(this).next('.slickbox').slideToggle("slow");
  });
  
  $('.slick-toggle2').click(function() {
   $('.slickbox2:first').slideToggle("slow");
  });  

  $('.shut').click(function() {
  	$(this).parent().parent().find(".slickbox").slideToggle();
  });

  $(".add").click(function() { 
  	var article = $(this).parent().parent().find("input[name='article']").val();
  	var fk = $(this).parent().parent().find("input[name='fk']").val();
  	var user = $(this).parent().parent().find("input[name='user']").val();
  	var comment = $(this).parent().parent().find("textarea[name='comment']").val();
  	comment = comment.replace(/\n/gi, '<br />');
  	
  	$(this).parent().parent("div").slideToggle("slow");
  	$(".added").slideToggle("slow");
  	
	//define ajax config object
	var ajaxOpts = {
		type: "post",
		url: "http://www.training.com.ua/ajax/addcomment.php",
		data: "&article=" + article + "&fk=" + fk + "&user=" + user + "&comment=" + comment,
		success: function(data) {
			
		}
	};
	$.ajax(ajaxOpts);
  });

  $('.action_row').mouseover(function() {
   $(this).children('td').css('background-color','#f2f2f2');
  }).mouseout(function(){
   $(this).children('td').css('background-color','');
  });
    
  $('.action_row').click(function(event) {
  	var action_link = $(this).find('.action_link').eq(0).attr("href");
   if(event.target.nodeName != "A"){
    window.location.href = action_link;
   }
  });
  
  $('.phone_button').mouseover(function() {
   $(this).css('border-color','#0B669E');
   $(this).css('cursor','pointer');
  }).mouseout(function(){
   $(this).css('border-color','');
    });   
  
  $(".phone_button").click(function() { 
  	var action_id = $(this).children('a').attr("name");
  	$obj = $(this);
  	
	var ajaxOpts = {
		type: "get",
		url: "http://www.training.com.ua/action",
		data: 'method=ajax&type=phone_click&action='+ action_id,
		success: function(data) {
		 $obj.css('display','none');	
		 $obj.next('div').css('display','block');	
		}
	};
	$.ajax(ajaxOpts);
  }); 
  
  $(".phone_vip_button").click(function() { 
  	var action_id = $(this).attr("name");
  	$obj = $(this);
  	
	var ajaxOpts = {
		type: "get",
		url: "http://www.training.com.ua/action",
		data: 'method=ajax&type=phone_click&action='+ action_id,
		success: function(data) {
		}
	};
	$.ajax(ajaxOpts);
  });     
    

  $('.phone_feedback li').mouseover(function() {
   $(this).css('border','1px solid #D7D7D7');
  }).mouseout(function(){
   $(this).css('border','1px solid #fff');
  });   
  
  $('.report_phone').click(function() {
  	$('.phone_feedback').slideToggle();
  }); 
  
  $('.phone_feedback li').click(function() {
  	
  	var feed_type = $(this).attr('class');
  	
  	$('.phone_feedback').slideToggle();
  	$('.report_phone').remove();
  	$('.ty').css('display','block');
  	
	var ajaxOpts = {
		type: "get",
		url: "http://www.training.com.ua/action",
		data: 'method=ajax&type=phone_feedback&feed_type='+ feed_type,
		success: function(data) {
		 $obj.css('display','none');	
		 $obj.next('div').css('display','block');	
		}
	};
	$.ajax(ajaxOpts);  	
  });    
   
  $("#from").attr("disabled", false);
  $("#to").attr("disabled", false);
  $("#autocomplete").attr("disabled", false);
  $("#autocomplete").attr("value", "");
  
  $("#autocomplete").focus(function() {
	$(this).autocomplete(data,{
		matchContains: true,
		minChars: 1,
		formatItem: function(row, i, max) {
			return row.to;
		},
		formatMatch: function(row, i, max) {
			return row.to;
		},
		formatResult: function(row) { 
			return row.to;
		}
	}).result(function(event, item) {
  	location.href = item.url;
	});  	
  });
  
  $("#keywords").focus(function() {
	$(this).autocomplete(data,{
		matchContains: true,
		minChars: 1,
		formatItem: function(row, i, max) {
			return row.to;
		},
		formatMatch: function(row, i, max) {
			return row.to;
		},
		formatResult: function(row) { 
			return row.to;
		}
	}).result(function(event, item) {
	location.href = item.url;
	});  	
  });

	var aImgFolding=$('img.folding');
	aImgFolding.each(function(i, img){
		var divComment = $(this).parent('div').children('div.comment-children:first');
		if (divComment && divComment.children('div.comment')[0]) {
		  $.makeImg($(this));
		} else {
			$(this).css('display','none');
		};
	}); 
	
  $('.dashed').mouseover(function() {
   $(this).removeClass("dashed");
   $(this).addClass("dashedhover");
  }).mouseout(function(){
   $(this).removeClass("dashedhover");
   $(this).addClass("dashed");
    });   
    
  $("#center").change( function() 
  {
	if($(this).val()>0)
	{
	 $('#theme_block').slideDown('slow');
	 
	 var list = document.getElementById("theme");
	 list.options.length = 0; 
	 
	 if(themes[$(this).val()])
	 {
	 	list.options[0] = new Option('Все специализации', 0);
	 	var j=1;
	    for (y=0; y < themes[$(this).val()].length; y++)
	    {
	     if(typeof(themes[$(this).val()][y]) != "undefined")
	     {	
	      list.options[j] = new Option(themes[$(this).val()][y], y);
	      j=j+1;
	     }
	    }	 	
	 }	 
	}
	else
	 $('#theme_block').slideUp('slow');
  }); 
  
  if ($('#mycarousel').length>0) {
   $('#mycarousel').jcarousel();
  }
  
  if ($('.carousel').length>0) {
	$(".carousel").jCarouselLite({
		vertical: true,
		hoverPause:true,
		visible: 1,
		auto:2000,
		speed:2000
	});
  }
  
  
  $('#corp').click(function() 
  {
   var type = document.getElementById("type");
   type.value='corp';
   
   $('#corp').html("Корпоративный");
   $('#open_active').html("");
   $('#corp_active').html("<img src='/images/galka.gif'>");
   $('#open').html("<a href='#'>Открытый</a>");
   $('#open_block').slideUp('slow');
   
  }); 
  
  $('#open').click(function() 
  {
   var type = document.getElementById("type");
   type.value='open';
   
   $('#open').html("Открытый");
   $('#open_active').html("<img src='/images/galka.gif'>");
   $('#corp_active').html("");
   $('#corp').html("<a href='#'>Корпоративный</a>");   
   $('#open_block').slideDown('slow');
  });   
  

  $('#article').click(function() 
  {
   $('#release').removeClass("block2");
   $('#release').addClass("head10");
   
   $('#article').removeClass("head10");
   $('#article').addClass("block2");
  	
   $('#release_block').hide();
   $('#article_block').show();
  }); 
  
  $('#release').click(function() 
  {
   $('#article').removeClass("block2");
   $('#article').addClass("head10");
   
   $('#release').removeClass("head10");
   $('#release').addClass("block2");  	
  	
   $('#article_block').hide();
   $('#release_block').show();
  });

  $('#comment').click(function() 
  {
   $('#topic').removeClass("active");
   $('#comment').addClass("active");
  	
   $('#topics_block').hide();
   $('#comments_block').show();
  }); 
  
  $('#topic').click(function() 
  {
   $('#comment').removeClass("active");
   $('#topic').addClass("active");  	
  	
   $('#comments_block').hide();
   $('#topics_block').show();
  });
  
});

 
$.fn.release_list=function()
{
 var b=this;
  $(b).find("li").each(function()
   {
    var c=$(this).find(".tooltip-container");
    $(this).children("a").leviTip({sourceType:"element",source:c,addClass:"tooltip",dropShadow:false})
   })
}; 


