$(document).ready(function() {

	//--------------------------------------------------------
	
	// CSS magic
		
	$('.widget_intro').attr('id', 'intro');	
	$('.widget_categoryposts').attr('id', 'news');
	$('.FeedburnerEmailWidget').attr('id', 'newsletter');
	$('#menu-social').parents('div.widget').attr('id', 'social');
	$('.widget_simple_related_posts').attr('id', 'related');	
	
	$('.widget_intro h2')
		.prepend('<span>&ldquo;</span>')
		.append('<span>&rdquo;</span>');

	$('a:has(img)').addClass('image-link');
	
	$('input[type="text"]').addClass('text');
	$('input[type="submit"]').addClass('submit');
	
	$('a:contains("Read More"), a:contains("Details")').addClass('more');

	$('#social.widget h2').remove();
	
	$('#social.widget a:contains("Facebook")').addClass('facebook');
	$('#social.widget a:contains("Twitter")').addClass('twitter');
	
	$('#related a').addClass('more');
	
	$('.gallery a').attr('rel', 'gallery');
	

	//--------------------------------------------------------

	// Lightbox
	
	$('.gallery-icon a').colorbox({ 
		'opacity':0.8, 
		'transition':'fade',
		'slideshow':true
	});


	//--------------------------------------------------------
	
	// Clear/reset form fields on focus
	
	var newsletter = $('#newsletter input[name="email"]');
	var newsletter_default = 'your.name@domain.com';

	$(newsletter).val(newsletter_default);
		
	$(newsletter)
		.focus(clear_input);
    // .blur(function() { 
    //  $(this).val(newsletter_default)
    // });
	
	$('#search')
		.ready(set_default)
		.focus(clear_input)
		.blur(restore_input);
		
	function set_default(){
		$(this).val == 'test';
	}
	
	function clear_input() {
		$(this).val('');
	}
	
	function restore_input()
	{
		if ($(this).val() == "") {
			$(this).val($(this)[0].defaultValue);
		};
	}
	
	$('#homesearch')
		.focus(clear_input)
		.blur(restore_input);
	
	function clear_input() {
		$(this).val('');
	}
	
	function restore_input()
	{
		if ($(this).val() == "") {
			$(this).val($(this)[0].defaultValue);
		};
	}
	
	$('#bdldrt-bdldrt')
		.focus(clear_input)
		.blur(restore_input);
	
	function clear_input() {
		$(this).val('');
	}
	
	function restore_input()
	{
		if ($(this).val() == "") {
			$(this).val($(this)[0].defaultValue);
		};
	}
	


	//--------------------------------------------------------
	
	// External links

	$('a').each(function() {
	
		var href = $(this).attr('href');
	  				
		if (this.hostname && this.hostname !== location.hostname)
		{
    	$(this)
    		.removeAttr('target')
    		.attr('rel', 'external')
        .attr('title', href)
				.addClass('external')
        .click(function() {
           window.open($(this).attr('href'));
           return false;
       });
		}
  
	});
	

});
