// JavaScript Document for Bin Base v1.0

/*------ Custom functions ---------*/

//* Vertical align element
(function ($) {
	$.fn.vAlign = function(container) {
		return this.each(function(i){
			if(container == null) {
				container = 'div';
			}
			$(this).html("<" + container + ">" + $(this).html() + "</" + container + ">");
			var el = $(this).children(container + ":first");
			var elh = $(el).height(); //new element height
			var ph = $(this).height(); //parent height
			var nh = (ph - elh) / 2; //new height to apply
			$(el).css('margin-top', nh);
		});
	};
})(jQuery);
/**/

jQuery(function($){
	$(document).ready(function(){
//------------ start ------------

/* TwitterJS
getTwitters('midFloater', {
	id: 'andisaleh', // Twitter ID 
	count: 1, 
	enableLinks: true, 
	ignoreReplies: true,
	timeout: 10,
	onTimeout: function () {
		this.innerHTML = '<div id="twStatus">Twitter sedang tidak bisa diakses saat ini, tapi Anda tetap bisa <a href="http://twitter.com/%user_screen_name%">mengikuti saya</a>.</div>';
	},
	onTimeoutCancel: true, // don't allow twitter to finsih the job
	template: '<div id="twStatus">%text%<br /><a style="font-size:0.75em" href="http://twitter.com/%user_screen_name%/statuses/%id%"><small>%time%</small></a></div><div class="twLink"><a title="Follow %user_screen_name%" href="http://twitter.com/%user_screen_name%"><strong>Follow me!</strong></a></div>'
});
/**/

/* Add favicons to external links
$("a.ext")
	.hover(
		function(){
			$(this).filter(function(){
				return this.hostname && this.hostname !== location.hostname;
			}).each(function() {
				var link = $(this);
				var faviconURL = link.attr('href').replace(/^(http:\/\/[^\/]+).*$/, '$1')+'/'+'favicon.ico';
				var faviconIMG = $('<img class="extIcon" src="" alt="" />')['appendTo'](link);
				var extImg = new Image();
				extImg.src = faviconURL;
				if (extImg.complete){
					faviconIMG.attr('src', faviconURL);
					link.addClass("extLink");
				} else {
					extImg.onload = function() { faviconIMG.attr('src', faviconURL); };
				}
			});
		},
		function(){
			$("img.extIcon", this).remove();
			$(this).removeClass("extLink");
		}
	);
/**/

/* Prepend empty span to element
$(".gradient").prepend("<span></span>");
/**/

//* Vertical align element
$("#blogRecentHome").vAlign();
/**/

//* Menu animation
$("#mainNav a").css({color: "black"});

$("#mainNav a").hover(
	function(){ $(this).animate({color: "white"}, { queue:false, duration:400}) },
	function(){ $(this).animate({color: "black", width: 1+"px"}, { queue:false, duration:400 })	});

$("#mainNav a.menuPort").hover(
	function(){ $(this).animate({width: 75+"px"}, { queue:false, duration:400}) },
	function(){ $(this).animate({width: 1+"px"}, { queue:false, duration:400 })	});
$("#mainNav a.menuBlog").hover(
	function(){ $(this).animate({width: 31+"px"}, { queue:false, duration:400}) },
	function(){ $(this).animate({width: 1+"px"}, { queue:false, duration:400 })	});
$("#mainNav a.menuProfil").hover(
	function(){ $(this).animate({width: 40+"px"}, { queue:false, duration:400}) },
	function(){ $(this).animate({width: 1+"px"}, { queue:false, duration:400 })	});
$("#mainNav a.menuKontak").hover(
	function(){ $(this).animate({width: 45+"px"}, { queue:false, duration:400}) },
	function(){ $(this).animate({width: 1+"px"}, { queue:false, duration:400 })	});
$("#mainNav a.menuSearch").hover(
	function(){ $(this).animate({width: 56+"px"}, { queue:false, duration:400}) },
	function(){ $(this).animate({width: 1+"px"}, { queue:false, duration:400 })	});
/**/

/* ThreeDots
$('.dots_3').ThreeDots({max_rows:3});
/**/

//* Autoheight and remove br
$("textarea.auto-size").TextAreaExpander(50,230); 
$('.wpcf7-form-control-wrap br').remove();
/**/

/* Expose
$(".portfolioItem").hover( 
    function() { 
        $(this).expose({color:"#000", loadSpeed:"fast", api: true}).load(); 
    }, 
    function() { 
         $(this).expose().close();     
    }     
);
/**/

//------------- end -------------
	});
});