jQuery(document).ready(function($) {
	var images = new Array();
	$('.product_description img').not(".soldout").each(function(index) {
		images[index] = $(this).attr('src').replace('thumbnail', 'info');
	});

	var options = new Array();
	$('#product_options option').each(function(index) {
		options[$(this).text()] = index;
	});
	var models = new Array();
	models = $('#models').val().split('|');

	var full_price = new Array();
	full_price = $('#full_price').val().split('|');
	
	if(parseFloat(window.location.hash.replace('#', '')) >= 0) {
		var imagenummer = parseFloat(window.location.hash.replace('#', ''))+1;
	
		$('#product_image a').attr('href', images[imagenummer].replace('info', 'popup'));
	
		$("#product_image img").not(".soldout").unreflect().attr('src', images[imagenummer])
			.load(function(){
				$(this).reflect({height:0.2});
			});

		$('#price').text(full_price[imagenummer]);

		$('#p_model').text(models[imagenummer]);
			
		$('#product_options option').each(function(index) {
			if(index == imagenummer)
				$(this).attr('selected', 'selected');
	
		});

		var imgtest = images[(options[$("select option:selected").text()])];
		var lower = imgtest.substr(-5).replace('.jpg', '');
		var higher = parseFloat(lower)+1;
		higher = images[(options[$("select option:selected").text()])].replace(lower+'.jpg', higher+'.jpg');

		if($("#product_image_nacht")) {
			$("#product_image_nacht img").not(".soldout").unreflect().attr('src', higher)
				.load(function(){
					$(this).reflect({height:0.2});
				});
		}
		
		
	}

	$('.changecolor').click(function() {

		var imagenummer = $(".changecolor").index(this);	

	
		$('#product_image a').attr('href', images[imagenummer].replace('info', 'popup'));
	
		$("#product_image img").not(".soldout").unreflect().attr('src', images[imagenummer])
			.load(function(){
				$(this).reflect({height:0.2});
			});
				
		$('#p_model').text(models[imagenummer]);
		$('#price').text(full_price[imagenummer]);
			
		$('#product_options option').each(function(index) {
			if(index == imagenummer)
				$(this).attr('selected', 'selected');
	
		});

		var imgtest = images[(options[$("select option:selected").text()])];
		var lower = imgtest.substr(-5).replace('.jpg', '');
		var higher = parseFloat(lower)+1;
		higher = images[(options[$("select option:selected").text()])].replace(lower+'.jpg', higher+'.jpg');

		if($("#product_image_nacht")) {
			$("#product_image_nacht img").not(".soldout").unreflect().attr('src', higher)
				.load(function(){
					$(this).reflect({height:0.2});
				});
		}


	});

	$('select').change(function(){
	
		$('#product_image a').attr('href', images[(options[$("select option:selected").text()])].replace('info', 'popup'));
		var imgtest = images[(options[$("select option:selected").text()])];
		var lower = imgtest.substr(-5).replace('.jpg', '');
		var higher = parseFloat(lower)+1;
		higher = images[(options[$("select option:selected").text()])].replace(lower+'.jpg', higher+'.jpg');

		if($("#product_image_nacht")) {
			$("#product_image_nacht img").not(".soldout").unreflect().attr('src', higher)
				.load(function(){
					$(this).reflect({height:0.2});
				});
		}

		$("#product_image img").not(".soldout").unreflect().attr('src', images[(options[$("select option:selected").text()])])
			.load(function(){
				$(this).reflect({height:0.2});
			});
			
		$('#p_model').text(models[(options[$("select option:selected").text()])]);
		$('#price').text(full_price[(options[$("select option:selected").text()])]);
	});
	

});

