ol(function()
{
	 $("select").jqTransform();
	$.browser.ie6 = ($.browser.msie && $.browser.version < 7);
	$("#toll-free input")
		.bind("focus click",function(){$(this).fadeTo(10,1).get(0).select();})
		.bind("blur",function(){$(this).fadeTo(10,0);})
	$("#menuitem-get-a-quote a").addClass("green");
	
	$(".re").each(function()
	{
		var html = $(this).html();
		$(this).replaceWith($.base64decode(html));
		
	});
});

// home news
var $n =
{
	init:function()
	{
		if($("#news-pagination").length==0) return;
		$n.slides = $(".news-slide");
		$n.count = $n.slides.length;
		if($n.count < 2) $("#news-pagination").hide();
		$("#news-pagination").pagination($n.count, $n.pagination_opts());
	}
	,pagination_opts:function()
	{
		return {
			items_per_page:1,
			num_display_entries:10,
			current_page:0,
			num_edge_entries:0,
			link_to:"javascript:;",
			prev_text:"&nbsp;",
			next_text:"&nbsp;",
			ellipse_text:"...",
			prev_show_always:false,
			next_show_always:false,
			callback: $n.populate
		};
	}
	,populate: function(page_index,jq)
	{
		var current = $n.slides.hide().eq(page_index).show();
	}
	
};
ol($n.init);



var $c = 
{
	submit:function(form)
	{
		$(".field-error").removeClass("field-error");
		$.ajax({url:'/application/request/'+form
		   ,data:$(document.contact).serialize()
		   ,success:function(data)
		   {
			   data = utils.eval(data);
			   $('.input-error').removeClass('input-error');
			   
			   if(!data.success)
					$c.errors(data.errors);
			   else
				    document.contact.reset();
				
				$.msg(data.msg,(!data.success?'error':'success'),!data.success);
			   
			   
		   }});
	}
	,errors:function(fields)
	{
	   if(fields)
	   {
		for(var i in fields)
		{
			$("input[name='"+fields[i]+"']").parent().prev('.field-label').addClass('field-error');	
		}
	   }
	}
};




$.msg = function(txt,type,timeout)
{
	$("#messages").remove();
	var box = $("<div id='messages' class='"+type+"-message' />").html(nl2br(txt)).appendTo("body").css({opacity:0.1});
	var but = $("<a href='' class='close'></a>")
				.bind('click',function(){box.fadeTo(300,0.1,function(){$(this).hide();});return false;}).appendTo(box);
	
	box.css({marginTop:'-'+Math.floor(box.outerHeight()/2)+'px'}).fadeTo(200,1);
	
	if(timeout)
	{
		setTimeout(function()
		{
			box.fadeTo(300,0.1,function(){$(this).remove();});
		},2000);
	}
	return;
};




$.fn.altrow = function()
{
	$(this).removeClass('odd').filter(function(i){return i%2!=0;}).addClass('odd');
	return this;
};

function nl2br (str, is_xhtml) {
    var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '<br />' : '<br>';

    return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1'+ breakTag +'$2');
}
