var oTimer = 0;

jQuery(document).ready(function(){


/******************************  leader slider ***********************************************/	
	jQuery("#leaderNext").click(function() {
		jQuery("#leaderDesc").stop().animate({left:"-470px"},  { "duration": "slow", "easing": "easeInQuad" });
		jQuery("#leaderNext").fadeOut("slow");
		jQuery("#leaderPrev").fadeIn("slow");
	});
	jQuery("#leaderPrev").click(function() {
		jQuery("#leaderDesc").stop().animate({left:"0px"},  { "duration": "slow", "easing": "easeInQuad" });
		jQuery("#leaderPrev").fadeOut("slow");
		jQuery("#leaderNext").fadeIn("slow");
	});
	
/******************************  gray menu hover ***********************************************/	

jQuery("h3.menuheader,a.menuheader").hover(
		function () {
        jQuery(this).css("color","#B1B3B6");
      }, 
      function () {
        jQuery(this).css("color","#FFFFFF");
      }		
	);
	jQuery("div.submenuheader").hover(
		function () {
        jQuery(this).css("color","#FFFFFF");
      }, 
      function () {
        jQuery(this).css("color","#B1B3B6");
      }		
	);
	jQuery("h3.menuheader2").hover(
		function () {
        jQuery(this).css("color","#B1B3B6");
      }, 
      function () {
        jQuery(this).css("color","#FFFFFF");
      }		
	);
	
	/****************** rotate big message images on home pages ************************/
		
		jQuery("#arrowzone,#bigarrow").mouseup(function(){
			cycleImg();
		});
						
/******************       CODE FOR MEGANAV FUNCTIONALITY         ***********************/		

		jQuery("#megaNavLink").click(function() {
			if(jQuery("#megaNav").css("display")=='none'){
				jQuery("#megaNav").fadeIn("slow");
			}else{
				jQuery("#megaNav").fadeOut("slow");
			}
		});
		
		jQuery("#closeLink").click(function(){
			jQuery("#megaNav").fadeOut("slow"); 
		});
		/*jQuery("#megaNav").bind("mouseleave", function(e) {
			jQuery("#megaNav").fadeOut("slow");
		});*/
	

		
/******************       CODE FOR hover arrow         ***********************/				
		
		var hide = false; 
     jQuery("#arrowzone,#bigarrow").hover(function(){ 
         if (hide) clearTimeout(hide); 
         jQuery("#bigarrow").fadeIn("slow"); 
     }, function() { 
         hide = setTimeout(function() { 
             jQuery("#bigarrow").fadeOut("slow"); 
         }, 250); 
     }); 

});//ALL
//alert(expand);
/******************** graybar menu initialization, calling functions in ddaccordion.js ************************************/
ddaccordion.init({
	headerclass: "expandable", //Shared CSS class name of headers group that are expandable
	contentclass: "categoryitems", //Shared CSS class name of contents group	
	revealtype: "click",
	collapseprev: true, //Collapse previous content (so only one open at any time)? true/false 
	defaultexpanded: [expand[0]], //index of content(s) open by default [index1, index2, etc]. [] denotes no content
	animatedefault: false, //Should contents open by default be animated into view?
	persiststate: false, //persist state of opened contents within browser session?
	toggleclass: ["", ""], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
	togglehtml: ["prefix", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
	animatespeed: "normal" //speed of animation: "fast", "normal", or "slow"
})
ddaccordion.init({
	headerclass: "subexpandable", //Shared CSS class name of headers group that are expandable
	contentclass: "subcategoryitems", //Shared CSS class name of contents group
	revealtype: "clickgo",
	collapseprev: true, //Collapse previous content (so only one open at any time)? true/false 
	defaultexpanded: [expand[1]], //index of content(s) open by default [index1, index2, etc]. [] denotes no content
	animatedefault: false, //Should contents open by default be animated into view?
	persiststate: false, //persist state of opened contents within browser session?
	toggleclass: ["", ""], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
	togglehtml: ["prefix", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
	animatespeed: "normal" //speed of animation: "fast", "normal", or "slow"
})
ddaccordion.init({
	headerclass: "expandable2", //Shared CSS class name of headers group that are expandable
	contentclass: "subcategoryitems2", //Shared CSS class name of contents group
	revealtype: "click",
	collapseprev: true, //Collapse previous content (so only one open at any time)? true/false 
	defaultexpanded: [expand], //index of content(s) open by default [index1, index2, etc]. [] denotes no content
	animatedefault: false, //Should contents open by default be animated into view?
	persiststate: false, //persist state of opened contents within browser session?
	toggleclass: ["", ""], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
	togglehtml: ["prefix", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
	animatespeed: "normal" //speed of animation: "fast", "normal", or "slow"
})

/****************** hover effects using image swap ************************/
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

/****************** function to rotate big message images on home pages ************************/
function cycleImg() {
	try {
		clearTimeout(oTimer);
	} catch(err) {}
	jQuery('div', $('#mainContent')).each(function() {
		var x;
		var sx;
		if($(this).css("display")=='block'){
			$(this).fadeOut(2000);
			var thisid = $(this).attr('id');
			var thisNum = thisid.charAt(thisid.length - 1);
			var i = parseInt(thisNum);
			//console.log(i);
			if((i+1)>bobiCount){
				x = 1;											
			}else{
				x=i+1;
			}
			sx=x.toString();
			//console.log(bobiName);					
			$("#"+bobiName+sx).fadeIn(2000);
			oTimer = setTimeout ( "cycleImg()", 5000 );
			return false;
		}
	});
}

// show any hidden element
function showMe(show) {
 jQuery(show).show();
 //toShow = @(show);
 //toShow.style.display = "block";
}
// hide any shown element
function hideMe(hide) {
 jQuery(hide).hide();
 //toHide = $(hide);
 //toHide.style.display = "none";
}
function showHideSvc() {
	if(jQuery("#svcDesc").css("display") == 'block'){
		jQuery("#svcDesc").hide();
		jQuery("#svcList").fadeIn("slow");
	}else{
		jQuery("#svcList").hide();
		jQuery("#svcDesc").fadeIn("slow");
	}
}
function showCompany() {
	if(jQuery("#company1").css("display") == 'block'){
		jQuery("#sliderControl_1").hide();
		jQuery("#sliderControl_2").show();
		jQuery("#company2").fadeOut("slow");
		jQuery("#company1").animate({
        marginLeft: "-649px"
      }, 2500 );
	}
}
function hideCompany() {

		var slideTimer = 0; 

	if(jQuery("#company1").css("display") == 'block'){
		jQuery("#sliderControl_1").show();
		jQuery("#sliderControl_2").hide();
		jQuery("#company1").animate({
        marginLeft: "0px"
      }, 2500 );
		slideTimer = setTimeout ( "showCompanyText()", 1500 );
		//jQuery("#experience2").fadeIn("slow");
	}
}
function showCompanyText() {
		jQuery("#company2").fadeIn("slow");
}
function showLeadership() {

		var slideTimer = 0; 

	if(jQuery("#leadership1").css("display") == 'block'){
		jQuery("#sliderControl_1").hide();
		jQuery("#sliderControl_2").show();
		jQuery("#leadership1").animate({
        marginLeft: "-258px"
      }, 1500 );
		slideTimer = setTimeout ( "showLeadershipText()", 1500 );
	}
}
function showLeadershipText() {
		jQuery("#leadership2").fadeIn("slow");
}
function hideLeadership() {
	if(jQuery("#leadership1").css("display") == 'block'){
		jQuery("#sliderControl_1").show();
		jQuery("#sliderControl_2").hide();
		jQuery("#leadership2").fadeOut("slow");
		jQuery("#leadership1").animate({
        marginLeft: "0px"
      }, 1500 );
	}
}
function showExperience() {
	if(jQuery("#experience1").css("display") == 'block'){
		jQuery("#sliderControl_1").hide();
		jQuery("#sliderControl_2").show();
		jQuery("#experience2").fadeOut("slow");
		jQuery("#experience1").animate({
        marginLeft: "-649px"
      }, 1250 );
	}
}
function hideExperience() {

		var slideTimer = 0; 

	if(jQuery("#experience1").css("display") == 'block'){
		jQuery("#sliderControl_1").show();
		jQuery("#sliderControl_2").hide();
		jQuery("#experience1").animate({
        marginLeft: "0px"
      }, 1250 );
		slideTimer = setTimeout ( "showExperienceText()", 1250 );
		//jQuery("#experience2").fadeIn("slow");
	}
}
function showExperienceText() {
		jQuery("#experience2").fadeIn("slow");
}

function showProcess_step1() {
	if(jQuery("#process").css("display") == 'block'){
		jQuery("#sliderControl_1").hide();
		//jQuery("#sliderControl_2").show();
		jQuery("#process_text1").fadeOut("fast");
		setTimeout (function () {jQuery("#process_text2").fadeIn("slow")}, 2000);
		setTimeout (function () {jQuery("#sliderControl_2").fadeIn("slow")}, 2000);
		jQuery("#process").animate({
        marginLeft: "-669px"
      }, 2250 );
	}
}
function showProcess_step2() {
	if(jQuery("#process").css("display") == 'block'){
		jQuery("#sliderControl_2").hide();
		//jQuery("#sliderControl_3").show();
		jQuery("#process_text2").fadeOut("fast");
		setTimeout (function () {jQuery("#process_text3").fadeIn("slow")}, 2000);
		setTimeout (function () {jQuery("#sliderControl_3").fadeIn("slow")}, 2000);
		jQuery("#process").animate({
        marginLeft: "-1319px"
      }, 2250 );
	}
}
function showProcess_step3() {
	if(jQuery("#process").css("display") == 'block'){
		jQuery("#sliderControl_3").hide();
		//jQuery("#sliderControl_4").show();
		jQuery("#process_text3").fadeOut("fast");
		setTimeout (function () {jQuery("#process_text4").fadeIn("slow")}, 2000);
		setTimeout (function () {jQuery("#sliderControl_4").fadeIn("slow")}, 2000);
		jQuery("#process").animate({
        marginLeft: "-1965px"
      }, 2250 );
	}
}
function showProcess_step4() {
	if(jQuery("#process").css("display") == 'block'){
		jQuery("#sliderControl_4").hide();
		//jQuery("#sliderControl_1").show();
		jQuery("#process_text4").hide();
		setTimeout (function () {jQuery("#process_text1").fadeIn("slow")}, 2000);
		setTimeout (function () {jQuery("#sliderControl_1").fadeIn("slow")}, 2000);
		jQuery("#process").animate({
        marginLeft: "0px"
      }, 2250 );
	}
}




function makearray(n) {
	this.length = n;
	for(var i = 1; i <= n; i++)
		this[i] = 0;
	return this;
}
function hex(i) {
	if (i < 0)	  return "00";
	else if (i > 255) return "ff";
	else		  return "" + hexa[Math.floor(i/16)] + hexa[i%16];
}
function hexnumtodec(hexchar) {
	if (parseInt(hexchar) == hexchar) return Number(hexchar)
	hexchar = hexchar.toUpperCase()
	switch (hexchar) {
		case 'A': return 10; break;
		case 'B': return 11; break;
		case 'C': return 12; break;
		case 'D': return 13; break;
		case 'E': return 14; break;
		case 'F': return 15; break;
	}
}
function hextodec(daHex) {
	var daDec = Number((16 * hexnumtodec(daHex.substring(0,1))) + hexnumtodec(daHex.substring(1,2)))
	return daDec
}
 
function setColor(r,g,b) {
	var hr = hex(r); var hg = hex(g); var hb = hex(b);
	var daColor = "#"+hr+hg+hb
	daEl.style.backgroundColor = daColor
	if (daColor == colorend.toLowerCase()) {
		clearInterval(iId)
		iId = null
		timerRunning = false
	}
}
 
function fade() {
	i++
	setColor(
		Math.floor(sr * ((step-i)/step) + er * (i/step)),
		Math.floor(sg * ((step-i)/step) + eg * (i/step)),
		Math.floor(sb * ((step-i)/step) + eb * (i/step)));
}
hexa = new makearray(16);
for(var i = 0; i < 10; i++)
	hexa[i] = i;
hexa[10]="a"; hexa[11]="b"; hexa[12]="c";
hexa[13]="d"; hexa[14]="e"; hexa[15]="f";
 
var i
var iId = null
var sr, sg, sb
var er, eg, eb
var interval = 1
var step = 16
var colorstart
var colorend
var daEl
var timerRunning = false
 
function myfade(el,cs,ce,iv,st) {
	daEl = el
	colorstart = cs
	colorend = ce
	interval = iv
	step = st
	i = 0
	if (timerRunning) {
		clearInterval(iId)
		iId = null
	}
	var myRe = /#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})/i
	if (colorstart.match(myRe)) {
		sr = hextodec(RegExp.$1)
		sg = hextodec(RegExp.$2)
		sb = hextodec(RegExp.$3)
	}
	if (colorend.match(myRe)) {
		er = hextodec(RegExp.$1)
		eg = hextodec(RegExp.$2)
		eb = hextodec(RegExp.$3)
	}
	timerRunning = false;
	iId = setInterval("fade()",interval)
	timerRunning = true;
}
function cellover(table_cell) {
	// play around with these values
	// element, from_color, to_color, interval(milliseconds), transition steps
	myfade(table_cell,'#F3F0EB','#ACA095',10,32)
}
function cellout(table_cell) {
	if (timerRunning) {
		clearInterval(iId)
		iId = null
	}
	table_cell.style.backgroundColor = '#F3F0EB'
}


