/* will load additional script libraries */

/*
var head= document.getElementsByTagName('head')[0];
   var script1= document.createElement('script');
   script1.type= 'text/javascript';
   script1.src= '/js/jquery.js';
   head.appendChild(script1);
   var script2= document.createElement('script');
   script2.type= 'text/javascript';
   script2.src= '/js/slider.js';
   head.appendChild(script2);
*/


function findObject(n) 
{ 
  var x;
  var NS4 = (document.layers) ? true : false;
  var NS6 = (document.getElementById && !document.all) ? true : false;

  if (!NS6)
  	{
 	 if(!(x = document[n]) && document.all) 
 	 x = document.all[n]; 
 	}
  else	
  	{
  	 x = document.getElementById(n);
  	}
  return x;
}



/* Hides or displays the menu based on passed parameters.
	L- it the menu name
	V- is if to show or hide
*/

function menu(l, v) 
{ 
  var obj;
  
    if ((obj=findObject(l))!=null) 
    { 
      if (obj.style) 
      { 
      	obj=obj.style; 
      	v=(v=='show')?'visible':(v=='hide')?'hidden':v; 
      }
      obj.visibility=v; 
    }
}

function menuSub(l, v, numofLevels, menuLevel) 
{ 
  var obj;
   
   if (v=="hide")
   {
	   if (menuLevel==1)
	   {
	   	for ( var t = 1; t < (numofLevels+1); t++ )
			{
	  	 m = l + t;
		    if ((obj=findObject(m))!=null) 
	 		   { 
	   		   if (obj.style) 
	     		 { 
			      obj=obj.style; 
	      	      obj.visibility="hidden"; 
	    		 }
				}
			}
		} else {
			m = l + menuLevel;
		    if ((obj=findObject(m))!=null) 
	 		   { 
	   		   if (obj.style) 
	     		 { 
			      obj=obj.style; 
	      	      obj.visibility="hidden"; 
	      	     }
				}
		}
	
	} 
   if (v=="show")
	{
   	for ( var t = menuLevel; t > 0; t-- )
   		{
   		m = l + t;
 		if ((obj=findObject(m))!=null) 
 		   { 
   		   if (obj.style) 
     		 { 
		      obj=obj.style; 
      	      obj.visibility="visible"; 
    		 }
			}
		}
	}
}
 
function closeEmAll()
{
/* yes its a hack */
/* add the name of any new menu into the array declaration */
var a = new Array();

a[0] = "browseConsultingMenu1";
a[1] = "browseConsultingMenu2";
a[2] = "browseWorkshopMenu";
a[3] = "browseClientsMenu";
a[4] = "browseProgramMenu";

for (var i = 0; i < a.length; i++)
	{
		if ((obj=findObject(a[i]))!=null) 
	    { 
	 	   if (obj.style) 
	   		 { 
			  obj=obj.style; 
	   	      obj.visibility="hidden"; 
	   	     }
		}
	}
}

/********************************************************************************************************************************************************************** */
/* rePosMain, rePos, findPosX and findPosY are used to re-position the div that acts as the drop-down menu by checking the position of the id it is being referenced to */

function rePosMain()
{
rePos("browseProgramMenu","ProgramMenu");
}


function rePos(obj,lyr) //repositions the menu to the box that 'calls' it through a mouse over
{
	var x = findObject(obj);
	var o = findObject(lyr);
	var newX = findPosX(o);
	var newY = findPosY(o) + 18; // offset to move the menu below the box
	x.style.top = newY + 'px';
	x.style.left = newX + 'px';
	
	changeShoppingCartDefaults();   //On the store pages--changes the home link title from 'Home' to something hard coded in the script
}

	



function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}




/***************************************************************************/
/* Following scripts are used on the Avaya freshman orientation registration pages to handle form submission and passing values to PayPal */
/***************************************************************************/

/* This fuinction combines allt the extra fields into the os0 and os1 fields that paypal allows user to pass through to it */
  function joinFields() {
    regform.os0.value = 'Fname:' + regform.fname.value + ',Lname:' + regform.lname.value + ',Org:' + regform.org.value + ',Title:' + regform.title.value + ',Diet:' + regform.diet.value;
	regform.os1.value = 'Add1:' + regform.add1.value + ',Add2:' + regform.add2.value + ',City:' + regform.rcity.value + ',State:' + regform.rstate.value + ',Zip:' + regform.rzip.value + ',phonea:' + regform.ph_area.value + ',phoneb:' + regform.ph_exchange.value + ',phonec:' + regform.ph_number.value + ',email:' + regform.remail.value;
 
 }



			function submitIt() {
				if (document.getElementById("fname").value=="") {
					alert("Please enter the attendee's first name.")
					document.getElementById("fname").focus()
					return false}
				if (document.getElementById("lname").value=="") {
					alert("Please enter the attendee's last name.")
					document.getElementById("lname").focus()
					return false}
				if (document.getElementById("org").value=="") {
					alert("Please enter your organization's name.")
					document.getElementById("org").focus()
					return false}
				if (document.getElementById("address1").value=="") {
					alert("Please provide a street address.")
					document.getElementById("address1").focus()
					return false}
					}


function clearMe()
{
  alert ("Howdy");
  var _s=top;
  var _d=_s.document;
  _d.open();
  _d.write("");
  _d.close();
}


/*
* jquery.vticker
* Tadas Juozapaitis ( kasp3rito@gmail.com )
*/

(function($){
$.fn.vTicker = function(options) {
	var defaults = {
		speed: 1500,
		pause: 7000,
		showItems: 1
	};

	var options = $.extend(defaults, options);

	moveUp = function(obj, height){
    	first = obj.children('ul').children('li:first').clone(true);
    	obj.children('ul')
    	.animate({top: '-=' + height + 'px'}, options.speed, function() {
        	$(this).children('li:first').remove();
        	$(this).css('top', '0px');
        });

    	first.appendTo(obj.children('ul'));
	};
	
	return this.each(function() {
		obj = $(this);
		maxHeight = 0;

		obj.css({overflow: 'hidden', position: 'relative'})
			.children('ul').css({position: 'absolute', margin: 0, padding: 0})
			.children('li').css({margin: 0, padding: 0});

		obj.children('ul').children('li').each(function(){
			if($(this).height() > maxHeight)
			{
				maxHeight = $(this).height();
			}
		});

		obj.children('ul').children('li').each(function(){
			$(this).height(maxHeight);
		});

		obj.height(maxHeight * options.showItems);
		
    	interval = setInterval('moveUp(obj, maxHeight)', options.pause);
	});
};
})(jQuery);

