var sidebar = {
	init: function() {
		$("#cntr_menu li > ul").parent().mouseover(function(){
			$(this).children("ul").show();
			$(this).children("a").addClass("active");
		}).mouseleave(function() {
			$(this).children("ul").hide();
			$(this).children("a").removeClass("active");
		});
	}
};

var exit = {
	loc: null,
	link: null,
	init: function() {
		var url = document.location.href;

		if(url.indexOf("espanol") != -1)
			$.ajax({
				url: "../includes/exit.html",
				success: function(html) {
					$("body").append(html);

					$("a").each(function(){
						var loc = $(this).attr("href");
						loc = loc.toLowerCase();

						if((loc.indexOf("http://") != -1 || loc.indexOf("https://")) != -1 && loc.indexOf("helmbankusa.com") == -1 && loc.indexOf("ibanking-services") == -1) {
							$(this).addClass("exit");
							exit.inject($(this));
						}
					});

					$("a.exit").fancybox({
						'hideOnContentClick': false,
						'frameWidth': 560,
						'frameHeight': 327,
						'padding': 0,
						'overlayOpacity': 0.5,
						'callbackOnClose': exit.restore
					});
				}
			});
		else
			$.ajax({
				url: "../includes/exit_en.html",
				success: function(html) {
					$("body").append(html);

					$("a").each(function(){
						var loc = $(this).attr("href");
						loc = loc.toLowerCase();

						if((loc.indexOf("http://") != -1 || loc.indexOf("https://")) != -1 && loc.indexOf("helmbankusa.com") == -1 && loc.indexOf("ibanking-services") == -1) {
							$(this).addClass("exit");
							exit.inject($(this));
						}
					});

					$("a.exit").fancybox({
						'hideOnContentClick': false,
						'frameWidth': 560,
						'frameHeight': 327,
						'padding': 0,
						'overlayOpacity': 0.5,
						'callbackOnClose': exit.restore
					});
				}
			});
	},
	inject: function($o) {
		$o.mousedown(function(){
			exit.loc = $o.attr("href");
			$("#lnk_alert_url").live("click", function(){
				window.open(exit.loc);
				$.fn.fancybox.close();
			});
			$("#lnk_close").live("click", function(){
				$.fn.fancybox.close();
			});

			$o.attr("href","#cntr_lightbox_alert");
			exit.link = $o;
		});
	},
	restore: function() {
		exit.link.attr("href",exit.loc);
	}
}

$(function(){
	sidebar.init();
	exit.init();
});
