// function as jquery plugin to test if selector is found on the current page
(function($){ $.fn.onpage = function() { return ($(this).length>0) ? true : false } })(jQuery);

//set up carousel in hero area on home
if ( jQuery('#hero').onpage() ) {
	var sbox = jQuery('#search').html();
	jQuery('#search').remove();
	jQuery('#leader').prependTo(jQuery('#hero .inset')).append("<div id='sbox'>"+sbox+"</div>");
	jQuery('#header').after(jQuery('#hero'));
	jQuery('#hero').show(); 
	jQuery('#carousel #loader').fadeOut(2500).remove();
	jQuery('#carousel ul').css('display','block').fadeIn(2500);
}
if ( jQuery('#contact-block').onpage() ) {
	var cbox = jQuery('#contact-block').html();
	jQuery('#contact-block').remove();
	jQuery('#container').after("<div id='contact-block' class='aside main-aside'><p>"+cbox+"</p></div>");
}

jQuery(function(){
	if ( jQuery('#carousel').onpage() ) {
		jQuery('#carousel').infiniteCarousel({
			transitionSpeed : 500,
			displayTime : 5000,
			textholderHeight : .25,
			displayProgressBar : 1
		});
	}
});

jQuery(document).ready(function() {
	
  var badBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
  if (badBrowser) {
    // get all pngs on page
    jQuery('img[src$=.png]').each(function() {
      if (!this.complete) {
        this.onload = function() { fixPng(this) };
      } else {
        fixPng(this);
      }
    });
  }
  
  // compare browser and rendering engine
  if (  ((jQuery.browser.mozilla) && (parseFloat(jQuery.browser.version) < 1.9)) 
	 || ((jQuery.browser.safari) && (parseFloat(jQuery.browser.version) < 523)) 
	 || ((jQuery.browser.msie) && (parseFloat(jQuery.browser.version) < 7)) 
	 ) { 
  		//alert('Please upgrade your browser ;-)');
  		//$('head > style').append("@import url('css/degradation.css');");
			var oldBrowser = true ;
  };
});

function fixPng(png) {
  // get src
  var src = png.src;
  // set width and height
  if (!png.style.width) { png.style.width = jQuery(png).width(); }
  if (!png.style.height) { png.style.height = jQuery(png).height(); }
  // replace by blank image
  png.onload = function() { };
  png.src = blank.src;
  // set filter (display original image)
  png.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
}

function transposeEm(userid,domain,subject)
{
	var email = domain +'@' + userid;
	var TempBefore = '';
	var TempAfter = '';
	var NewString = '';
	var Start = 0;
	
	var WhereHash = email.indexOf ('@');
	for (Count = 1; Count <= WhereHash; Count ++)
	{
		TempBefore += email.substring (Start, Count);
		Start++
	}
	Start = WhereHash;
	Start ++
	WhereHash +=2;
	for (Count = WhereHash; Count <=email.length; Count++)
	{
		TempAfter +=email.substring (Start, Count)
		Start++
	}
	NewString = TempAfter +'@' + TempBefore;
	parent.location = 'mai' + 'lto:'+NewString+'?subject='+subject;
}
//i n f o [ a t ] capstonecashflow [ d o t ] c o m
//<a id="transposeEm" href="/contact-us">Contact us</a>
if ( jQuery('#contact-block a, #contact-text a').onpage() ) {
	var hUsr = "in" + "fo";
	var hDom = "capstonecashflow" + "." + "com";
	var hSub = "Message from capstonecashflow" + hDom ;
	var textEm = hUsr +'@' +hDom;
	jQuery('#contact-block a, #contact-text a').removeAttr('href');
	jQuery('#contact-block a, #contact-text a').attr('href','#');
	jQuery('#contact-block a, #contact-text a').click(function() { transposeEm(hUsr,hDom,hSub) });
	jQuery('#contact-block a, #contact-text a').text(textEm);
}
