/***********************************************************************************
* Conditionally Sticky Sidebar                                                     *
***********************************************************************************/
/*window.onscroll = function()
{
	if( window.XMLHttpRequest ) { // IE 6 doesn't implement position fixed nicely...
		if (document.documentElement.scrollTop > 180 || self.pageYOffset > 180) {
			document.getElementById('right').style.position = 'fixed'; 
			document.getElementById('right').style.top = '15px';
		} else {
			document.getElementById('right').style.position = 'absolute'; 
			document.getElementById('right').style.top = 'auto';
		}
	}
}*/

window.onscroll = function()
{
	if( window.XMLHttpRequest ) { // IE 6 doesn't implement position fixed nicely...
		//alert("t = " + document.documentElement.scrollTop + "\n" + "b = " + document.documentElement.scrollBottom);
		if (document.documentElement.scrollTop > 180 || self.pageYOffset > 180) {
			// start changing the position if we drop down
			formTop = document.documentElement.scrollTop ? document.documentElement.scrollTop : self.pageYOffset;
			formBottom = formTop + document.getElementById('right').offsetHeight; // size of form
			topOfFooter = document.getElementById('foot-banner').offsetTop;
			//alert("t = " + topOfFooter)
			if(formBottom > topOfFooter ) {
				// if we get to the footer then push the form back up
				//formBottom > footerTop then set formTop = (footerTop - formBottom)
				document.getElementById('right').style.position = 'fixed'; 
				document.getElementById('right').style.top = (topOfFooter - formBottom - 30 ) + 'px';
			} else {
				// otherwise keep it at the top
				document.getElementById('right').style.position = 'fixed'; 
				document.getElementById('right').style.top = '15px';
			}
	    } else {
			document.getElementById('right').style.position = 'absolute'; 
			document.getElementById('right').style.top = 'auto';
		}
	}
}

/***********************************************************************************
* Popup Script                                                                     *
***********************************************************************************/
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
//<%
//Dim yy
//yy = DatePart("yyyy",Now())
//%> 

/***********************************************************************************
* Anchor Slider by Cedric Dugas                                                    *
* Http://www.position-absolute.com ***                                             *
* 	                                                                               *
* You can use and modify this script for any project you want, but please          *
* leave this comment as credit. Never have an anchor jumping your content,         *
* slide it. Just add the class anchor at your <a> tag and it will slide,           *
* user with no javascript will still go to destination with the normal             *
* html anchor. Don't forget to put an id to your anchor !	                       *
***********************************************************************************/		
$(document).ready(function() {
	anchor.init()
});

anchor = {
	init : function()  {
		$("a.anchorLink").click(function () {	
			elementClick = $(this).attr("href")
			destination = $(elementClick).offset().top;
			$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 1100 );
		  	return false;
		})
	}
}

/***********************************************************************************
* Form Background Fader Script                                                     *
***********************************************************************************/
// main function to process the fade request //
function colorFade(id,element,start,end,steps,speed) {
  var startrgb,endrgb,er,eg,eb,step,rint,gint,bint,step;
  var target = document.getElementById(id);
  steps = steps || 20;
  speed = speed || 20;
  clearInterval(target.timer);
  endrgb = colorConv(end);
  er = endrgb[0];
  eg = endrgb[1];
  eb = endrgb[2];
  if(!target.r) {
    startrgb = colorConv(start);
    r = startrgb[0];
    g = startrgb[1];
    b = startrgb[2];
    target.r = r;
    target.g = g;
    target.b = b;
  }
  rint = Math.round(Math.abs(target.r-er)/steps);
  gint = Math.round(Math.abs(target.g-eg)/steps);
  bint = Math.round(Math.abs(target.b-eb)/steps);
  if(rint == 0) { rint = 1 }
  if(gint == 0) { gint = 1 }
  if(bint == 0) { bint = 1 }
  target.step = 1;
  target.timer = setInterval( function() { animateColor(id,element,steps,er,eg,eb,rint,gint,bint) }, speed);
}

// incrementally close the gap between the two colors //
function animateColor(id,element,steps,er,eg,eb,rint,gint,bint) {
  var target = document.getElementById(id);
  var color;
  if(target.step <= steps) {
    var r = target.r;
    var g = target.g;
    var b = target.b;
    if(r >= er) {
      r = r - rint;
    } else {
      r = parseInt(r) + parseInt(rint);
    }
    if(g >= eg) {
      g = g - gint;
    } else {
      g = parseInt(g) + parseInt(gint);
    }
    if(b >= eb) {
      b = b - bint;
    } else {
      b = parseInt(b) + parseInt(bint);
    }
    color = 'rgb(' + r + ',' + g + ',' + b + ')';
    if(element == 'background') {
      target.style.backgroundColor = color;
    } else if(element == 'border') {
      target.style.borderColor = color;
    } else {
      target.style.color = color;
    }
    target.r = r;
    target.g = g;
    target.b = b;
    target.step = target.step + 1;
  } else {
    clearInterval(target.timer);
    color = 'rgb(' + er + ',' + eg + ',' + eb + ')';
    if(element == 'background') {
      target.style.backgroundColor = color;
    } else if(element == 'border') {
      target.style.borderColor = color;
    } else {
      target.style.color = color;
    }
  }
}

// convert the color to rgb from hex //
function colorConv(color) {
  var rgb = [parseInt(color.substring(0,2),16), 
    parseInt(color.substring(2,4),16), 
    parseInt(color.substring(4,6),16)];
  return rgb;
}