CPOProductTabs = { //singleton
	init: function(el, nav) {
		this.blocks = $(el).find('>div');

		// this.links = $(nav).find('li');
		this.links = $(nav).find('a');

		
		this.select(0);
		this.links.each(function(i){
			$(this).bind('click', function(){
				CPOProductTabs.select(i);
				var container = $('#content .product-overview .container');
				if($(this).is('.wide')) {
					container.addClass('full-width');
				} else {
					container.removeClass('full-width');
				}
				return false;
			});
		});
	},
	
	select: function(index) {
		if (typeof index == 'string') {
			for (var i=0; i<this.links.length; i++) {
				if (this.links[i].innerHTML.toLowerCase() == 
						index.toLowerCase()) {
					index = i;
					break;
				}
			};
		}
		this.blocks.each(function(i) {		
			if (i == index) {
				$(this).show();
				$(CPOProductTabs.links[i]).addClass('current');
			} else {			
				$(this).hide();
				$(CPOProductTabs.links[i]).removeClass('current');
			}
		})
	}
}

$(document).ready(function() {
	var overview = $('#content .product-overview');
	if (overview.length) {
		var left = overview.find('.left-content').eq(0);
		var container = overview.find('.container').eq(0);		
		if (left.length) container = left;
		
		CPOProductTabs.init(
			container, 
			overview.find('.product-tabs').eq(0)
		);
	}

  function related_accs_list(related) {
		related.each(function(i) {
			if ((i >= 5) && (i < related.length - 1)) {
				$(this).hide();
			}
		});
		related.find('.view-more').eq(0).click(function() {
			related.show();
			$(this).parent().hide();
			related.parent().css('background-image', 'none');
			return false;
		});	
  }
	
  var related = $('#related-accessories > #related_accessories_add_to_cart_form > ul > li');
	if (related.length) {
    related_accs_list(related);
  }
	
	var rollover = $('#rollover');
	if (rollover) {
		var whybox = $('.why-buy-box').eq(0);
		rollover.hide().hover(function() {}, function() {
			rollover.hide();
		});
		whybox.hover(function() {
			$('#rollover').show();
		}, function() {});
	}

  var about_our_price_rollover = $('#rollover2');
  if (about_our_price_rollover) {
    var aboutourpricebox = $('.about-our-price-link').eq(0);
   about_our_price_rollover.hide().hover(function() {}, function() {
      about_our_price_rollover.hide();
    });
    aboutourpricebox.hover(function() {
      $('#rollover2').show();
    }, function() {});
  }
  
  // Change title for power reviews
  var snippet_title = $(".prSnippetTitle")
  if(snippet_title){
    snippet_title.html("Customer Rating:");
  }

});
