/* *******************************************************
J  a  v  a  c  a  t  z
Filename:   atac.js
Purpose:    This file is created to hold common functions
            that are used in Casbaa only.
            Please do not put other codes in this file.
Created by: KY 2008.06.23
******************************************************* */

/* Print bar + Adjust fontsize */
var smallerFontSizePc = 100;	// in %
var biggerFontSizePc = 120;	// in %
addthis_pub  = 'javacatz';
/* full printBar */
var printBar = "<a href=\"http://www.addthis.com/bookmark.php\" onMouseOver=\"return addthis_open(this, '', '[URL]', '[TITLE]')\" onMouseOut=\"addthis_close()\" onClick=\"return addthis_sendto()\" title='Share this page'><img src='img/ico_share.gif' alt='Share' /></a> &nbsp;<img src='img/printbar_vline.gif' alt='|' /> &nbsp;<a href='email.html' title='Email this page'><img src='img/ico_email.gif' alt='Email' /></a> &nbsp;<img src='img/printbar_vline.gif' alt='|' /> &nbsp;<a href='javascript:printPage2();' title='Print this page'><img src='img/ico_print.gif' alt='Print' /></a> &nbsp;<img src='img/printbar_vline.gif' alt='|' /> &nbsp;<a href='javascript:adjustFontsizePc(" + smallerFontSizePc + ");' title='Smaller Text'><img src='img/ico_smallersize.gif' alt='' /></a> <a href='javascript:adjustFontsizePc(" + biggerFontSizePc + ");' title='Bigger Text'><img src='img/ico_biggersize.gif' alt='' /></a>";
var printBar2 = "<a href='javascript:adjustFontsizePc(" + smallerFontSizePc + ");' title='Smaller Text'><img src='img/ico_smallersize.gif' alt='' /></a> <a href='javascript:adjustFontsizePc(" + biggerFontSizePc + ");' title='Bigger Text'><img src='img/ico_biggersize.gif' alt='' /></a>";

function printbar_init() {
	/* show print bar */
	/*
	var tags = $$('.printBar');
	if(tags!=null && tags!="" && tags.length>0) {
		tags.each( function(node) { $(node).innerHTML = printBar; } );
	}
	tags = $$('.printBar2');
	if(tags!=null && tags!="" && tags.length>0) {
		tags.each( function(node) { $(node).innerHTML = printBar2; } );
	}
	*/
}
function adjustFontsizePc(sizechangePc) {
	if( sizechangePc == 'small' ) fontsizePc = smallerFontSizePc;	// same as font-size in body
	else if( sizechangePc == 'large') fontsizePc = biggerFontSizePc;
	else if( !isNaN(sizechangePc) ) fontsizePc = sizechangePc;
	$$('.fontSize').each( function(node) { $(node).style.fontSize = fontsizePc + "%"; } );
}



/* KY Slide Menu 2008.02.28 */
var ky_slidemenu_closing = false;
var ky_slidemenu_opening = false;
var lastopenitem = new Array();
function ky_slidemenu(level, id) {
	if(!ky_slidemenu_opening && !ky_slidemenu_closing) {
		ky_slidemenu_opening = true;
		if($(lastopenitem[level])) {
			ky_slidemenu_closing = true;
			new Effect.toggle(lastopenitem[level], "blind", { duration:0.75, afterFinish: function() { $(lastopenitem[level]).parentNode.className = $(lastopenitem[level]).parentNode.className.replace(' current', ''); ky_slidemenu_closing=false; if(lastopenitem[level]!=id) new Effect.toggle(id, "blind", { duration:0.75, afterFinish: function() { $(id).parentNode.className += ' current'; ky_slidemenu_opening=false; lastopenitem[level]=id; } }); else { $(id).parentNode.className = $(id).parentNode.className.replace(' current', ''); ky_slidemenu_opening=false; lastopenitem[level]=null; } } });
		} else {
			new Effect.toggle(id, "blind", { duration:0.75, afterFinish: function() { $(id).parentNode.className += ' current'; ky_slidemenu_opening=false; lastopenitem[level]=id; } });
		}
	}
}
function ky_slidemenu_init(bool_openFirst) {
	var slidemenu_class = '.ky_slidemenu';

	// added special FCK anchor removal
	$$('.ky_slidemenu_remove').each( function (node) { $(node).remove(); } );
	
	// find out how many levels in total
	var level_counter = 0;
	var tmp_ky_slidemenu_class = slidemenu_class;
	while($$(tmp_ky_slidemenu_class).length > 0) {
		tmp_ky_slidemenu_class += " " + slidemenu_class;
		level_counter++;
	}

	var counter;
	for(level_index=level_counter; level_index>0; level_index--) {
		counter = 0;
		
		tmp_ky_slidemenu_class = "";
		for(i=0;i<level_index;i++) tmp_ky_slidemenu_class += " " + slidemenu_class;
		if(tmp_ky_slidemenu_class!="") tmp_ky_slidemenu_class = tmp_ky_slidemenu_class.substring(1);
		
		var ky_slidemenus = $$(tmp_ky_slidemenu_class + ' .slideitem');
		if(ky_slidemenus) {
			ky_slidemenu_closing = true;
			ky_slidemenus.each( function(node) {
				if($(node).id == "") {
					var item_id = "slideitem_" + level_index + "_" + counter;
					$(node).id = item_id;
					// $(node).innerHTML = '<a name="slidedescription_' + level_index + '_' + counter + '"></a>' + $(node).innerHTML;
					var title = $(node).getElementsByClassName('title')[0];
					title.id = "slidetitle_" + level_index + "_" + counter;
					if(title.className.indexOf("noSlide") == -1) title.innerHTML = '<a name="#slidedescription_' + level_index + '_' + counter + '" href="#slidedescription_' + level_index + '_' + counter + '" onclick="ky_slidemenu(\'' + level_index + '\', \'slidedescription_' + level_index + "_" + counter + '\');">' + title.innerHTML + '</a>';
					var description = $(node).getElementsByClassName('description')[0];
					description.id = "slidedescription_" + level_index + "_" + counter;
					if(bool_openFirst && counter==0) {
						AddClass($(node),'current');
						description.style.height = "auto";
						description.style.visibility = "visible";
						lastopenitem[level_index] = 'slidedescription_' + level_index + "_" + counter;
					} else {
						new Effect.BlindUp(description.id,{duration:0, afterFinish: function() {description.style.height = "auto"; description.style.visibility = "visible";} });
					}
					counter++;
				}
			} );
			ky_slidemenu_closing = false;
		}
	}
}



/* KY put back to top 2007.11.06 */
var backTopHTML = "<a href='#top' title='Back to top'><img src='img/ico_backTop.gif' alt='[^]' /> Back to top</a>";
var const__ky_backTop;
function ky_backTop_init(interval) {
	if(interval==null) interval = 500;
	const__ky_backTop = $$('.backTop');
	if(const__ky_backTop.length>0) {
		setInterval('ky_backTop()',interval);
	}
}
function ky_backTop() {
	const__ky_backTop.each( function(node) {
		if(findPos(node)[1] > displaySize('height') + 40) {
			if($(node).innerHTML.indexOf("#top") == -1) {	// use meaningful substring in your backTopHTML for indexOf
				$(node).innerHTML = backTopHTML;
			}
		} else {
			if($(node).innerHTML.trim()!="") $(node).innerHTML = "";
		}
	} );
}



function showCurrentTime(formatIndex) {
	var currentDate;
	currentDate = new Date;
	$$('.show_current_time').each( function(node) { $(node).innerHTML = formatTime(currentDate,"+formatIndex+"); } );
	setInterval("currentDate = new Date; $$('.show_current_time').each( function(node) { $(node).innerHTML = formatTime(currentDate,"+formatIndex+"); } );", 1000);
}
function showCurrentDate(formatIndex) {
	var currentDate;
	currentDate = new Date; $$('.show_current_date').each( function(node) { $(node).innerHTML = formatTime(currentDate,formatIndex); } );
}



function tableAltRow(id) {
	var boolDark = false;
	$$('#'+id+' tr').each( function(node) { if(boolDark) AddClass($(node),"tr_even"); else AddClass($(node),"tr_odd"); boolDark = !boolDark; } );
}


function tabpanel_init() {
	var counter = 0;
	if($$('#main .tab_button').length > 0) {
		var firstTabButton = $$('#main .tab_button').first();
		firstTabButton.addClassName("first");
		firstTabButton.addClassName("current");
		var tabButtons = $$('#main .tab_button');
		tabButtons.each( function(node) {
			if($(node).id == "") {
				var item_id = "tab_button_" + counter;
				$(node).id = item_id;
				node.onclick = function() {
					$$('#main .tab_button').each( function(n){ n.removeClassName("current"); } );
					$$('#main .tab_content').each( function(n){ n.removeClassName("current"); } );
					node.addClassName("current");
					var tab_index = node.id.substr('tab_button_'.length);
					$('tab_content_' + tab_index).addClassName("current");
					$('donate_online').style.display = (tab_index == '2') ? 'none' : 'block';
					return false;
				};
			}
			counter++;
		});
	}
	counter = 0;
	if($$('#main .tab_content').length > 0) {
		var firstTab = $$('#main .tab_content').first();
		firstTab.addClassName("current");
		var tabs = $$('#main .tab_content');
		tabs.each( function(node) {
			if($(node).id == "") {
				var item_id = "tab_content_" + counter;
				$(node).id = item_id;
			}
			counter++;
		});
	}
}


//*** This code is copyright 2003 by Gavin Kistner, gavin@refinery.com
//*** It is covered under the license viewable at http://phrogz.net/JS/_ReuseLicense.txt
//*** Reuse or modification is free provided you abide by the terms of that license.
//*** (Including the first two lines above in your source code satisfies the conditions.)
	function FindXY(obj){
		var x=0,y=0;
		while (obj){
			x+=obj.offsetLeft - (obj.scrollLeft || 0);
			y+=obj.offsetTop - (obj.scrollTop || 0);
			obj=null;
		}
		return {x:x,y:y};
	}

	function FindXYWH(obj){
		if (!obj) return { x:0, y:0, w:0, h:0 };
		var objXY = FindXY(obj);
		return { x:objXY.x, y:objXY.y, w:obj.offsetWidth||0, h:obj.offsetHeight||0 };
	}

	function AttachEvent(obj,evt,fnc,useCapture){
		if (obj.addEventListener){
			obj.addEventListener(evt,fnc,useCapture);
			return true;
		} else if (obj.attachEvent) return obj.attachEvent("on"+evt,fnc);
		else obj['on'+evt]=fnc;
		return true;
	}

	function HasClass(obj,cName){ return (!obj || !obj.className)?false:(new RegExp("\\b"+cName+"\\b")).test(obj.className) }
	function AddClass(obj,cName){ if (!obj) return; if (obj.className==null) obj.className=''; return obj.className+=(obj.className.length>0?' ':'')+cName; }
	function KillClass(obj,cName){ if (!obj) return; return obj.className=obj.className.replace(RegExp("^"+cName+"\\b\\s*|\\s*\\b"+cName+"\\b",'g'),''); }
	
	
