$(function() {
		$('body').addClass('Ready');
		Cufon.refresh();
		
		
		
			$("body .Cl.Cl350 .Cl2-2 img.Gray").each(function(){
				Pixastic.process(this, "desaturate");
		});	
		$("body .Cl.Cl350 .Cl2-2").hover(function() { 
				Pixastic.revert($(this).find('canvas').eq(0)[0]);
		} , function() { 
				Pixastic.process($(this).find('img').eq(0)[0], "desaturate");
		});
		
		
  					
																
		$('.BtView.On.Articles a').click(function() {
				$x = $(this).attr('class');
				$class = $x.split(' ');
                    
				$('.BtView.Articles a').each(function() {
						$(this).removeClass('current');
				});
				$(this).addClass('current');  
                    
				$('.Articles').each(function() {
						$(this).removeClass('List');
						$(this).removeClass('Block');
				});
				$('.Articles').addClass($class[0]); 
                    
				$ArticlesView = $class[0];
				$.cookie('ArticlesView',$ArticlesView,{
						expires: 7,
						path: '/',
						domain: 'blog.sensors.pl'
				});
		});
                
                
		$('.BtView.Authors a').click(function() {
				$x = $(this).attr('class');
				$class = $x.split(' ');
                    
				$('.BtView.Authors a').each(function() {
						$(this).removeClass('current');
				});
				$(this).addClass('current');  
                    
				$('.Authors').each(function() {
						$(this).removeClass('List');
						$(this).removeClass('Block');
				});
				$('.Authors').addClass($class[0]);
                    
				$AuthorsView = $class[0];
				$.cookie('AuthorsView',$AuthorsView,{
						expires: 7,
						path: '/',
						domain: 'blog.sensors.pl'
				});
                   
		});
		
                
		$('.Categories a').click(function() {
				$(this).toggleClass("On");
          
		});
		$('.Categories .Hover .Checkbox').click(function() {	
				$Categories = '';
				$('input[type=checkbox]').each(function () {
						if (this.checked) {
								$Categories = $Categories + $(this).val() + ',';                     
						}
				});
                    
				$.cookie('CategoriesView',$Categories,{
						expires: 7,
						path: '/',
						domain: 'blog.sensors.pl'
				});
                    
				$(this).parent().parent().toggleClass('On');
		});
          
		  
		  
    
                
	
                
                
            
                
                
		$(".Gallery").scrollable({
				circular: false,
				prev: '.Gallerys .Nav .Prev',
				next: '.Gallerys .Nav .Next'
		});
                
                

  
               
															
															
															
		// Blog
		$('body img').each(function() {
				if($(this).height() < 21){
		//$(this).css('display','none');
		}
		});
                                
                                
		$('body blockquote').each(function() {
				$(this).html('<span class="Top"><span class="Bottom">'+$(this).html()+'</span></span>');
		});
			
                        
		function HeightBox()
		{
				$('.Articles .Rows').each(function() {
                        
						$m=0;
						$(this).find('.Article.Block').each(function() {
												
								if ($(this).css("display") == "none"){
									//	$(this).show();
										$('.Articles').removeClass('List');
										$('.Articles').addClass('Block');
										$o = $(this).outerHeight(true)+70;
										$('.Articles').removeClass('Block');
										$('.Articles').addClass('List');
									//	$(this).hide();
								}else{
										$o = $(this).outerHeight(true)+70;
								}
                            
								if($o>$m) $m=$o;                          
						});
						$(this).find('.Article.Block').each(function() {
								$(this).css('height',$m);
						});		
				});
		}
                
                
																
																
		$BiuroPrasoweH = $('.BiuroPrasowe').height();
		$TitterLiHSum = 0;
		$n = 0;
		$start = 0;
		$Play = true;
		$('ul.twitter li').each(function() {	
				$d1 = $BiuroPrasoweH - $TitterLiHSum;
				$TitterLiH = $(this).height();
				$TitterLiHSum += $TitterLiH;	
				$d2 = $BiuroPrasoweH - $TitterLiHSum;
        
				if($TitterLiHSum > $BiuroPrasoweH && $Play == true){
						if(Math.abs($d1) < Math.abs($d2)){
								$Play = false;
								$start = $n-1;
						}else{
								$Play = false;
								$start = $n;
						}
				}

				$n++;
		});
		$('ul.twitter li').eq($start).addClass('End');
		for($x = ($start+1); $x < $n; $x++){
				$('ul.twitter li').eq($x).css('display','none');
		}
																
																
																
		Cufon.CSS.ready(function() {
				HeightBox();
				$('body').addClass('Ready');
				Cufon.refresh();
		});  
         
		$('body.home .Article .Click').hover(function(){
				$(this).parents('.Article').eq(0).addClass('hover');
				$x = 	$(this).parents('.Article');
				Cufon.refresh();
		},function(){
				$(this).parents('.Article').eq(0).removeClass('hover');
				Cufon.refresh();
		});  
																												
		$('.Articles .Article .Click').hover(function(){
				$(this).parents('.Article').eq(0).addClass('hover');
				$x = 	$(this).parents('.Article');
				Cufon.refresh();
		},function(){
				$(this).parents('.Article').eq(0).removeClass('hover');
				Cufon.refresh();
		});
			
                        
                        
                    
                    
                    
		// Overlay                
                    
		$('.Rss a').click(function() {
				$("#Rss").data('overlay').load();
                     
		});  
		$('a.InformacjePrawne').click(function() {
				$("#InformacjePrawne").data('overlay').load();
                     
		});  
		$('a.SieciOrganizacyjne').click(function() {
				$("#SieciOrganizacyjne").data('overlay').load();
                     
		});  
    
    
		$(".Overlay").overlay({
				top: 160,
				mask: {
						color: '#000000',
						loadSpeed: 200,
						opacity: 0.8
				},
				closeOnClick: true,
		});
           
           
           
		$('.Categories a.More').click(function() {
				$(this).parent().toggleClass('Open');
		});
        
        
           


		$.tools.validator.localize("pl", {
				':Kod'    : 'Podaj kod',
				':email'  : 'Podaj email',
				'[required]'  : 'Wymagane'
		});
		$.tools.validator.fn("input[rel]", function(input, value) {
				var rel = input.attr("rel");
					
				return value != rel ? true : {     
						pl: "Wymagane"
				};
		});
		$.tools.validator.fn("textarea[rel]", function(input, value) {
				var rel = input.html();
					
				return value != rel ? true : {     
						pl: "Wymagane"
				};
		});
		$('#Kontakt').validator({
				lang: 'pl',
				offset: [18, 0],
				position: 'top right'
		}).submit(function(e){
				if (!e.isDefaultPrevented()) {
						$('.Information.Success').addClass('Show');
						$('.Information.Error').removeClass('Show');
						e.preventDefault();
				}else{
						$('.Information.Error').addClass('Show');
				}
		});







});



$(document).ready(function($) {
		$('body').addClass('Ready');
		$('body').css('visibility','visible');
		Cufon.refresh();
});

