
	jQuery(function() {
		
		// style login widget
		jQuery('#logoutform').find('li').hide().slice(0,2).show().each(function() { $(this).contents().eq(0).wrap('<span></span>'); }); 
		jQuery('#logoutform').find('li:last').addClass('logout').show().find('a').text('Log out');
		jQuery('#logoutform').find('li:last').before('<li class="details"><a href="' + xm_blog + 'wp-admin/profile.php">Edit details</a></li>');
		
		jQuery('#loginform').find('br').remove();
		jQuery('#loginform').find('p label').each(function() { $(this).contents().eq(0).wrap('<span></span>'); }); 
		jQuery('#loginform').find('p:last').before('<p class="register">Not registered? <a href="' + xm_blog + 'wp-login.php?action=register">Click here</a></li>');
		jQuery('#loginform').find('p.submit input').hide();
		jQuery('#loginform').find('p.submit').prepend('<a href="#">Log in</a>');
		jQuery('#loginform').find('p.submit a').click(function() { jQuery('#wp-submit').click(); });
								
		// Cufon :)
		Cufon.set('fontFamily','PTSans');
			Cufon('.gpf-title-block .entry-date');
			if(!IE67) Cufon('.form-label label');
		Cufon.set('hover',true);
			Cufon('h1,h2,h3,#primary .cat-item a,blockquote,.gpf-title-block .entry-categories, #logoutform .logout a, #loginform p.submit a');
			if(!IE67) Cufon('#comments-list .comment-author span');
							
		// make top menu work in IE6
		jQuery('#access li.page_item').hover( function() { jQuery(this).addClass('sfHover'); }, function() { jQuery(this).removeClass('sfHover'); });
		
		// add ▼ and ► to top menu
		jQuery('#access > .menu > ul > li').has('li').children('a').append(' <span>▼</span>');	
			jQuery('#access > .menu > ul > li > ul > li').has('li').children('a').append(' <span>►</span>');
			
		// fix wordpress captions 10px bug
		jQuery('.wp-caption').each(function() { jQuery(this).width($(this).find('img').width()); }); 
			
		if(jQuery('#content .homepage').length) {
			
			// scroll images on homepage
			jQuery('.homepage .entry-content .wp-caption').wrapAll('<div id="hp-slide"><div id="hp-slider"></div></div>');
			jQuery('#hp-slider .wp-caption').each(function() {
				var t = $(this).find('p').text();
				jQuery(this).find('p').remove();
				jQuery(this).find('a').append('<em></em><span>' + t + '</span>');
			});
			var slideshowLength = jQuery('#hp-slider .wp-caption').length;
			var slideshowLeft = 0;
			jQuery('#hp-slider .wp-caption').slice(0,2).clone().appendTo('#hp-slider');
			jQuery('#hp-slider .wp-caption a em').css({'opacity':0.5});
			Cufon('#hp-slider .wp-caption a span');
						
			window.setInterval(function () {
  				$('#hp-slider').animate({'left':'-=600px'},1500,'easeOutBack',function() {
  					if(++slideshowLeft >= slideshowLength) { 
  						$('#hp-slider').css('left',0);
  						slideshowLeft = 0;
  					}
  				});	
			},5000);
		
			// shorten long titles on homepage
			jQuery('.hp_title span').each(function() {
				var st = jQuery(this);
				var pt = jQuery(this).find('a:last');
				if(pt.height() > 50) {
					var shorten_more = true;
					while(shorten_more) {
						pt.find('.cufon:last').remove();
						if(pt.height() <= 50 && st.width() <= 420) shorten_more = false;
					}
					pt.append('...');
					Cufon.refresh();
				}
			});
			
			// shorten post text on homepage
			jQuery('.hp_text p').each(function() {
				var pt = jQuery(this);
				if(pt.height() > 50) {
					var shorten_more = true;
					while(shorten_more) {
						while(pt.text().slice(-1) != ' ') {
							pt.text(pt.text().slice(0,-1));
						}
						pt.text(pt.text().slice(0,-1));
						if(pt.height() <= 50) shorten_more = false;
					}
					while(pt.text().slice(-1) != ' ') {
						pt.text(pt.text().slice(0,-1));
					}
					pt.text(pt.text().slice(0,-1));
					pt.append('...');
				}
			});
				
		}
					
		// sidebar categories animation
		jQuery('.widget_mycategoryorder > ul > li > a').click(function() {
			if(jQuery(this).next('ul.children').length) {
				jQuery(this).next('ul.children').slideToggle(300);
				return false;
			}
		});
		
		// open sidebar category if you're in it
		jQuery('.widget_mycategoryorder .current-cat').parents('ul.children').show();
		
		// set default text to search box
		if(jQuery('#s').val() == '') jQuery('#s').val('Search the site');
		
		// remove/restore default text in search box on click
		jQuery('#s').focusin(function() { if(jQuery(this).val() == 'Search the site') jQuery(this).val(''); });
		jQuery('#s').focusout(function() { if(jQuery(this).val() == '') jQuery(this).val('Search the site'); });
				
	});