
/*
Yetii - Yet (E)Another Tab Interface Implementation
http://www.kminek.pl/lab/yetii/
Copyright (c) 2007 Grzegorz Wojcik
Code licensed under the BSD License:
http://www.kminek.pl/bsdlicense.txt
*/

function Yetii() {

	this.defaults = {

		id: null,
		active: 1,
		timeout: null,
		interval: null,
		tabclass: 'tab',
		activeclass: 'active'

	};

	for (var n in arguments[0]) { this.defaults[n]=arguments[0][n]; };

	this.getTabs = function() {


        var retnode = [];
        var elem = document.getElementById(this.defaults.id).getElementsByTagName('*');

		var regexp = new RegExp("(^|\\s)" + this.defaults.tabclass.replace(/\-/g, "\\-") + "(\\s|$)");

        for (var i = 0; i < elem.length; i++) {
        if (regexp.test(elem[i].className)) retnode.push(elem[i]);
        }

        return retnode;

    };

	this.links = document.getElementById(this.defaults.id + '-nav').getElementsByTagName('div');

	this.show = function(number){

        for (var i = 0; i < this.tabs.length; i++) {
        this.tabs[i].style.display = ((i+1)==number) ? 'block' : 'none';
        this.links[i].className = ((i+1)==number) ? this.defaults.activeclass : 'off';
        }

    };

	 this.rotate = function(interval){

        this.show(this.defaults.active);
        this.defaults.active++;

        if(this.defaults.active > this.tabs.length) this.defaults.active = 1;

        var self = this;
        this.defaults.timeout = setTimeout(function(){self.rotate(interval);}, interval*1000);

    };

	this.tabs = this.getTabs();
	this.show(this.defaults.active);

	var self = this;
	for (var i = 0; i < this.links.length; i++) {
	this.links[i].customindex = i+1;
	this.links[i].onclick = function(){ if (self.defaults.timeout) clearTimeout(self.defaults.timeout); self.show(this.customindex); return false; };
    }

	if (this.defaults.interval) this.rotate(this.defaults.interval);

}

function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
	{
	   var arVersion = navigator.appVersion.split("MSIE")
	   var version = parseFloat(arVersion[1])
	   if ((version >= 5.5) && (document.body.filters))
	   {
	      for(var i=0; i<document.images.length; i++)
	      {
	         var img = document.images[i]
	         var imgName = img.src.toUpperCase()
	         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
	         {
	            var imgID = (img.id) ? "id='" + img.id + "' " : ""
	            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
	            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
	            var imgStyle = "display:inline-block;" + img.style.cssText
	            if (img.align == "left") imgStyle = "float:left;" + imgStyle
	            if (img.align == "right") imgStyle = "float:right;" + imgStyle
	            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
	            var strNewHTML = "<span " + imgID + imgClass + imgTitle
	            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
	            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
	            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
	            img.outerHTML = strNewHTML
	            i = i-1
	         }
	      }
	   }
	}


function land(ref, target)
	{
	lowtarget=target.toLowerCase();
	if (lowtarget=="_self") {window.location=loc;}
	else {if (lowtarget=="_top") {top.location=loc;}
	else {if (lowtarget=="_blank") {window.open(loc);}
	else {if (lowtarget=="_parent") {parent.location=loc;}
	else {parent.frames[target].location=loc;};
	}}}
	}

function jump(menu)
	{
	ref=menu.choice.options[menu.choice.selectedIndex].value;
	splitc=ref.lastIndexOf("*");
	target="";
	if (splitc!=-1)
	{loc=ref.substring(0,splitc);
	target=ref.substring(splitc+1,1000);}
	else {loc=ref; target="_self";};
	if (ref != "") {land(loc,target);}
	}


window.addEvent("domready", function(){
if(typeof(jQuery) !== 'undefined') {
	jQuery.noConflict();	
	}
		correctPNG();
		
		var printme	= $$('.printme');
		
		if(printme.length>0)
		{
		
			printme.each(function(e,idx)
			{
				e.addEvent('click',function(f){
					f	= new Event(f).stop();
					window.print();
				});
				
				
			});
		}

	if($chk($('return_to')))
	{
		$('page').setStyle('padding-top','33px');

		$('return_to_close').addEvent('click',function(c){
			$('page').setStyle('padding-top','4px');
			$('return_to_bg').setStyle('display','none');
			$('return_to').setStyle('display','none');
			var myRequest = new Request({url: '/leaders/unsetreturnto'}).send();

		});

	}

	
		
});


