//=======================================
// Rosser Generic Javscript
//=======================================

//------------------------
// Page Centering
// Modified to center horizontally only!
//------------------------

/*
 * 
 * Center Plugin 1.0 - Easy cross-browser centering a div!
 * Version 1.0.1
 * @requires jQuery v1.3.0
 * 
 * Copyright (c) 2010 Matthias Isler
 * Licensed under the GPL licenses:
 * http://www.gnu.org/licenses/gpl.html
 * 
 */
jQuery.fn.center = function(init) {
		
	var object = this;
		
	if(!init) {
			
	//	object.css('margin-top', $(window).height() / 2 - this.height() / 2);
		object.css('margin-left', $(window).width() / 2 - this.width() / 2);
			
		$(window).resize(function() {
			object.center(!init);
		});
		
	} else {
			
                var contentWidth = $('#content_wrapper').width();
                var windowWidth = $(window).width();
                var calcOffset = (windowWidth/2) - (contentWidth/2);
                var calcOffsetNorm = calcOffset + (calcOffset/2);

	//	var marginTop = $(window).height() / 2 - this.height() / 2 + "px";
		var marginLeft = $(window).width() / 2 - this.width() / 2 + "px";
			
	//	marginTop = (marginTop < 0) ? 0 : marginTop;
	//	marginLeft = (marginLeft < 0) ? 0 : marginLeft;
		marginLeft = (marginLeft < 0) ? calcOffsetNorm : marginLeft;

		object.stop();
		object.animate(
			{
	//			marginTop: marginTop, 
				marginLeft: marginLeft
			}, 
			0, 
			'linear'
		);
		
	}
}

//------------------------------------------------
// Run .ready Methods
//------------------------------------------------
    $(document).ready(function() {
        $('#interior_main').center();
        $('#mid_content_wrapper').center();
        $('#interior_foot').center();
        $('#wrapper').center();
    });


//=================================================================
// Side Menus
//=================================================================

var timeout    = 200;
var closetimer = 0;
var submenuitem = 0;

//==============================
// OPEN 
//==============================

function submenu_open()
{
   var thisItemClass = $(this).attr('class');

//alert('this attr class = ' + thisItem );

   var parentContainerTop = $('#side_navigation').offset().top;

   submenu_canceltimer();
   submenu_close();

   //--------------------------
   // Display This Side Menu
   // Item Hover State
   //--------------------------

      var thisItemTop = $(this).offset().top;

      thisTop = ( thisItemTop - parentContainerTop );

      var thisItemHoverClass = thisItemClass + "_hover";
      var thisItemHtml = $(this).html();

      var thisHoverItem = '<li class="' + thisItemHoverClass + '" style="top:' + thisTop  + 'px;" class="no">' + thisItemHtml + '</li>'; 

      $(this).after(thisHoverItem) ;

   //--------------------------
   // Display Submenu If Exist For This
   // Side Menu Item
   //--------------------------
      submenuitem = $(this).find('ul');

  if(typeof(submenuitem) !== 'undefined'  && submenuitem != null)
  { 
      submenuitem.css('visibility', 'visible');
      
      //--------------------------
      // Position Subnav Div Below/Right Of Parent Nav
      //--------------------------

      var menuItemTop = $(this).offset().top;

      ulTop = ( menuItemTop - parentContainerTop );

      submenuitem.css('top', ulTop  );
  }
}

//==============================
// CLOSE 
//==============================
function submenu_close()
{  
   $(this).find('ul').css('visibility', 'hidden');
}

//==============================
// SET TIMER (TO CLOSE) 
//==============================

function submenu_timer()
{

   //--------------------------
   // Display This Side Menu
   // Item NON Hover State
   //--------------------------

   var thisItemClass = $(this).attr('class');

   var hoverItem = "." + thisItemClass + "_hover";

   $(hoverItem).remove();

//   closetimer = window.setTimeout(submenu_close(), timeout);

   var closesubmenuitem = $(this).find('ul');
   closesubmenuitem.css('visibility', 'hidden');



}

//==============================
// CANCEL TIMER (TO CLOSE) 
//==============================
function submenu_canceltimer()
{
//   alert("made it into submenu_canceltimer function");
   if(closetimer)
   { 
       window.clearTimeout(closetimer);
       closetimer = null;
   }
}


//==============================
// INITIATE jQuery Call
//==============================
$(document).ready(function()
{
// COMMENTING OUT FOR NOW... SINCE HAVING SO MANY ISSUES WITH
// JQUERY TRYING TO MAKE RIGHT NAV DROP SHADOWS APPEAR.
/*
   $('#side_navigation > li').bind('mouseover', submenu_open );

   $('#side_navigation > li').bind('mouseout',  submenu_timer );
*/
}
);

//document.onclick = submenu_close;


//------------------------











