//Start sidebar

		// DOM Ready
		$(window).load(function(){
		
			var mainContent = $("#content"),         /* "Caching" */
				height      = mainContent.outerHeight(),
				aside       = $("#sidebar"),
				module      = 1,                           /* Start with the first, increments */
				buffer      = 500,                          /* To prevent sidebar from growing way taller than main content if it's only barely shorter */
				done        = false;                       /* If no more modules to be had */ 
				setTimeout(getMoreContent, 5000);
			       
			function getMoreContent() {
					
				$.get("http://www.animeonsen.com/wp-content/themes/animeonsen/sidebarmodule.php", { "module": module }, function(data) {
					
					//if (data != "No more modules" && (window.location.href != 'index.php')) {
					if (data != "No more modules") {
						// Increment # so next time it will grab a differnet module
						module++;
					
						// Create sidebar box
						$("<div />", {
						
							"class"  : "sidebar-box",
							"id"     : "sidebar-box-" + module,
							"html"   : data,
							"css"    : {
								"position": "relative",
								"top": 25
							}
						
						// Fancy revealing of new content
						}).hide().appendTo(aside).fadeIn(200, function() {
							$(this).animate({
								"top": 0
							});
						});
						
						// If after getting new module, sidebar is still too short, start over					
						if ((height > (aside.outerHeight() + buffer)) && !done) {							
							getMoreContent();
						}
					
					}
				
				});
			
			}
			
			// Initial test			
			if (height > (aside.outerHeight() + buffer)) {				
				getMoreContent();
			}	
		
		});
//End sidebar

//Scroll to top
$(document).ready(function(){

	// hide #back-top first
	$("#back-top").hide();
	
	// fade in #back-top
	$(function () {
		$(window).scroll(function () {
			if ($(this).scrollTop() > 100) {
				$('#back-top').fadeIn();
			} else {
				$('#back-top').fadeOut();
			}
		});

		// scroll body to 0px on click
		$('#back-top a').click(function () {
			$('body,html').animate({
				scrollTop: 0
			}, 800);
			return false;
		});
	});

});		
//End scroll to top

//Search animated
$(function(){

    var input = $('input#s');
    var divInput = $('div.input');
    var width = divInput.width();
    var outerWidth = divInput.parent().width() - (divInput.outerWidth() - width) - 28;
    var submit = $('#searchSubmit');
    var txt = input.val();
    
    input.bind('focus', function() {
        if(input.val() === txt) {
            input.val('');
        }
        $(this).animate({color: '#000'}, 300); // text color
        $(this).parent().animate({
            width: outerWidth + 'px',
            backgroundColor: '#fff', // background color
            paddingRight: '43px'
        }, 300, function() {
            if(!(input.val() === '' || input.val() === txt)) {
                if(!($.browser.msie && $.browser.version < 9)) {
                    submit.fadeIn(300);
                } else {
                    submit.css({display: 'block'});
                }
            }
        }).addClass('focus');
    }).bind('blur', function() {
        $(this).animate({color: '#b4bdc4'}, 300); // text color
        $(this).parent().animate({
            width: width + 'px',
            backgroundColor: '#e8edf1', // background color
            paddingRight: '15px'
        }, 300, function() {
            if(input.val() === '') {
                input.val(txt)
            }
        }).removeClass('focus');
        if(!($.browser.msie && $.browser.version < 9)) {
            submit.fadeOut(100);
        } else {
            submit.css({display: 'none'});
        }
    }).keyup(function() {
        if(input.val() === '') {
            if(!($.browser.msie && $.browser.version < 9)) {
                submit.fadeOut(300);
            } else {
                submit.css({display: 'none'});
            }
        } else {
            if(!($.browser.msie && $.browser.version < 9)) {
                submit.fadeIn(300);
            } else {
                submit.css({display: 'block'});
            }
        }
    });
});
//End search animated	

//Hide IE errors
	function handleError(){
	return true;
	}
	window.onerror = handleError;
//End hide IE errors
