
jQuery(document).ready(function() {

jQuery("#first .learn-more, #second .learn-more").hide();

enableLinks = true;




jQuery("#bottles li").click(function() {

if(enableLinks == true) {

	var c = jQuery(this).attr('id');

	if(c == 'first') {
		var order =["third","first","second"];		
		enableLinks = false;		
	} else if (c == 'second') {
		var order =["first","second","third"];	
		enableLinks = false;		
	} else if (c == 'third') {
		enableLinks = true;	
		return;
	}

	jQuery("#bottles #" + order[0]).css({'z-index' : 2}).animate({left : 100, top: 80}, 500).find('img.bottle').animate({height : 250}, 500, function(){
		jQuery(this).parent().attr('id', 'second');//.find('img.button').show();
	}).siblings('a.learn-more').hide();
	//jQuery("#bottles #" + order[0]).find('img.button').animate({top : 150 });

	jQuery("#bottles #" + order[1]).css({'z-index' : 3}).animate({left : 250, top: 0}, 500).find('img.bottle').animate({height : 425}, 500, function() {
		jQuery(this).parent().attr('id', 'third').find('.learn-more').show();	
		enableLinks = true;		
	});//.siblings('img.button').animate({top:250}, 500);

	jQuery("#bottles #" + order[2]).css({'z-index' : 1}).animate({left : 0, top: 130}, 500).find('img.bottle').animate({height : 150}, 500, function() {
		jQuery(this).parent().attr('id', 'first');//.find('img.button').show();
	}).siblings('a.learn-more').hide();
	
	//jQuery("#bottles #" + order[2]).find('img.button').animate({top : 100 });

	var t = jQuery(this).attr('class');
	if(t == 'bottle3') {
		// original
		jQuery("#stainless-bg, #plastic-bg").fadeOut();	
		jQuery("#desc-"+t).show().siblings('.description').hide();
	} else if (t == 'bottle1') {
		// half twist plastic
		jQuery("#stainless-bg").css({'z-index' : 1});
		jQuery("#plastic-bg").css({'z-index' : 2}).hide().fadeIn();
		jQuery("#desc-"+t).show().siblings('.description').hide();		
	} else if (t == 'bottle2') {
		// half twist metal
		jQuery("#plastic-bg").css({'z-index' : 1});
		jQuery("#stainless-bg").css({'z-index' : 2}).hide().fadeIn();	
		jQuery("#desc-"+t).show().siblings('.description').hide();		
	}
	
}
	
});

/*	jQuery("#bottles img.bottle").hover(function() {
		h  = jQuery(this).height();
		if (!(jQuery(this).hasClass("hover"))) {
		jQuery(this).addClass('hover').animate({height : h + 10}, {queue: false, duration: 100, complete: function() {
			jQuery(this).removeClass('hover');
		}});
		}
	}, function() {
		if (!(jQuery(this).hasClass("moving"))) {
			jQuery(this).animate({height : h}, {queue: false, duration: 100});
		}
	});*/
});

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

jQuery.preloadImages("http://www.polarbottle.com/wp-content/themes/polar/imgs/home/bg-plastic.jpg", "http://www.polarbottle.com/wp-content/themes/polar/imgs/home/bg-insulated.jpg");
