// JavaScript Document
//Prevents error from using console.log in IE
try { console.log('init console... done'); } catch(e) { console = { log: function() {} } }

IE_List = function() {
	if (document.all&&document.getElementById) {
		var ul_array = document.getElementsByTagName("ul");
		for (i=0; i<ul_array.length; i++) {
			if(ul_array[i].className == 'hover') {
				setList(ul_array[i]);
			}
		}
	}
}
addLoadListener(IE_List);

var setIEOvers = function(list) {
	listItems = list.getElementsByTagName("li");
	for(k=0; k<listItems.length; k++) {
		var node = listItems[k];
		node.onmouseover=function() {this.className+=" over";}
		node.onmouseout=function() {this.className=this.className.replace(" over", "");}
	}
}

/* 18/10/2006 - addLoadListener, PopupWindow, addClass, removeClass */
function addLoadListener(fn){if(typeof window.addEventListener!='undefined'){window.addEventListener('load',fn,false);}else if(typeof document.addEventListener!='undefined'){document.addEventListener('load',fn,false);}else if(typeof window.attachEvent!='undefined'){window.attachEvent('onload',fn);}else{var oldfn=window.onload;if(typeof window.onload!='function'){window.onload=fn;}else{window.onload=function(){oldfn();fn();};}}};
var win=null;function PopupWindow(url,n,w,h,sc){var sw=screen.availWidth;var sh=screen.availHeight;lp=(sw)?(sw-w)/2:0;tp=(sh)?(sh-h)/2:0;se='height='+h+',width='+w+',top='+tp+',left='+lp+',scrollbars='+sc+',resizable=no';win=window.open(url,n,se);win.focus();}
function addClass(t,c){var p=new RegExp("(^| )" + c + "( |$)");if(!p.test(t.className)){if(t.className == "")t.className=c;else t.className+=" "+c;}return true;}
function removeClass(t,c){var r=t.className;var p=new RegExp("(^| )"+c+"( |$)");r=r.replace(p,"$1");r=r.replace(/ $/,"");t.className=r;return true;}

sfHover = function() {
	if (document.getElementById("mainNavContainer") != null)
	{
	var sfEls = document.getElementById("mainNavContainer").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
	}
}

if (window.attachEvent) window.attachEvent("onload", sfHover);

/* function for 1st level left nav*/
skHover = function() {
	if(document.getElementById("LeftNav") !=null)
	{
	var sfEls = document.getElementById("LeftNav").getElementsByTagName("li");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" skhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" skhover\\b"), "");
		}
	}
	}
}
if (window.attachEvent) window.attachEvent("onload", skHover);

/* function for left nav*/
slHover = function() {
	if(document.getElementById("secondLevel") !=null)
	{
	var sfEls = document.getElementById("secondLevel").getElementsByTagName("li");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" slhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" slhover\\b"), "");
		}
	}
	}
}
if (window.attachEvent) window.attachEvent("onload", slHover);

/* function for "Our Expertise" nav*/
smHover = function() 
{
  if(document.getElementById("ourExpertiseTable") !=null)
  {
    var sfEls = document.getElementById("ourExpertiseTable").getElementsByTagName("li");
	for (var i=0; i<sfEls.length; i++) 
	{
	  sfEls[i].onmouseover=function() 
	  {
        // Class name of "more" is a speical case so take care of it
		if(this.className.indexOf("more") != -1)
		{
		  this.className+=" smhover";
		}
		else
		{
		  this.className+=" snhover";
		}
	  }
	  sfEls[i].onmouseout=function() 
	  {
	    this.className=this.className.replace(new RegExp(" smhover\\b"), "");
	    this.className=this.className.replace(new RegExp(" snhover\\b"), "");
	  }
	}
  }
}
if (window.attachEvent) window.attachEvent("onload", smHover);

/* Setting items in a dynamic list to active */
function mdynamicListActive(thisClass)
{
  if(document.getElementById("dynamicContainer") != null)
  {
    var sfEls = document.getElementById("dynamicContainer").getElementsByTagName("a");
	for (var i=0; i<sfEls.length; i++) 
	{
	    sfEls[i].className=sfEls[i].className.replace(new RegExp("dynamicListActive\\b"), "");
    }
    thisClass.className="dynamicListActive";
  }
}

/* IE6 underline on mouseover for dynamic anchor */
function displayUnderline(thisClass)
{
  thisClass.textDecoration = "underline";
}

/* Remvoe IE6 mouseout for dynamic anchor */

function removeUnderline(thisClass)
{
  thisClass.textDecoration = "none";
}





/*
     _/\/\/\/\/\/\______________________________________/\/\________/\/\____/\/\____/\/\_______________
    _/\/\__________/\/\__/\/\____/\/\/\______/\/\/\____/\/\________________/\/\____/\/\______/\/\/\/\_ 
   _/\/\/\/\/\____/\/\/\/\____/\/\/\/\/\__/\/\/\/\/\__/\/\/\/\____/\/\____/\/\____/\/\____/\/\/\/\___  
  _/\/\__________/\/\________/\/\________/\/\________/\/\__/\/\__/\/\____/\/\____/\/\__________/\/\_   
 _/\/\__________/\/\__________/\/\/\/\____/\/\/\/\__/\/\__/\/\__/\/\/\__/\/\/\__/\/\/\__/\/\/\/\___    
__________________________________________________________________________________________________     
*/





/* Random banners on the home page */


function DEV__rBanners(thisArray, links) {
	console.log('DEV_rBanners is running');
	imageArray = new Array();
	totalBanners = 0;
	imgCt = thisArray.length;
    for (i = 0; i < imgCt; i++) {
     	if (thisArray[i] != "") {
        	imageArray[totalBanners] = thisArray[i];
            totalBanners = totalBanners + 1;
        }
	}
	if (totalBanners != 0) {
	  ranNum = Math.floor(Math.random() * totalBanners);
	  var chosenLink = links[ranNum] + "?source=banner";
	  //chosenLink += "?source=banner";
	  //create homepage banner in template, then appendTo here
	  document.write("<a href='" + chosenLink + "'><img src='" + imageArray[ranNum] + "' border='0'></a>");
	}
}

/*
bannerImages = new Array("/images/tivey_john_home_tile_520x292_miningBlog(1).jpg", "/images/fox_michelle_home_tile_520x292_navy.jpg", "/images/blue_christopher_0700_home_tile_520x292.JPEG");
bannerLinks = new Array("http://freehillsmining.blogspot.com/", "/123.aspx", "/313.aspx");
*/




//Rewriting for new pattern
var freehillsPage = function(){
	
	/* Variables */
		
	
	
	
	/* Bindings */
		function bindEvents(){
			
			/* Zebra Tables*/		
			$(".zebra tr:nth-child(odd)").addClass("odd");
			
			/* Social bookmarks fly-out widget  */
			if (jQuery.tools){
				$(".strigger").tooltip({
									tip: '#socialpop',
									delay: 333
				}); 
			}
			
			/* Homepage 'awards' fade in-out cycle*/
			if (jQuery.innerfade){
				$('#awards_animation').innerfade({ 
									 speed: 'slow', 
									 timeout: 7000, 
									 type: 'sequence', 
									 containerheight: '235' 
				}); 		
			}
			
			/* Tabs on internatinoal expertise pages */	
			if(jQuery.ui){
					$( "#inttabs" ).tabs();
			}
		
				

			
		}/*end bindEvents()*/
	
	
	/* Functions */
		function internationalMapInteractive(){
				
				// Checks if still hovering somthing relevent, otherwise fade out
				function checkHover(){				
					if( $('#asiaShape').data('hover') == true || $('#asiaMenu').data('hover') == true ){
						return;
					}
					else{
						$('.mapHoverImg, #asiaMenu').stop(true,true).fadeOut('600');
						$('#asiaMenu').data('hover', false);
					}
				}

				$('#asiaMenu').hover( 
					function(){
						$(this).data('hover', true);
					},
					function(){
						$(this).data('hover', false);
						setTimeout(checkHover, 10);
					});
				

				$('.mapShape').hover(
					function () {
						var id = this.id;
						$(this).data('hover', true);

						if( id == 'asiaShape' && $('#asiaMenu').css('display') == 'block' ){} 
						// If going from asiaMenu to asiaShape && menu is already visible, do nothing
						else{
							$('.mapHoverImg, #asiaMenu').not('#'+id.replace('Shape', 'Dark')).stop(true,true).fadeOut('600');
							$('#'+id.replace('Shape', 'Dark')).stop(true,true).fadeIn('600');
						}
						// else hovering onto a hotspot? fade out everything except currenet, fadein relevent on-hover image
						
						if(id == 'asiaShape'){
							$('#asiaMenu').stop(true,true).fadeIn('600');
						}
						// Hovering the asiaShape? Fade in asiaMenu too
					
					},
					function(){
						var id = this.id;
						$(this).data('hover', false);
						
						if( id == 'asiaShape' && $('#asiaMenu').css('display') == 'block' ){
							setTimeout(checkHover, 10);
						}
						else{
							$('.mapHoverImg, #asiaMenu').stop(true,true).fadeOut('600');
							//$('#asiaMenu').data('hover', false);
						}
						
					}
				);
		}

	return {
		/* Initialise function*/
		init: function(){
			bindEvents();
			internationalMapInteractive();
		}
	}	
	
}();





$(document).ready(function() { 
	freehillsPage.init();
});
