/**
 * Apex Bikes
 * User scripts
*/

// when the DOM is ready...
$(document).ready(function () {

  /* Set up product tabs */
	var tabs = $('.tabs a');
	if(tabs.length){
		$.tabs('.tabs a');
	}

	//bind the product dropdowns
	if(typeof(prod_original_price)!="undefined") {
	  $("#product_options div.option select").each(function(){
		  $(this).change(update_product_price);
	  });

	  update_product_price();
	}
	
	// Enable DropKick
  $('.fancy').dropkick({
    change: function (value, label) {update_product_price();
//      alert('You picked: ' + label + ':' + value);
    }
  });

  // Enable Fancybox on gallery items
  $("a[rel=gallery]").fancybox();  
  
  // Enable product reflection images
	$(".mainview .details figure img").reflect({
	  height: 0.20
	});
	$(".categoryview figure img").reflect({
	  height: 0.20
	});
	
	
  /* Simple dropdown menu */
/*    $("ol.dropdown li").hover(function(){
    
        $(this).addClass("hover");
        $('ul:first',this).css('visibility', 'visible');
    
    }, function(){
    
        $(this).removeClass("hover");
        $('ul:first',this).css('visibility', 'hidden');
    
    });
    
    $("ol.dropdown li ul li:has(ul)").find("a:first").append(" &raquo; ");
  */ 
});

var update_product_price = function(){
	//get the original price
	var original = parseFloat(prod_original_price).toFixed(2);

	//fetch every value from the dropdowns
	var values = [];
	values.push(original);
	$("#product_options div.option select").each(function(){
		var opt = this.options[this.selectedIndex];
		values.push(parseFloat($(opt).attr("rel")).toFixed(2));
	});

	var total = 0.0;
//	console.log(values);
	for(i=0;i<values.length;i++){
		if(values[i]!="NaN"){
			total+=parseFloat(values[i]);
		}
	}

	var t = total.toFixed(2).replace(".",",");

	//update visual
	var holder = $("#price_field");
	holder.html('&euro; ' + t);

	// Highlight price field
  doBGFade(holder,[245,255,159],[255,255,255],'transparent',75,20,4 );



};

