$(document).ready(function() {

var dropDown = function() {
		if ($('#pulldown').css('display') !== 'block')
            {
            $('#pulldown').slideDown(1000);
            $('#blocker').fadeIn(800);
            }
        }
 
var liftUp = function() {
        if ($('#pulldown').css('display') == 'block')
            {
            $('#pulldown').slideUp(1000);
            $('#blocker').fadeOut(800);
            }
         }

var basketBtn = $('#basketBtn');
var basketPane = $('#basketPane');
var sih = $('#signInHref');
var sib = $('#signInBtn');
var buyBtn = $('#buyBtn');
var sip = $('#signInPane');
var suh = $('#signUpHref');
var sub = $('#signUpBtn');
var sup = $('#signUpPane');
var hb = $('#helpBtn');
var hp = $('#helpPane');
var nb = $('#newsBtn');
var np = $('#newsPane');
var cb = $('#contactBtn');
var ch = $('#contactHref');
var cp = $('#contactPane');

var blocker = $('#blocker');

$(basketBtn).click(function() {$(basketPane).fadeIn(1000)});
$(basketBtn).click(dropDown);

$(sib).click(function() {$(sip).fadeIn(1000)});
$(sib).click(dropDown);
$(sih).click(function() {$(sip).fadeIn(1000)});
$(sih).click(dropDown);
$(buyBtn).click(function() {$(sip).fadeIn(1000)});
$(buyBtn).click(dropDown);

$(sub).click(function() {$(sup).fadeIn(1000)});
$(sub).click(dropDown);
$(suh).click(function() {$(sup).fadeIn(1000)});
$(suh).click(dropDown);

$(hb).click(function() {$(hp).fadeIn(1000)});
$(hb).click(dropDown);

$(nb).click(function() {$(np).fadeIn(1000)});
$(nb).click(dropDown);

$(cb).click(function() {$(cp).fadeIn(1000)});
$(cb).click(dropDown);
$(ch).click(function() {$(cp).fadeIn(1000)});
$(ch).click(dropDown);


$(blocker).click(liftUp);
$(blocker).click(function() {$('.slidepane').fadeOut(800)});

$('#fpwd').click(function() {$('#signInPane').css("display", "none"); $('#forgotPasswordPane').css("display", "block");});
$('#signup').click(function() {$('#signInPane').css("display", "none"); $('#signUpPane').css("display", "block");});
$('#signInHref').click(function() {$('#basketPane').css("display", "none"); $('#signInPane').css("display", "block");});
$('#signUpHref').click(function() {$('#signInPane').css("display", "none"); $('#signUpPane').css("display", "block");});

// onFontResize actually makes the three divs the same height...
function onFontResize(){
$('#sameHeights>div>div>div').height("auto");
var heightGauge = $('#sameHeights').height();
$('#sameHeights>div>div>div').height(heightGauge);
}

// Calls function onFontResize when text resize is detected...
function init(){
      var iBase = TextResizeDetector.addEventListener(onFontResize,null );
    }

// set id of element to have its height sampled by the equal heights detector...
TextResizeDetector.TARGET_ELEMENT_ID = 'sampler';

TextResizeDetector.USER_INIT_FUNC = init;

// Equal heights script is run initially...
onFontResize();

$('#formJoin').validate({
			rules: {
				firstName: {required: true, maxlength: 30},
				lastName: {required: true, maxlength: 30},
				email: {required: true, email: true},
				password: {required: true, minlength: 6},
				cpassword: {required: true, minlength: 6, equalTo: "#cpswd"},
				privacy: "required"
			},
			messages: {
				firstName: {required: "This is a required field.", maxlength: "Names cannot be longer than 30 characters."},
				lastName: {required: "This is a required field.", maxlength: "Names cannot be longer than 30 characters."},
				email: {required: "This is a required field.", email: "Sorry, this does not appear to be a valid email address. Please try another."},
				password: {required: "Sorry, passwords must be a minimum of 6 characters and may not contain spaces.", minlength: "Sorry, passwords must be a minimum of 6 characters and may not contain spaces."},
				cpassword: {required: "Please confirm your password.", equalTo: "Sorry, this password doesn't match. Please type your password again."},
				privacy: "Please indicate that you accept our Terms of Service."
			}
		});
		
$('.newsletter').validate({
			rules: {
				firstName: {required: true, maxlength: 30},
				lastName: {required: true, maxlength: 30},
				email: {required: true, email: true},
				privacy: "required"
			},
			messages: {
				firstName: {required: "This is a required field.", maxlength: "Names cannot be longer than 30 characters."},
				lastName: {required: "This is a required field.", maxlength: "Names cannot be longer than 30 characters."},
				email: {required: "This is a required field.", email: "Sorry, this does not appear to be a valid email address. Please try another."},
				privacy: "Please indicate that you accept our Terms of Service."
			}
		});
		
$('#formContact').validate({
			rules: {
				firstName: {required: true, maxlength: 30},
				lastName: {required: true, maxlength: 30},
				email: {required: true, email: true}
			},
			messages: {
				firstName: {required: "This is a required field.", maxlength: "Names cannot be longer than 30 characters."},
				lastName: {required: "This is a required field.", maxlength: "Names cannot be longer than 30 characters."},
				email: {required: "This is a required field.", email: "Sorry, this does not appear to be a valid email address. Please try another."}
			}
		});
		
$(this).oneTime(3000, "hide", function() {
    $('.success').fadeOut(3000);
	$('.error, .warning').fadeOut(8000);
  });
  
$('.obfuscated').defuscate();

$('div.bigTarget h3 a').bigTarget({
    hoverClass: 'over', // CSS class applied to the click zone onHover
    clickZone : 'div:eq(0)' // jQuery parent selector
  });

// end of script...
});

