$(document).ready(function() {

	initialize();
	
});

function initialize() {

	// Back to Top Animation
	$('#back-to-top').top_animation('easeInOutExpo', 800);

	// Remove underlining for images
	$('a img').each(function() { $(this).parent().hover(function() { $(this).css('border','none'); }); });

	// Add Input button, to prevent Spam
	$('#form-submit').html('<input type="submit" value="Send Message" />');

	// Initialize form validation (after input button has been added)
	init_forms();

	// Initialize Twitter
	twitter_init();

	// Old Browser Fixes
	ie_fixes();

	// Remove title from navigation links
	$('#navigation li a').attr('title','');

	// Hover effect for header icons
	var t = 300;
	$('#header').hover(function() {

		$('#header #header-icons').stop().animate({'bottom':'15px'}, t, 'easeOutQuad');

	}, function() {

		$('#header #header-icons').stop().animate({'bottom':'-30px'}, t*0.7, 'easeOutQuad');

	})

	// Click event for Header Search icon
	search_widget_visible = false;
	$('#header #header-icons .header-search').click(function() {

		t = 300;

		if (search_widget_visible) {

			search_widget_visible = false;

			$('#search-popup').stop().animate({'padding' : '1px 0 0 0'}, t*1.5, 'easeOutExpo' );

		} else {

			search_widget_visible = true;

			$('#search-popup').stop().animate({'padding' : '90px 0 0 0'}, t, 'easeOutQuad' );

			$('#search-popup input[type=text]').focus();

		}

		return false;

	});

	$('#search-popup a.close-btn').click(function() {

		search_widget_visible = false;

		$('#search-popup').stop().animate({'padding' : '1px 0 0 0'}, t*1.5, 'easeOutExpo' );

		return false;

	});

	// Add autocomplete=off to search fields
	$('input[name=s]').attr('autocomplete','off');

	// Enable submit button for comments via javascript, to prevent spam
	$('#comment-submit-button').prepend('<input name="submit" type="submit" id="submit" tabindex="5" value="Submit Comment" />');

}

function twitter_init() {

	//$('#footer .tweet').twitter('derdesign', function() {});

	$('#footer .tweet').tweets({
		tweets:1,
		username: "derdesign",
		callback: function(tweet) {
			$('#footer .tweet').html(tweet);
		}
	});

}

function ie_fixes() {

	if (IE67) {
		$('#header #navigation li.current_page_item > a').attr('style','color: black;');
	}

	if (IE6) { 
		$('#categories-search, .typoFlower').css('background','none');
		$('a').css({'border-bottom': 'none'});
		$('#back-to-top').css({ 'top':'-10px', 'left': '332px' });
	}

	if (IE7) {
		$('#back-to-top').css({ 'top':'-3px', 'left': '352px' });
	}

}