(function($) {
$(function() {
$(document).ready(function() {

	$('ul.tabs').delegate('li:not(.current)', 'click', function() {
		
		$(this).addClass('current').siblings().removeClass('current')
			.parents('div.section').find('div.box').hide().eq($(this).index()).fadeIn(150);
            


            //var temp = this.id;

            if ($(this).parents(".tabs").attr('id') == 'days')
            {
               	str = $('ul#events li.current');
 		     	id = str.attr('id');
                  day = $(this).attr('val');
             
            }

            if ($(this).parents(".tabs").attr('id') == 'events')
            {
			str = $('ul#days li[current=\'yes\']');
                  id = this.id;
             	day = str.attr('val');
            }
		
		var temp = id;

		$.ajax({ 
                  url: "/afisha_preview/",  
                  cache: true,
				  data :({id :id, day1: day}),
				  dataType : "html",
                  beforeSend : function(){
				 $("div[id='"+temp+"']").html('<div id = \'preloader\' style  =\'height:262px;\'><center><br/><br/><br/><br/><br/><br/><br/><br/>Идет загрузка</center></div>');
                         },
                  success: function(html){  
                      $("div[id='"+temp+"']").html(html);
                      $("#preloader").hide();
                      if ($('#qty').text() == 0)
                      {

				$("div[id='"+temp+"']").html('<div id = \'preloader\' style  =\'height:262px;\'><center><br/><br/><br/><br/><br/><br/><br/><br/>Событий нет</center></div>');
                      }

                      if($('#qty').text() > 4)
                       {
                         $('#all_happend').css('display','block');
                       }
                      else
                      {
    				 $('#all_happend').css('display','none');
                         
                      }
                    }  
                });
                $('#qty').remove();
 
	})

      $('#all_happend').click(function(){
		str1 = $('ul#days li[current=\'yes\']');
		str2 = $('ul#events li.current');
            
            id = str2.attr('id');
		day = str1.attr('val');


		$.ajax({ 
                  url: "/afisha_preview/",  
                  cache: true,
				  data :({id :id, day1: day, limit: 'no'}),
				  dataType : "html",
                  success: function(html){  
                      $("div[id='"+id+"']").html(html);
                    }  
                });
            
            $(this).hide();

	})

})
})
})(jQuery)
