
/*

Image Preloader
http://farinspace.com/2009/05/jquery-image-preload-plugin/
*/

function imgpreload(a,b){if(b instanceof Function){b={all:b}}if(typeof a=="string"){a=[a]}var c=[];var t=a.length;var i=0;for(i;i<t;i++){var d=new Image();d.onload=function(){c.push(this);if(b.each instanceof Function){b.each.call(this)}if(c.length>=t&&b.all instanceof Function){b.all.call(c)}};d.src=a[i]}}if(typeof jQuery!="undefined"){(function($){$.imgpreload=imgpreload;$.fn.imgpreload=function(b){b=$.extend({},$.fn.imgpreload.defaults,(b instanceof Function)?{all:b}:b);this.each(function(){var a=this;imgpreload($(this).attr('src'),function(){if(b.each instanceof Function){b.each.call(a)}})});var c=[];this.each(function(){c.push($(this).attr('src'))});var d=this;imgpreload(c,function(){if(b.all instanceof Function){b.all.call(d)}});return this};$.fn.imgpreload.defaults={each:null,all:null}})(jQuery)}



/*
Octopus Engine - Round Courners 
http://dragon-labs.com/articles/octopu
*/
function addEvent(obj, evType, fn) {
	if (obj.addEventListener) {
		obj.addEventListener(evType, fn, true);
		return true;
	} else if (obj.attachEvent) {
		var r = obj.attachEvent("on"+evType, fn);
		return r;
	} else {
		return false;
	}
}

function initOctopus() {
	classTree     = new Array(3);
	classTree[0]  = ["north","east","south","west","ne","se","sw","nw"];
	classTree[1]  = ["faux","north","south"];
	classTree[2]  = ["north", "east", "west", "south"];
	classNames    = ['octopus', 'squid', 'swordfish'];
	
	tempdivs = [];
	divs = document.getElementsByTagName('div');
	for (i=0;i<divs.length;i++) {
		for (j=0; j<3; j++) {
			cdiv = divs[i];
			if (cdiv.className.indexOf(classNames[j]) > -1) {
				tempinner = cdiv.innerHTML;
				cdiv.innerHTML = "";
				prevdiv = cdiv;
				for (a=0; a<classTree[j].length; a++) {
					tempdivs[a] = document.createElement('div');
					tempdivs[a].className = classTree[j][a];
					prevdiv.appendChild(tempdivs[a]);
					prevdiv = tempdivs[a];
				}
				prevdiv.innerHTML = tempinner;
			}
		}
	}
}

if (document.getElementById && document.createElement) { addEvent(window, 'load', initOctopus); }
/* end of octopus engine */

/* Image Rollver and Preloader */
PEPS = {};

PEPS.rollover =
{
   init: function(){
      this.preload();
     
      $(".hover").hover(
         function () { $(this).attr( 'src', PEPS.rollover.newimage($(this).attr('src')) ); },
         function () { $(this).attr( 'src', PEPS.rollover.oldimage($(this).attr('src')) ); }
      );
   },

   preload: function() {
      $(window).bind('load', function() {
         $('.hover').each( function( key, elm ) { $('<img>').attr( 'src', PEPS.rollover.newimage( $(this).attr('src') ) ); });
      });
   },
   
   newimage: function( src ) {
      return src.substring( 0, src.search(/(\.[a-z]+)$/) ) + '_o' + src.match(/(\.[a-z]+)$/)[0];
   },

   oldimage: function( src ){
      return src.replace(/_o\./, '.');
   }
};
/* Image Rollver and Preloader */


function scrollTo(selector) {
    var targetOffset = $(selector).offset().top;
    $('html,body').animate({scrollTop: targetOffset}, 1500);
}


function toggleDiv(id){
	$(id).slideToggle();
}

$(document).ready( function(){
   PEPS.rollover.init();
	
	 $(".listingTable tr:nth-child(odd)").addClass("oddRow");
	 
	$(".imageWrap").wrap('<div class="octopus"><div class="bodyImageWrapper"></div></div>');

	$('#whatsNew').cycle({ 
		fx:      'scrollUp', 
		speed:    800, 
		timeout:  6000 
	});
	
	$('#workshopPics').cycle({ 
		fx:    'turnRight', 
		speed:  4000 
	 });

	$('#homeFeaturedProjectsBot').cycle({ 
		fx:     'scrollDown', 
		speed:  800, 
		timeout: 0, 
		next:   '#fpNext', 
		prev:   '#fpPrev' 
	});


    $(".equipmentsImage").hover(
      function () {
		$(this).children("h4").animate({ marginLeft: "0.6in"}, 300 );
      }, 
      function () {
		$(this).children("h4").animate({ marginLeft: "0"}, 300 );
      }
    );
	
	
});

