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



$(document).ready(function(){

   if ($('body').is('.home')) {
      slider();
   }
	$('a.buylink, a.selllink').fancybox({
		'titleShow'		: false,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'width'				: 600,
		'height'			: 500,
		'autoDimensions': false,
		'autoScale': false
	});
   $('a.buylink, a.selllink').click(function(){
         setTimeout (function(){
            forminteraction();
         }, 1500);
   }); //click
});






/*==( Homepage Animated Slider )======================================================*/

function slider() {

   $('#hero').append('<div class="panelnav"></div>');
   $('.panelnav').append('<a href="#" class="goleft">Previous</a><a href="#" class="goright">Next</a>');
   
   $('.panel').each(function(){
   $(this).css({'display': 'none'});
   $(this).append('<div></div>');
   $(this).children('h3').appendTo($(this).children('div'));
   $(this).children('a').appendTo($(this).children('div'));
   $(this).children('div').append('<p>'+$(this).children('div').children('a').text()+'</p>');
   $(this).children('div').children('a').appendTo($(this));
   $(this).children('div').css({'bottom': '-150px'});
   }); //each panel
   
   $('.panelcontainer').children('li:first-child').addClass('active').css({'display': 'block'}).children('div').css({'bottom': '0px'});
   
   
   
   looper = setInterval (function(){
      $('.goright').click();
   }, 5000); //bigpromotionloop
   
   
   $('#hero').find('a').hover(function(){
if (!$.browser.msie) {
   $(this).animate({'opacity': '1'}, 200);
}; //if
   }, function() {
if (!$.browser.msie) {
   $(this).stop().animate({'opacity': '0'}, 200);
}; //if
   }); //hover
   
   
   
         $('#hero').hover(function(){
            clearInterval(looper);
         }, function(){
            clearInterval(looper);
            looper = setInterval(function() {
               $('a.goright').click();
            }, 5000);
         }); //hover
   
   gofunctions();      
   };//slider
   function gofunctions(){
   $('.goright').live('click', function(){
   if ($('.panelcontainer').children().children('div').is(':animated')) {
   } else {
      if ($('.panelcontainer').children('li:last-child').is('.active')) {
         $('.panelcontainer').children('.active').children('div').animate({'bottom': '-150px'}, {duration: 1000, easing: 'expoinout'});
         setTimeout (function(){
            $('.panelcontainer').children('.active').fadeOut(1000).removeClass('active').siblings('li:first-child').addClass('active').fadeIn(1000);
         }, 500);
         setTimeout (function(){
            $('.panelcontainer').children('.active').children('div').animate({'bottom': '0px'}, {duration: 1000, easing: 'expoinout'});
         }, 1000);
      } else {
         $('.panelcontainer').children('.active').children('div').animate({'bottom': '-150px'}, {duration: 1000, easing: 'expoinout'});
         setTimeout (function(){
            $('.panelcontainer').children('.active').fadeOut(1000).removeClass('active').next('li').addClass('active').fadeIn(1000);
         }, 500);
         setTimeout (function(){
            $('.panelcontainer').children('.active').children('div').animate({'bottom': '0px'}, {duration: 1000, easing: 'expoinout'});
         }, 1000);
      }; //if active
   }; //if animated
      return false;
   }); //click
   
   
   $('.goleft').live('click', function(){
   if ($('.panelcontainer').children().children('div').is(':animated')) {
   } else {
      if ($('.panelcontainer').children('li:first-child').is('.active')) {
         $('.panelcontainer').children('.active').children('div').animate({'bottom': '-150px'}, {duration: 1000, easing: 'expoinout'});
         setTimeout (function(){
            $('.panelcontainer').children('.active').fadeOut(1000).removeClass('active').siblings('li:last-child').addClass('active').fadeIn(1000);
         }, 500);
         setTimeout (function(){
            $('.panelcontainer').children('.active').children('div').animate({'bottom': '0px'}, {duration: 1000, easing: 'expoinout'});
         }, 1000);
      } else {
         $('.panelcontainer').children('.active').children('div').animate({'bottom': '-150px'}, {duration: 1000, easing: 'expoinout'});
         setTimeout (function(){
            $('.panelcontainer').children('.active').fadeOut(1000).removeClass('active').prev('li').addClass('active').fadeIn(1000);
         }, 500);
         setTimeout (function(){
            $('.panelcontainer').children('.active').children('div').animate({'bottom': '0px'}, {duration: 1000, easing: 'expoinout'});
         }, 1000);
      }; //if active
   }; //if animated
      return false;
   }); //click


}; //gofunctions







/*==( Form Interaction )======================================================*/

function forminteraction() {
$('.boxdetails').find('select').change(function(){

howmanyboxdetailsarethere = $('.theul').children('li.boxdetails').index($('.boxdetails:last'));
//alert(howmanyboxdetailsarethere);
whereami = $('.theul').children('li.boxdetails').index($(this).parent('li').parent('ul').parent('li.boxdetails'));

if (whereami == howmanyboxdetailsarethere) {
addanother();
}

}); //change
}; //forminteraction

function addanother(){
$('.boxdetails:last').clone().insertAfter($('.boxdetails:last'));
forminteraction();
}; //addanother


