// Superfish Menu
jQuery(document).ready(function($){ 
	$('.menu-header .menu').superfish({
		animation: {opacity:'show',height:'show'}
	 })
});

// Cufon Font Replacement
Cufon.replace('h1, h2, h3, h4, h5, h6, .docufon', { hover: true });

// nth-child for portfolio/gallery
jQuery(document).ready(function($){
	$('ul.folioitem li:nth-child(10n+1)').css({'float' : 'right','margin-right' : '0'});
	$('ul.folioitem li:nth-child(8n+0)').css({'margin-right' : '0'});
	$('ul.folioitem li:nth-child(10n+0)').css({'margin-right' : '0'});
});

// nth-child for portfolio/gallery 4 column
jQuery(document).ready(function($){
	$('ul.gallery-four-boxes li:nth-child(4n+0)').css({'margin' : '0 0 40px 0'});	
});

jQuery(document).ready(function($){
//Tooltips
	var tip;
	$(".tip_trigger").hover(function(){

		//Caching the tooltip and removing it from container; then appending it to the body
		tip = $(this).find('.tip').remove();
		$('body').append(tip);

		//tip.show(); //Show tooltip
		tip.fadeIn('fast'); //Show tooltip and fad it in and out

	}, function() {

		tip.hide().remove(); //Hide and remove tooltip appended to the body
		$(this).append(tip); //Return the tooltip to its original position

	}).mousemove(function(e) {
	//console.log(e.pageX)
		  var mousex = e.pageX + 20; //Get X coodrinates
		  var mousey = e.pageY + 20; //Get Y coordinates
		  var tipWidth = tip.width(); //Find width of tooltip
		  var tipHeight = tip.height(); //Find height of tooltip

		 //Distance of element from the right edge of viewport
		  var tipVisX = $(window).width() - (mousex + tipWidth);
		  var tipVisY = $(window).height() - (mousey + tipHeight);

		if ( tipVisX < 20 ) { //If tooltip exceeds the X coordinate of viewport
			mousex = e.pageX - tipWidth - 20;
			$(this).find('.tip').css({  top: mousey, left: mousex });
		} if ( tipVisY < 20 ) { //If tooltip exceeds the Y coordinate of viewport
			mousey = e.pageY - tipHeight - 20;
			tip.css({  top: mousey, left: mousex });
		} else {
			tip.css({  top: mousey, left: mousex });
		}
	});
});	

// Digicordian hover effect for text area
jQuery(document).ready(function(){
	jQuery(".digicordian").hover(function(){
		jQuery(this).find(".digicordian-alt").stop().fadeTo(500, 0.9);
	},
		function(){ jQuery(".digicordian-alt").stop().fadeTo(100, 0);
	});
		jQuery(".digicordian").hover(function(){
		jQuery(this).find(".digicordian-title").stop().fadeTo(100, 0);
	},
		function(){ jQuery(".digicordian-title").stop().fadeTo(500, 0.9);
	});	 
});

// Preloader for images makes it Sexy Time
jQuery(document).ready(function(){
(function($){
    $.fn.preloadImages = function(options){

        var defaults = {
            showSpeed: 500,
            easing: 'easeOutQuad'
        };

        var options = $.extend(defaults, options);

        return this.each(function(){
            var container = $(this);
            var image = container.find('img');

            $(image).css({ "visibility": "hidden", "opacity": "0" });
            $(image).bind('load error', function(){
                $(this).css({ "visibility": "visible" }).animate({ opacity:"1" }, {duration:options.showSpeed, easing:options.easing}).parent(container).removeClass('preload');
            }).each(function(){
                if(this.complete || ($.browser.msie && parseInt($.browser.version) == 6)) { $(this).trigger('load'); }
            });
        });
    }
})(jQuery);
});

(function() {
var s = document.createElement('SCRIPT'), s1 = document.getElementsByTagName('SCRIPT')[0];
s.type = 'text/javascript';
s.async = true;
s.src = 'http://widgets.digg.com/buttons.js';
s1.parentNode.insertBefore(s, s1);
})();
