var request_id = 0;
$(document).ready(function(){
    if($('#color').length > 0){
	
	$('#color').bind('change', function() {
	    if(switch_image){
		jQuery().get_image($('#color').val());
	    } else {
		var target_path = document.location.protocol + '//' + document.location.host + script_name + '/info/p' + product_id;
		document.location.replace(target_path + '/sub_color_id/' + $('#color').val());
	    }
	}); 
	if(switch_image){
		jQuery("select#color option[value='" + product_color + "']").attr("selected", "selected");
		jQuery('#color').trigger('change');
	} else 	{
		jQuery("select#color option[value='" + product_color + "']").attr("selected", "selected");
	}
	 
  }
});
jQuery.fn.get_image = function(color) { 
  request_id++;
  var data = 'color_id=' + color + '&product_id=' + product_id 
  
  this_request_id = request_id;
  jQuery.ajax({
    url: 'get_image_to_product.php',
    data: data,
    type: "GET",
    cache: false,
    success: function(answer) {
      if (this_request_id != request_id) {
        return;
      }
      
      answer = jQuery.parseJSON(answer);
      $('#flashcontent').html('<a href="' + answer.popup_path + answer.image + '" class="cloud-zoom" id="zoom1" rel="adjustX: 10, adjustY:-4, softFocus:true">' +
		    '<img width="343" height="402" src="' + answer.info_path + answer.image + '" alt="Produktfoto" title="' + answer.products_name + ' - ' + answer.manufacturers_name + '" />' +
		'</a>');
      $('.cloud-zoom, .cloud-zoom-gallery').CloudZoom();
    }
  });
}

//function fullPath() {
//  return document.location.protocol + '//' + document.location.host + Drupal.settings.basePath;
//}
//
//jQuery.fn.change_url = function(desired_url) {
//    var url = desired_url;
//    var hashUrl = url.replace(fullPath(), '');
//    //url_last = document.location.toString();
//    if(window.history && history.pushState ) {
//      history.pushState(null, null, url);
//    } else {
//      location.hash = hashUrl;
//    }
//};


