var $j = jQuery.noConflict();

$j(function(){
	$j(document).ready(function(){
	//console.log($j('.widget_democracy em.dem-total-votes').length);
		
		if($j('#searchform #s').length == 1){
			$j('#searchform #s').val('przeszukaj bloga...');
		
		
			$j('#searchform #s').focus(function() {
				$j('#searchform #s').val('');
			});
			
			
			$j('#searchform #s').blur(function() {
				if($j('#searchform #s').val() == ''){
					$j('#searchform #s').val('przeszukaj bloga...');
				}
			});
			
		}
		
		$j('.random_from_cat a').each(function(index) {
/*     		console.log(index + ': ' + $j(this).text()); */
    		
    		var elem = $j(this);
    		if($j('#sidebar').hasClass('home')){
    			var limit = 45;
    		} else {
    			var limit = 39;
    		}
                            
            var str = elem.text();
            var count = str.length
            if(count > limit){       
            var strtemp = str.substr(0,limit);   
               	str = strtemp + '...<span style="display: none;">' + str.substr(limit,str.length) + '</span>';
                elem.html(str);
            }
		});
		
		
		
		if($j('.widget_democracy em.dem-total-votes').length > 0){
			$j('<div class="clear"></div>').insertBefore($j('.widget_democracy em.dem-total-votes:first'));
			$j('.widget_democracy .wiecej').css({'margin-top':'0px !important','clear':'both'});
		}
			
		$j('#admin').mouseenter(function(){
			$j('#admin').css('background-position-y','35px');

		}).mouseleave(function(){
			$j('#admin').css('background-position-y','0px');
		});
		$j('#admin').click(function () {
			window.location = 'wp-admin/';
		});
		
		$j('#facebook .tab').mouseenter(function(){
			$j('#facebook .tab').css('left','40px');
		}).mouseleave(function(){
			$j('#facebook .tab').css('left','37px');
		});
		
		$j('#facebook .tab').click(function () {
			$j('#facebook').animate({left: 0},200);
			$j('#facebook .tab').css('left','37px');
		});
		$j('#facebook').mouseleave(function(){
			$j('#facebook').animate({left: -300},150);
		});
	});
    
	if($j.browser.msie){
		$j('#content .posts h2.title').css('margin-right','30px;');
		$j('input.text').addClass('ieFix');
		$j('#content #commentform input, #content #commentform input#submit').addClass('ieFix');
		if($j.browser.version == '6.0'){
			$j('#facebook').css('display','none');
		}
	}
});
