/**
 * Golden Egg (http://www.goldenegg.ie)
 * 
 * @author Ambient Age (http://www.ambientage.com : @davkell)
 * @version 0.2
 *
 */
// JQuery
jQuery(document).ready(function($){


    var menuBg = new Image();
    menuBg.src = 'http://socialbits.net/wp-content/themes/socialbits/images/bg-button-orange-on.jpg';

    
/**
 * Do some funky scrolling
 * @author: Karl Swedberg
 * @link: http://www.learningjquery.com/2007/10/improved-animated-scrolling-script-for-same-page-links
 */

  function filterPath(string) {
	  return string
	 .replace(/^\//,'')
	 .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
	 .replace(/\/$/,'');
  }
  var locationPath = filterPath(location.pathname);
  $('a[href*=#]').each(function() {
 		var thisPath = filterPath(this.pathname) || locationPath;
		if (  locationPath == thisPath && (location.hostname == this.hostname || !this.hostname) && this.hash.replace(/#/,'') ) {
		   var $target = $(this.hash), target = this.hash;
		   if (target) {
			  var targetOffset = $target.offset().top;
			  $(this).click(function(event) {
				    event.preventDefault();
				    $('html, body').animate({scrollTop: targetOffset}, 700, function() {
					   location.hash = target;
				    });
			  });
   			}
 		}
  });


   
	
	/**
	 * Search form tweaking
	 */
	$('#searchform label').remove();
	$('input#s').val('search...' ).css({color: '#666', 'fontStyle': 'italic'});
	
	$('input#s').focus(function(){
		$(this).val('').css({color: '#000'});
	});
	

        $('#footer-latest hr:last').remove();
	$('div.footer-latest-article').mouseover(function(){
            $(this).css({
                    backgroundColor: '#333',
                    cursor: 'pointer'
            });
	}).mouseout(function(){
		$(this).css({backgroundColor: ''});
	}).click(function(){
		var url = $(this).find('a').attr('href');
		window.location = url;
	});

        $('div.home-event').mouseover(function(){
            $(this).css({
                    backgroundColor: '#ccc',
                    cursor: 'pointer'
            });
	}).mouseout(function(){
		$(this).css({backgroundColor: ''});
	}).click(function(){
		var url = $(this).find('a').attr('href');
		window.location = url;
	});


  // Blog Comment form validation
	$('#respond form').submit(function(){
		
		$('#comment-notes').removeClass('error').empty();
		
		var comment = $('#commentform #comment').val();
		var author =  $('#commentform #author').val();
		var em	=  $('#commentform #email').val();
		
		var err = '';
		
		if(comment == ''){
			err = 'You forgot to enter a Comment!';
				
			$('#comment-notes').empty().addClass('error').text( err );
			return false;
		}
		if(author == ''){
			err = 'You forgot to enter your name!';
				
			$('#comment-notes').empty().addClass('error').text( err );
			return false;
		}
		if((em == "") || (em.indexOf("@") == -1) || (em.lastIndexOf("@") != em.indexOf("@")) || (em.indexOf(".") == -1)){
			err = 'Your email address doesn\'t look correct. Could you check it and try again';
				
			$('#comment-notes').empty().addClass('error').text( err );
			return false;
		}
		
		return true;
		
	});
	
}); // .ready
