/**
 * Copyright (C) 2009 Marcelo Costanzi - www.dotdev.com.ar
 * 
 * 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() {

	setNavigationBar();
	
   $('#nav LI').mouseover(function(){
   	  $('#nav_items > LI').hide().filter('#'+$(this).attr('id')+'_items').fadeIn(300);
   })
   
   $(window).resize(setNavigationBar);
   
  var zIndexNumber = 1000;
  $('.ie7 div').each(function() {
    $(this).css('zIndex', zIndexNumber);
    zIndexNumber -= 10;
  });

   
})

function setNavigationBar() {
  $('#nav_items > LI').each(function(){
    var top = $('#'+$(this).attr('rel')).offset().top - 17;
    var top =  - 8;
    var left = $('#'+$(this).attr('rel')).offset().left - ($('#nav').offset().left);
    var contentLeft = 0;
    var totalW = parseInt($('#nav').css('width'));
    var boxW = parseInt($(this).children('.items').css('width'));
    if ((totalW - boxW) < left - 20)
    {
      contentLeft =  0 + totalW - (totalW + boxW - (totalW - left));
    }
    $(this).css({'top': top,'left': left,'z-index' : 1000});
    if (contentLeft < 0)
    {
      $(this).children('.items').css('left', contentLeft+'px');
      $(this).children('.foot').css('left', (contentLeft)+'px');
      $(this).css({'width': parseInt($('#'+$(this).attr('rel')).css('width')) + 10});
    }
    var H4width = parseInt($('#'+$(this).attr('rel')).css('width')) - 30;
    $(this).children('H4').css('width', H4width);
    
    $(this).children('H4, .items').hover(
      function(){ $(this).parent().stopTime('hide-nav');}, 
      function(){ $(this).parent().oneTime(100,'hide-nav', function(){
         $(this).hide()
      })
    });
  })
}