// JavaScript Document
tabSwitch = { 

	init:function() {
		
		var anchors = document.getElementsByTagName('a');
		
		for (var i=0; i<anchors.length; i++) {
			
			var anchor = anchors[i];
		
			var newSS=document.createElement('link');
			newSS.rel='stylesheet';
			newSS.type='text/css';
			newSS.href='css/hasjavascript.css';
			document.getElementsByTagName("head")[0].appendChild(newSS);
			
			// document.write('<link rel="stylesheet" href="css/hasjavascript.css" type="text/css">');
			
			var relAttribute = String(anchor.getAttribute('rel'));
			
			if (anchor.getAttribute('href') && (relAttribute.toLowerCase().match('tabs'))){		
				var url = anchor.href; 
				anchor.onclick = function () {tabSwitch.activate(this,anchors); return false; } 
			} else if (anchor.getAttribute('href') && (relAttribute.toLowerCase().match('shrink'))){	
				anchor.onclick = function () {tabSwitch.ShrinkStart(this); return false; }
			}else if (anchor.getAttribute('href') && (relAttribute.toLowerCase().match('grow'))){
				var div = anchor.hash.substr(1);
				document.getElementById(div).style.display = 'none';
				
				anchor.onclick = function () {tabSwitch.GrowStart(this); return false;}
				
			} //end init
		}
	
	}, //end init function
	
	ShrinkStart:function(ShrinkLink) {
		
	anchor = ShrinkLink.hash.substr(1);
		
		Effect.SlideUp(anchor);
		
	},

	GrowStart:function(GrowLink) {
		
	anchor = GrowLink.hash.substr(1); 
		
	Effect.SlideDown(anchor);
	},
	
	ShowClients:function(clist) {
		Effect.SlideDown(clist);
	},
	
	HideClients:function(clist) {
		
		Effect.SlideUp(clist);
	},
	MoveLeft:function (distance,ndistance)
	{
	
    	new Effect.MoveBy('left_inner', 0, ndistance , 
            {
              duration: 1,  
              transition: Effect.Transitions.sinoidal
            });
	},

	MoveRight:function(distance,ndistance)
	{
		
    new Effect.MoveBy('left_inner', 0, -ndistance , 
        {
           duration: 1,  
           transition: Effect.Transitions.sinoidal
        });
	},
	
	activate:function(anc,anchors) {
		
		
		
		for (var i=0; i<anchors.length; i++) {
			
			var anchor = anchors[i];
			
			//var theclass = String(anchor.getAttribute('class'));
			
			var theclass = String(anchor.className);
					
			
			if (anchor.className && (theclass.toLowerCase().match('sactive'))){		
				
				var Active = anchor.hash.substr(1);
				
			}
		
		}
		
		var destination = anc.hash.substr(1);
		// CLEAR AND RESET ACTIVE ITEM
		
		for (var i=0; i<anchors.length; i++) {
			
			var anchor = anchors[i];
			var relAttribute = String(anchor.getAttribute('rel'));
			
			if (relAttribute.toLowerCase().match('tabs')) { Element.removeClassName(anchor, 'sactive'); } //remove anchor tags so we can set the current active one
			
		}
		
		anc.className = 'sactive';
				
		if (Active > destination) { tabSwitch.ScrollRight(Active,destination); }
		else if (Active < destination) { tabSwitch.ScrollLeft(Active,destination); }
		else if (Active = destination) { return; }
			
	}, 
	
	ScrollLeft:function(Active,destination) {
		
		var distance = Active - destination; 
		
		var ndistance = distance * 785;
		
		tabSwitch.MoveLeft(distance,ndistance);
	
	},
	
	ScrollRight:function(Active,destination) {
		
		var distance = Active - destination;
		
		var ndistance = distance * 785;
		
		tabSwitch.MoveLeft(distance,ndistance);
	
	},
	
/*	scrollright:function(destx,CurrentXPos) {
		
	var place = CurrentXPos;
	var destination = destx;

	if (place > destination) {
		
			var place = place - 15;
			
			document.getElementById('left_header').scrollLeft = place;
			setTimeout("tabSwitch.scrollright(" + destination + "," + place + ");",10);
		}
	else { document.getElementById('left_header').scrollLeft = destx; }
	
	},
	
	scrollleft:function(destx,CurrentXPos) {
		
	var place = CurrentXPos;
	var destination = destx;
	
	if (place < destination) {
			
			var place = place + 15;
			
			document.getElementById('left_header').scrollLeft = place;
			
			setTimeout("tabSwitch.scrollleft(" + destination + "," + place + ");",10);
		}
	else { document.getElementById('left_header').scrollLeft = destx; }

	}, */
	
	getTarget:function(e){
		var target = window.event ? window.event.srcElement : e ? e.target : null;
		if (!target){return false;}
		if (target.nodeName.toLowerCase() != 'a'){target = target.parentNode;}
		return target;
	},
	
	
	addEvent: function(elm, evType, fn, useCapture){
		if (elm.addEventListener) 
		{
			elm.addEventListener(evType, fn, useCapture);
			return true;
		} else if (elm.attachEvent) {
			var r = elm.attachEvent('on' + evType, fn);
			return r;
		} else {
			elm['on' + evType] = fn;
		}
	}
	
	
} // 

tabSwitch.addEvent(window, 'load', tabSwitch.init, false);
