///*
//	Copyright DTDigital         :: www.dtdigital.com.au ::
//	Unauthorised modification / use is a criminal offence, and
//	will be prosecuted to the fullest extent permitted by law.
//	All Rights Reserved
//*/




// jQuery functions that run on "dom ready"

var _jQueryLoaded = (typeof(jQuery) == "function");

if (_jQueryLoaded)
{
	$(document).ready(function()
	{
		InitNav();
		ButtonsInit();
		InitScrolling();

		// Makes links open in new window when they have rel=external || class="external-link" || href startes with http:		$("a[rel=external], a.external-link, a[href^=http://]").attr("target", "_blank");
		// Reset attribute for absolute internal links http://www.newgencoal.com.au or http://newgencoal.com.au
		$("a[href^=http://www.newgencoal], a[href^=http://newgencoal]").removeAttr("target");
		
		// Adds default blur text to all empty inputs with this class according to title="" attribute
		$(".fieldhint").fieldhint();
		
		// Applies tooltip functionality
		tooltip();
		
		// IE 6 PNG fix for elements:
		// Elements to "fix" are stored in array for readability, converted back to string to feed into fix.
		var DD_fix =
			[
				"a.btn",
				"input.btn",
				"a.fLink",
				".TB_window-btm-left",
				".TB_window-btm-right",
				".TB_window-top-left",
				".TB_window-top-right",
				"#TB_window #TB_window-top .TB_window-top-left",
				"#TB_window #TB_window-top .TB_window-top-right",
				"#TB_window #TB_window-btm .TB_window-btm-left",
				"#TB_window #TB_window-btm .TB_window-btm-right"
			].toString();

		(typeof DD_belatedPNG == "object") ? DD_belatedPNG.fix(DD_fix) : "";
		
	});
}

function ButtonsInit()
{
	if ($.browser.msie && $.browser.version<7) {
		
		function BtnMouseOver()
		{
			$(this).addClass("btn-hover");
		}
		function BtnMouseOut()
		{
			$(this).removeClass("btn-hover");
		}
		$("input.btn").mouseover(BtnMouseOver).mouseout(BtnMouseOut);
		
	}
	
}


//Smoothe scrolling
function InitScrolling()
{
	var opera = $.browser.opera;
	var isie6 = $.browser.msie && $.browser.version<7;
	var isie7 = $.browser.msie && $.browser.version==7;
	
	if (!opera) { // do not fix header in Opera
		$('#fixedHeader #header, #fixedHeader #bodycontainer').addClass("headerJSON");
	}
	
	if (!isie6 && !isie7 && !opera) { // all good browsers except Opera
		$.localScroll.hash({
			offset: {top:-161, left:0}
		});
		$.localScroll({
			hash:true,
			offset: {top:-161, left:0}
		});
	}
	
	if (isie7) { //ie7 doesn't like the offset and hash
		$.localScroll.hash({
			offset: {top:-161, left:0}
		});
		$.localScroll({
			//hash:true,
			offset: {top:-161, left:0}
		});
	}
	
	if (isie6) { //ie6 doesn't have fixed header
		$.localScroll.hash({
			offset: {top:-20, left:0}
		});
		$.localScroll({
			//hash:true,
			offset: {top:-20, left:0}
		});
	}
}


// Add .hover for ie6
function InitNav()
{
	var bcgImagePath = $("ul#navList li.on").css("background-image").replace(/"/g,"").replace(/url\(|\)$/ig, "");
	$("ul#navList > li.off").hover(function() { //Hover over
		$(this).addClass("over");
		$("ul#navList li.on").css("background-image","none");
	}, function() { //on hover out...
		$(this).toggleClass("over");
		$("ul#navList li.on").removeAttr("style").css("background-image", bcgImagePath);
	});
	
	var hash = (document.location.toString().split('#')[1]);
    if ( hash )
        $('#navList li.on ul a[href$="#' + hash + '"]').attr('class', 'selected');
	
	$("#navList li.on ul a").click(function() { //highlight on click
		$("#navList li.on ul a").removeClass("selected");
		$(this).addClass("selected");
		
	});
}

// field Hints
jQuery.fn.fieldhint = function () {
  return this.each(function (){
    // get jQuery version of 'this'
    var t = jQuery(this); 
    // get it once since it won't change
    var title = t.attr('title'); 
    // only apply logic if the element has the attribute
    if (title) { 
      // on blur, set value to title attr if text is blank
      t.blur(function (){
        if (t.val() == '') {
          t.val(title);
          t.addClass('fieldhint_blur');
        }
      });
      // on focus, set value to blank if current value 
      // matches title attr
      t.focus(function (){
        if (t.val() == title) {
          t.val('');
          t.removeClass('fieldhint_blur');
        }
      });

      // clear the pre-defined text when form is submitted
      t.parents('form').submit(function(){ // THIS USED TO SAY form:first()
          if (t.val() == title) {
              t.val('');
              t.removeClass('fieldhint_blur');
          }
      });
                  // do the same when the window is unloaded
                  $(window).unload(function(){ // THIS USED TO SAY form:first()
          if (t.val() == title) {
              t.val('');
              t.removeClass('fieldhint_blur');
          }
      });

      // now change all inputs to title
      t.blur();
    }
  });
 }

// Simple tooltip script without the need for plugins
this.tooltip = function(){	
	/* CONFIG */		
		var xOffset = 150;
		var yOffset = -280;	
		// these 2 values are fallback values if the browser fails to determine the offset		
	/* END CONFIG */		
	
	// Glossary link tooltip
	$("a.popup-link").hover(function(e){											  
		xOffset = $(this).offset().top;
		
		this.t = this.title;
		this.title = "";	
							  
		$("body").append("<div id='tooltip02'><div class='tooltip-top'>&nbsp;</div><div class='tooltip-container'><div class='tooltip-inner'><h4 class='subtitle08'>"+ this.t.split("::::")[0] + "</h4><p>" + this.t.split("::::")[1] + "</p><div class='clear'>&nbsp;</div></div><div class='clear'>&nbsp;</div></div><div class='tooltip-btm'>&nbsp;</div></div>");
		var tooltipHeight = $("#tooltip02").height();
		$("#tooltip02")
			.css({
				top: (xOffset-tooltipHeight) + "px",
				left: (e.pageX + (yOffset+149)) + "px"
			}).show().pngFix();
	},
	function(){
		this.title = this.t;
		$("#tooltip02").remove();	
	})
	
	// Image bank tooltip
	$("a.tooltip").hover(function(e){											  
		xOffset = $(this).offset().top;
		yOffset = $(this).offset().left-80;
		
		this.t = this.title;
		this.title = "";	
		$(this).css({ position: "relative" });	
							  
		$(this).append("<span class='tooltip-hover' style='display: none;'>&nbsp;</span>");
		$("body").append("<div id='tooltip'><div class='tooltip-top'>&nbsp;</div><div class='tooltip-inner'><h4 class='subtitle08'>"+ this.t.split("::::")[0] + "</h4><p>" + this.t.split("::::")[7] + "</p><div class='clear'>&nbsp;</div></div></div>");
		var tooltipHeight = $("#tooltip").height();
		$("#tooltip")
			.css({
				top: (xOffset-tooltipHeight-16),
				left: ($(this).width()/2) + yOffset
			}).show().pngFix();	
		$(".tooltip-hover")
			.css({
				display: "block",
				position: "absolute",
				top: 0,
				left: 0,
				width: ($.browser.msie) ? $(this).find("img").width()-4 : $(this).find("img").width()-8,
				height: ($.browser.msie) ? $(this).find("img").height()-4 : $(this).find("img").height()-8,
				border: "4px solid #ffffff"
			});	
	},
	function(){
		this.title = this.t;
		$("#tooltip, .tooltip-hover").remove();
		$(this).css("position","");
	}).click(function(){
		this.title = this.t;
	});	
};



// footer column equal height
function setEqualHeight(columns)  {  
	var tallestcolumn = 0;  
	columns.each(  
	function()  
{  
	currentHeight = $(this).height();  
	if(currentHeight > tallestcolumn)  
	{ tallestcolumn  = currentHeight; }}  
);  
	columns.height(tallestcolumn);  
		} $(document).ready(function() {  
	setEqualHeight($(".multi-column01  > div"));  
});  

	 
