$(document).ready(function() {

	///
	/// fix all IE6 issues.
	///
	if(IE6) {

		/// lack of CSS selector support
		$("div p:first-child").addClass('first-child');
		$("div p:last-child").addClass('last-child');
		$("ul#homeNews li:last-child").addClass('last-child');
		$("#page div#side ul#navSide>li:first-child").addClass('first-child');
		$("#page div#side ul#navSide>li:last-child").addClass('last-child');

		// fix flickering background images
		document.execCommand("BackgroundImageCache",false,true);
		
		// fix fixed elements
		$(window).scroll(function() {
		    $('div#navStripe').css('top', (19+$(this).scrollTop()) + "px");
		});
		
		$('div#footer').css("top", $(window).height()-60)
		$(window).scroll(function() {
		    $('div#footer').css('top', (($(window).height()-60)+$(this).scrollTop()) + "px");
		});
		
	}

	///
	/// fix all IE7/IE8 issues.
	///
	if ($.browser.msie && $.browser.version > 6 ) {
		/// lack of CSS :last-child selector support in IE
		$("div p:last-child").addClass('last-child');
		$("ul#homeNews li:last-child").addClass('last-child');
		$("#page div#side ul#navSide>li:last-child").addClass('last-child');
	}

	///
	/// unfix footer for mobile Safari
	///
	if((navigator.userAgent.indexOf('iPod') != -1) || (navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPad') != -1)) {
		$('#footer').css({
			'position': 'relative',
			'margin-top': '-60px'
		});
	}

	///
	/// footer login box show/hide
	///
	$('#footLogin a').click(function(){ 
		if ($('#memberLogin').is(':visible')) { 
			$('#memberLogin:visible').slideUp();
		} else {
			$('#memberLogin:hidden').slideDown();
		}
		return false;
	});
	$('#memberLogin a.boxClose').click(function(){
		$('#memberLogin:visible').slideUp();
		return false;
	});
	$('a#footSignUp').click(function(){
		if ($('#emailSignUp').is(':visible')) {
			$('#emailSignUp:visible').slideUp();
		} else {
			$('#emailSignUp:hidden').slideDown();
		}
		return false;
	});
	$('#emailSignUp a.boxClose').click(function(){
		$('#emailSignUp:visible').slideUp();
		return false;
	});

	///
	/// login/email boxes focus/blur effect
	///
	$('input#user').focus(function() {
		var init = $(this).attr('init');
		if(!init || init.length == 0) {
			init = $(this).val();
			$(this).attr('init', init);
		}
		if($(this).val() == init) {
			$(this).val('');
			$(this).css('color', '#565656');
		}
	}).blur(function() {
		var init = $(this).attr('init');
		if($(this).val() == '') {
			$(this).val(init);
			$(this).css('color', '#bababa');
		}
	});
	$('input#pass').focus(function() {
		var init = $(this).attr('init');
		if(!init || init.length == 0) {
			init = $(this).val();
			$(this).attr('init', init);
		}
		if($(this).val() == init) {
			$(this).val('');
			$(this).css('color', '#565656');
		}
	}).blur(function() {
		var init = $(this).attr('init');
		if($(this).val() == '') {
			$(this).val(init);
			$(this).css('color', '#bababa');
		}
	});
	$('input#firstName').focus(function() {
		var init = $(this).attr('init');
		if(!init || init.length == 0) {
			init = $(this).val();
			$(this).attr('init', init);
		}
		if($(this).val() == init) {
			$(this).val('');
			$(this).css('color', '#565656');
		}
	}).blur(function() {
		var init = $(this).attr('init');
		if($(this).val() == '') {
			$(this).val(init);
			$(this).css('color', '#bababa');
		}
	});
	$('input#lastName').focus(function() {
		var init = $(this).attr('init');
		if(!init || init.length == 0) {
			init = $(this).val();
			$(this).attr('init', init);
		}
		if($(this).val() == init) {
			$(this).val('');
			$(this).css('color', '#565656');
		}
	}).blur(function() {
		var init = $(this).attr('init');
		if($(this).val() == '') {
			$(this).val(init);
			$(this).css('color', '#bababa');
		}
	});
	$('input#eMail').focus(function() {
		var init = $(this).attr('init');
		if(!init || init.length == 0) {
			init = $(this).val();
			$(this).attr('init', init);
		}
		if($(this).val() == init) {
			$(this).val('');
			$(this).css('color', '#565656');
		}
	}).blur(function() {
		var init = $(this).attr('init');
		if($(this).val() == '') {
			$(this).val(init);
			$(this).css('color', '#bababa');
		}
	});
	
	$('a.resetpass').click(function(){
		dynamItLoad('/members/password-reset/dialog', null, 472, 'auto', null);
		return false;
	});

});

function slideDownMail() {
	$('#emailSignUp:visible').slideUp();
}

function slideDownLogin() {
	$('#memberLogin:visible').slideUp();
}

function emailVerify(form) {
	var emailOk = true;

	if( $("#firstName").val() == "First Name *" || $("#firstName").val() == "") {
		$("#firstName").css("border", "2px solid #C23F2C");
		emailOk = false;
	} else {
		$("#firstName").css("border", "1.1px solid #F0F0F0");
	}

	if( $("#lastName").val() == "Last Name *" || $("#lastName").val() == "") {
		$("#lastName").css("border", "2px solid #C23F2C");
		emailOk = false;
	} else {
		$("#lastName").css("border", "1.1px solid #F0F0F0");
	}

	if( $("#eMail").val() == "Email *" || $("#eMail").val() == "") {
		$("#eMail").css("border", "2px solid #C23F2C");
		emailOk = false;
	} else {
		$("#email").css("border", "1.1px solid #F0F0F0");
	}

	if(emailOk)
		return dynamItPublish(form);
	else
		return false;
	
}