﻿$(document).ready(function(){

	$(".legislation h2").click(function(){
		$(this).next("ul").slideToggle("fast")
		.siblings("ul:visible").slideUp("fast");
		$(this).toggleClass("active");
		$(this).siblings("h2").removeClass("active");
	});
	
	  $("#fade1, #fade2, #fade3").idTabs(function(id,list,set){ 
    $("a",set).removeClass("selected") 
    .filter("[@href='"+id+"']",set).addClass("selected"); 
    for(i in list) 
      $(list[i]).hide(); 
    $(id).fadeIn("fast"); 
    return false; 
	  });
	  
	   $("#top_news").idTabs("!mouseover"); 

        $(function() {
		$("#datepicker").datepicker({dateFormat: 'dd M yy', minDate: new Date(2009, 1 - 1, 1), maxDate: '+0D'});
	});
	  
	$(".sitemap-slide").click(function(){
		$("#panel-site_map").slideToggle(100);
		$(this).toggleClass("active"); return false;
	});
	
	$.fn.inputDefualts = function(options) {
		var defaults = {
 			cl: 'inactive',
 			text: this.val()  
  		}, 	opts = $.extend(defaults, options);	
  		
  		this.addClass(opts['cl']);
  		this.val(opts['text']);
  		
  		this.focus(function() {
  			if($(this).val() == opts['text']) $(this).val('');
  			$(this).removeClass(opts['cl']);
  		});
  		
  		this.blur(function() {
  			if($(this).val() == '') {
  				$(this).val(opts['text']);
  				$(this).addClass(opts['cl']);
  			}
  		});
	};
	
	$('#search_input').inputDefualts({
		cl: 'inactive',
		text: 'Поиск'
	});

	//Show Banner
	$(".top_news-image .desc").show(); //Show Banner
	$(".top_news-image .block").animate({ opacity: 0.85 }, 1 ); //Set Opacity

	//Click and Hover events for thumbnail list
	$(".top_news-teaser ul li:first").addClass('active'); 
	$(".top_news-teaser ul li").mouseover(function(){ 
		//Set Variables
		var imgAlt = $(this).find('img').attr("alt"); //Get Alt Tag of Image
		var imgTitle = $(this).find('.block img').attr("src"); //Get Main Image URL
		var imgDesc = $(this).find('p').html(); 	//Get HTML of block
		var imgTime = $(this).find('span').html(); 	//Get HTML of block
		var imgDescHeight = $(".top_news-image").find('.block').height();	//Calculate height of block	
		
		if ($(this).is(".active")) {  //If it's already active, then...
			return false; // Don't click through
		} else {
			//Animate the Teaser		
			$(".top_news-image img").animate({ opacity: 0}, 100 );
			$(".top_news-image .block").animate({ opacity: 0, marginBottom: "0" }, 100 , function() {
				$(".top_news-image .block").html(imgDesc).animate({ opacity: 0.85,	marginBottom: "0" }, 100 );
				$(".top_news-image .time").html(imgTime).animate({ opacity: 0.85,	marginBottom: "0" }, 100 );
				$(".top_news-image img").attr({ src: imgTitle , alt: imgAlt}).animate({ opacity: 1}, 100 );
			});
		}
		
		$(".top_news-teaser ul li").removeClass('active'); //Remove class of 'active' on all lists
		$(this).addClass('active');  //add class of 'active' on this list only
		return false;
		
	}) .hover(function(){
		$(this).addClass('hover');
		}, function() {
		$(this).removeClass('hover');
	});
			
	//Toggle Teaser
	$("a.collapse").click(function(){
		$(".top_news-image .block").slideToggle();
		$("a.collapse").toggleClass("show");
	});
	
});


