$(document).ready(function(){

	// adds tab functionality through jQ
	$("#tabs").tabs();
	
	//removing "current" class from non js element
	$("#tabs li.current").each(function(){
		$(this).removeClass("current");
	});

	// the cookie thingy for remembering tabs
	var selectedTab = $.cookie("selectedTab");
	$("#tabs").tabs("select", parseInt(selectedTab));

	$("#tabs li a").click(function(){
		$.cookie("selectedTab", $("#tabs").tabs("option", "selected"));
	});

});

function addHover(img1, img1Hover, img1Click, img2, img2Hover, img2Click){
	//adds mouse over effects for CTA buttons
	var cta = $(".cta");
	if ((cta) && (cta.length > 0)) {
		// preloading images
		image1 = new Image(1, 1);
		image1.src = img1Hover;
		image1Hover = new Image(1, 1);
		image1Hover.src = img1Click;
		image2 = new Image(1, 1);
		image2.src = img2Hover;
		image2Hover = new Image(1, 1);
		image2Hover.src = img2Click;

		var apply = cta.find(".apply img");
		var finish = cta.find(".finish img");

		apply.hover(
				function() { 
					$(this).attr("src", img1Hover);
				}, 
				function() { 
					$(this).attr("src", img1); 
				}
		);
		apply.click(function() {
			$(this).attr("src", img1Click);
		});

		finish.hover(
				function() { 
					$(this).attr("src", img2Hover);
				}, 
				function() { 
					$(this).attr("src", img2); 
				}
		);
		finish.click(function(){
			$(this).attr("src", img2Click);
		});
	}
}

/** used by the table component */
function setNormalTableStyle(tableId) {
	$(document).ready(function(){

		var tableSelector = "div#" + tableId + " table";
		var table = $(tableSelector);
		//table.attr("class", "transBankingTable");
		table.attr("width", "100%").attr("cellSpacing","0");
		table.prepend("<thead/>");
		$(tableSelector + " thead").append($(tableSelector + " tr:first"));

		var numberOfColumns=$(tableSelector + " tbody tr:eq(1) td").size();
		$(tableSelector + " thead tr td").each(function(){
			$(this).replaceWith("<th colspan='" + numberOfColumns + "'>" + $(this).html() + "</th>")
		});

		$(tableSelector + " td").each(function(){
			$(this).replaceWith("<td><div>" + $(this).html() + "</div></td>")
		});

		//$(tableSelector + " tbody tr:odd").attr("class", "shaded");

		//yep, I know it's stupid, but hey, it wasn't me doing the CSS
		$(tableSelector + " tbody tr:odd").attr("class", "even"); 

		$(tableSelector + " tbody tr").attr("valign", "top");
		$(tableSelector + " tbody tr:last-child").addClass("last");
		$(tableSelector + " tbody tr:last-child td:last-child").attr("class", "last");
		//$(tableSelector + " tbody tr th:last-child, " + tableSelector + " tbody tr td:last-child").css("border-right", "none");
	});
}
/** used by the table component */
function setCustomTableStyle(tableId) {
	$(document).ready(function(){
		var table = $("div#" + tableId + " table");
		table.attr("class", "transBankingTable");
	});
}

/** used by the table component */
function tablePopup(link) {
	window.open(link ,"",'menubar=no, toolbar=no, location=no, scrollbars=yes, resizable=yes, status=no, width=800, height=600');
}

