//functions to be executed on page load
$(function(){
	
	//Open all links with rel="external" in new window
	$(function(){
		$('a').filter(function(){
			return (!this.target && (this.href.indexOf(window.location.hostname) == -1 || this.href.match(/\.pdf$/i)));
		}).attr('target', '_blank');
	});


	//Clear value in search input box
	swapValues = [];
	$("#T_EMAIL").each(function(i){
		swapValues[i] = $(this).val();
		$(this).focus(function(){
			if ($(this).val() == swapValues[i]) {
				$(this).val("");
			}
		}).blur(function(){
			if ($.trim($(this).val()) == "") {
				$(this).val(swapValues[i]);
			}
		});
	});

		
});

$(window).load(function() {
	if($('#slideshow li').length > 1) {	 
		$("#slideshow li").css("display","block");
		$('#slideshow').fadeSlideShow({
			PlayPauseElement: false,
			NextElement: false,
			PrevElement: false,
			ListElement: false
		});
	};						
});

//functions to be executed inline
var mylib =
{
	dropDown :
	{
		init : function()
		{
			var zIndexNum = 1000;
			$("div").each(function(){
				$(this).css('zIndex',zIndexNum);
				zIndexNum -= 10;
			});
			$(".sub-nav,dl").hide();
			//$(".show").show();
			$('.sub-nav li:last-child').css('border-bottom','none 0');
			
			$("#nav > li").hover(function(){
				$(this).addClass("active");
				$(".sub-nav,dl",this).show();
			},
			function(){
				$(this).removeClass("active");
				$(".sub-nav,dl",this).hide();
			});
			
			$("#sub-nav a").click(function () {
	            $("#sub-nav,dl").hide();
	        });
		}
	},
	gmap :
	{
		init : function()
		{
		$(function () {

                    $("#map").gMap({ markers: [{ latitude: 53.33649, longitude: -6.25839,
                        html: "<img src='images/googleMapLogo.jpg' /><br /><strong>Avoca Capital</strong><br />75 St. Stephens Green, Dublin 2",
                        popup: true
                        }],								   
						controls: ["GSmallMapControl"],						
                        zoom: 14
                    });
                });			
		}
	},
	gmap_london :
	{
		init : function()
		{
		$(function () {

                    $("#map").gMap({ markers: [{ latitude: 51.51581, longitude: -0.08388,
                        html: "<img src='images/googleMapLogo.jpg' /><br /><strong>Avoca Capital</strong><br />Level 9, Tower 42,<br />25 Old Broad Street, London",
                        popup: true
                        }],								   
						controls: ["GSmallMapControl"],						
                        zoom: 14
                    });
                });			
		}
	},
	mega_dropdown :
	{
		init : function()
		{
		$(function() {
			$(".sub-list").hide();
			$("#open-ended-funds,#closed-ended-wrap,.hide").hide();
			var currentSection = $(".current-open").attr("id");
			var currentSub = $(".current-section").next().slideDown(350);
			$("#"+currentSection).show();
			//$("#"+currentSection+" ul.sub-list").first().slideDown(350);
			//$("#"+currentSection+" ul.sub-list").first().prev().addClass("current-section");
			$(".level-two-section a.section").click(function() {
				var parent = $(this).parent().attr("class");
				var overall = $(this).parent().siblings("a").attr("class");
				if (parent != "level-two-section opened"){
					$(".level-two-section .sub-list").slideUp(350);
					$(".level-two-section a").removeClass("current-section");
					$(".level-two-section a").parent().removeClass("opened");
					$(this).next().slideToggle(350);
					$(this).toggleClass("current-section");
					$(this).parent().addClass("opened");
				}
				return false;
			});
			
			$(".overall-section").click(function() {															
				var current = $(".current-open").attr("id");
				var clicked = $(this).attr("id");
				var clickedClass = $("#"+clicked).attr("class");
				if (clickedClass != "overall-section current") {
					$("#open-ended,#closed-ended").removeClass("current");
					$("#open-ended,#closed-ended").next().removeClass("current-open");
					$("#open-ended,#closed-ended").next().slideUp(350);
					$("#"+clicked).next().slideDown(350);
					$("#"+clicked).addClass("current");
				}
				return false;
			});	
			
		});
		}
	}
	

}
