$(document).ready(function() {
  $('a').click(function() {this.blur();});
  menucartFun();
  $('.dropdown').css('display', 'none');
  for(var i=0; i<2; i++) {
    eval("$('#main-navigation').children('li:eq("+i+")').mouseenter(function(e) {\
      $('.dropdown:eq("+i+")').stop().css('display', '').animate({opacity:1}, { duration: 500, queue: false });\
    })");
    eval("$('#main-navigation').children('li:eq("+i+")').mouseleave(function() {\
      $('.dropdown:eq("+i+")').stop().animate({opacity:0}, { duration: 500, queue: false, complete: function() { $('.dropdown:eq("+i+")').css('display', 'none') } });\
    })");
    eval("$('.dropdown:eq("+i+")').find('a').click(function() {\
      $('.dropdown:eq("+i+")').stop().animate({opacity:0}, { duration: 250, queue: false, complete: function() { $('.dropdown:eq("+i+")').css('display', 'none') } });\
    })");
  }
  $('#main-navigation').children('li:eq(1)').find('a').click(function() {$('.dropdown:eq(1)').stop().animate({opacity:0}, { duration: 250, queue: false, complete: function() { $('.dropdown:eq(1)').css('display', 'none') } });
  });
  $('#sub_navigation a').click(function() {
    $('#sub_navigation li').removeClass('here');
    $(this).parent().addClass('here');
  });
  $('#product_sidebar a').click(function() {
    $('#product_sidebar span').removeClass('on');
    $(this).children('span').addClass('on');
  });


$('#share_box input:text, #share_box textarea').each(function() {
	$(this).data('default', $(this).val());
})
.focus(function() {
	if($(this).val() == $(this).data('default')) $(this).val('');
})
.blur(function() {
	if($(this).val() == '') $(this).val($(this).data('default'));
});

$('#share_box .submit').live('mouseover', function() {
	$(this).css({ 'background-color' : '#959595', color : '#ffffff' });
}).live('mouseout', function() {
	$(this).css({ 'background-color' : '#ffffff', color : '#959595' });
});

$('.sharelink').click(shareOn);
$('#share_mask, #share_box .close_button').click(shareOff);

$("#sub_navigation a:contains('Specs'), #sub_navigation a:contains('specs'), #sub_navigation a:contains('SPECS')").click(function() {
  $('#lightbox').load($(this).attr("href"), "ajax=true").css({
    display: 'block', opacity: 0
  }).animate({
    opacity: 1
  }, {
    duration: 500, queue: false
  }).ajaxComplete(function(event,request, settings){
    $('#lightbox_mask').css({ width : $(document).width(), height : $(document).height() });
  });
  $('#lightbox_mask').css({ display: 'block', opacity: .7, width : $(document).width(), height : $(document).height() });
  return false;
});

$('#lightbox_mask, #lightbox .close_button').live('click', function(e) {
  $('#lightbox_mask').css({ display: 'none' });
  $("#sub_navigation a:contains('Specs'), #sub_navigation a:contains('specs'), #sub_navigation a:contains('SPECS')").parent().removeClass('here');
  $('#lightbox').animate({
    opacity: 0
  }, {
    duration: 250, queue: false, complete : function() { $('#lightbox').css('display', 'none'); }
  });
});

});


function shareOn() {
	updateShareLinks();
	$('#share_mask').css({
						width : $(document).width(),
						height : $(document).height(),
						display : 'block'
						});
	$('#share_mask').animate({ opacity : .7}, { duration : 500, queue : false, complete : function() {
		var h = $('#inner .body-block').height() + 20;
		$('#share_box_wrapper1').css({
										opacity : 0,
										display : 'block',
										top : 250 + $('#inner .orange').height()
									 }).animate({ opacity : 1 }, { duration : 500, queue : false, complete : function() {
										 if(jQuery.browser.msie) this.style.removeAttribute("filter");
									 }});//.find('#share_box').css('height', $('#body').height());
	}});
}
function shareOff() {
	$('#share_mask').css({
						display : 'none'
						});
	$('#share_box_wrapper1').animate({ opacity : 0}, {duration : 500, queue : false, complete : function() { if(jQuery.browser.msie) this.style.removeAttribute("filter"); $(this).css('display', 'none'); } });
	$('#share_mask').animate({ opacity : 0}, {duration : 500, queue : false, complete : function() { if(jQuery.browser.msie) this.style.removeAttribute("filter");} });
}
  function updateShareLinks() {
	var hash = window.location.hash;
	var url = encodeURIComponent('http://'+window.location.host+window.location.pathname+hash.substr(1));
	var sharelinks = $('div.share_column a');
	var links = new Array(
		'http://reddit.com/submit?title='+encodeURIComponent(document.title)+'&url='+url+'&',
		'http://www.facebook.com/share.php?u='+url+'&t='+encodeURIComponent(document.title)+'&',
		'http://del.icio.us/post?url='+url+'&',
		'http://friendfeed.com/share?url='+url+'&',
		'http://digg.com/submit?phase=2&title='+encodeURIComponent(document.title)+'&url='+url+'&',
		'http://www.hugg.com/node/add/storylink?edit[title]='+encodeURIComponent(document.title)+'&edit[url]='+url+'&',
		'http://www.stumbleupon.com/submit?title='+encodeURIComponent(document.title)+'&url='+url+'&',
		'http://www.mixx.com/submit?page_url='+url+'&',
		'http://www.linkedin.com/shareArticle?mini=true&ro=true&url='+url+'&title='+encodeURIComponent(document.title)+'&summary=&source=&armin=armin',
		'http://twitter.com/home?status='+url+'&',
		'http://slashdot.org/bookmark.pl?title='+encodeURIComponent(document.title)+'&url='+url+'&',
		'http://current.com/clipper.htm?title='+encodeURIComponent(document.title)+'&src=st&url='+url+'&'
	);
	sharelinks.each( function (i) {
		$(this).attr('href', links[i]);
		if(links[i] != 'javascript:')
			$(this).attr('target', '_blank');
		else
			$(this).attr('target', '');
	});
  }
function shareToggle() {
   if (shareopen != 1){
    var shareopen=1;
    shareOn();
   }
   else{
   shareopen=0;
   shareOff();
   }
 }


setInterval ( "menucartFun()", 500 );
function menucartFun(){
  var numberInCart = $('#foxee_product_count').html();
  if (numberInCart == '' || numberInCart == 0){$('.menucart-empty').css({display:'inline'});
    $('.menucart-full').css({display:'none'});
  } else {$('.menucart-empty').css({display:'none'});
    $('.menucart-full').css({display:'inline'});
  }
}

setInterval(resizeCart, 500 );

function resizeCart() {
    $('#fc_tb_iframeContent').css('height', Math.max(200, $(document).height() - 100));
    $('#fc_tb_window').css({
      marginTop : 0,
      top: 0,
      position: 'absolute'
    });
}

function addVideo() {$('#video_spot').css({display:'block'}).flash({swf:'http://www.regenliving.com/images/video/spot.swf',height:556,width:950,params:{wmode:'transparent'} });
}

function removeVideo() {
	$('#video_spot').html(' ').css({display:'none'});
}