/**
 * Copyright (C) 2009 Drumbit - www.drumbit.com
 * 
 * This file is part of ExperienceGifts
 *
 * ExperienceGifts is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * ExperienceGifts is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with ExperienceGifts.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */


$(document).ready(function() {

	$('#nav_items > LI').each(function(){
		var top = $('#'+$(this).attr('rel')).offset().top - 22; 
		var left = $('#'+$(this).attr('rel')).offset().left - ($('#nav').offset().left + 3);
		var contentLeft = 0;
		var totalW = parseInt($('#nav').css('width'));
		var boxW = parseInt($(this).children('.items').css('width'));
		var H4width = parseInt($('#'+$(this).attr('rel')).css('width')) - 30;
		
		if ((totalW - boxW) < left - 20)
		{
			contentLeft =  10 + totalW - (totalW + boxW - (totalW - left));
		}
		$(this).css({'top': top,'left': left,'z-index' : 1000});
		if (contentLeft < 0)
		{
			$(this).css({'width': 500});
			$(this).css('left', (  totalW - boxW + 10)+'px');
			$(this).children('H4').css('margin-left', 0 - contentLeft + 4);
		}
		if (!isNaN(H4width))
		  $(this).children('H4').css('width', H4width+'px');
		
		$(this).children('H4, .items').hover(
        function(){ $(this).parent().stopTime('hide-nav');}, 
        function(){ $(this).parent().oneTime(150,'hide-nav', function(){
         $(this).hide()
      })
    });
	})
	
   $('#nav LI').mouseover(function(){
   	  $('#nav_items > LI').hide().filter('#'+$(this).attr('id')+'_items').show();
   })
//   
//  var zIndexNumber = 1000;
//  $('.ie7 div').each(function() {
//    $(this).css('zIndex', zIndexNumber);
//    zIndexNumber -= 10;
//  });

   
})
