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

jbrowser.js : Website Functionality

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

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

/***********************************************************************************************************************
* PRELOAD
************************************************************************************************************************/

// 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/semantic_website_design.gif",
"./images/miami-solar-power-installers-bg1.gif",
"./images/Miami_Solar_Energy.gif",
"./images/solar-energy-miami-bg1.png",
"./images/solar-panel-installation-bg1.gif",
"./images/solar-panels-miami-bg1.jpg",
"./images/submit.png",
"./images/textholder-bg1.png",
"./solar_power_miami_florida/1001.jpg",
"./solar_power_miami_florida/1002.jpg",
"./solar_power_miami_florida/1003.jpg",
"./solar_power_miami_florida/1004.jpg",
"./solar_power_miami_florida/1005.jpg",
"./solar_power_miami_florida/1006.jpg",
"./solar_power_miami_florida/1007.jpg",
"./solar_power_miami_florida/1008.jpg",
"./solar_power_miami_florida/1009.jpg"
);

/***********************************************************************************************************************
* ON DOCUMENT READY
************************************************************************************************************************/

// FORM CHECK
function check_it(the_form){
  $(window).scrollTop(0); 
  check_it2(the_form);
  return retVal;
}
function check_it2(the_form){
    var headerOffset = 110;
    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;  
    }
    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; 
}

// DOCUMENT READY
$(document).ready(function(){
  // CAROUSEL
	$('#carousel').infiniteCarousel({
		transitionSpeed: 1200,
		displayTime: 15000,
		inView:1,
		advance:1,
		imagePath: './js/infinitecarousel/images/',
		easeLeft: 'easeOutCirc',
		easeRight:'easeOutCirc',
		textholderHeight : .17,
		padding:'10px',
		autoHideCaptions: false,
		prevNextInternal: false,
		displayProgressBar: true
	});
	$('div.thumb').parent().css({'margin':'0 auto','width':'560px'});
	$('#carouselWrapper > div:eq(1)').css('margin-top','56px');
	$('#carouselWrapper > div:eq(2)').css('margin-top','56px');
  // CORNERS
	DD_roundies.addRule('.menu1', '5px', true);
	// DD_roundies.addRule('.textholder', '15px 0px 0px 0px', true);
	DD_roundies.addRule('#solar-panel-installation', '15px', true);
	DD_roundies.addRule('#solar-panels-miami', '15px', true);
	DD_roundies.addRule('#spamcheck', '5px', true);
  // 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;
      }
    }
  } 
  // FORMS INIT 
  $('#Contact').submit(function() {
	var retVal = false; 
	return check_it(this)
  });
  $("#submit").hover(
    function () {
 	$(this).css('padding','2px 0px 0px 2px'); 
    },
    function () {
 	$(this).css('padding','1px'); 
    }
  );
  $('.ContactFocus').click(function() {
      var headerOffset = 110;
  	$(window).scrollTop(0); 
      $('html,body').animate({ scrollTop: ( $("#Contact_Name").offset().top - headerOffset ) },
       'slow', 'swing', function() {
		$('#Contact_Name').focus();
      });
	return false;  
  });
  // ANIMATE
  if ( $.browser.msie ) { 
    $(".menu1").css( "display","inline" ); 
  } else { 
    $(".menu1").css( "display","inline-block" ); 
  } 
  $(".menu1").hover(
    function () {
 	$(this).css('font-size','16px'); 
 	$(this).css('margin','0px 8px 0px 8px'); 
 	$(this).css('padding','2px 6px 4px 6px'); 
  },
    function () {
 	$(this).css('font-size','14px'); 
 	$(this).css('margin','2px 8px 0px 8px'); 
 	$(this).css('padding','3px 6px 5px 6px'); 
  }
  );
  $("#solar-energy-contractors").hover(
    function () {
 	$(this).css('width','229px'); 
 	$(this).css('height','62px'); 
 	$(this).css('padding','0px'); 
  },
    function () {
 	$(this).css('width','227px'); 
 	$(this).css('height','60px'); 
 	$(this).css('padding','1px'); 
  }
  );
  $(".water-heaters").hover(
    function () {
 	$(this).css('padding','3px 1px 1px 3px'); 
  },
    function () {
 	$(this).css('padding','2px'); 
  }
  );
  $("#daylighting-systems").hover(
    function () {
 	$(this).css('width','162px'); 
 	$(this).css('height','179px'); 
 	$(this).css('padding','0px 0px 0px 5px'); 
  },
    function () {
 	$(this).css('width','160px'); 
 	$(this).css('height','177px'); 
 	$(this).css('padding','0px 0px 2px 7px'); 
  }
  );
  $("#solar-star-attic-fans").hover(
    function () {
 	$(this).css('width','162px'); 
 	$(this).css('height','139px'); 
 	$(this).css('padding','5px 5px 0px 0px'); 
  },
    function () {
 	$(this).css('width','160px'); 
 	$(this).css('height','137px'); 
 	$(this).css('padding','5px 7px 2px 0px'); 
  }
  );
  $("#solar-water-heaters").hover(
    function () {
 	$(this).css('width','162px'); 
 	$(this).css('height','119px'); 
 	$(this).css('padding','0px 0px 0px 5px'); 
  },
    function () {
 	$(this).css('width','160px'); 
 	$(this).css('height','117px'); 
 	$(this).css('padding','0px 0px 2px 7px'); 
  }
  );
  $("#photovoltaic-solar-panels").hover(
    function () {
 	$(this).css('width','162px'); 
 	$(this).css('height','115px'); 
 	$(this).css('padding','0px 5px 0px 0px'); 
  },
    function () {
 	$(this).css('width','160px'); 
 	$(this).css('height','113px'); 
 	$(this).css('padding','0px 7px 2px 0px'); 
  }
  );
});

/***********************************************************************************************************************
* ON WINDOW LOAD
************************************************************************************************************************/

// 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); 

function loaded1() {
	$('#solar-energy-miami-overlay').attr('class','hideMe');
      $('html,body').animate({ scrollTop: ( $("#miami-solar-energy").offset().top ) },
       1500, 'swing', function() {
      	$('html,body').animate({ scrollTop: ( $("#solar-power-miami-florida").offset().top ) },
       	1000, 'swing', function() {
  			$(window).scrollTop(0); 
			$('#Contact_Name').focus();
      	});
      });
}

// WINDOW LOAD
$(window).load(function() {  
	$('#solar-power-miami-florida').attr('class','isvisibleMe');
	setTimeout('loaded1()', 500);
});


/***********************************************************************************************************************
* ON WINDOW UNLOAD
************************************************************************************************************************/

$(window).bind('beforeunload', function() { 
  	// $(window).scrollTop(0); 
});

/***********************************************************************************************************************
* ON WINDOW RESIZE
************************************************************************************************************************/

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


