$(document).ready(function(){
	
	$('#slider').nivoSlider({controlNav:false, effect: 'fade', pauseTime: 5000});
	
	$("#social a, .tip, abbr").tipsy({gravity: 's', fade: true});
	
	$("#content a, aside a").not(".storytitle a").each(function(){
		if($(this).attr('title') != '') {	
				$(this).tipsy({gravity: 's', fade: true});
				}
	});
	
	$("aside li a").each(function(){
		if($(this).attr('title') != '') {	
				$(this).tipsy({gravity: 'e'});
				}
	});
	
	$('#s').css('transform', 'rotate(-7deg)');
	$('#menu-about').css('transform', 'rotate(7deg)');
	$('#menu-portfolio').css('transform', 'rotate(7deg)');
	
	$('#s').focus(function(){
		searchtext = $('#s').attr('value');
		$('#s').attr('value', '');
			});
			
	$('#s').blur(function(){
		$('#s').attr('value', searchtext);
			});
			
		setInterval(function(){
		$('#twitter-status li').filter(':visible').fadeOut(500,function(){
			if($(this).next('li').size()){
				$(this).next().fadeIn(500);
			}
			else{
				$('#twitter-status li').eq(0).fadeIn(500);
			}
		});
	},9000);	

 $('.storycontent, .comment-text').selectedText({ 
    min: 3, 
    stop: function(text, e) { 
        $('#contextmenu').css({ 
        top: (e.pageY+10)+'px', 
        left: (e.pageX+10)+'px'
        }).fadeIn();
		  
		  $('#ctx-text').attr('value', text);
    } 
    }); 
    var timeout; 
    $('#contextmenu').mouseout(function() { 
    timeout = setTimeout(function() { 
        $('#contextmenu').fadeOut(); 
    },500); 
 
    }).mouseover(function() { 
    clearTimeout(timeout); 
    }); 
   
    $('#ctx-reply').click(function() { 
    window.location='#comment';
    var quote = '<quote>' + $('#ctx-text').attr('value') + '</quote>'
    $('#comment').val(quote);
 
    }); 
    
    $('#ctx-search').click(function() { 
    window.open('http://google.pl/search?q=' + $('#ctx-text').attr('value'));
    
 
    }); 
	 
	 $("a.fancy").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	true,
		'overlayColor'	:	'#000',
		'centerOnScroll' : true,
		'titleShow'	: true,
		'titlePosition'	: 'inside'
	});


	 $("#content a img").parent().fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	true,
		'overlayColor'	:	'#000',
		'centerOnScroll' : true,
		'titleShow'	: true,
		'titlePosition'	: 'inside'
	});


	
	 $("a.fancy-swf").click(function() {
                 $.fancybox({
                'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	true,
		'overlayColor'	:	'#000',
		'centerOnScroll' : true,
		'titleShow'	: true,
                'href'                : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
                'type'                : 'swf',    // <--add a comma here
                'swf'                 : {'allowfullscreen':'true'} // <-- flashvars here
                  });
                 return false;

            }); 

	$(".menu li:has(ul) ").addClass('TopLevelMenu');
	$(".menu li:has(ul) ").hover(function(){
		$(this).children(' .sub-menu').slideDown('fast');
		},
		function(){
		$(this).children(' .sub-menu').slideUp('fast');	});


		$(".imgbox").hover(function(){
			$(this).children(".desc").fadeIn();		},
			function(){
			$(this).children(".desc").fadeOut();}
			);

		
		$('.recommend-btn').click(function fbs_click() {
			u=$(this).attr('rel');
			t=$(this).attr('title');
			window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
			return false;
			});

			$(".fb-share-btn").each(function(){
				var surl = $(this).attr("href");
				$(this).attr({
							'name': 'fb_share',
							'type': 'button_count',
							'share_url': surl
							});
							});
							


});
  
