
$(document).ready(function(){
	
	$('.anchorDiv a').hover(function(event){
		
		$(this).find('img').attr('src', 'https://lib.store.yahoo.net/lib/yhst-91214505727833/ey-leftnav-on-dot.jpg');
		
	}, function(event){
		
		$(this).find('img').attr('src', 'https://lib.store.yahoo.net/lib/yhst-91214505727833/ey-leftnav-off-dot.jpg');
		
	});
	
});


/**
 * getValue
 * specialized function for the candygram store / multi option update feature
 * pass this function the value of an option, and you will get the price that was attached to that option
 * 
 */

function getValue(optValue) {
	
	var value = optValue.split('(');
	
	if (value.length > 1) {
	
		value = value[1].replace('+$', '');
		value = value.replace(')', '');
		
		return parseFloat(value);
		
	} else {
		
		return 0.0;
		
	}
	
}

/**
 * getVar
 * introduces the ability to pass variables to javascript via the HTML
 * class attribute by searching through string of given classnames to
 * return your desired variable
 * @param classes
 *    a string of class names (preferably using the element.className
 *    prototype attribute)
 * @param variable
 *    the target variable you would like to return
 * @return the value of the desired variable, false if variable is not present
 *
 * @example
 *    the format:
 *    - the variable you would like to pass should be formatted the following way:
 *      - class="var_example*value"
 * @example
 *    the markup:
 *    <a id="page_1_link" class="links var_page*1" href="/add-module/1/1">page 1</a>
 *    the js:
 *    element = $('page_1_link');
 *    the function call:
 *    getVar(element.className, 'page');
 *    - the function would return 1 (the value of the page variable)
 */
function getVar(classes, variable) {
  var arrClasses = '';
  var varClass = false;
  
  arrClasses = classes.split(" ");
  
  if(arrClasses == '') {
    return false;
  }
  
  $(arrClasses).each(function (index, value) {
    if (value.indexOf('var_' + variable) != -1) {
      varClass = arrClasses[(index)];
      return false;
    }   
  });
  
  //Check to make sure varClass is defined
  if(!varClass) {
    return false;
  }
  
  //split the value by the variable name and dash to return the value, if no value is present return false
  //although you shouldn't be cluttering up the markup it's not necessary
  return !varClass.split(variable + '*')[1] ? false : varClass.split(variable + '*')[1];
  
}

Number.prototype.isEven = function(){
    return (this % 2 == 0) ? true : false;
};

Number.prototype.toCash = function(){
	num = Math.ceil(this * 100) / 100;	
	return num.toFixed(2);
};

var addOnPricing = 0.0;
var addOnPricing2 = 0.0;

$(document).ready(function(){
		
	$('#item-options select').each(function(){
		
		$(this).unbind('focus');
		
		$(this).bind('focus', function(){
	        
			var oldValue = getValue($(this).attr('value'));				
			var price = parseFloat($('#hidden-price').html());
			var price2 = parseFloat($('#hidden-reg-price').html());
			
			if (oldValue) {
				addOnPricing -= oldValue;
				addOnPricing2 -= oldValue;
			}
			
			if (addOnPricing < 0 || addOnPricing2 < 0) {
				addOnPricing = 0;
				addOnPricing2 = 0;
			}
							
			$(this).unbind('change');
			
			$(this).bind('change', function(event){
				
	        	var newValue = getValue($(this).find(':selected').attr('value'));
	        	
	        	var price = parseFloat($('#hidden-price').text());
	        	var price2 = parseFloat($('#hidden-reg-price').text());
	        	
				if (newValue) { //if newValue is not zero
					addOnPricing += newValue;   
					addOnPricing2 += newValue;   
				}
				
				if (addOnPricing < 0 || addOnPricing2 < 0) {
					addOnPricing = 0;
					addOnPricing2 = 0;
				}
				
				$(this).blur();
				
				addOnPricing = parseFloat(addOnPricing);
				addOnPrcing2 = parseFloat(addOnPricing2);
				
				price += addOnPricing;
				price = price.toFixed(2);
				
				price2 += addOnPricing2;
				price2 = price2.toFixed(2);
				
				if ($('#item-sale-price').length) {
					$('#item-sale-price span').html('$' + price);
				} else {
					$('#item-our-price span').html('$' + price);
				}
				
				if ($('#item-reg-price').length) {
					$('#item-reg-price span').html('$' + price2);
				} 
																	
			});
	        
		});
		
	});
	
});


$(document).ready(function(){
	
	$('#tab-button-wrapper .tabs').unbind();
	
	$('#tab-button-wrapper .tabs').bind('click', function(event){
		
		$('#tab-button-wrapper .tabs').removeClass('active');
		$(this).addClass('active');
		$('.swap-tabs').hide();
		
		if ($(this).attr('id') == 'tab-button-1') {
			$('#tab-button-wrapper').css({'background-position': '0 0'});
			$('#tab-1').show();
		}
		
		if ($(this).attr('id') == 'tab-button-2') {
			$('#tab-button-wrapper').css({'background-position': '0 -26px'});
			$('#tab-2').show();
		}
		
		if ($(this).attr('id') == 'tab-button-3') {
			$('#tab-button-wrapper').css({'background-position': '0 -52px'});
			$('#tab-3').show();
		}
		
		if ($(this).attr('id') == 'tab-button-4') {
			$('#tab-button-wrapper').css({'background-position': '0 -78px'});
			$('#tab-4').show();
		}
		
		if ($(this).attr('id') == 'tab-button-5') {
			$('#tab-button-wrapper').css({'background-position': '0 -104px'});
			$('#tab-5').show();
		}
		
		if ($(this).attr('id') == 'tab-button-6') {
			$('#tab-button-wrapper').css({'background-position': '0 -130px'});
			$('#tab-6').show();
		}
		
	});
	
});
