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

$(document).ready(function(){
   checkboxinteraction();
   if ($('body').is('#home')) {
      homepageimagemarquee();
      if ($('#mainsection').is('.teaser')) {
      $('.submitbutton').click(function(){
      $(this).parent('li').parent('ul').parent('div').parent('div').parent('fieldset').parent('form').submit();
      }); //click
      } else {
      hashtaghandler();
      homepageformhandler();
      homepageholdopen();
      }
   } else {
//      imagemarquee();
      newimagemarquee();
      formhandler();
   } //if home
   if ($('.imagecontainer.designstyles').length) {
      designstyles();
   } // if imagecontainer exists
   if ($('body').is('.blog')) {
      blognavsettings();
//      alert($('h3.pagetitle').text());
if ($('h3.pagetitle').text() == "Events"){
$('h3.pagetitle').text("News & Events");
}; //if events
   } //if blog
   if($('#system_message').length) {
      fadesystemmessage();
   } //if system_message
   if($('a.zoom').length) {
      initializefancybox();
   } //fancybox
   if($('.fancytrigger').length) {
      initializefancybox();
   } //fancybox
   if($('a.closed').length) {
      faqopenshut();
   } //if faq closers
   if ($('.businesshome').length) {
      businesshomebgposition();
   } //if businesshome
   if($('.leadstatus').length) {
      leadstatuschange();
   } //if leadstatus
   if($('.whatsthis').length) {
      verificationpopup();
   } //if leadstatus
   if($('#content').is('.business')) {
      checktheremotecontrollength();
   } //if content is business
   if($('body').is('#subscription')) {
      subscriptionfailsafe();
   } //if body is subscription
});




/*==( Checkbox Replacemenet/Interaction )======================================================*/

function checkboxinteraction() {
	$('input:checkbox').checkbox();
	$('input:radio').checkbox();

	$('span.jquery-checkbox').click(function(){
   	$(this).siblings('label').focus();
	}); //focus

	$('input:checkbox').focus(function() {
   	$(this).next('span.jquery-checkbox').children('span').addClass('jquery-checkbox-hover');
	}); //focus
	$('input:radio').focus(function() {
   	$(this).next('span.jquery-checkbox').children('span').addClass('jquery-checkbox-hover');
	}); //focus

	$('input:checkbox').blur(function() {
   	$(this).next('span.jquery-checkbox').children('span').removeClass('jquery-checkbox-hover');
	}); //focus
	$('input:radio').blur(function() {
   	$(this).next('span.jquery-checkbox').children('span').removeClass('jquery-checkbox-hover');
	}); //focus


	$('input:checkbox').siblings('label').css({'paddingLeft': '25px'});
	$('input:radio').siblings('label').css({'paddingLeft': '25px'});

   if (jQuery.browser.msie) {
     if(parseInt(jQuery.browser.version) < 8) {
      	$('input:checkbox').siblings('label').css({'float': 'left'});
      	$('input:radio').siblings('label').css({'float': 'left'});
     } //ifparseint
   } //ifie

	
}; //checkboxinteraction




/* ==( Marquee Image Rotation )========================================================*/

function imagemarquee() {
if ($('#content').is('.businesshome')) {

} else {
   howmanyimagesarethere = 41;
   randomimage1=Math.floor(Math.random()*howmanyimagesarethere)+1;
   randomimage2=Math.floor(Math.random()*howmanyimagesarethere)+1;
   randomimage3=Math.floor(Math.random()*howmanyimagesarethere)+1;
   randomimage4=Math.floor(Math.random()*howmanyimagesarethere)+1;
   randomimage5=Math.floor(Math.random()*howmanyimagesarethere)+1;
   getrandomimage1();
   getrandomimage2();
   getrandomimage3();
   getrandomimage4();
   getrandomimage5();
   $('ul.imagemarquee').children('li').eq(0).children('img').attr({'src': '/images/marquee/marquee'+randomimage1+'.jpg'});
   $('ul.imagemarquee').children('li').eq(1).children('img').attr({'src': '/images/marquee/marquee'+randomimage2+'.jpg'});
   $('ul.imagemarquee').children('li').eq(2).children('img').attr({'src': '/images/marquee/marquee'+randomimage3+'.jpg'});
   $('ul.imagemarquee').children('li').eq(3).children('img').attr({'src': '/images/marquee/marquee'+randomimage4+'.jpg'});
   $('ul.imagemarquee').children('li').eq(4).children('img').attr({'src': '/images/marquee/marquee'+randomimage5+'.jpg'});

   imagemarqueeloop();
   }; //if
}; //imagemarquee



function in_array(val, array) {
   for ( i = 0; i < array.length; i++ ) {
      if( array[i] == val ) return true;
   }
   return false;
}


var neworder = [2,4,0,1,3];


function newimagemarquee() {
if ($('#content').is('.businesshome')) {

} else {

   var rand_arr = new Array();
   var max = 41;
   var display_max = 5;
   
   do {
      var r = Math.floor(Math.random()*max)+1;
      if( !in_array( r, rand_arr ) ) rand_arr[rand_arr.length] = r;
   } while (rand_arr.length < max)
   
   
//   $('body').append('<div>' + rand_arr.join(',') + '</div>');

   var display_array = new Array();
   for( i = 0; i < display_max; i++ ) {
      display_array[i] = rand_arr[i];
   }
   
//   $('body').append('<div id="test"><ul><li>' + display_array.join('</li><li>') + '</li></ul></div>');

   var idx = 0;

for (n=0; n<display_max; n++) {
   if(i == max) i = 0;
   if(idx == display_max) idx = 0;
   
   
$('ul.imagemarquee').children('li').eq(neworder[idx++]).children('img').attr({'src': '/images/marquee/marquee'+(rand_arr[i++])+'.jpg'});
}; //for

   setInterval(function() {
      if(i == max) i = 0;
      if(idx == display_max) idx = 0;


      $('ul.imagemarquee').children('li').eq(neworder[idx]).children('img').animate({'opacity': '0'}, 1000);
      setTimeout( function () {$('ul.imagemarquee').children('li').eq(neworder[idx++]).children('img').attr({'src': '/images/marquee/marquee'+(rand_arr[i++])+'.jpg'})}, 1000 );
      $('ul.imagemarquee').children('li').eq(neworder[idx]).children('img').animate({'opacity': '1'}, 1000);
      
   }, 4000);

}; //if
}; //newimagemarquee




function homepageimagemarquee() {

   howmanyimagesarethere = 41;
   
   $('ul.imagemarquee').children('li').eq(1).css({'float': 'right'}).parent('ul').children('li').eq(2).css({'float': 'right'});
   randomimage1=Math.floor(Math.random()*howmanyimagesarethere)+1;
   randomimage2=Math.floor(Math.random()*howmanyimagesarethere)+1;
   randomimage3=Math.floor(Math.random()*howmanyimagesarethere)+1;
   randomimage4=1000; //arbitrary number
   randomimage5=1001; //arbitrary number
   getrandomimage1();
   getrandomimage2();
   getrandomimage3();
   $('ul.imagemarquee').children('li').eq(0).children('img').attr({'src': '/images/marquee/marquee'+randomimage1+'.jpg'});
   $('ul.imagemarquee').children('li').eq(1).children('img').attr({'src': '/images/marquee/marquee'+randomimage2+'.jpg'});
   $('ul.imagemarquee').children('li').eq(2).children('img').attr({'src': '/images/marquee/marquee'+randomimage3+'.jpg'});

   homepageimagemarqueeloop();

}; //homepageimagemarquee






function getrandomimage1(){
      randomimage1=Math.floor(Math.random()*howmanyimagesarethere)+1;
   if (randomimage1 == randomimage2 || randomimage1 == randomimage3 || randomimage1 == randomimage4 || randomimage1 == randomimage5) {
      getrandomimage1();
   } //if
}; //getrandomimage1

function getrandomimage2(){
   randomimage2=Math.floor(Math.random()*howmanyimagesarethere)+1;
   if (randomimage2 == randomimage1 || randomimage2 == randomimage3 || randomimage2 == randomimage4 || randomimage2 == randomimage5) {
      getrandomimage2();
   } //if
}; //getrandomimage2

function getrandomimage3(){
   randomimage3=Math.floor(Math.random()*howmanyimagesarethere)+1;
   if (randomimage3 == randomimage1 || randomimage3 == randomimage2 || randomimage3 == randomimage4 || randomimage3 == randomimage5) {
      getrandomimage3();
   } //if
}; //getrandomimage3

function getrandomimage4(){
   randomimage4=Math.floor(Math.random()*howmanyimagesarethere)+1;
   if (randomimage4 == randomimage1 || randomimage4 == randomimage2 || randomimage4 == randomimage3 || randomimage4 == randomimage5) {
      getrandomimage4();
   } //if
}; //getrandomimage3

function getrandomimage5(){
   randomimage3=Math.floor(Math.random()*howmanyimagesarethere)+1;
   if (randomimage5 == randomimage1 || randomimage5 == randomimage2 || randomimage5 == randomimage3 || randomimage5 == randomimage4) {
      getrandomimage5();
   } //if
}; //getrandomimage3

function homepageimagemarqueeloop() {
   setTimeout( function () {
      getrandomimage2();
      $('ul.imagemarquee').children('li').eq(1).children('img').animate({'opacity': '0'}, 1000);
      setTimeout( function () {$('ul.imagemarquee').children('li').eq(1).children('img').attr({'src': '/images/marquee/marquee'+randomimage2+'.jpg'})}, 1000 );
      $('ul.imagemarquee').children('li').eq(1).children('img').animate({'opacity': '1'}, 1000);
   }, 7000 );
   setTimeout( function () {
      getrandomimage3();
      $('ul.imagemarquee').children('li').eq(2).children('img').animate({'opacity': '0'}, 1000);
      setTimeout( function () {$('ul.imagemarquee').children('li').eq(2).children('img').attr({'src': '/images/marquee/marquee'+randomimage3+'.jpg'})}, 1000 );
      $('ul.imagemarquee').children('li').eq(2).children('img').animate({'opacity': '1'}, 1000);
   }, 3000 );
   image1loop = setInterval (function(){
      getrandomimage1();
      $('ul.imagemarquee').children('li').eq(0).children('img').animate({'opacity': '0'}, 1000);
      setTimeout( function () {$('ul.imagemarquee').children('li').eq(0).children('img').attr({'src': '/images/marquee/marquee'+randomimage1+'.jpg'})}, 1000 );
      $('ul.imagemarquee').children('li').eq(0).children('img').animate({'opacity': '1'}, 1000);
   }, 10000); //verbloop
   setTimeout( function () {
      image2loop = setInterval (function(){
         getrandomimage2();
         $('ul.imagemarquee').children('li').eq(1).children('img').animate({'opacity': '0'}, 1000);
         setTimeout( function () {$('ul.imagemarquee').children('li').eq(1).children('img').attr({'src': '/images/marquee/marquee'+randomimage2+'.jpg'})}, 1000 );
         $('ul.imagemarquee').children('li').eq(1).children('img').animate({'opacity': '1'}, 1000);
      }, 10000); //verbloop
   }, 7000 );
   setTimeout( function () {
      image3loop = setInterval (function(){
         getrandomimage3();
         $('ul.imagemarquee').children('li').eq(2).children('img').animate({'opacity': '0'}, 1000);
         setTimeout( function () {$('ul.imagemarquee').children('li').eq(2).children('img').attr({'src': '/images/marquee/marquee'+randomimage3+'.jpg'})}, 1000 );
         $('ul.imagemarquee').children('li').eq(2).children('img').animate({'opacity': '1'}, 1000);
      }, 10000); //verbloop
   }, 3000 );
}; //homepageimagemarqueeloop


function imagemarqueeloop() {
   setTimeout( function () {
      getrandomimage2();
      $('ul.imagemarquee').children('li').eq(1).children('img').animate({'opacity': '0'}, 1000);
      setTimeout( function () {$('ul.imagemarquee').children('li').eq(1).children('img').attr({'src': '/images/marquee/marquee'+randomimage2+'.jpg'})}, 1000 );
      $('ul.imagemarquee').children('li').eq(1).children('img').animate({'opacity': '1'}, 1000);
   }, 7000 );

   setTimeout( function () {
      getrandomimage3();
      $('ul.imagemarquee').children('li').eq(2).children('img').animate({'opacity': '0'}, 1000);
      setTimeout( function () {$('ul.imagemarquee').children('li').eq(2).children('img').attr({'src': '/images/marquee/marquee'+randomimage3+'.jpg'})}, 1000 );
      $('ul.imagemarquee').children('li').eq(2).children('img').animate({'opacity': '1'}, 1000);
   }, 3000 );

   setTimeout( function () {
      getrandomimage4();
      $('ul.imagemarquee').children('li').eq(3).children('img').animate({'opacity': '0'}, 1000);
      setTimeout( function () {$('ul.imagemarquee').children('li').eq(3).children('img').attr({'src': '/images/marquee/marquee'+randomimage4+'.jpg'})}, 1000 );
      $('ul.imagemarquee').children('li').eq(3).children('img').animate({'opacity': '1'}, 1000);
   }, 11000 );

   setTimeout( function () {
      getrandomimage5();
      $('ul.imagemarquee').children('li').eq(4).children('img').animate({'opacity': '0'}, 1000);
      setTimeout( function () {$('ul.imagemarquee').children('li').eq(4).children('img').attr({'src': '/images/marquee/marquee'+randomimage5+'.jpg'})}, 1000 );
      $('ul.imagemarquee').children('li').eq(4).children('img').animate({'opacity': '1'}, 1000);
   }, 15000 );



   image1loop = setInterval (function(){
      getrandomimage1();
      $('ul.imagemarquee').children('li').eq(0).children('img').animate({'opacity': '0'}, 1000);
      setTimeout( function () {$('ul.imagemarquee').children('li').eq(0).children('img').attr({'src': '/images/marquee/marquee'+randomimage1+'.jpg'})}, 1000 );
      $('ul.imagemarquee').children('li').eq(0).children('img').animate({'opacity': '1'}, 1000);
   }, 19000); //verbloop



   setTimeout( function () {
      image2loop = setInterval (function(){
         getrandomimage2();
         $('ul.imagemarquee').children('li').eq(1).children('img').animate({'opacity': '0'}, 1000);
         setTimeout( function () {$('ul.imagemarquee').children('li').eq(1).children('img').attr({'src': '/images/marquee/marquee'+randomimage2+'.jpg'})}, 1000 );
         $('ul.imagemarquee').children('li').eq(1).children('img').animate({'opacity': '1'}, 1000);
      }, 19000); //verbloop
   }, 7000 );



   setTimeout( function () {
      image3loop = setInterval (function(){
         getrandomimage3();
         $('ul.imagemarquee').children('li').eq(2).children('img').animate({'opacity': '0'}, 1000);
         setTimeout( function () {$('ul.imagemarquee').children('li').eq(2).children('img').attr({'src': '/images/marquee/marquee'+randomimage3+'.jpg'})}, 1000 );
         $('ul.imagemarquee').children('li').eq(2).children('img').animate({'opacity': '1'}, 1000);
      }, 19000); //verbloop
   }, 3000 );


   setTimeout( function () {
      image4loop = setInterval (function(){
         getrandomimage4();
         $('ul.imagemarquee').children('li').eq(3).children('img').animate({'opacity': '0'}, 1000);
         setTimeout( function () {$('ul.imagemarquee').children('li').eq(3).children('img').attr({'src': '/images/marquee/marquee'+randomimage4+'.jpg'})}, 1000 );
         $('ul.imagemarquee').children('li').eq(3).children('img').animate({'opacity': '1'}, 1000);
      }, 19000); //verbloop
   }, 11000 );


   setTimeout( function () {
      image5loop = setInterval (function(){
         getrandomimage5();
         $('ul.imagemarquee').children('li').eq(4).children('img').animate({'opacity': '0'}, 1000);
         setTimeout( function () {$('ul.imagemarquee').children('li').eq(4).children('img').attr({'src': '/images/marquee/marquee'+randomimage5+'.jpg'})}, 1000 );
         $('ul.imagemarquee').children('li').eq(4).children('img').animate({'opacity': '1'}, 1000);
      }, 19000); //verbloop

   }, 15000 );

}; //imagemarqueeloop




/* ==( Homepage Form AJAX )========================================================*/

function hashtaghandler() {
   hashvalue = window.location.hash.substring(1);
   if (hashvalue.length) {
      hashtagindex(hashvalue);
   }; //if hashvalue length
}; //hashtaghandler

function hashtagindex(hashvalue) {
   switch(hashvalue) {
      case "storesandproducts":
         gotohomepagestepb();
         break;
      case "peopleandservices":
         gotohomepagestepc();
         break;
      default:
   } //switch
}; //hashtagindex

function gotohomepagestepb() {
if ($('input#cat1').is(':checked')) {
   $('body').append('<div class="imaletyoufinish"><span>Loading</span></div>');
   setTimeout( function () { $('#submitbutton1').click() }, 100 );
   $('.imaletyoufinish').css({'width': $(window).width(), 'height': $(window).height()});
   $('.imaletyoufinish').children('span').css({'width': $(window).width(), 'height': $(window).height()});
   setTimeout( function () { $('.imaletyoufinish').remove() }, 3000 );
} else {
   setTimeout( function () {
      $('input#cat1').click();
      $('#submitbutton1').click();
   }, 100 );
   $('body').append('<div class="imaletyoufinish"><span>Loading</span></div>');
   $('.imaletyoufinish').css({'width': $(window).width(), 'height': $(window).height()});
   $('.imaletyoufinish').children('span').css({'width': $(window).width(), 'height': $(window).height()});
   setTimeout( function () { $('.imaletyoufinish').remove() }, 3000 );
} //if
}; //gotohomepagestepb

function gotohomepagestepc() {
if ($('input#cat2').is(':checked')) {
   $('body').append('<div class="imaletyoufinish"><span>Loading</span></div>');
   setTimeout( function () { $('#submitbutton1').click() }, 100 );
   $('.imaletyoufinish').css({'width': $(window).width(), 'height': $(window).height()});
   $('.imaletyoufinish').children('span').css({'width': $(window).width(), 'height': $(window).height()});
   setTimeout( function () { $('.imaletyoufinish').remove() }, 5000 );
   setTimeout( function () { 
   if ($('ul.cat2sub').children('li').children('p.clickable').length) {
      $('ul.cat2sub').children('li').children('p.clickable').click();
   }; //if submitbutton2
   }, 3000 );
} else {
   setTimeout( function () {
      $('input#cat2').click();
      $('#submitbutton1').click();
   }, 100 );
   $('body').append('<div class="imaletyoufinish"><span>Loading</span></div>');
   $('.imaletyoufinish').css({'width': $(window).width(), 'height': $(window).height()});
   $('.imaletyoufinish').children('span').css({'width': $(window).width(), 'height': $(window).height()});
   setTimeout( function () { $('.imaletyoufinish').remove() }, 3000 );
} //if
}; //gotohomepagestepb
















function homepageformhandler() {

   setTimeout( function () { $('.formproper').find('select').eq(0).focus() }, 100 );

   $('#submitbutton1').click(function(){

	if ($('input#cat2').is(':checked')||$('input#cat1').is(':checked')) {
      $(this).unbind();

      if ($('#region').val() == 0) {
         alert("Please select where your project is located.");
         return(false);
      }
   

   	$.ajax({
   		type: "POST",
   		url: "/category_list",
   		dataType: "html",
		data: "region="+$('#region').val(),
   		success: function(pulleddata) {
   			
			var flag;
			flag = false;
      		if ($('input#cat1').is(':checked')) {
				if ($(pulleddata).find('ul.cat1sub').length>0) {
					flag = true;
					$('.formproper').append('<div class="section" id="cat1section"></div>');
					$(pulleddata).find('ul.cat1sub').each(function(i){
						$(this).appendTo('#cat1section');
					});
				}
      		} //if storesandproducts
   
      		if ($('input#cat2').is(':checked')) {
				if ($(pulleddata).find('ul.cat2sub').length>0) {
					flag = true;
					$('.formproper').append('<div class="section" id="cat2section"></div>');
					$(pulleddata).find('ul.cat2sub').each(function(i){						
						$(this).appendTo('#cat2section');
					});
				}
      		} //if storesandproducts
			if(!flag){
				$('.formproper').append('<div>There are no categories available for the selected region. </div>');
			}





            checkboxinteraction();

      		if ($('input#cat2').is(':checked')||$('input#cat1').is(':checked')) {
               setTimeout( function () { $('#mainsection').next('.section').children('ul').children('li:first').children('ul:first').children('li:first').children('input').focus() }, 250);
               dontignoreyourkids();
               $('.section#mainsection').slideUp(800).next('.section').slideDown(800);
               $('.formproper').children('div.section:last').find('.submitbutton').addClass('continue');
            } //if either option on the initial screen is checked, proceed.

            $('#submitbutton2').click(function(){
         		if ($('input#cat2').is(':checked')) {

               isitsafetogo = 0;
               $('#submitbutton2').parent('li').prev('li').children('ul').children('li').each(function() {
                  if ($(this).children('input').is(':checked')) {
                     isitsafetogo = 1;
                  }; //if
               }); //each
               if (isitsafetogo == 1) {
            		twotothree();
            		return false;
               } else {
                  $('#submitbutton2').parent('li').prev('li').children('p').css({'position': 'relative'}).animate({'left': '-5px'}, 100).animate({'left': '5px'}, 100).animate({'left': '-5px'}, 100).animate({'left': '5px'}, 100).animate({'left': '0px'}, 100);
               } //if any checkboxes are checked
         		} //if
            }); //click #submitbutton2
            
               $('.submitbutton.continue').click(function(){
               isitsafetogo = 0;
               $('.submitbutton.continue').parent('li').prev('li').children('ul').children('li').each(function() {
                  if ($(this).children('input').is(':checked')) {
                     isitsafetogo = 1;
                  }; //if
               }); //each
               if (isitsafetogo == 1) {
                  $('div.homepageform').children('form').submit();
               } else {
                  $('.submitbutton.continue').parent('li').prev('li').children('p').css({'position': 'relative'}).animate({'left': '-5px'}, 100).animate({'left': '5px'}, 100).animate({'left': '-5px'}, 100).animate({'left': '5px'}, 100).animate({'left': '0px'}, 100);
               } //if any checkboxes are checked
            }); //submit form

            $('ul').siblings('input:checkbox').click(function(){
               if ($(this).siblings('ul').hasClass('open')) {
                  $(this).siblings('ul').removeClass('open').slideUp(500);
                  $(this).siblings('ul').children('li').children('input:checked').click();
               } else {
                  $(this).siblings('ul').addClass('open').slideDown(500);
               } //if
            }); //click checkbox with a ul sibling

            if ($('input#cat2').is(':checked')&&$('input#cat1').is(':checked')) {
               $('.section#cat2section').children('ul').children('li').eq(1).css({'display': 'none'});
               $('.section#cat2section').children('ul').children('li').eq(0).children('ul').css({'display': 'none'});
               $('.section#cat2section').slideDown(800);

               $('.section#cat2section').children('ul').children('li:first').children('p').addClass('clickable');
               $('.section#cat2section').children('ul').children('li:first').children('p').click(function() {
                  twotothree();
               }); //click second p

            } //if both options on the initial screen are checked, set functions to be able to move between them.

   		} //success
   	}); //ajax
      return false;
	} else {
      $('#mainsection').children('ul').children('li').eq(1).children('p').css({'position': 'relative'}).animate({'left': '-5px'}, 100).animate({'left': '5px'}, 100).animate({'left': '-5px'}, 100).animate({'left': '5px'}, 100).animate({'left': '0px'}, 100);
   } //if either is checked
   }); //click
}; //homepageformhandler

function twotothree(){
   $('.section#cat2section').children('ul').children('li').eq(1).slideDown(800);
   $('.section#cat2section').children('ul').children('li').eq(0).children('ul').slideDown(800);
   $('.section#cat1section').children('ul').children('li').eq(1).slideUp(800);
   $('.section#cat1section').children('ul').children('li').eq(0).children('ul').slideUp(800);
   setTimeout( function () { $('input#cat2-1').focus() }, 250 );

   $('.section#cat1section').children('ul').children('li:first').children('p').addClass('clickable');

   $('.section#cat2section').children('ul').children('li:first').children('p').unbind().removeClass('clickable');
   $('.section#cat1section').children('ul').children('li:first').children('p').click(function() {
   $('.section#cat2section').children('ul').children('li:first').children('p').addClass('clickable');
      threetotwo();
   }); //click first p
}; //twotothree

function threetotwo(){
   $('.section#cat2section').children('ul').children('li').eq(1).slideUp(800);
   $('.section#cat2section').children('ul').children('li').eq(0).children('ul').slideUp(800);
   $('.section#cat1section').children('ul').children('li').eq(1).slideDown(800);
   $('.section#cat1section').children('ul').children('li').eq(0).children('ul').slideDown(800);
   setTimeout( function () { $('input#cat1-1').focus() }, 250 );

   $('.section#cat1section').children('ul').children('li:first').children('p').unbind().removeClass('clickable');
   $('.section#cat2section').children('ul').children('li:first').children('p').click(function() {
   $('.section#cat1section').children('ul').children('li:first').children('p').addClass('clickable');
      twotothree();
   }); //click second p
}; //twotothree



function formhandler() {

   dontignoreyourkids();

   $('ul').siblings('input:checkbox').click(function(){
      if ($(this).siblings('ul').hasClass('open')) {
         $(this).siblings('ul').removeClass('open').slideUp(500);
         $(this).siblings('ul').children('li').children('input:checked').click();
      } else {
         $(this).siblings('ul').addClass('open').slideDown(500);
      } //if
   }); //click checkbox with a ul sibling

}; //formhandler


function designstyles() {
   $('.imagecontainer.designstyles').parent('div').siblings('.left').find('li').children('label').hover(function(){
      idofhovered = $(this).siblings('input').attr('id');
      hoveredimage = $("#"+idofhovered+"_image").val();
      $('.imagecontainer.designstyles').children('p').text($(this).text());
      $('.imagecontainer.designstyles').children('img').attr({'src': '/images/design_styles/'+hoveredimage});
   }, function(){
   }); //hover
   $('.imagecontainer.designstyles').parent('div').siblings('.left').find('li').children('span').hover(function(){
      idofhovered = $(this).siblings('input').attr('id');
      hoveredimage = $("#"+idofhovered+"_image").val();
      $('.imagecontainer.designstyles').children('p').text($(this).siblings('label').text());
      $('.imagecontainer.designstyles').children('img').attr({'src': '/images/design_styles/'+hoveredimage});
   }, function(){
   }); //hover
}; //design image box hover fx



function dontignoreyourkids() {
   setTimeout( function () {
      $('span.jquery-checkbox-checked').siblings('ul').addClass('open').slideDown(500);
   }, 800 );
}; //dontignoreyourkids; open child uls of checked elements





/*==( Blog Navigation Active States )======================================================*/

function blognavsettings() {
$('div.remotecontrolcontent').children('ul.subnav').find('li').each(function(){
if ($(this).children('a').text() == $('.majorhead h3 span').text()) {
$(this).addClass('active');
} // if
}); //each li in accountnav in remotecontrolcontent
}; //blognavsettings






/*==( Error Messaging )======================================================*/

function fadesystemmessage() {
   setTimeout( function () {
   $('#system_message').fadeOut(1000);
   }, 5000 );
}





/*==( Fancybox )======================================================*/

function initializefancybox() {

$('a.fancytrigger').siblings('input:hidden[value="yes"]').siblings('a.fancytrigger').addClass('on');
$('a.fancytrigger').siblings('input:hidden[value="1"]').siblings('a.fancytrigger').addClass('on');

$('a.zoom').append('<span class="zoomin">Zoom In</span>');
$("a.zoom").fancybox({
	'zoomSpeedIn'		:	500,
	'zoomSpeedOut'		:	500
});
$(".fancytrigger").fancybox({
	'zoomSpeedIn'		:	500,
	'zoomSpeedOut'		:	500
});

$('a.fancytrigger').click(function() {
$(this).addClass('on');
if($(this).parent().find('input:hidden').length) {
$(this).parent().find('input:hidden').val('1');
}
});

}; //initializefancybox


/*==( FAQ Open/Closing )======================================================*/

function faqopenshut() {
   $('a.closed').siblings().css({'display': 'none'});
   
   $('a.closed').toggle(function(){
      $(this).siblings().slideDown();
   }, function() {
      $(this).siblings().slideUp();
   }); //toggle

}; //faqopenshut



/*==( Business Homepage )======================================================*/

function businesshomebgposition() {
majorheadheightplus = $('.majorhead').height() - 40;
businesshomebgvar = "0px "+majorheadheightplus +"px";
$('div#content').css({'backgroundPosition': businesshomebgvar});
$('div.subscriptionstatus').css({'height': $('.subscriptionstatus').prev('div.promo').height()+12});
}; //businesshomebgposition




/*==( Lead Status Change )======================================================*/

function leadstatuschange() {
   $('select.leadstatus').change(function(){
      $(this).parent('td').css({'backgroundColor': '#654459', 'color': '#fff'});
      $(this).parent('td').animate({'backgroundColor': '#ebe2d1', 'color': '#575249'}, 1500);
   }); //change
}; //leadstatuschange



/*==( Verification Popup )======================================================*/

function verificationpopup() {
   $('a.whatsthis').toggle(function(){
      $(this).parent('label').parent('li').parent('ul').after('<p class="verificationpopup">A Card Verification Code, or CVC, is a number that provides extra security to credit and debit card holders, in case an unauthorized person gets a hold of your account number. CVCs are one way to make sure someone has the actual card in his or her possession. <br /><br /> The CVC on American Express cards is four digits, and is located on the front of the card, on the right side. Discover, MasterCard, and Visa use three-digit CVCs, which are listed on the back of the card. The CVC is the last three digits of the number that appears on your signature bar.</p>');
      $('p.verificationpopup').css({'top': $(this).position().top-50});
      return false;
   }, function() {
      $('p.verificationpopup').remove();
      return false;
   }); //change
}; //leadstatuschange




/*==( Remote Control Length )======================================================*/

function checktheremotecontrollength() {
   remotecontrolheight = $('.remotecontrol').height();
   if (($('.remotecontrol').offset().top+$('.remotecontrol').height()) < $('.contentproper').offset().top ) {
      $('.remotecontrolcontent').css({'height': $('.contentproper').offset().top - ($('.remotecontrol').offset().top+$('.remotecontrol').height()) + $('.remotecontrol').height() -50 });
   }; //if
};


/*==( Subscription Fail-Safe )======================================================*/

function subscriptionfailsafe() {
   $('input#save').click(function() {
      disableinput($(this));
   });
   $('input#purchaseextracredits').click(function() {
      disableinput($(this));
   });
}; //subscriptionfailsafe


function disableinput(todisable) {
   todisable.css({'visibility': 'hidden'});
}; //disableinput




/*==( Homepage Content Height )======================================================*/

function homepageholdopen() {

//alert($('.homepageminor').height())
$('#content').css({'minHeight': $('.homepageminor').height()});

}; //homepageholdopen

