$(document).ready(function() {
   // do stuff when DOM is ready
   //$.localScroll();
   
   // qTip
   $.fn.qtip.styles.mystyle = { // Last part is the name of the style
   		name: 'dark', 
		border: {
			width: 7,
			radius: 5,
			color: '#333333'
		},
		tip: true
	}
	
   $('.qtip').qtip({
	   show: 'mouseover',
	   hide: 'mouseout',
	   style: {name: 'mystyle'}
	})
	
	$('.active_advert img').each(function()
   {
      $(this).qtip(
      {
        style: {
            padding: '8px',
            name: 'dark',
            background: '#333333',
            border: {
    			width: 3,
    			radius: 8,
    			color: '#333333'
             },
		    tip: true
         },
         position: { adjust: { screen: true } },
         hide: {
            delay: 1000,
            fixed: true
         }
      });
   });
	
	//$('a[title]').qtip({ style: { name: 'mystyle' } })
	//$('img[title]').qtip({ style: { name: 'mystyle' } })
	
	// LI animation
	var fadeDuration = 150; //time in milliseconds
	
	$('.v-animated-list li a').hover(function() {
        $(this).animate({ paddingLeft: '30px' }, fadeDuration);
        $(this).append("<span></span>");
        $(this).children('span').show().animate({ left: -5 }, fadeDuration);
    }, function() {
        $(this).animate({ paddingLeft: '0px' }, fadeDuration);
        $(this).children('span').animate({ left: -35 }, fadeDuration).fadeOut(fadeDuration, 
            function() {
                $(this).children('span').remove();
            }
        );          
    });
});

function vote(id, direction) {
    $.post('/pixels/'+id+'/'+direction+'vote/', {HTTP_X_REQUESTED:'XMLHttpRequest'},
    function(data) {
        if (data.success == true) {
            $('#'+id+'score').text(data.score.score);
            //$('#'+id+'num_votes').text(data.score.num_votes);
        } else {
            add_error('ERROR: ' + data.error_message);
        }
    }, 'json')
    
    return false;
}

function add_error(message) {
    if($('#messages').length > 0) {
        $('#messages').append('<li><span>' + message + '</span></li>');
    }
    else {
        $('#content-inner').prepend('<ul id="messages" class="plain-list error"><li><span>' + message + '</span></li></ul><br/>');
    }
};

function blockuimessage_css() {
    css = { 
        border: 'none', 
        padding: '0px 15px 15px 15px', 
        backgroundColor: '#000', 
        '-webkit-border-radius': '10px', 
        '-moz-border-radius': '10px', 
        opacity: .5, 
        color: '#fff'
    }
    return css
}