//This code was created by the fine folks at Switch On The Code - http://blog.paranoidferret.com

//This code can be used for any purpose
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();
//alert(BrowserDetect.browser + ' ' + BrowserDetect.version);
var speed = 250;
frams_divider = 40;
var ie_browser = false;
if(BrowserDetect.browser == 'Explorer' && BrowserDetect.version=='7'){
 speed = 120;
 frams_divider = 70;
  ie_browser = true;
}
if(BrowserDetect.browser == 'Explorer'){
	 ie_browser = true;
	 speed = 350;
}
var selectab  = '';
var h = '';
var openTab=0;
var auto_width = true;
var current_menu_div ='';
var opened_menu_div ='';
var all_menu_module = new Array();
var all_menu_module_id = new Array();
function set_in(id){
	current_menu_div = id; 
}


function slideExample2(elementId, headerElement,elementId1,height,height1)
{	
    set_auto_width('sidetabs','');
	if(opened_menu_div !='' && opened_menu_div != elementId){		
		opened_menu_div2 = opened_menu_div.replace('examplePanel','slide');		
		animate(opened_menu_div, 0, -10000, -30, all_menu_module[opened_menu_div+"_height"], speed-10, null);
		animate(opened_menu_div,  0, -10000,   0, all_menu_module[opened_menu_div+"_height"], speed-10, null);
		animate(opened_menu_div2, 0, -30000,  30, all_menu_module[opened_menu_div+"_height1"],speed-10, null);	
	}
	
	animate(elementId,    2,  0,  160, all_menu_module[elementId+"_height"], speed, null);
	//animate(elementId,    4,  0,  160, all_menu_module[elementId+"_height"], speed, null); 
	animate(elementId1, 163,  0,   30, all_menu_module[elementId+"_height1"], speed, null);
	opened_menu_div  = elementId;
    current_menu_div = elementId;
	auto_width = false;
	
}

function closer(){
	openTab =1;
}

function close_all_menu(elementId){
   // set_auto_width('sidetabs','');
	for(i in all_menu_module_id){
		if((i.indexOf('sample') != -1 ) || (i.indexOf('examplePanel') != -1 ) || (i.indexOf('slide') != -1 )){
			//alert(i);
			elementId  = i.substr(0,i.indexOf('_h'));
			elementId1 = elementId.replace('examplePanel','slide');		
			animate(elementId, 0, -10000, -30, all_menu_module[elementId+"_height"], 250, null);
			animate(elementId,  0, -10000,   0, all_menu_module[elementId+"_height"], 250, null);
			animate(elementId1, 0, -30000,  30, all_menu_module[elementId+"_height1"],250, null);	
		}
	}

}
function set_auto_width(parentDiv1,width){

	if(ie_browser){
		return;	
	}
    var parent1 = document.getElementById(parentDiv1);
	var thisChild = parent1.firstChild;
	parent1.style.width=width;
	while ( thisChild != parent1.lastChild )
	{
		//if ( thisChild.nodeType == 1 )
		{
			//alert(thisChild+":"+thisChild.nodeType);
			//alert(thisChild.style);
			if(thisChild.style){
				thisChild.style.width=width;
				//alert(thisChild.style.width);
			}
		}
		thisChild = thisChild.nextSibling;
	}
}
function close_menu(elementId){
	//alert(height1)
	if(elementId && current_menu_div !=elementId){	  
	    elementId2 = elementId.replace('examplePanel','slide');	
		//set_auto_width('sidetabs','');
		animate(elementId, 0, -10000, -30, all_menu_module[elementId+"_height"], speed-10, null);
	    animate(elementId,  0, -10000,   0, all_menu_module[elementId+"_height"], speed-10, null);
	    animate(elementId2, 0, -30000,  30, all_menu_module[elementId+"_height1"],speed-10, null);	
        opened_menu_div=''; 
		auto_width = true;
		//set_auto_width('sidetabs','');
	    //close_all_menu(elementId);
	   //setTimeout('close_all_menu("'+elementId+'","'+height+'");',1000);
	  // setTimeout('close_all_menu("'+elementId+'","'+height+'");',1);
	}	
}

function close_timly(elementId){
	 current_menu_div ="";	
	 action = 'close_menu("'+elementId+'");';   
	 setTimeout(action , 1000);
}
function slideExample22(elementId, headerElement,elementId1,height,height1){
	 close_timly(elementId);
}


function animate(elementID, newLeft, newTop, newWidth,newHeight, time, callback){
	auto_width= false;
	set_auto_width('sidetabs','');
  var el = document.getElementById(elementID);


  if(el == null)

    return;

 

  var cLeft = parseInt(el.style.left);

  var cTop = parseInt(el.style.top);

  var cWidth = parseInt(el.style.width);

  var cHeight = parseInt(el.style.height);

 

  var totalFrames = 1;

  if(time> 0)

    totalFrames = time/frams_divider;



  var fLeft = newLeft - cLeft;

  if(fLeft != 0)

    fLeft /= totalFrames;

 

  var fTop = newTop - cTop;

  if(fTop != 0)

    fTop /= totalFrames;

 

  var fWidth = newWidth - cWidth;

  if(fWidth != 0)

    fWidth /= totalFrames;

 

  var fHeight = newHeight - cHeight;

  if(fHeight != 0)

    fHeight /= totalFrames;

   

  doFrame(elementID, cLeft, newLeft, fLeft,

      cTop, newTop, fTop, cWidth, newWidth, fWidth,

      cHeight, newHeight, fHeight, callback);

}



function doFrame(eID, cLeft, nLeft, fLeft, cTop, nTop, fTop, cWidth, nWidth, fWidth, cHeight, nHeight, fHeight, callback){
	

   var el = document.getElementById(eID);

   if(el == null)

     return;



  cLeft = moveSingleVal(cLeft, nLeft, fLeft);

  cTop = moveSingleVal(cTop, nTop, fTop);

  cWidth = moveSingleVal(cWidth, nWidth, fWidth);

  cHeight = moveSingleVal(cHeight, nHeight, fHeight);



  el.style.left = Math.round(cLeft) + 'px';

  el.style.top = Math.round(cTop) + 'px';

  el.style.width = Math.round(cWidth) + 'px';

  el.style.height = Math.round(cHeight) + 'px';

 

  if(cLeft == nLeft && cTop == nTop && cHeight == nHeight && cWidth == nWidth) {
	
     if(callback != null)
      callback();
    return;
  }

   

  setTimeout( 'doFrame("'+eID+'",'+cLeft+','+nLeft+','+fLeft+','

    +cTop+','+nTop+','+fTop+','+cWidth+','+nWidth+','+fWidth+','

    +cHeight+','+nHeight+','+fHeight+','+callback+')', 1	);

}



function moveSingleVal(currentVal, finalVal, frameAmt)

{

  if(frameAmt == 0 || currentVal == finalVal)

    return finalVal;

 

  currentVal += frameAmt;

  if((frameAmt> 0 && currentVal>= finalVal)

    || (frameAmt <0 && currentVal <= finalVal))

  {

    return finalVal;

  }

  return currentVal;

}

function clear_width(){
	if(opened_menu_div == "" && auto_width && current_menu_div==""){
		if(document.getElementById('sidetabs')){
			set_auto_width('sidetabs','40px');
		}
	}	
	setTimeout(clear_width,400);
}
clear_width();
