$(document).ready(function(){

  $('#id_buy_this').click(function() {

    if ($.cookie("email_address")) {  

    user_email = $.cookie("email_address");
    postid = $("#id_buy_this").val();
        
    $("#sending_email").show();

    $.ajax({
      type: "POST",
      URL: "http://www.squareball.com/wp-content/plugins/email_ajax_01.php",
      data: "useremail="+user_email+"&postid="+postid,
      success: function(msg){
        $("#sending_email").hide();
        $("#sucessfully_sent").show();
        $("#id_buy_this").attr("disabled", true);         
      }
     }); 

    }	else {
  
      $("#id_buy_this_wrapper").hide();  
      $("#addemail").show();
    
    }
      
});

  	  

  
  $("#email_address_form").validate({
    submitHandler: function(form) {
    $("#sending_email").show();

    user_email = $("#email_address").val();
    postid = $("#id_buy_this").val();

    $.ajax({
      type: "POST",
      URL: "http://www.squareball.com/wp-content/plugins/email_ajax_01.php",
      data: "useremail="+user_email+"&postid="+postid,
      success: function(msg){
        $("#sending_email").hide();
        $("#addemail").hide();
        $("#id_buy_this_wrapper").show();  
        $("#sucessfully_sent").show();
        $("#id_buy_this").attr("disabled", true);        

        if (!$.cookie("email_address")) {  
          $.cookie("email_address", user_email, { expires: 52, path: '/' });
        }
        
      }
     });    

    
   }
  });
  
$.validator.addMethod(
    "legalName",
    function(value, element) {
        return (element.value.indexOf('.') == -1);
    },
    "* your username cannot contain periods, full stops [.]"
);


  $("#registerform").validate({
        rules: {
            uname: {
                legalName: true
            }
        },
    });

  $('.customer_service_block ul li > a').click(function() {
  
    if ($(this).parent("li").children("ul").length) {
      if ($(this).parent("li").children("ul").is(':visible')) {
        $(".customer_service_block ul li ul").slideUp();
      } else {
        $(".customer_service_block ul li ul").slideUp();
        $(this).parent("li").children("ul").slideDown();
      }
      return false;    
    }
  
  });

  $('#central_ad').cycle({ 
      timeout:  5000 
  }); 
    

  // Reset Font Size
  var originalFontSize = $('.tshirt_container h2').css('font-size');
  $(".resetFont").click(function(){
  $('.tshirt_container h2').css('font-size', originalFontSize);
  });
  // Increase Font Size
  $(".increaseFont").click(function(){
  	var currentFontSize = $('.tshirt_container h2').css('font-size');
 	var currentFontSizeNum = parseFloat(currentFontSize, 10);
    var newFontSize = currentFontSizeNum*1.2;
	$('.tshirt_container h2').css('font-size', newFontSize);
	return false;
  });
  // Decrease Font Size
  $(".decreaseFont").click(function(){
  	var currentFontSize = $('.tshirt_container h2').css('font-size');
 	var currentFontSizeNum = parseFloat(currentFontSize, 10);
    var newFontSize = currentFontSizeNum*0.8;
	$('.tshirt_container h2').css('font-size', newFontSize);
	return false;
  });



  $('#products_info_sidebar #all a').click(function() {
    $(".hoodies").show("slow");
    $(".tshirt").show("slow");
    $(".polos").show("slow");
  
    return false;        
  });      
  
  $('#products_info_sidebar #hoodies a').click(function() {
    $(".tshirt").hide("slow");
    $(".polos").hide("slow");
    $(".hoodies").show("slow");
  
    return false;        
  });         
  
  $('#products_info_sidebar #polos a').click(function() {
    $(".tshirt").hide("slow");
    $(".hoodies").hide("slow");
    $(".polos").show("slow");
  
    return false;                
  });
  
  $('#products_info_sidebar #tshirts a').click(function() {
    $(".hoodies").hide("slow");
    $(".polos").hide("slow");
    $(".tshirt").show("slow");
  
    return false;        
  });
     
     
if ($('.tabbed-page').length) {

	var jqFirst = true;
	
	$(function () {
		var tabContainers = $( '.tabbed-page' );
		if ( !jqFirst ) {
			tabContainers.hide();
		}
		
		var menuItems = $( 'ul#tab_menu a' );
		menuItems.click( function() { 
			menuItems.removeClass( 'page_active' );
			$(this).addClass( 'page_active' );
			
			var linkLocation = $(this).attr( 'href' );
			var linkBits = linkLocation.split( '/' );
			var divLocation = linkBits[ linkBits.length - 2 ];
	
			if ( !jqFirst ) {
				$( '.tabbed-page' ).hide();
				$( '#' + divLocation ).fadeIn( 300 );
			} else {
				jqFirst = false;
			}
			
			return false;
		});	
		
		menuItems.filter( ':first' ).click();	
	});
}
     

});
