// Create elements =============================================================
document.createElement("bonus");
document.createElement("container");
document.createElement("homepage");
document.createElement("column");
document.createElement("top");
document.createElement("posts");
document.createElement("article");
document.createElement("twitter");
document.createElement("rss");
document.createElement("facebook");
document.createElement("friends");
document.createElement("nav");
document.createElement("info");
document.createElement("contact");
document.createElement("footer");

// External links ==============================================================
this.blankwin = function(){
	var hostname = window.location.hostname;
	hostname = hostname.replace("www.","").toLowerCase();
	var a = document.getElementsByTagName("a");	
	this.check = function(obj){
		var href = obj.href.toLowerCase();
		return (href.indexOf("http://")!=-1 && href.indexOf(hostname)==-1) ? true : false;				
	};
	this.set = function(obj){
		obj.target = "_blank";
		obj.className += " " + "external";
	};	
	for (var i=0;i<a.length;i++){
		if(check(a[i])) set(a[i]);
	}		
};
// script initiates on page load.
this.addEvent = function(obj,type,fn){
	if(obj.attachEvent){
		obj['e'+type+fn] = fn;
		obj[type+fn] = function(){obj['e'+type+fn](window.event );};
		obj.attachEvent('on'+type, obj[type+fn]);
	} else {
		obj.addEventListener(type,fn,false);
	}
};
addEvent(window,"load",blankwin);

// Tooltip =====================================================================
/*
 * Tooltip script 
 * powered by jQuery (http://www.jquery.com)
 * 
 * written by Alen Grakalic (http://cssglobe.com)
 * 
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 *
 */
this.tooltip = function(){	
	/* CONFIG */		
		xOffset = 0;
		yOffset = 15;
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$("a.tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<span id='tooltip'>"+ this.t +"</span>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("slow");
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};
// starting the script on page load
$(document).ready(function(){
	tooltip();
});

// Scroll to comments ==========================================================
$(document).ready(function(){
  $('a[href*=#comment-hook]').click(function() {
    if (location.pathname.replace(/^\//,") == this.pathname.replace(/^\//,")
    && location.hostname == this.hostname) {
      var $target = $(this.hash);
      $target = $target.length && $target
      || $('[name=' + this.hash.slice(1) +']');
      if ($target.length) {
        var targetOffset = $target.offset().top;
        $('html,body')
        .animate({scrollTop: targetOffset}, 1500);
       return false;
      }
    }
  });
});

$(document).ready(function(){
  $('a[href*=#top]').click(function() {
    if (location.pathname.replace(/^\//,") == this.pathname.replace(/^\//,")
    && location.hostname == this.hostname) {
      var $target = $(this.hash);
      $target = $target.length && $target
      || $('[name=' + this.hash.slice(1) +']');
      if ($target.length) {
        var targetOffset = $target.offset().top;
        $('html,body')
        .animate({scrollTop: targetOffset}, 1500);
       return false;
      }
    }
  });
});

// Comment Reply
$(document).ready(function(){
    $('.comment-reply-link').click(function(){
      $('div.reply-highlight').removeClass('reply-highlight');
      $(this).parent().parent().addClass('reply-highlight');
    });
	$('#cancel-comment-reply-link').click(function(){
		$('div.reply-highlight').removeClass('reply-highlight');
	});
});

// Masonry
$(document).ready(function(){
	$('single ul , single ol').masonry();
});	

