$(document).ready(function(){

	// Main Menu
	$.each($("#menu li ul"), function() {
		if ( $("li", this).size() > 1 ){
			$(this).addClass("submenu").closest("li").hover(function(){
				$("a:first", this).addClass("hover");
				$("ul", this).stop().fadeTo("fast", 0.95, function(){
					$(this).show();
				});
			}, function(){
				$("a:first", this).removeClass("hover");
				$("ul", this).stop().fadeTo("fast", 0, function(){
					$(this).hide();
				});
			});			
		}
	});

	// Alpha Images
	$(".pngfix").pngfix();

	// External Links
	$("a[href*='http://']:not([href*='"+location.hostname+"']):not([rel='special'])").attr("target","_blank");
	
	// Lonsec PDF for financial advisors
	if ($('a.lonsec').length) {
		var lonsec = '<div id="lonsec-container" style="background-color:#eee; display:none; margin-bottom:20px; padding:10px 10px 5px 10px; border:1px solid #ccc;"><p><strong>ADVISER ACKNOWLEDGMENT</strong></p>';
		lonsec = lonsec + '<p>The information provided is for the use of licensed financial advisors only. In no circumstances is it to be used by a potential investor for the purposes of making a decision about a financial product or class of products. Any advice is not personal advice and has been prepared without taking into account investors objectives, financial situation or needs.</p>';
		lonsec = lonsec + '<p><form><input type="checkbox" name="lonsec" id="lonsec" /> <label for="lonsec"><strong>I confirm that I am a licensed financial advisor.</strong></label></form></p>';
		lonsec = lonsec + '<p><a href="' + $('a.lonsec').attr('href') +'" id="lonsec-dl" style="display:none;">Click here to download the Lonsec Research Report summary</a></p></div>';
	
		$('a.lonsec').attr('href', '#');
		$('a.lonsec').parent().after(lonsec);
	
		$('input#lonsec').click(function(e) {
			if ($(this).is(':checked')) {
				$('#lonsec-dl').show();
			} else {
				$('#lonsec-dl').hide();
			}
		});
	
		$('a.lonsec').click(function(e) {
			e.preventDefault(); 
			if ($('#lonsec-container').is(':visible')) {
				$('#lonsec-container').slideUp();
			} else {
				$('#lonsec-container').slideDown();
			}
		});		
	}

	// Document Links
	/*
	$("#page a[href$='.pdf']:not(:has(img))").addClass("pdf").addClass("document");
	$("#page a[href$='.doc']:not(:has(img))").addClass("doc").addClass("document");
	$("#page a[href$='.docx']:not(:has(img))").addClass("doc").addClass("document");
	$("#page a[href$='.xls']:not(:has(img))").addClass("xls").addClass("document");
	$("#page a[href$='.xlsx']:not(:has(img))").addClass("xls").addClass("document");
	*/

	// Page Tools
	$("#tools a.print").click(function(){ window.print(); });
	$("#tools a.email").attr("href","mailto:?subject=Charter Hall&body="+location.href+"%0A%0A");
	$("#tools a").hover(function(){
		$("span, label", this).stop().fadeTo("fast", 1);
	}, function(){
		$("label", this).stop().fadeTo("fast", 0);
		$("span", this).stop().fadeTo("fast", 0.5);
	});
	
	// Quick Search
	var searchText = "Search";
	$("#searchText").defaultvalue(searchText);
	$("#search").submit(function(){
		if( $("#searchText").val() == searchText ){
			$("#searchText").val("").focus();
			return false;
		}
		return true;
	});	
});
