// JQuery Scripting
jQuery(document).ready(function(){
								
	// Image Crossfade
	jQuery("img.a").hover(
	function() {
		jQuery(this).stop().animate({"opacity": "0"}, 100);
	},
	function() {
		jQuery(this).stop().animate({"opacity": "1"}, 600);
	});

	// Smooth Scroll
	jQuery('.middle-container').localScroll();
	
	// Custom Scrollbars
	jQuery(function()
	{
		jQuery('.twitterfeed').jScrollPane();
    	});
	
	// Twitter Feed
	jQuery(".social-feed").getTwitter({
		userName: "unlikeabank",
		numTweets: 1,
		loaderText: "Loading tweets...",
		slideIn: true,
		slideDuration: 750,
		showHeading: true,
		headingText: "Latest Tweet",
		showProfileLink: false,
		showTimestamp: true
	});

	// Homepage Header Flip
	jQuery(function () {
		var tabs = [];
		var headers = [];

		jQuery('#tab1 a').each(function () {
			if(this.pathname.replace(/^\//,'') == window.location.pathname.replace(/^\//,'')) {
				tabs.push(this);
				headers.push(jQuery(this.hash).get(0));
			}
		});
		jQuery('#tab2 a').each(function () {
			if(this.pathname.replace(/^\//,'') == window.location.pathname.replace(/^\//,'')) {
				tabs.push(this);
				headers.push(jQuery(this.hash).get(0));
			}
		});
		jQuery('#tab3 a').each(function () {
			if(this.pathname.replace(/^\//,'') == window.location.pathname.replace(/^\//,'')) {
				tabs.push(this);
				headers.push(jQuery(this.hash).get(0));
			}
		});

		jQuery(headers).hide();
		jQuery('.header-container:first').show();

		jQuery(tabs).click(function () {
			// hide all tabs
			jQuery(headers).hide().filter(this.hash).fadeIn(500);

			// turn off all other selected classes
			jQuery(tabs).parent().removeClass('tabs-hoveron');
			jQuery(tabs).parent().addClass('tabs-hover');

			// set up the selected class
			jQuery(tabs).filter(this).parent().removeClass('tabs-hover');
			jQuery(tabs).filter(this).parent().addClass('tabs-hoveron');
		});
	});

	// Content Expand
	jQuery(".form-download-container").hide();
	jQuery(".form-container-dropdown").click(function()
	{
		jQuery(this).next(".form-download-container").slideToggle(300);
	});

	// Search Dropdown
	jQuery('.search-dropdown').hide();
	jQuery('.printemail-sub #search').click(function() {
	    jQuery('.search-dropdown').slideToggle(300);
    });

    // Font Size Dropdown
    jQuery('.fontsize-dropdown').hide();
    jQuery('.printemail-sub #fontsize').click(function () {
        jQuery('.fontsize-dropdown').slideToggle(300);
    });

    // Font Resizing
    $("#up").fontscale("p", "up", { unit: "px", increment: 1, useCookie: true });
    $("#down").fontscale("p", "down", { unit: "px", increment: 1, useCookie: true });
    $("#reset").fontscale("p", "reset");

    $("#up").fontscale("h3", "up", { unit: "px", increment: 1, useCookie: true });
    $("#down").fontscale("h3", "down", { unit: "px", increment: 1, useCookie: true });
    $("#reset").fontscale("h3", "reset");

});


// Image Hover
if (document.images) {
    picOurCommunityon = new Image(122, 34);
    picOurCommunityon.src = "/image/OurCommunityButtonOn.jpg";

    picOurCommunityoff = new Image(122, 34);
    picOurCommunityoff.src = "/image/OurCommunityButtonOff.jpg";

    picOurLifestyleson = new Image(110, 34);
    picOurLifestyleson.src = "/image/OurLifestylesButtonOn.jpg";

    picOurLifestylesoff = new Image(110, 34);
    picOurLifestylesoff.src = "/image/OurLifestylesButtonOff.jpg";

    picOurCareon = new Image(79, 34);
    picOurCareon.src = "/image/OurCareButtonOn.jpg";

    picOurCareoff = new Image(79, 34);
    picOurCareoff.src = "/image/OurCareButtonOff.jpg";

    picYourIndependenceon = new Image(143, 34);
    picYourIndependenceon.src = "/image/YourIndependenceButtonOn.jpg";

    picYourIndependenceoff = new Image(143, 34);
    picYourIndependenceoff.src = "/image/YourIndependenceButtonOff.jpg";

    picCareerson = new Image(71, 34);
    picCareerson.src = "/image/CareersButtonOn.jpg";

    picCareersoff = new Image(71, 34);
    picCareersoff.src = "/image/CareersButtonOff.jpg";

    picContactUson = new Image(90, 34);
    picContactUson.src = "/image/ContactUsButtonOn.jpg";

    picContactUsoff = new Image(90, 34);
    picContactUsoff.src = "/image/ContactUsButtonOff.jpg";
}

function lightup(imgName) {
    if (document.images) {
        imgOn = eval(imgName + "on.src");
        document[imgName].src = imgOn;
    }
}

function turnoff(imgName) {
    if (document.images) {
        imgOff = eval(imgName + "off.src");
        document[imgName].src = imgOff;
    }
}


// Search Removes and Adds
function RemoveSearchPhrase()
{
    if (document.SearchForm.Search.value != "Search Phrase")
    {
        
    }
    else
    {
        document.SearchForm.Search.value = "";
    }
}
function AddSearchPhrase()
{
    if (document.SearchForm.Search.value != "")
    {
        
    }
    else
    {
        document.SearchForm.Search.value = "Search Phrase";
    }
}


// Search Validation
function SearchValidate()
{
    if (document.getElementById("SearchPhrase").value.length <= 2)
	{
		alert("Search Phrase Selection - Please provide a valid entry");
		return false;
	}
	else
	{
		return true;
	}
}


// ENewsletter Removes and Adds
function RemoveEmail()
{
    if (document.subform.email.value != "Email Address")
    {
        
    }
    else
    {
        document.subform.email.value = "";
    }
}
function AddEmail()
{
    if (document.subform.email.value != "")
    {
        
    }
    else
    {
        document.subform.email.value = "Email Address";
    }
}

function RemoveFirstName()
{
    if (document.subform.name.value != "First Name")
    {
        
    }
    else
    {
        document.subform.name.value = "";
    }
}
function AddFirstName()
{
    if (document.subform.name.value != "")
    {
        
    }
    else
    {
        document.subform.name.value = "First Name";
    }
}

function RemoveLastName()
{
    if (document.subform.lastname.value != "Last Name")
    {
        
    }
    else
    {
        document.subform.lastname.value = "";
    }
}
function AddLastName()
{
    if (document.subform.lastname.value != "")
    {
        
    }
    else
    {
        document.subform.lastname.value = "Last Name";
    }
}


// ENewsletter Validation
function $Npro(field)
{
    var element =  document.getElementById(field);
    return element;
    return false;
}

function emailvalidation(field, errorMessage)
{
    var goodEmail = field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\.info)|(\.sex)|(\.biz)|(\.aero)|(\.coop)|(\.museum)|(\.name)|(\.pro)|(\..{2,2}))$)\b/gi);
    apos=field.value.indexOf("@");
    dotpos=field.value.lastIndexOf(".");
    lastpos=field.value.length-1;
    
    var badEmail = (apos<1 || dotpos-apos<2 || lastpos-dotpos<2)

    if (goodEmail && !badEmail)
    {
        return true;
    }
    else
    {
        //alert(errorMessage);
        $Npro("Error").innerHTML=errorMessage;
        $Npro("Error").style.display="inline";
        field.focus();
        field.select();
        return false;
    }
}

function emptyvalidation(entered, errorMessage)
{
    $Npro("Error").innerHTML="";
    with (entered)
    {
        if (value==null || value=="")
        {
            //alert(errorMessage);
            $Npro("Error").innerHTML=errorMessage;
            $Npro("Error").style.display="inline";
            return false;
        }
        else
        {
            return true;
        }
    }
}

function formvalidation(thisform)
{
    with (thisform)
    {
        if (emptyvalidation(name,"Please enter your name")==false)
        {
            name.focus();
            return false;
        };
        if (emptyvalidation(lastname,"Please enter your last name")==false)
        {
            lastname.focus();
            return false;
        };
        if (emailvalidation(email,"Please enter your valid email address")==false)
        {
            email.focus();
            return false;
        };
    }
}


// Contests ENewsletter Validation
function $Npro2(field)
{
	var element =  document.getElementById(field);
	return element;
	return false;
}

function emailvalidation2(field, errorMessage)
{
	var goodEmail = field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\.info)|(\.sex)|(\.biz)|(\.aero)|(\.coop)|(\.museum)|(\.name)|(\.pro)|(\..{2,2}))$)\b/gi);

	apos = field.value.indexOf("@");
	dotpos = field.value.lastIndexOf(".");
	lastpos = field.value.length-1;

	var badEmail = (apos<1 || dotpos-apos<2 || lastpos-dotpos<2)

	if (goodEmail && !badEmail)
	{
		return true;
	}
	else 
	{
		//alert(errorMessage);
		$Npro2("Error").innerHTML=errorMessage;
		$Npro2("Error").style.display="inline";
		field.focus();
		field.select();
		return false;
	}
}

function emptyvalidation2(entered, errorMessage)
{
	$Npro2("Error").innerHTML="";

	with (entered)
	{
		if (value==null || value=="")
		{
			//alert(errorMessage);
			$Npro2("Error").innerHTML=errorMessage;
			$Npro2("Error").style.display="inline";
			return false;
		}
		else
		{
			return true;
		}
	}
}

function formvalidation2(thisform)
{
	with (thisform)
	{
		if (emptyvalidation2(name,"Please enter your name")==false)
		{
			name.focus();
			return false;
		};
		if (emptyvalidation2(lastname,"Please enter your last name")==false)
		{
			lastname.focus();
			return false;
		};
		if (emailvalidation2(email,"Please enter your valid email address")==false)
		{
			email.focus();
			return false;
		};
		if (emptyvalidation2(subphone1,"Please enter your phone number")==false)
		{
			subphone1.focus();
			return false;
		};
		if (emptyvalidation2(address,"Please enter your address")==false)
		{
			address.focus();
			return false;
		};
		if (emptyvalidation2(city,"Please enter your city")==false)
		{
			city.focus();
			return false;
		};
		if (emptyvalidation2(zip,"Please enter your zip")==false)
		{
			zip.focus();
			return false;
		};
	}		
}
