//  Jquery style 
$(function(){
	/* Smoothscroll trigger START */
	$('a[href*=#]').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}, {duration: 1500});
				return false;
			}
		}
	});
	/* Smoothscroll trigger STOP */
	/* DropDown menu START */
	$("ul.children").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)
	$("ul.top_menu li a").hover(function() { //When trigger is clicked...
	
		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).parent().find("ul.children").slideDown('fast').show(); //Drop down the subnav on click

		$(this).parent().hover(function() {
		}, function(){
			$(this).parent().find("ul.children").slideUp('fast'); //When the mouse hovers out of the subnav, move it back up
		});
		
		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() {
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
	});
	/* DropDown menu STOP */
	/* Open posts links in new window START  */
	$("a[href*='http://']:not([href*='"+location.hostname+"'])").attr("target","_blank");
	/* Open posts links in new window STOP  */

	/* CSS Gallery Fader START */
	$(".gallery_element img").fadeTo("slow", 0.6); // This sets the opacity of the thumbs to fade down to 60% when the page loads
	$(".gallery_element img").hover(function(){
	$(this).fadeTo("slow", 1.0); // This should set the opacity to 100% on hover
		},function(){
		$(this).fadeTo("slow", 0.6); // This should set the opacity back to 60% on mouseout
	});
	/* CSS Gallery Fader STOP */

$("img").lazyload({
	effect: "fadeIn"
});

});

/* Cufon START */
	Cufon.replace('h2.cufon', { fontSize: '32px' });
	Cufon.replace('div.sidebar h3,div.sidebar div.side_cats h3', { fontSize: '20px' });
	Cufon.replace('div.entry h3,div.footer_box h3.cufon,div.footer_box h3.recent', { fontSize: '24px' });
	Cufon.replace('div.entry h4', { fontSize: '20px' });
	Cufon.replace('span.prev_link a,span.next_link a', { fontSize: '24px' });
/* Cufon STOP */
/* Sexy bookmarks START */
jQuery(document).ready(function() {

	// xhtml 1.0 strict way of using target _blank
	jQuery('.sexy-bookmarks a.external').attr("target", "_blank");

	// this block sets the auto vertical expand when there are more than 
	// one row of bookmarks.
	var sexyBaseHeight=jQuery('.sexy-bookmarks').height();
	var sexyFullHeight=jQuery('.sexy-bookmarks ul.socials').height();
	if (sexyFullHeight>sexyBaseHeight) {
		jQuery('.sexy-bookmarks-expand').hover(
			function() {
				jQuery(this).animate({
						height: sexyFullHeight+'px'
				}, {duration: 400, queue: false});
			},
			function() {
				jQuery(this).animate({
						height: sexyBaseHeight+'px'
				}, {duration: 400, queue: false});
			}
		);
	}
	// autocentering
	if (jQuery('.sexy-bookmarks-center') || jQuery('.sexy-bookmarks-spaced')) {
		var sexyFullWidth=jQuery('.sexy-bookmarks').width();
		var sexyBookmarkWidth=jQuery('.sexy-bookmarks:first ul.socials li').width();
		var sexyBookmarkCount=jQuery('.sexy-bookmarks:first ul.socials li').length;
		var numPerRow=Math.floor(sexyFullWidth/sexyBookmarkWidth);
		var sexyRowWidth=Math.min(numPerRow, sexyBookmarkCount)*sexyBookmarkWidth;
		
		if (jQuery('.sexy-bookmarks-spaced').length>0) {
			var sexyLeftMargin=Math.floor((sexyFullWidth-sexyRowWidth)/(Math.min(numPerRow, sexyBookmarkCount)+1));
			jQuery('.sexy-bookmarks ul.socials li').css('margin-left', sexyLeftMargin+'px');
		} else if (jQuery('.sexy-bookmarks-center'.length>0)) {
			var sexyLeftMargin=(sexyFullWidth-sexyRowWidth)/2;
			jQuery('.sexy-bookmarks-center').css('margin-left', sexyLeftMargin+'px');
		}
		
	}
});
/* Sexy bookmarks STOP */
