// JavaScript Document
var LTG = {
	start: function(){
		LTG.addLoadEvent(function(){
			// add code you want to run on page load here
			//Rounded('rounded', 10, 10);
			//Rounded('rounded_tab', 10);
			$("#tabs li").mouseover(function(){
				$(this).addClass("active");								 
			});
			$("#tabs li").not(".active").mouseout(function(){
				$(this).removeClass("active");								 
			});
			//document.getElementById("search_input").focus();
			LTG.makeTab("#tabs #teachers_tab");
			LTG.makeTab("#tabs #parents_tab");
			LTG.makeTab("#tabs #students_tab");
			LTG.makeTab("#tabs #youthworkers_tab");
			LTG.makeTab("#tabs #faithgroups_tab");
			LTG.makeTab("#tabs #indschools_tab");
			LTG.makeTab("#tabs #lessonplans_tab");
			LTG.makeTab("#tabs #resources_tab");
			
			$.preloadImages("/_graphics/teachers_active.png", "/_graphics/parents_active.png", "/_graphics/students_active.png", "/_graphics/youthworkers_active.png", "/_graphics/indschools_active.png", "/_graphics/lessonplans_active.png", "/_graphics/resources_active.png");
			
			// Change font size
			$(".increaseFont, .decreaseFont").click(function(){
				var ourText = $('body');
				var currFontSize = ourText.css('fontSize');
				var finalNum = parseFloat(currFontSize, 10);
				var stringEnding = currFontSize.slice(-2);
				var multiplier;
				if($.browser.msie){
					multiplier = 1.15;
				} else {
					multiplier = 1.05;
				}
				if($(this).is(".increaseFont")) {
					finalNum *=multiplier;
				} else {
					finalNum /=multiplier;
				}
				ourText.css('fontSize', finalNum + stringEnding);
			});			
		});
	},
	addLoadEvent: function(func){
		$(document).ready(function(){
			func();
		 });
	},
	makeTab: function(selector) {
		$(selector).click(function() {
			location.href = $(this).children("a:first").attr("href");					   
	    });
	},
	
	expandSearch: function(element){
		$(element)
			.css("border","1px solid #80B62A")
			.css("background","white url()")
			.blur(function() {
				$(this)
					.css("border","1px solid #D9EC9A")
					.css("background","white url(/_graphics/google_search_bg.jpg) no-repeat right");
			});
	},
/*
	"search_timeout" : 0,
	growSearch: function(element, currWidth){
		currWidth += (195-currWidth)/4;
		element.style.width = currWidth+"px";
		if(currWidth < 190){
			LTG.search_timeout = setTimeout(function(){LTG.growSearch(element, currWidth);},15);	
		}
	},
	shrinkSearch: function(element, currWidth){
		currWidth -= (currWidth-100)/4;
		element.style.width = currWidth+"px";
		if(currWidth > 100){
			LTG.search_timeout = setTimeout(function(){LTG.shrinkSearch(element, currWidth);},15);
		}
	},
	collapseSearch: function(element){
		clearTimeout(LTG.search_timeout);
		if(element.value == ""){
			element.value = "search";
			LTG.shrinkSearch(element, $(element).width());
		}
	},
	*/
	tryPrint: function() {
		if(a.id) { a.href = "/_css/print.css"; }
		try { 
			window.focus(); 
			window.print(); 
		} catch(e) { 
			alert('Browser security settings prevent printing this page using this link.\nTry selecting print from your browser\'s "File" menu.');
		}
	}
};
LTG.start();

jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}


// JavaScript Document
function t(i) {
	var e = document.getElementById(i);
	if (e!=undefined) {
		var t = e.className;
		if (t.match('invisible')) { 
			t = t.replace(/invisible/gi, 'visible'); 
		} else { 
			t = t.replace(/visible/gi, 'invisible'); 
		}
		e.className = t;
	}
}


/* Toggles state of all matching elements */
function t_name(baseName,howMany) {
	var e
	var t
	for (var n = 1; n < howMany+1; n++)  {
		e = document.getElementById(baseName + n);
		if (e!=undefined) {
			t = e.className;
			if (t.match('invisible')) { 
				t = t.replace(/invisible/gi, 'visible'); 
			} else { 
				t = t.replace(/visible/gi, 'invisible'); 
			}
			e.className = t;
		}
	}
}

function t_off(i) {
	var e = document.getElementById(i);
	if (e!=undefined) {
		var t = e.className;
		if (t=='visible') { 
			t = 'invisible'; 
		}
		e.className = t;
	}
}

function t_on(i) {
	var e = document.getElementById(i);
	if (e!=undefined) {
		var t = e.className;
		if (t=='invisible') { 
			t = 'visible'; 
		}
		e.className = t;
	}
}

/* Hides all matching elements */
function t_all_off(baseName,howMany) {
	var e
	var t
	for (var n = 0; n < howMany+1; n++)  {
		t_off(baseName + n);
		t_off(baseName + n + 'minus');
		t_on(baseName + n + 'plus');
	}
}

/* Shows all matching elements */
function t_all_on(baseName,howMany) {
	var e
	var t
	for (var n = 0; n < howMany+1; n++)  {
		t_on(baseName + n);
		t_on(baseName + n + 'minus');
		t_off(baseName + n + 'plus');
	}
}


/* prints out the links to open and close the content */
function t_plus_minus(id,state,open_text,closed_text) {
	var plus = 'invisible';
	var minus = 'visible';
	if (state=='invisible') {
		plus = 'visible';
		minus = 'invisible';
	}
	if ((open_text==undefined)||(closed_text==undefined)) {
		open_text='+';
		closed_text='-';
	}
	document.write('<a onclick="t(\''+id+'\');t(\''+id+'plus\');t(\''+id+'minus\');" id="'+id+'plus" class="'+plus+'">'+open_text+'</a>');
	document.write('<a onclick="t(\''+id+'\');t(\''+id+'plus\');t(\''+id+'minus\');" id="'+id+'minus" class="'+minus+'">'+closed_text+'</a>');

}


/* prints out the links to open and close the content */
function t_show_all_hide_all(id,number,state,open_text,closed_text) {
	var plus = 'invisible';
	var minus = 'visible';
	if (state=='invisible') {
		plus = 'visible';
		minus = 'invisible';
	}
	if ((open_text==undefined)||(closed_text==undefined)) {
		open_text='Show All';
		closed_text='Hide All';
	}	
	document.write('<a onclick="t_all_on(\''+id+'\',\''+number+'\');t(\'t_showall\');t(\'t_hideall\');" id="t_showall" class="'+plus+'">'+open_text+'</a>');
	document.write('<a onclick="t_all_off(\''+id+'\',\''+number+'\');t(\'t_showall\');t(\'t_hideall\');" id="t_hideall" class="'+minus+'">'+closed_text+'</a>');
}


/* Function so IE doesn't display active X control approval dialog 
function embed_qt(filename,width,height,autostart) {
	document.write('<embed src="' + filename + '" width="' + width + '" height="' + height + '" autostart="' + autostart + '" style="background-color:white"></embed>');
}
*/
function embed_qt(filename,width,height,autostart) {
	document.write('<object width="' + width + '" height="' + height + '" style="z-index:1">');
	document.write('<param name="src" value="' + filename + '" />');
	document.write('<param name="autostart" value="' + autostart + '" />');
	document.write('<param name="wmode" value="transparent" />');
	document.write('<embed src="' + filename + '" width="' + width + '" height="' + height + '" autostart="' + autostart + '" style="background-color:white"></embed></object>');
}

function embed_flash(filename,width,height,id,bgcolor) {
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="'+width+'" height="'+height+'" id="'+id+'" align="middle">');
	document.write('<param name="allowScriptAccess" value="sameDomain" />');
	document.write('<param name="movie" value="'+filename+'" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="wmode" value="transparent" />');
	if(bgcolor=="") {
		document.write('<param name="bgcolor" value="'+bgcolor+'" />');
	} else {
		document.write('<param name="bgcolor" value="#ffffff" />');
	}
	
	document.write('<embed src="'+filename+'" quality="high" bgcolor="#ffffff" width="'+width+'" height="'+height+'" name="'+id+'" wmode="transparent" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
}

function safeMail(part1,part2,part3) {
	document.write("<a href=\"mail" + "to:" + part1 + "@" + part2 + "." + part3 + "\">" + part1 + "@" + part2 + "." + part3 + "</a>");
}

function trace( msg ){
	if( typeof( jsTrace ) != 'undefined' ){
		jsTrace.send( msg );
	}
}

var newWindow = null;

function closeWin() {
	if (newWindow != null) {
		if(!newWindow.closed) {
			newWindow.close();
		}
	}
}

function surf(el) {
	location = el.value;
}

function Popup(P,O,H,W,S,R,T,M) {
	closeWin()  // Close any existing popup window
	if (P==undefined) { P="" }    // Web file name or Angel identifier
	if (O == undefined) {O = "popup"}                    // New window identifier - default is "popup"
	if (H==undefined){H=400}                             // Window height, default 400 pixels
	if (W==undefined){W=600}                             // Window width, default 600
	if (S=='n' || S==0) {S='no'}
	if (S==undefined) {S='yes'}                           // Scrollbars? Default is yes
	if (R==undefined) {R='yes'}                           // Resisable? Default is no
	if (T==undefined) {T='no'}                           // Toolbar? Default is no
	if (M==undefined) {M='yes'}                          // Menubar? Default is yes

	// Other parameters except resizable default to no, change here if you want.
	// eg. add ,menubar=yes after resizable=yes to see a menubar in your window.
	newWindow = window.open(P,O, 'height='+H+',width='+W+', scrollbars='+S+', resizable='+R+',toolbar='+T+',menubar='+M+'')
	newWindow.focus()  // Closes old window, opens new on top.
	return false;      // Ensures HTML takes over if JS not enabled.
}

// Online payment donation management system by ClickandPledge
// Pledge Pop-up Window
function ChargeWindow(OrgID) {
	window.open('https://128bit.clickandpledge.com/Default.asp?ID='+OrgID,'ChargeWindow','toolbar=no,location=no,directories=no,status=yes,menubar=no,resizable=yes,copyhistory=no,scrollbars=yes,width=710,height=600');
}
