// Don't throw errors if Firebug isn't running
//if( !('console' in window) || !('firebug' in console)) {
//  var names = ['log', 'debug', 'info', 'warn', 'error', 'assert', 'dir', 'dirxml',
//  'group', 'groupEnd', 'time', 'timeEnd', 'count', 'trace', 'profile', 'profileEnd'];
//
//  window.console = {};
//  for( var i = 0; i < names.length; ++i ) {
//    window.console[names[i]] = function(){};
//  }
//}
if(typeof console === "undefined") {
  console = { log: function() { } };
}

$(function() {

// Center facebox modal vetically
$(document).bind('afterReveal.facebox', function() {
  var windowHeight = $(window).height();
  var faceboxHeight = $('#facebox').height();

  if(faceboxHeight < windowHeight) {
    $('#facebox').css('top', (Math.floor((windowHeight - faceboxHeight) / 2) + $(window).scrollTop()) );
  }
});

  // Initialise Facebox Modal window:
  $('a[rel*=modal]').facebox();

$('.cart_popup').click(function() {
	$.facebox($('#cart_popup').html());
	$('#facebox').css('width', '350px');
	
	var windowWidth = $(window).width();
  	var faceboxWidth = $('#facebox').width();

	  if(faceboxWidth < windowWidth) {
	    $('#facebox').css('left', (Math.floor((windowWidth - faceboxWidth) / 2) + $(window).scrollLeft()) );
	  }
});

$('#accountDropdown').click(function() {
	$('ul#dropdownMenu', this).toggle();

});

$('#account_welcome a.current_location').click(function() {
	$('#account_welcome ul.location_menu').toggle();
});

//Contact Form.
$('#Contact_Method').change(function() {

	if ($(this).val() == 'Phone') {
		$('#phoneNumber').show();
		$('#contactEmail').hide();
		
	} else if ($(this).val() == 'E-Mail') {
		$('#contactEmail').show();
		$('#phoneNumber').hide();
	} else {
		$('#contactEmail').hide();
		$('#phoneNumber').hide();
	}

});

$('input[name="fileOption"]').change(function() {
	if ($(this).val() == 'yes') {
		$('#fileUploader').show();
	} else {
		$('#fileUploader').hide();
	}
});

});

if (top.location != location) {
    top.location.href = document.location.href ;
  }

// Slider for Recommended Products.
var sliderFunc = function() {
	// Get selected item
	var curSlide = $('.feature-slider .sel');
	var prev = $(this).hasClass('prev');

	// Which direction (backward or forward)?
	if (prev) {
		// Get the preceding element, or wrap around to the final one if none
		var slide = curSlide.prev('li');
		if (!slide.length) slide = $('.feature-slider li:last-child');
	}
	else {
		// Get the next element, or wrap around to the first one if none, and remove the selected class
		var slide = curSlide.next('li');
		if (!slide.length) slide = $('.feature-slider li:first-child');
	}

	// Disable nav clicking to prevent goofy behavior
	$('.feature-slider .slider-nav a').unbind('click');
	$('.feature-slider .slider-nav a').click(function() { return false; }); // Prevents href from firing

	// Move to the prev/next slide
	slide.addClass('sel').css('left',(prev)? '-100%':'100%').animate({'left':'0'}, 500);
	curSlide.animate({'left':(prev)? '100%':'-100%'}, 500, null, function() {
		$(this).removeClass('sel');

		// Reactivate nav clicking
		$('.feature-slider .slider-nav a').click(sliderFunc);
	});

	return false;
} // End function sliderFunc()

// Simple validation for newsletter
$(document).ready(function() {
	
	$('#newsletter_form').submit(function() {
	
		if ($('#newsletter_form input[name="first_name"]').val() == '' || $('#newsletter_form input[name="last_name"]').val() == '' || $('#newsletter_form input[name="email"]').val() == '') {
		
			alert('Please make sure to fill in all fields.');
		
		} else {
			
			// Simple validation passed = continue on.
			return true;
		}
		
		return false;
	});
	
});
