/*
Phil Renaud the mad scientist behind this.
phil@rhinointernet.com
http://rhinointernet.com
*/



$(document).ready(function(){
	if ($('.gallery').length) {
		initializegallery();
	} // if imagecontainer exists
if ($('body').hasClass('home')) {
randomfact();
}; //if

navigation();

tablestyles();

});





function navigation() {

   $('ul#navigation').children('li').each(function() {
      if (window.location.pathname.indexOf($(this).children('a').text()) != -1) {
         $(this).addClass('active');
      }; // if
   }); //each link in navigation

}; //navigation





function tablestyles() {
$('.modulesizetable').find('table').find('tbody').find('tr:odd').children('td').css({'backgroundColor': '#fbdb94'});
$('.pricingtable').find('tr:even').children('td').css({'backgroundColor': '#fbdb94'});
}; //tablestyles







/*==( Gallery, Grid, etc. )======================================================*/

function initializegallery() {

$('.gallery').after('<ul class="grid"></ul>');

$('.gallery').children('ul').children('li').eq(0).addClass('active');

$('.gallery').children('ul').children('li').each(function() {
$(this).clone().appendTo('ul.grid');
$(this).append('<div class="description"></div>');
$(this).children('.description').text($(this).children('img').attr('alt'));
}); //each gallery li

$('.gallery').css({'height': '504px', 'marginBottom': '-504px'});

howmanyarethere = $('.gallery').children('ul').children('li').length
//alert(howmanyarethere);
$('.gallery').css({'display': 'none'})
galleryinteraction();

}; //initializegallery







function galleryinteraction() {

$('ul.grid').children('li').hover(function() {
$(this).siblings('li').css({'opacity': '0.8'});
}, function() {
$(this).siblings('li').css({'opacity': '1'});
}); //hover


   $('span.next').click(function(){
      whichisactive = $('.grid').children('li').index($('.grid').children('li.active'));
      if (whichisactive == howmanyarethere-1) {
         $('.grid').children('li').eq(0).click();
      } else {
         $('.grid').children('li').eq(whichisactive+1).click();
      } //if
   }); //click next

   $('span.previous').click(function(){
      whichisactive = $('.grid').children('li').index($('.grid').children('li.active'));
      if (whichisactive == 0) {
         $('.grid').children('li').eq(howmanyarethere-1).click();
      } else {
         $('.grid').children('li').eq(whichisactive-1).click();
      } //if
   }); //click prev

$('ul.grid').children('li:not("active")').click(function() {
//      whichisactive = $('.grid').children('li').index($('.grid').children('li.active'));
$('.gallery').css({'display': 'block'});
   whichdidiclick = $('.grid').children('li').index(this);
   $('.gallery ul').css({'left': -$('.gallery ul').children('li').eq(whichdidiclick).position().left});
   $(this).addClass('active').siblings('.active').removeClass('active');
/*
$('body').append('whichdidiclick: ' + whichdidiclick + '<br />');
$('body').append('whichisactive: ' + whichisactive + '<br />');
$('body').append('howmanyarethere: ' + howmanyarethere + '<br /><br />');
*/

}); //click specific gridspot

$('span.backtogallery').click(function() {
$('.gallery').css({'display': 'none'});
}); //click backtogallery

}; //galleryinteraction
























function randomfact() {
   howmanyfacts = $('div.bluebar').children('div').length;
   randomfactnumber=Math.floor(Math.random()*howmanyfacts);
   $('div.bluebar').children('div').eq(randomfactnumber).addClass('active').show();
thefactloop();

}; //randomfact







function thefactloop() {
factloop = setInterval(function() {
   randomfactnumber=Math.floor(Math.random()*howmanyfacts);
   if (randomfactnumber == $('div.bluebar').children('div').index($('div.bluebar').children('div.active'))) {
   clearInterval(factloop);
   thefactloop();
   } else {
      $('div.bluebar').children('div.active').removeClass('active').hide(500);
      $('div.bluebar').children('div').eq(randomfactnumber).addClass('active').show(500);
   }; //if
}, 6000); //factloop
}; //thefactloop











