// JavaScript Document for common routines

// jquery onload actions
$(document).ready(function(){
	scroller()
	maptabs()
	regularity()
	clearinputext()
});

function clearinputext() {
	var defaulttext = ""
	$("input[type=text]").focusin(function(){
		defaulttext = $(this).val();
		if (defaulttext.indexOf("...") > 0) {
			$(this).val("");
		}
	});
	$("input[type=text]").focusout(function(){
		if ($(this).val() == "") {
			$(this).val(defaulttext);
		}
	});
}

function scroller() {
	$("#scroller div.scroller").css("display", "none"); 			//hide all divs
	$("#scroller #scroller-tabs li a").removeClass("selected");	//remove the active classes
	
	$("#scroller div.scroller:eq(0)").css("display", "block");	//show the second div
	$("#scroller #scroller-tabs li:eq(0) a").addClass("selected"); 
	
	$("#scroller #scroller-tabs li a").click(function () {		//if someone click a tab
		$("#scroller div.scroller").css("display", "none");		//hide all divs
		$("#scroller #scroller-tabs li a").removeClass("selected"); //remove the active classes
		
		var divid = $(this).attr("href");				//grab the value of the link
		$(this).addClass("selected");					//show the selected class on the tab clicked
		$(divid).css("display", "block");				//show the div for the clicked tab
		return false;
	});
}

function maptabs() {
	$("div.tabbed").css("display", "none"); 			//hide all tabbed divs
	$("#tabs li a").removeClass("selected");			//remove the active classes
	
	$("div.tabbed:eq(0)").css("display", "block");		//show the second div
	$("#tabs li:eq(0) a").addClass("selected"); 
	
	$("#tabs li a").click(function () {					//if someone click a tab
		$("div.tabbed").css("display", "none");			//hide all divs
		$("#tabs li a").removeClass("selected"); 		//remove the active classes
		
		var divid = $(this).attr("href");				//grab the value of the link
		$(this).addClass("selected");					//show the selected class on the tab clicked
		$(divid).css("display", "block");				//show the div for the clicked tab
		return false;
	});
}

function regularity() {
	$("#once").css("display", "none"); 			//hide the option fieldsets
	$("#once div, #monthly div").css("display", "none"); 	//hide the description divs
	$("#once label, #monthly label").removeClass("selected");
	$("label span.description").css("display", "none");
	
	$("input[name=regularity]:radio").click(function () {
		var choice = $("input:radio[name=regularity]:checked").val();
		$("#once, #monthly").css("display", "none");

		$("#" + choice).css("display", "block");		
	});
	
	$("#once label, #monthly label, #other div").click(function () {					//if someone click a tab
		$("#once label, #monthly label, #other div").removeClass("selected"); 		//remove the active classes
		
		$(this).addClass("selected");					//show the selected class on the tab clicked
	});
	
	$("#once label, #monthly label").hover(
		function () {
			$(this).animate({width: "260"}, 100, "swing", function() {
				$(this).children(".description").fadeIn(100);
			});
			
		},
		function () {
			$(this).stop();
			$(this).children(".description").fadeOut(100, function(){
				$(this).parent().animate({width: "110"}, 100, "swing");
			});
		}
	);
}

/*add target="blank" for external links */
function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") &&
		anchor.getAttribute("rel") == "external")
		anchor.target = "_blank";
	}
}
addEvent(window, 'load', externalLinks);
//window.onload = externalLinks;