var busting_banner_name;
$(document).ready(function(){
	var contact = $(".contactform");

	jQuery.each($("input,textarea",contact),function(){
		$(this).attr("dvalue",this.value);
	});

	$("input,textarea",contact).focus(function(){
		if($(this).attr("dvalue")==this.value){
			this.value = "";
		}
	}).blur(function(){
		if(this.value==""){
			this.value = $(this).attr("dvalue");
		}
	});

	var banner_closed = getCookie("banner_closed");
	var banner_open_counter = (parseInt(getCookie("banner_open_counter"))||0);
	var busting_banner = $(".busting_banner");
	busting_banner_name = $(".close",busting_banner).next().attr("id");

	if((banner_closed!="true")&&(banner_open_counter<3)){
		window.setTimeout(function(){
			banner_open_counter++;
			setCookie("banner_open_counter",banner_open_counter);
			_gaq.push(['_trackEvent','Bursting Banner',busting_banner_name,'Show']);
			busting_banner.slideDown(1000,"easeInOutSine");
		},1000);
	}
	$(".banner",busting_banner).click(function(){
		bursting_banner_click($(this).attr("href"));
		return(false);
	});
	$(".close",busting_banner).click(function(){
		setCookie("banner_closed","true");
		_gaq.push(['_trackEvent','Bursting Banner',busting_banner_name,'Close']);
		$(this).parent().slideUp(1000,"easeInOutSine");
	})
});

function bursting_banner_click(url){
	window.open(url);
	_gaq.push(['_trackEvent','Bursting Banner',busting_banner_name,'Click']);
}

jQuery.extend( jQuery.easing,
{
	easeInOutSine: function (x, t, b, c, d) {
		return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
	}
});

function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  x=x.replace(/^\s+|\s+$/g,"");
  if (x==c_name)
    {
    return unescape(y);
    }
  }
}

function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}
