$(document).ready(function() {
	
	if ($.browser.msie){
		$("a.arrowLink").each(function() {
			if ($(this).height() > 13 ){
				$(this).addClass("arrowLinkFix");
	        	$(this).append('&nbsp;<span class="iconArrowLink"></span>');
			}
	     });
	}
	
	// Fix thickbox when a tab changes
	function tbPreload() {
		$(".thickbox, area.thickbox, input.thickbox").unbind();
		tb_init("a.thickbox, area.thickbox, input.thickbox");
		imgLoader = new Image();
		imgLoader.src = tb_pathToImage;
	}
	// Tabs
	if ($("#apdTabsInnerR")) {
		$("#apdTabsInnerR > ul").tabs({
			//cache: true,
			spinner: '',
			load: function() {
				tbPreload();
				expander();
			}
		});
	}
	/* Dynamically display commerce boxes for buy buttons that go to a tab rather than add-to-cart */
	$('ul#apdTabsUl > li > a').click(function(){
		var currentTabText = $(this).attr('title').toLowerCase();
		if (currentTabText == 'how to buy' || currentTabText == 'sign up' || currentTabText == 'apply now' || currentTabText == '2 ways to buy') {
			$('.buttonHowApply').fadeOut(500);
		} else {
			$('.buttonHowApply').fadeIn(500);
		}
		
		// Send Omniture data to custom links
		var whichTab = $(this).attr('title').replace(/ /,'_');
		sendClickEvent(pageTitle + '_' + whichTab);
	});
	$('.buttonHowApply').click(function() {
		var $tabs = $("#apdTabsInnerR > ul").tabs();
		var whichTab = $(this).attr('id');
		var whichTabLn = whichTab.length;
		var whichTabCt = whichTab.charAt(whichTabLn-1);
		$tabs.tabs('select', parseFloat(whichTabCt));
		$('.buttonHowApply').fadeOut(500);
		return false;
	});
	
	// Commerce display handlers
	var anchor=location.hash;
	if(anchor=="" && anchor != "#New" && anchor != "#Upgrade"){
		$('div.cdTabList div:eq(0)').addClass('activeTab');
		$('div.tabPanel:eq(0)').show();
	}
	else{
		anchor=anchor.replace(/#/,"");
		if (anchor=="") {
			$('div.cdTabList div:eq(0)').addClass('activeTab');
			$('div.tabPanel:eq(0)').show();
		} else if (anchor == "New" || anchor == "Upgrade") {
			$('#tab'+anchor).addClass('activeTab');
			$('#'+anchor).show();
		} else {
			$('div.cdTabList div:eq(0)').addClass('activeTab');
			$('div.tabPanel:eq(0)').show();
		}
	};
	
	
	// Commerce display tabs		
	$('#tabbedCD .cdTabList a').click(function(){ //When any link is clicked
		$('#tabbedCD div').removeClass('activeTab'); // Remove active class from all links
		$(this).parent().addClass('activeTab'); //Set clicked link class to active
		var currentTab = $(this).attr('href'); // Set variable currentTab to value of href attribute of clicked link
		$('#tabbedCD div.tabPanel').hide(); // Hide all divs
		$(currentTab).show(); // Show div with id equal to variable currentTab
		return false;
	});
	
});
/* Stop flickering, stupid IE6 */
if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
	var ieversion=new Number(RegExp.$1)
	if (ieversion>=6) {
		try {
		  document.execCommand("BackgroundImageCache", false, true);
		} catch(err) {}
	}
}
//this code is for capturing the clicks on the expanding/contracting content pieces.  
//the arguement 'clickEvent' is the name you want omniture to capture.
var howManyClicks =  0;
function addEvent(clickEvent) {
	for (var x = 0; x <= 5; x++) {
	   	if (x == 0) {
			if (howManyClicks == 1) {
				break;
			}
			sendClickEvent(pageTitle + clickEvent);
			howManyClicks = 1;
			break;
		}
	}
}
var howManyClicks = howManyClicks + 0;
/* Function for opening popup windows */
function OpenT(name,childX,childY) {
	popupWin = window.open(name,'open_window',',status=0,resizable=0,scrollbars=1,width=' + childX + ',height=' + childY);
}
/* Stop errors from other sites */
function pushEvent(foo) {}
function pushProduct(foo) {}
function MM_swapImage() {}
function MM_swapImgRestore() {}
/* Set the current year */
var date = new Date();
var currentDate = date.getFullYear();