/****************************************/
// preload images
/****************************************/
$.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}

/****************************************/
// window resize
/****************************************/
function resize()
{
	var a = $('#wrapper').height(),
		b = $('#footer').height(),
		h = a+b;
		  
	 if($(window).height() >= h) 
	   $('#footer').css({ position: 'absolute', bottom: 0 });
	 else
	   $('#footer').css('position', 'relative');
}

$(document).ready(function()	   
{  
	var news = '';
	
	/****************************************/
	//	navigation menu
	/****************************************/
   $('#navigation ul li').hover(function()
   {
	   var hoverWidth = $(this).width(); 
	   $(this).addClass('hover');
	   $('ul', this).css('width', hoverWidth+12);
   }, function() { $(this).removeClass('hover'); });
	
    /****************************************/
	//checks browser window's inner height
	/****************************************/
	var a = $('#wrapper').height(),
		b = $('#footer').height(),
		h = a+b;
		
	if($(window).height() >= h) 
		$('#footer').css({ position: "absolute", bottom: 0 });
		
	/****************************************/
	//add custom CSS to window resize
	/****************************************/
    $(window).resize(function(){ resize(); });

	/****************************************/
	//check for safari
	/****************************************/
	if($.browser.safari)
	{
		$('.header-right ul').css('fontSize','10px');
		$('.header-right label').css({ float: 'left', marginLeft: '35px', marginTop: '3px', paddingRight: '0' });   
		$('.header-right input:eq(1)').css('margin-top','-8px');
		$('.content-left').css('margin-top', '40px');
		$('.content-right').css('margin-top', '-30px');
	}
   
	/****************************************/
	//check for internet explorer 6
	/****************************************/
	if($.browser.msie && $.browser.version < 7.0)
	{
		$('.header-right ul li:first-child a').css({ color: '#6C6D71', fontWeight: 'normal' });
		$('#navigation li').hover(function(){ $(this).addClass('hover'); }, function() { $(this).removeClass('hover'); });
		$('#navigation li li').hover(function(){ $(this).addClass('hover'); }, function() { $(this).removeClass('hover'); });
		
		//navigation menu ie6
	    $('#navigation ul li').hover(function()
	    {
		   var hoverWidth = $(this).width(); 
		   $(this).addClass('hover');
		   $(this).css('text-transform', 'uppercase');
		   $('ul', this).css('width', hoverWidth);
	    }, function() { $(this).removeClass('hover'); });

		$('#navigation li, #navigation ul ul li, #navigation ul ul lu li').hover(function(){ $(this).css('text-transform', 'uppercase') }, function() {  });
		
		$('.navigation-calming li').hover(function(){ $(this).css('background', '#908F2C'); }, function() { $(this).css('background', '#908F2C'); });
		$('.navigation-purifying li').hover(function(){ $(this).css('background', '#45787C'); }, function() { $(this).css('background', '#45787C'); });
		$('.navigation-revitalizing li').hover(function(){ $(this).css('background', '#C36021'); }, function() { $(this).css('background', '#C36021'); });
		$('.navigation-gentlemans li').hover(function(){ $(this).css('background', '#404041'); }, function() { $(this).css('background', '#404041'); });
		
		// footer ie6
		$('#footer li img').each(function()
		{
			var png = $(this).attr('src')
			$(this).attr('src', png.replace('.png', '.gif'));
		});
		
		//badges ie6
		$('.badges').hover(function() { $(this).css('cursor', 'pointer'); }, function(){}).click(function(){ $('#modal').removeClass('hidden'); $('.modal-popup').fadeIn('fast'); });
	}
	
	if($.browser.msie){	$('#navigation a').each(function(){ $(this).attr('title', ''); });	}
   
   /****************************************/
   //modal window
   /****************************************/
   $('body').append('<div id="modal" class="hidden"><div class="modal-popup"><a href="#"></a></div></div>');
   $('.badges a').click(function()
	{
	   var mclass = $(this).parent('li').attr('class'),
		   mtitle = $(this).attr('title');
		   mtext = '',
		   mcontent = '';
			   
	   switch (mclass)
	   {
		   case 'calming':
				mcontent += 'The last thing flushed, dehydrated skin needs is a chemical added over the top, so gentle, natural, anti-inflammatory oils are carefully joined to gently treat reactive, easily flushed, dry or dehydrated skin from within. <strong>Ideal for those who commonly say, "Nothing works on my skin."</strong>';
				break;
		   case 'purifying':
				mcontent += 'Hormonal phases throughout life, be it puberty, mid-30\'s body changes, or menopause often create complex skin challenges. These changes are best treated naturally by unblocking follicles, balancing skin Ph and increasing circulation to cleanse sluggish, toxic, allergy-prone, blemish-laden skin and blocked pores from within. <strong>Ideal for those dealing with hormonal shifts, regardless of age</strong>.';
				break;
		   case 'revitalizing':
				mcontent += 'Women over their mid-40\'s need no longer fall to the mass-market pressure to look younger no matter what the cost. With age comes graceful beauty and a natural need for collagen regeneration. This blend helps reinvigorate cell memory and tones skin with natural oils that hydrate, brighten complexion and increase circulation. <strong>Designed for women ages 45+ to help you look even more beautiful</strong>.';
				break;
		   case 'gentlemans':
				mcontent += 'Because your morning routine often involves a face washed quickly with bar soap and then shaving, followed by a day in the wind and weather, a man\'s skin faces challenges unique of itself. You\'re dryer, stripped of important oils, sun burned and often irritated by razorburn— all of which require the natural hydration of these soothing oils.';
				break;
		   default:
				mcontent += 'The last thing flushed, dehydrated skin needs is a chemical added over the top, so gentle, natural, anti-inflammatory oils are carefully joined to gently treat reactive, easily flushed, dry or dehydrated skin from within. <strong>Ideal for those who commonly say, "Nothing works on my skin."</strong>';
				break;
	   };
		   
	   mtext += '<a href="#"></a>';
	   mtext += '<h1 class="' + mclass + '"><span>' + mtitle + '</span></h1>';
	   mtext += '<p>' + mcontent + '</p>';
		   
	   $('.modal-popup').html(mtext);
	   $('#modal').removeClass('hidden');
	   $('.modal-popup').fadeIn('fast');
	   
	   return false;
	});
   $('.modal-popup a, #modal').click(function()
   {
		$('.modal-popup').fadeOut('fast');
		$('#modal').addClass('hidden');
   });
   
   /****************************************/
   //news parse
   /****************************************/
   $('a.press').click(function()
	{
		var url = $(this).attr('href'),
		    news = $('.content-body').html();
			
		$.get(url, function(data){ $('.content-body').html(data); resize(); });
		return false;
	});
   
   /****************************************/
   //  as seen on tv
   /****************************************/
   $('a[rel="video"]').click(function(){ window.open( $(this).attr('href'), 'video','status = 1, height = 265, width = 320, resizable = 0'); return false; });

   
   /****************************************/
   //preload images
   /****************************************/
   $.preloadImages('/images/bg_modal-window.png', '/images/button_modal-close.png', '/images/bg_modal-calming-header.png', '/images/bg_modal-purifying-header.png', '/images/bg_modal-revitalizing-header.png', '/images/bg_modal-gentlemans-header.png');
});