/* LOAD CUFON JSs ON WINDOWS OS */

if (navigator.appVersion.indexOf("Win")!=-1) 
{
	// loadScript("/js/cufon-yui.js", null);
	// loadScript("/js/Uni-Sans-SemiBold_400.font.js", null);
	loadScript("/js/cufon_replace.js", null);
}	

function loadScript(url, callback)
{
	// adding the script tag to the head as suggested before
   var head= document.getElementsByTagName('head')[0];
   var script= document.createElement('script');
   script.type= 'text/javascript';
   script.src= url;

   // then bind the event to the callback function 
   // there are several events for cross browser compatibility
   script.onreadystatechange = callback;
   script.onload = callback

   // fire the loading
   head.appendChild(script);
}
/* LOAD CUFON JSs ON WINDOWS OS */

function showBody()
{
	$("body").fadeIn();
}

var current_supporters;
var supporters_interval;

function switch_supporters()
{
  var supporters_count = $("ul#supporters li").length;
  var next_supporters = (current_supporters + 1) % supporters_count;
  
  $("ul#supporters li").animate({opacity:0},300,"linear",function(){
			$(this).animate({opacity:1},300);
			$('ul#supporters li.active').removeClass('active');
			$('ul#supporters li:eq(' + next_supporters + ')').addClass('active');
  });
  
  current_supporters = next_supporters;

}

$(document).ready(function () {	
	/* SUPPORTERS */
	current_supporters = 0;
	supporters_interval = setInterval ("switch_supporters()", 10000);	// switch supportners every 10 seconds;

    setTimeout ('showBody()', 500);
	  
    
    /* next article box and go to top button */
    
    var $nextArticleDiv = $("#next_article");
    var $goTopDiv = $("#go_to_top");
    var height= $(window).height();
    
    
	$(window).scroll(function(){	
		var article_height= $('#article_content').height();
		
		if($(window).scrollTop()>article_height-300){
			$nextArticleDiv.show();
		}
		if($(window).scrollTop()<article_height-300){
			$nextArticleDiv.hide();
		}
		
		if($(window).scrollTop()>500){
			$goTopDiv.show();
		}
		if($(window).scrollTop()<500){
			$goTopDiv.hide();
		}
					
		$nextArticleDiv
			.stop()
			.animate({"top": ($(window).scrollTop() + (height-150)) + "px"}, "fast" );			
		
		$goTopDiv
			.stop()
			.animate({"top": ($(window).scrollTop() + (height-350)) + "px"}, "fast" );			
	});
	/* next article box and go to top button */

	/* replace tab titles discqus comments */

	$('li#dsq-combo-tab-people a').html('Top commentators');
	$('li#dsq-combo-tab-recent a').html('Recent comments');
	$('li#dsq-combo-tab-popular a').html('Popular articles');
	
});

$(document).ready(function() {
	$("a.anchorLink").anchorAnimate()
});

jQuery.fn.anchorAnimate = function(settings) {

 	settings = jQuery.extend({
		speed : 1100
	}, settings);	
	
	return this.each(function(){
		var caller = this
		$(caller).click(function (event) {	
			event.preventDefault()
			var locationHref = window.location.href
			var elementClick = $(caller).attr("href")
			
			var destination = $(elementClick).offset().top;
			$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, settings.speed, function() {
				window.location.hash = elementClick
			});
		  	return false;
		})
	})
}

