/***********************************************************************************************************************

jbrowser.js : Website Functionality

Author:          Bruce Arnold (bruce@webredesignmiami.com)
Copyright:       2011 (c) Bruce Arnold | Web3.0DesignMiami.com  
License:         All Rights Reserved

************************************************************************************************************************/

// PRELOAD IMAGES
(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)
jQuery.preLoadImages(
"./images/infectious-waste-bg2.png"
);



// ON WINDOW LOAD
$(window).load(function() {  
	$('body').css('background-color', '#000000');
	$('#infectious-waste').animate({
		bottom: '-65px'
  	}, 500, 'linear', function() {
		//
		$('#biomedical-waste-management').animate({
			marginTop: '0px'
	  	}, 500, 'swing', function() {
			//
			$('#biomedical-waste-disposal').animate({
				marginTop: '0px'
 		 	}, 500, 'swing', function() {
 		    		$('#Contact_Name').focus();
			});
			//
		});
		//
	});
	//
	$('#infectious-waste-iPad').animate({
		bottom: '0px'
  	}, 500, 'linear', function() {
		//
		$('#biomedical-waste-management').animate({
			marginTop: '0px'
	  	}, 500, 'swing', function() {
			//
			$('#biomedical-waste-disposal').animate({
				marginTop: '0px'
 		 	}, 500, 'swing', function() {
 		    		$('#Contact_Name').focus();
			});
			//
		});
		//
	});
});

// TWITTER UPDATE
function loadSearch1() {
	$.ajax({
	type: "GET",
	url: "./php/search.php",
	cache: false,
	beforeSend: function(html) 
	{
  	  document.getElementById("insert-search").innerHTML = ''; 
	  $('#update1').removeClass('hide');
	  $('#update1').html('<img src="./images/semantic_website_design.gif" width="32" height="32" alt="Loading..." />');	               
      },
	success: function(html)
	{
	  $('#update1').attr('class','show');
	  $("#insert-search").append(html);
	  $('#update1').attr('class','hide');
	  $(function() {
		$("#insert-search a").attr("target", "_blank");
	  });
	}
	});
}

// FORM CHECK
var retVal = false; 
function check_it(the_form){
  $(window).scrollTop(0); 
  check_it2(the_form);
  return retVal;
}
function check_it2(the_form){
    var headerOffset = 20;
    if (the_form.Contact_Name.value == '') {
        alert('Please enter a Contact Name');
        $('html,body').animate({ scrollTop: ( $("#Contact_Name").offset().top - headerOffset ) },
           { duration: 'slow', easing: 'swing'});
        the_form.Contact_Name.focus(); 
        retVal = false;  
        return false;  
    }
    var illegalChars1= /[\(\)\<\>\,\;\:\\\/\"\@\[\]]/
    if (the_form.Contact_Name.value.match(illegalChars1)) {
        alert('Contact name contains illegal characters');
        $('html,body').animate({ scrollTop: ( $("#Contact_Name").offset().top - headerOffset ) },
           { duration: 'slow', easing: 'swing'});
        the_form.Contact_Name.focus(); 
        retVal = false;  
        return false;  
    }
    var illegalChars2= /[\(\)\<\>\,\;\:\\\/\"\[\]]/
    if (the_form.email.value.match(illegalChars2)) {
        alert('The email address contains illegal characters');
        $('html,body').animate({ scrollTop: ( $("#email").offset().top - headerOffset ) },
           { duration: 'slow', easing: 'swing'});
        the_form.email.focus();
        retVal = false;  
        return false;  
    }
    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(the_form.email.value))) { 
        alert('Please enter a valid email address');
        $('html,body').animate({ scrollTop: ( $("#email").offset().top - headerOffset ) },
           { duration: 'slow', easing: 'swing'});
        the_form.email.focus();
        retVal = false;  
        return false;  
    }
    if(the_form.email.value != the_form.email_confirm.value){
        alert('Email address does not match Email Confirm.');
        $('html,body').animate({ scrollTop: ( $("#email").offset().top - headerOffset ) },
           { duration: 'slow', easing: 'swing'});
        the_form.email.focus();
        retVal = false;  
        return false;  
    }
    if (the_form.Telephone_No.value == '') {
        alert('Please enter a Telephone Number');
        $('html,body').animate({ scrollTop: ( $("#Telephone_No").offset().top - headerOffset ) },
           { duration: 'slow', easing: 'swing'});
        the_form.Telephone_No.focus(); 
        retVal = false;  
        return false;  
    }
    if (the_form.Fax_No.value == '') {
        alert('Please enter a Fax Number');
        $('html,body').animate({ scrollTop: ( $("#Fax_No").offset().top - headerOffset ) },
           { duration: 'slow', easing: 'swing'});
        the_form.Fax_No.focus(); 
        retVal = false;  
        return false;  
    }
    var checkdigit4 = parseInt(the_form.checkdigit1.value)+ parseInt(the_form.checkdigit2.value);
    if(parseInt(the_form.checkdigit3.value) != checkdigit4 ){
        alert('Invalid Spam Check Digit.');
        $('html,body').animate({ scrollTop: ( $("#checkdigit3").offset().top - headerOffset ) },
           { duration: 'slow', easing: 'swing'});
        the_form.checkdigit3.focus();
        retVal = false;  
        return false;  
    }
    retVal = true; 
}

// FORM FOCUS
sfFocus = function() { 
  var sfEls1 = document.getElementsByTagName("input"); 
  for (var i=0; i<sfEls1.length; i++) { 
    if( (sfEls1[i].getAttribute("type") != "checkbox") &&
        (sfEls1[i].getAttribute("type") != "radio") )
    {
      sfEls1[i].onfocus=function() { this.className="sfFocus"; } 
      sfEls1[i].onblur=function() { this.className="formbox"; } 
    } 
  } 
  var sfEls2 = document.getElementsByTagName("select"); 
  for (var i=0; i<sfEls2.length; i++) { 
    sfEls2[i].onfocus=function() { this.className="sfFocus"; } 
    sfEls2[i].onblur=function() { this.className="formbox"; } 
  } 
  var sfEls3 = document.getElementsByTagName("textarea"); 
  for (var i=0; i<sfEls3.length; i++) { 
    sfEls3[i].onfocus=function() { this.className="sfFocus"; } 
    sfEls3[i].onblur=function() { this.className="formbox"; } 
  } 
} 
if (window.attachEvent) window.attachEvent("onload", sfFocus); 

// DOCUMENT READY FUNCTIONS
$(document).ready(function(){
  // LINKS
  var anchors = document.getElementsByTagName("a"); 
  for (var i=0; i<anchors.length; i++) { 
    var anchor = anchors[i]; 
    // EXTERNAL
    if (anchor.getAttribute("href") && (anchor.getAttribute("rel") == "external" || anchor.getAttribute("rel") == "external nofollow" )){ 
      anchor.target = "_blank"; 
    }
    // ADD2FAVS
    if ( anchor.className == "add2Favs" ){
      anchor.onclick = function(){
        var titlef = document.title;
        var urlf = location.href;
        if (window.sidebar) { 
          window.sidebar.addPanel(titlef, urlf,""); 
        } 
        else if( document.all ) {
          window.external.AddFavorite( urlf, titlef);
        } 
        else if( window.opera && window.print ) {
          return true;
        }
        return false;
      }
    }
    // ADD2SOCIAL
    if ( anchor.className == "add2Social" ){
      anchor.onclick = function(){
        var titlef = document.title;
        var urlf = location.href;
        window.open('http://www.addthis.com/bookmark.php?v=250&username=&url='+encodeURIComponent(urlf)+'&title='+encodeURIComponent(titlef)+'','_blank');
        return false;
      }
    }
  } 
  // BEG KUDOS UPDATE1
  if ( document.getElementById('kudos-ajax-1') )
  {
    $(function() {
      $(document).ready(function() {
          loadKudos1();
          setInterval("loadKudos1()",30000);
      });
    });
  }
  // END KUDOS UPDATE1
  // TWITTER UPDATE INIT 
  if ( document.getElementById('web30-twitter-4') ) {
    loadSearch1();
    setInterval("loadSearch1()",30000);
  }
  // FORMS INIT 
  $('#Contact').submit(function() {
	return check_it(this)
  });
  $('#Quote').submit(function() {
	return check_it(this)
  });
  // CLICKABLE DIVS
  $(".clickable").click(function(){
     window.location=$(this).find("a").attr("href");
     return false;
  });
  $(".clickable").hover(
    function () {
 	$(this).css('cursor','pointer'); 
    }, 
    function () {
	$(this).css('cursor','auto'); 
    }
  );
});

// SCROLL/BUTTON CONTROLS
$(document).ready(function(){
$("#submit").hover(
  function () {
 	$(this).css('padding','2px 0px 0px 2px'); 
  },
  function () {
 	$(this).css('padding','1px'); 
  }
);
});

// IMAGE ENLARGEMENTS/TRAILER ANIMATION
$(document).ready(function(){
$("#infectious-waste").hover(
  function () {
	$(this).stop();
	$(this).animate({bottom: "0px"}, 300, "swing");
  },
  function () {
	$(this).stop();
	$(this).animate({bottom: "-65px"}, 300, "swing");
  }
);
$(".miami-fl").hover(
  function () {
 	$(this).css('padding','5px 0px 0px 4px'); 
  },
  function () {
 	$(this).css('padding','3px 2px'); 
  }
);
$("#biohazard-biomedical-waste").hover(
  function () {
 	$(this).css('width','162px'); 
 	$(this).css('height','193px'); 
  },
  function () {
 	$(this).css('width','160px'); 
 	$(this).css('height','191px'); 
  }
);
$("#medical-waste-management-florida").hover(
  function () {
 	$(this).css('padding','0'); 
 	$(this).css('width','230px'); 
 	$(this).css('height','120px'); 
  },
  function () {
 	$(this).css('padding','0px 1px 1px 1px'); 
 	$(this).css('width','228px'); 
 	$(this).css('height','119px'); 
  }
);
$(".pixleft1").hover(
  function () {
 	$(this).css('margin','6px 8px 1px 0px'); 
 	$(this).css('width','167px'); 
 	$(this).css('height','167px'); 
  },
  function () {
 	$(this).css('margin','7px 10px 2px 0px'); 
 	$(this).css('width','165px'); 
 	$(this).css('height','165px'); 
  }
);
$(".pixright1").hover(
  function () {
 	$(this).css('margin','6px 0px 1px 8px'); 
 	$(this).css('width','167px'); 
 	$(this).css('height','167px'); 
  },
  function () {
 	$(this).css('margin','7px 0px 2px 10px'); 
 	$(this).css('width','165px'); 
 	$(this).css('height','165px'); 
  }
);
$(".florida").hover(
  function () {
 	$(this).css('border','1px dotted #ff0000'); 
  },
  function () {
 	$(this).css('border','1px solid #144314'); 
  }
);
});

// ON UNLOAD
$(window).bind('beforeunload', function() { 
  $('body').css('backgroundColor','#ffffff');
  $(window).scrollTop(0); 
  $('#auto-insurance').animate({
	marginTop: "1200px"
  	}, 200, "linear", function() {
 	// Done
  });
});

// ON RESIZE
$(window).resize(function() {
  var pageWidth = $(document).width();
  var viewportWidth = $(window).width();
  if ( pageWidth > viewportWidth ) {
    $('body').css('width',pageWidth);
  }else{
    $('body').css('width','auto');
  }
});



