$(document).ready(function() {
	$('#main-tabs.index').tabs();
	$('#demases').tabs({ selected: 1 });
	 simple_tooltip(".social a","tooltip");
	$(function() {
	$(".slider").slider(
	    { change: handleChange,
	        slide: handleSlide,
	        min: -100,
	    max: 16,
	orientation: 'vertical' });
	});
	$('.thumb img,.thumb .post-metadata, .pics img').hover(function(){
		$(this).animate({opacity: 0.8}, 200);
	}, function(){
		$(this).animate({opacity: 1}, 200);
	});

});
function handleChange(e, ui) {
    var maxScroll = $(".scroller")
      .attr("scrollHeight") -
      $(".scroller").height();
    $(".scroller")
      .animate({ scrollTop: -ui.value *
     (maxScroll / 100)
    }, 1000);

}

function handleSlide(e, ui) {
    var maxScroll = $(".scroller")
      .attr("scrollHeight") -
      $(".scroller").height();
    $(".scroller")
      .attr({ scrollTop: -ui.value
        * (maxScroll / 100)   });

}
function simple_tooltip(target_items, name){
 $(target_items).each(function(i){
		$("body").append("<div class='"+name+"' id='"+name+i+"'><p>"+$(this).attr('title')+"</p></div>");
		var my_tooltip = $("#"+name+i);

		if($(this).attr("title") != "" && $(this).attr("title") != "undefined" ){

		$(this).removeAttr("title").mouseover(function(){
					my_tooltip.css({display:"none"}).fadeIn(400);
		}).mousemove(function(kmouse){
				var border_top = $(window).scrollTop();
				var border_right = $(window).width();
				var left_pos;
				var top_pos;
				var offset = 3;
				if(border_right - (offset *2) >= my_tooltip.width() + kmouse.pageX){
					left_pos = kmouse.pageX+offset;
					} else{
					left_pos = border_right-my_tooltip.width()-offset;
					}

				if(border_top + (offset *3)>= kmouse.pageY - my_tooltip.height()){
					top_pos = border_top +offset;
					} else{
					top_pos = kmouse.pageY-my_tooltip.height()-offset;
					}	

				my_tooltip.css({left:left_pos, top:top_pos});
		}).mouseout(function(){
				my_tooltip.css({left:"-9999px"});
		});

		}

	});
}


