/******************************************************
*
*	Softscroll
*
******************************************************/
$(document).ready(function(){
$('a[href$=#header]').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}, 1000);
			return false;
		}
	}
});
});

/******************************************************
*
*	Cufon visibility in IE8
*
******************************************************/
$(window).one("load", function(){
	$('#logo,#bottom-logo').css({'display':'inline'});
});

/******************************************************
*
*	Rounded corner on menu and submenu in general
*
******************************************************/
$(function() {
    $('#bio_menu li').hover(
	function() { 
		$(this).addClass('bio_hover');
	},
	function() { 
		$(this).removeClass('bio_hover');
	});
});

$(function() {
    $('#bio_menu ul li:last-child').addClass("last");
});

/******************************************************
*
*	Initialize scrolldown menu
*
******************************************************/
$(function() {
	jQuery('#bio_menu').superfish({
		delay:200, 
		animation:{opacity:'show',height:'show'},
		speed:'fast',
		autoArrows:false,
		dropShadows:false 
	});
});

/******************************************************
*
*	Background effect on mouse over
*
  ******************************************************/
$(window).one("load", function(){
	$('.nivo-prevNav')
		.css( {backgroundPosition: "8px 0"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0 0)"}, {duration:100})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(8px 0)"}, {duration:100, complete:function(){
				$(this).css({backgroundPosition: "8px 0"})
			}})
		})
	$('.nivo-nextNav')
		.css( {backgroundPosition: "-8px 0"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0 0)"}, {duration:100})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(-8px 0)"}, {duration:100, complete:function(){
				$(this).css({backgroundPosition: "-8px 0"})
			}})
		})
});

/******************************************************
*
*	Entry img
*
  ******************************************************/
$(document).ready(function(){
	$('.showcase .showcasebox').wrapInner('<div class="paddingimg" />');
	$('.entry, .bio_recent_comments, #author_info, #commentlist').not(':has(.showcasebox)').not(':has(.contenteditor)').find('img').not('.noBorder').wrap('<div class="paddingimg" />');
	$('.entry object').wrap('<div class="paddingimg" />');
	$('.paddingimg').wrap('<div class="borderimg" />');
	$('.entry').not(':has(.showcasebox)').find('.paddingimg').wrapInner('<div class="iconimg" />');
	$('.entry img.alignleft').not('.noBorder').removeClass('alignleft').parent().parent().parent().addClass('alignleft');
	$('.entry img.alignright').not('.noBorder').removeClass('alignright').parent().parent().parent().addClass('alignright');
	$('.entry img.aligncenter').not('.noBorder').removeClass('aligncenter').parent().parent().parent().addClass('aligncenter');
	$('.entry .aligncenter').wrap('<div class="alignleft" style="width:100%" />');
	$('.entry .aligncenter').each(function() {
    	var wrapW = $(this).parent('div').width();
    	var thisW = $(this).width();
        $(this).css('margin-left',((wrapW - (thisW + 2))*0.5) +'px'); 
    });
	$('.entry img.alignnone').not('.noBorder').removeClass('alignnone').parent().parent().parent().addClass('alignnone');
	$('.entry .alignnone').wrap('<div class="alignleft" style="width:100%" />');
	$('.showcasebox img').before('<div class="iconimg" />');
	$('.showcase .iconimg').css('opacity','0.6');
});
$(window).one("load", function(){
	$('.showcase .iconimg').each(function(){
    	var padH = $(this).parent().height();
        $(this).css('height',padH+22+'px');
    });
});


/******************************************************
*
*	Hover effect in general
*
  ******************************************************/
(function($) {
	$.fn.customFadeIn = function(speed, callback) {
		$(this).fadeIn(speed, function() {
			if(!$.support.opacity)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
	$.fn.customFadeOut = function(speed, callback) {
		$(this).fadeOut(speed, function() {
			if(!$.support.opacity)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
	$.fn.customFadeTo = function(speed,to,callback) {
		return this.animate({opacity: to}, speed, function() {
			if (to == 1 && jQuery.browser.msie)
				this.style.removeAttribute('filter');
			if (jQuery.isFunction(callback))
				callback();
		});
	};
})(jQuery);

$(function() {
    $('a img, #logo, #bottom-logo').hover(function(){
            $(this).stop(true,false).animate({'opacity':'0.7'},150);
        },function(){
            $(this).stop(true,false).animate({'opacity':'1'},150);
        });
        $('.iconimg img, .entry a img').hover(function(){
            $(this).stop(true,false).animate({'opacity':'0.2'},150);
        },function(){
            $(this).stop(true,false).animate({'opacity':'1'},150);
        });
});

/******************************************************
*
*	Cut bg
*
  ******************************************************/
$(window).one("load", function(){
	$('.cut').wrapInner('<div class="vertical_cut" />');
	$('.vertical_cut').wrapInner('<div class="vertical_cut-bottom" />');
	$('.vertical_cut-bottom').wrapInner('<div class="vertical_cut-top" />');
	$('.cut').find('.double .post:first').css('margin-top','-20px');
	$('.cut').find('.sidebar .bio_widget:first').css('margin-top','-5px');
	$('.cut').find('.sidebar .bio_widget:last').css('background','none');
});

/******************************************************
*
*	Credits vertical align
*
  ******************************************************/
$(window).one("load", function(){
	var lineH = $('#bottom-logo').height();
	if (lineH > 15) {
		$('#credits').css({'line-height':lineH+'px'});
	}
	if (lineH > 28) {
		var marginT = (lineH - 28)*0.5;
		$('#backtotop').css({'margin-top':marginT+'px'});
	}
});

/******************************************************
*
*	HR totop
*
******************************************************/
$(function() {
	$('hr').wrap('<div class="hr" />');
	$('hr.totop').wrap('<div class="hrtotop" />');
	$('.hrtotop').after('<span class="totop" />');
	$('span.totop').click(function(){
		$('html,body').animate({scrollTop: 0}, 500);
	});
});

/******************************************************
*
*	Widget list
*
******************************************************/
$(document).ready(function(){
    $('.sidebar ul').find('li:last').css('background','none');
    $('.bio_widget li a:not(.current-page)').hover(
	function() { 
		$(this).stop(true,false).animate({'padding-left': '25px'},200, function() {
			$(this).addClass('hover_current');
		});
	},
	function() { 
		$(this).removeClass('hover_current');
		$(this).stop(true,false).animate({'padding-left': '10px'},200);
	});
});


/******************************************************
*
*	IE list bug
*
******************************************************/
/*$(document).ready(function(){
    $('.post ul, .post ol').wrap('<div class="alignleft" style="width:100%; padding:0; background:none" />');
}); HBD */


/******************************************************
*
*	Icon classes
*
******************************************************/
$(window).one("load", function(){
    $(".paddingimg").parent().parent("div:has(a[href*='http'])").find('.iconimg').addClass('readMore');
    $(".paddingimg").parent().parent("div:not(:has(a[href*='http']))").find('.iconimg').addClass('readMore');
    $(".paddingimg").parent().parent("div:has(a[href$='.jpg'])").find('.iconimg').addClass('enlargePicture');
    $(".paddingimg").parent().parent("div:has(a[href$='.gif'])").find('.iconimg').addClass('enlargePicture');
    $(".paddingimg").parent().parent("div:has(a[href$='.png'])").find('.iconimg').addClass('enlargePicture');
    $(".paddingimg").parent().parent("div:has(a[href*='vimeo'])").find('.iconimg').addClass('watchVideo');
    $(".paddingimg").parent().parent("div:has(a[href*='youtube'])").find('.iconimg').addClass('watchVideo');

    $("a[href*='http']").find('.iconimg').addClass('readMore');
    $("a[href^='http']").find('.iconimg').addClass('readMore');
    $("a[href$='jpg']").find('.iconimg').addClass('enlargePicture');
    $("a[href$='gif']").find('.iconimg').addClass('enlargePicture');
    $("a[href$='png']").find('.iconimg').addClass('enlargePicture');
    $("a[href*='vimeo']").find('.iconimg').addClass('watchVideo');
    $("a[href*='youtube']").find('.iconimg').addClass('watchVideo');
});
