
$(document).ready(function() {                
              
	/*external link*/

	$('a[@rel$="external"]').click(function(){this.target = "_blank";});
		
		$('ul.gallery_thumb').galleria({
			history   : true,
			clickNext : false,
			insert    : '#gallery_display',
			onImage   : function(image,thumb) { // let's add some image effects for demonstration purposes
				
				// fade in the image & caption
				image.css('display','none').fadeIn(1000);
				
				// fetch the thumbnail container
				var _li = thumb.parents('li');
				
				// fade out inactive thumbnail
				_li.siblings().children('img.selected').fadeTo(500,0.3);
				
				// fade in active thumbnail
				thumb.fadeTo('fast',1).addClass('selected');
				
				// add a title for the clickable image
				image.attr('title','Next image >>');
			},
			
			onThumb : function(thumb) { // thumbnail effects goes here
				
				// fetch the thumbnail container
				var _li = thumb.parents('li');
				
				// if thumbnail is active, fade all the way.
				var _fadeTo = _li.is('.active') ? '1' : '0.3';
				
				// fade in the thumbnail when finnished loading
				thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);
				
				// hover effects
				thumb.hover(
					function() { thumb.fadeTo('fast',1); },
					function() { _li.not('.active').children('img').fadeTo('fast',0.3); } // don't fade out if the parent is active
				)
			}
		});

					
});


/***********************************************
* Safe email links
***********************************************/

function hideEmail() {
	var s1 = "info";
			var s2 = "@";
			var s3 = "cgcgroup.com.au";
			var s4 = "?Subject=Enquiry%20from%20" + s3;
			var s5 = s1 + s2 + s3;
			document.write("<a href=" + "mail" + "to:" + s1 + s2 + s3 + s4 + ">" + s5 + "</a>");
}


/***********************************************
* Form fields Validation Script
***********************************************/

function ValidateForm(f){

      with(f){
         if (isEmpty(_1_Name.value)) {
            alert("Please enter your Name");
            _1_Name.focus();
            return false;
         }

         if (isEmpty(_2_Email_From.value)) {
            alert("Please enter your Email Address");
            _2_Email_From.focus();
            return false;
         }

         if ( !isEmail(_2_Email_From.value) ) {
            alert("Please enter a valid Email Address.");
            _2_Email_From.focus();
            return false;
         }

         if (!isEmpty(_3_Phone.value)) {
	         if (!IsNumber(_3_Phone.value, true)) {
            	alert("Please enter only numbers for your Phone");
            	_3_Phone.focus();
            	return false;
         	}
         }
         if (!isEmpty(_4_Fax.value)) {
         if (!IsNumber(_4_Fax.value, true)) {
            	alert("Please enter only numbers for your Fax");
            	_4_Fax.focus();
            	return false;
         	}
         }
         if (isEmpty(_5_Enquiries.value)) {
            alert("Please enter your Enquiry");
            _5_Enquiries.focus();
            return false;
         }
   	}
   return true;
 }



/***********************************************
* Random Images Script
***********************************************/

<!-- Begin
// Set up the image files to be used.
var theImages = new Array() // do not change this
// To add more image files, continue with the
// pattern below, adding to the array.

theImages[0] = 'images/inner-banner1.jpg'
theImages[1] = 'images/inner-banner2.jpg'
theImages[2] = 'images/inner-banner3.jpg'
theImages[3] = 'images/inner-banner4.jpg'

// do not edit anything below this line

var j = 0
var p = theImages.length;
var preBuffer = new Array()
for (i = 0; i < p; i++){
   preBuffer[i] = new Image()
   preBuffer[i].src = theImages[i]
}
var whichImage = Math.round(Math.random()*(p-1));
function showimage(){
document.write('<img src="'+theImages[whichImage]+'">');
}

//  End -->



/***********************************************
* show-hide caption
***********************************************/

//Handle hiding or showing the current id
function ShowOrHideTable(sTheID) {

	if ( document.getElementById(sTheID).style.display == "" )  {
		document.getElementById(sTheID).style.visibility = "hidden";
	}
	else {
		HideAll("caption");
		document.getElementById(sTheID).style.display = "";
		document.getElementById(sTheID).style.visibility = "";
	}
}

function HideAll(sPrefix) {

	var oTags = document.getElementsByTagName("*");
	var iPrefixLength = sPrefix.length;

	//Loop through the entire document looking at each tag
	for (var i = 0; i < oTags.length; i++) {
		//If the current tag supports having an ID, continue
		if ( oTags[i].id ) {
			//If the current tag has an ID, continue
			if ( oTags[i].id.length > iPrefixLength ) {
				//Check to see if the current ID is prefixed with what we are trying to hide
				if ( oTags[i].id.substring(0,iPrefixLength) == sPrefix ) {
					document.getElementById(oTags[i].id).style.display = "none";
				}
			}
		}
	}
}

/***********************************************
* Popup URL Script
***********************************************/


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


/***********************************************
* Image Preloader
***********************************************/

//<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

MM_preloadImages('images/banner.jpg','images/inner-banner1.jpg','images/inner-banner2.jpg','images/inner-banner3.jpg','images/inner-banner4.jpg','images/bg-header.gif','images/bg-nav.gif','images/logo.gif')

//-->

/***********************************************
* Dropdown Fix for IE
***********************************************/

sfHover = function() {
	var sfEls = document.getElementById("nav").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);



