(function($){
 $.fn.extend({
 
 	customStyle : function(options) {
	  if(!$.browser.msie || ($.browser.msie&&$.browser.version>6)){
	  return this.each(function() {
	  
			var currentSelected = $(this).find(':selected');
			$(this).after('<span class="customStyleSelectBox"><span class="customStyleSelectBoxInner">'+currentSelected.text()+'</span></span>').css({position:'absolute', opacity:0,fontSize:$(this).next().css('font-size')});
			var selectBoxSpan = $(this).next();
			var selectBoxWidth = parseInt($(this).width()) - parseInt(selectBoxSpan.css('padding-left')) -parseInt(selectBoxSpan.css('padding-right'));			
			var selectBoxSpanInner = selectBoxSpan.find(':first-child');
			selectBoxSpan.css({display:'inline-block'});
			// selectBoxSpanInner.css({width:selectBoxWidth, display:'inline-block'});
			var selectBoxHeight = parseInt(selectBoxSpan.height()) + parseInt(selectBoxSpan.css('padding-top')) + parseInt(selectBoxSpan.css('padding-bottom'));
			$(this).height(selectBoxHeight).change(function(){
				selectBoxSpanInner.text($(this).val()).parent().addClass('changed');
			});
			
	  });
	  }
	}
 });
})(jQuery);

// Country Select Menu
$(function() {
	$('.countrySelect').customStyle();
	//$('.countrySelect').live("change", function() {	
	$('.countrySelect').change(function() {	
		var dataString = $('form#countrySelect').serialize();
		var page = $(location).attr('href');
		$.ajax({
			type: "POST",
			url: page,
			cache: false,
			data: dataString,
			dataType: "text",
			success: function() {
			location.reload();
			}
		});
		//$.post(page, dataString);
		//location.reload();
	});
});
	
function swapStory(storyName){
	$('div.currentStory').hide();
	$('div.currentStory').removeClass('currentStory');
	$('div [id = ' + storyName + ']').addClass('currentStory');
	$('div [id = ' + storyName + ']').fadeIn("slow");
}

$(function() {

	$('div#success_story_column > div:not(".currentStory")').hide();
	$('a.success_thumb_link').click(function(){
		swapStory($(this).attr("id"));
		return(false);
	});

	/*==== Moved to _header_intl.cfm because it was conflicting with the jquery accordion that the
		   new science page uses.
	$('dl#plan_list dd:not(:first)').hide('slow'); // use this to expand first box
	// $('dl#plan_list dd').hide('slow'); // comment this one out before hiding first
	$('dl#plan_list dt').hover(
		function(){
			$(this).css({'color' : '#950000', 'cursor' : 'pointer'});
		},
		function(){
			$(this).css({'color' : '#555555'});
		});
	$('dl#plan_list dt').click(function(){
		$(this).next('dd').slideToggle().siblings("dd:visible").slideUp("slow");
	});*/
});

// Popup Colorbox Videos
$(function() {
	// Videos
	$(".video").colorbox({maxWidth:"999px", maxHeight:"700px", opacity:"0.35"});	   
	// Popups
	$(".popup").colorbox({maxWidth:"500px", maxHeight:"500px", opacity:"0.35"});
	// Email
	$(".emailpop").colorbox({maxWidth:"650px", maxHeight:"625px", opacity:"0.35"});
});

/*
$(function() {
  $("#menu img").hover(function() {
    $(this).attr("src", $(this).attr("src").split(".").join("-hover."));
  }, function() {
    $(this).attr("src", $(this).attr("src").split("-hover.").join("."));
  });
});*/

function popURL(strURL,strType,strHeight,strWidth) 
	{
		var strOptions="";

		if (strType=="console") strOptions="resizable,height="+strHeight+",width="+strWidth;
		if (strType=="fixed") strOptions="status,height="+strHeight+",width="+strWidth;
		if (strType=="elastic") strOptions="scrollbars,resizable,height="+strHeight+",width="+strWidth;

		newWin = window.open(strURL, 'newWin', strOptions);

		newWin.focus();
}

$(function() {

	//$(".popup").colorbox({maxWidth:"500px", maxHeight:"500px", opacity:"0.35"});
	$('.flavorSelect').customStyle(); // Change Flavor Menu
	
	// Product Page Show/Hide
	// Hide opt2 onLoad
	$('img.opt2_img').hide();
	$('li.opt2_buy').hide();
	$('ul.opt2_prc').hide();
	// Hide opt3 onLoad
	$('img.opt3_img').hide();
	$('li.opt3_buy').hide();
	$('ul.opt3_prc').hide();
	
	// Change Flavor Menu
	$('.flavor').change(function() {
		// What menu item was selected?
		var option = $('#options :selected').attr('id');

		if (option == 3) {
			// Hide opt1
			$('img.opt1_img').hide();
			$('li.opt1_buy').hide();
			$('ul.opt1_prc').hide();
			// Hide opt2
			$('img.opt2_img').hide();
			$('li.opt2_buy').hide();
			$('ul.opt2_prc').hide();
			// Show opt3
			$('img.opt3_img').show();
			$('li.opt3_buy').show();
			$('ul.opt3_prc').show();
			//if (option3) {
				// Hide opt1
				//$('dl.opt1_prc').hide();
				//$('li.opt1_buy').hide();
				// Show opt2
				//$('dl.opt2_prc').show();
				//$('li.opt2_buy').show();
			//}
		}
		if (option == 2) {
			// Hide opt1
			$('img.opt1_img').hide();
			$('li.opt1_buy').hide();
			$('ul.opt1_prc').hide();
			// Show opt2
			$('img.opt2_img').show();
			$('li.opt2_buy').show();
			$('ul.opt2_prc').show();
			// Hide opt3
			$('img.opt3_img').hide();
			$('li.opt3_buy').hide();
			$('ul.opt3_prc').hide();
			//if (option3) {
				// Hide opt1
				//$('dl.opt1_prc').hide();
				//$('li.opt1_buy').hide();
				// Show opt2
				//$('dl.opt2_prc').show();
				//$('li.opt2_buy').show();
			//}
		}
		else if (option == 1) {
			// Show opt1
			$('img.opt1_img').show();
			$('li.opt1_buy').show();
			$('ul.opt1_prc').show();
			// Hide opt2
			$('img.opt2_img').hide();
			$('li.opt2_buy').hide();
			// Hide opt3
			$('img.opt3_img').hide();
			$('li.opt3_buy').hide();
			$('ul.opt3_prc').hide();
			//if (option3) {
				// Hide opt1
				$('ul.opt2_prc').hide();
				//$('li.opt1_buy').hide();
				// Show opt2
				//$('dl.opt1_prc').show();
				//$('li.opt2_buy').show();
			//}
		}
	});
});
