var rbNav;
$(document).ready(function(){
	rbNav = new clickNav();
	// external_check =  new external_links();
});

var clickNav = function()
{
	/*Create a reference to self for use inside of object, if needed*/
	var self = this;
	
	/*Class names we're using to reveal flyouts*/
	var li_class_name = "sfhover";
	var anchor_class_name = "active";
	
	/*Store visible element*/
	var needs_to_be_closed;
	
	/*Get all the correct hover items. Not fool-proof*/
	$('body').click(function(e){
		//if it should be open, let's open it
		if( $(e.target).parent().parent().hasClass('flyout') == true && $(e.target).parent().hasClass(li_class_name) == false && $(e.target).parent().hasClass('ignore') == false )
		{
			close_flyouts(); //close previously opened menus
			needs_to_be_closed = $(e.target).parent();
			$(needs_to_be_closed).addClass(li_class_name);
			$(e.target).addClass(anchor_class_name);
			e.preventDefault();
		}
		//if it's a fly out and it is currently open let's close it
		else if( $(e.target).parent().parent().hasClass('flyout') == true && $(e.target).parent().hasClass(li_class_name) == true && $(e.target).parent().hasClass('ignore') == false )
		{
			close_flyouts();
			e.preventDefault();
		}
		//let's also close it if it's not a flyout
		else if ( $(e.target).parent().parent().hasClass('flyout') == false ||  $(e.target).parent().hasClass('ignore') == true)
		{
			close_flyouts();
		}
	});
	function close_flyouts()
	{
		if(needs_to_be_closed != null)
		{
			$(needs_to_be_closed).removeClass(li_class_name);
			$(needs_to_be_closed).children('a').first().removeClass(anchor_class_name);
			needs_to_be_closed = null;
		}
	}
}

// function external_links()
// {
// 	var self = this;
// 	
// 	//Let's get the current domain in a dynamic way
// 	this.domain_patt = function()
// 	{
// 		var domain_str = new String(window.location);
// 		
// 		//Get the domain, the stuff after http://
// 		domain_str = domain_str.slice( domain_str.indexOf("//") + 2 );
// 		
// 		//Chop off the stuff after the domain
// 		if( domain_str.match(/\//g) != null )
// 		{
// 			domain_str = domain_str.slice( 0, domain_str.indexOf("/") );
// 		}
// 		
// 		//Chop off the www
// 		if( domain_str.match(/www\./g) != null )
// 		{
// 			domain_str = domain_str.slice(4);
// 		}
// 		
// 		/*Let's figure out if domain has 2 or more dots let's strip out the www. and domain
// 		(don't forget that some domains have 3 dots www. and .co.uk)*/
// 		if( domain_str.match(/\./g) != null )
// 		{
// 			domain_str = domain_str.slice( 0, domain_str.indexOf(".") );
// 		}
// 		return new RegExp(domain_str);
// 	}
// 	
// 	//checks for any http protocol
// 	this.http_test = function(string){
// 		if ( string.match(/http/g) != null )
// 		{
// 			return true;
// 		}
// 		else
// 		{
// 			return false;
// 		}
// 	}
// 	
// 	//Checks link destination, returns true if the link is internal
// 	this.internal_link = function(href_string)
// 	{
// 		//Does the string have a http:// in it? (sometimes internal links won't have it)
// 		if( self.http_test(href_string) == false )
// 		{
// 			return true;
// 		}
// 		//If it has http, let's find out if it has a domain
// 		else if (href_string.match(self.domain_patt()) != null )
// 		{
// 			return true;
// 		}
// 		//if not, it's very likely an external link
// 		else
// 		{
// 			return false;
// 		}
// 	};
// 	
// 	//External Links array
// 	this.links_array = new Array();
// 	$('a').each(function(){
// 		if ( self.internal_link($(this).attr("href")) == false )
// 		{
// 			self.links_array.push( $(this) );
// 		}
// 	});
// 	
// 	//add click handler for each item of the external link array, display confirmation message and allow users to continue to their destination if it's an external link. 
// 	$(self.links_array).each(function()
// 	{
// 		var confirmation_text = "Republic Bank has no control over information at any site hyperlinked to from this Site and makes no representation concerning and is not responsible for the quality, content, nature, or reliability of any hyperlinked site  and is providing this hyperlink to you only as a convenience. The inclusion of any hyperlink does not imply any endorsement, investigation, verification or monitoring by Republic Bank of any information in any hyperlinked site. In no event shall Republic Bank be responsible for your use of a hyperlinked site. \n\nTo remain at our site, click Cancel. To leave our site for the link you selected, click OK. Thank you for visiting our site.";
// 		
// 		$(this).click(function(e){
// 			if( confirm(confirmation_text) == true )
// 			{
// 				
// 			}
// 			else
// 			{
// 				e.preventDefault();
// 			}
// 		});
// 	});
// 	
// 	
// }
