(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)

jQuery(document).ready(function() {	
	/* Flash-Text Replacement: Content H2
	$('.content h2 span, #homepage .screen h2 span').flash(
		{ 
			src: basePath+'interface/flash/helvetica-neue_67-medium-condensed.swf',  
			flashvars: { 
				css: [
					'* { color: #ef8d06; }',
					'a { color: #ef8d06; text-decoration: none; }',
					'a:hover { text-decoration: underline; }'
				].join(' ')
			},
			wmode: "transparent"
		},
		{ version: 7 },
		function(htmlOptions) {
			htmlOptions.flashvars.txt = this.innerHTML;
			this.innerHTML = '<span>'+this.innerHTML+'</span>';
			var $alt = $(this.firstChild);
			htmlOptions.height = $alt.height();
			htmlOptions.width = $alt.width();
			$alt.addClass('alt');
			$(this)
				.addClass('flash-replaced')
				.prepend($.fn.flash.transform(htmlOptions));						
		}
	);
	*/
	// Lead Form
	$(".subpanel form, #homepage #frmSubscribe").ajaxForm({
        success: function(responseText){
            $.fancybox({
				overlayOpacity: 0.8,
				zoomSpeedIn: 10,
				hideOnContentClick: false,
				type: 'ajax',
				width: 300,
				height: 180,
                'content': responseText
            });
        }
    });
	
	// Menu
	$(".header li").hoverIntent({
		sensitivity: 1, 
		interval: 1, 
		over: function() {
			$(this).addClass("selected");
			$(".sub", this).removeClass("hide").animate({opacity: 1}, 500);
		}, 
		timeout: 50, 
		out: function() {
			$(this).removeClass("selected");
			$(".sub", this).addClass("hide").animate({opacity: .0}, 100);
		}
	});
	$(".header .sub").addClass("hide");
	
	// Homepage
	if(document.getElementById('homepage')) {
		//featuretabs
		$("#featureTabs .controls a").click(
			function() {
				$(this).parents("ul").find("a").removeClass("active");
				$(this).addClass("active");
				$("#featureTabs .containers .active").removeClass("active");
				base = $(this).attr("href").split("#");
				$("#"+base[1]).addClass("active");
				
				return false;
			}
		);
		// lifephases
		$(".lifephases .panel").hover(
			function() { $(this).addClass("panelactive"); $(".header").addClass("header"+$(this).attr("id")); },
			function() { $(this).removeClass("panelactive"); $(".header").removeClass("header"+$(this).attr("id")); }
		);
	}
	
	$("#ddlNumberOfDependants").change(
		function() {
			numItems = $("#ddlNumberOfDependants").val();
			$(".dependant").addClass("offleft");
			for(i=1;i<(parseInt(numItems)+1);i++) {
				$("#Dependant"+i).removeClass("offleft");
			}
		}
	);
	
	if(document.getElementById("gMap")) {
		$('#gMap').jmap('init', {mapCenter:[-27.4652, 153.020], mapZoom:15, mapEnableScrollZoom:true})
		$('#gMap').jmap("searchAddress",
			{address: "162 Petrie Terrace, Brisbane, Qld, 4000"},
			function(options, point) {
				$('#gMap').jmap('addMarker', {pointLatLng:[point.y, point.x], pointHTML: "Chris Humphrey<br/>162 Petrie Terrace<br/>Brisbane Qld 4000"});
			}
		);
	}
	
	$("#SearchForm_SearchForm_Search").focus(
		function() { if($(this).val()=="Search") { $(this).val(""); } }
	);
	$("#SearchForm_SearchForm_Search").blur( 
		function() { if($(this).val()=="") { $(this).val("Search");} }
	);
	$("#txtEmailSubscribe").focus(
		function() { if($(this).val()=="Enter your email address") { $(this).val(""); } }
	);
	$("#txtEmailSubscribe").blur( 
		function() { if($(this).val()=="") { $(this).val("Enter your email address");} }
	);
	
	if(document.getElementById('LeadSource')) {
		$("input[name='LeadSource']").val(window.location.pathname);
	}
	
	$(".sidepanel .navigation a").each(
		function() {
			if($(this).attr("href").match(".html/")) {
				$(this).attr("href", ($(this).attr("href").replace(".html/", "/"))+".html");
			}
		}
	);
});

$(window).bind('load', function() {
	if(document.getElementById('homepage')) {
		jQuery.preLoadImages(
			"themes/chrishumphrey/interface/images/banners/homepage.jpg", 
			"themes/chrishumphrey/interface/images/banners/foundation.jpg", 
			"themes/chrishumphrey/interface/images/banners/assest_building.jpg", 
			"themes/chrishumphrey/interface/images/banners/wealth.jpg", 
			"themes/chrishumphrey/interface/images/banners/retirement_planning.jpg", 
			"themes/chrishumphrey/interface/images/banners/retirement.jpg"
		);
	}
});


function printPage() {
	if (window.print) {
		window.print() ;
	} else {
		var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
		document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
		WebBrowser1.ExecWB(6, 2);//Use a 1 vs. a 2 for a prompting dialog box WebBrowser1.outerHTML = "";
	}
}

// Debugging
jQuery.fn.debug = function() {
  return this.each(function(){
    alert(this);
  });
};
jQuery.log = function(message) {
  if(window.console) {
     console.debug(message);
  } else {
     alert(message);
  }
};