$(document).ready(function() {	
	$('.to-basked').click(function() {
		colorId = $(':radio:checked[id^=color-]').attr('id').substr(6);
		window.location = $(this).attr('href') + '?product_color_id=' +  colorId;
		return false;
	});

	$('.preview-color').click(function() {		
		var radio = $(':radio[id^=color-]', this).get(0);
		$(radio).attr('checked', true);

		if($('img',this).attr('class') == 'disabled') return;

		img = $('img', this).attr('src').substr(6);
		oldSrc = $('#product').attr('src');
		newSrc = oldSrc.substr(0, oldSrc.lastIndexOf('/')) + img.substring(img.lastIndexOf('/'), img.length - 6) + '.jpg';
		$('#product').attr('src', newSrc);

		oldLink = $('#zoom').attr('href');
		link = oldLink.substr(0, oldSrc.lastIndexOf('/')) + img.substring(img.lastIndexOf('/'), img.length - 6) + '-full.jpg';
		$('#zoom,#zoom2').attr('href', link);

		$(':input', $(this)).attr('checked', true);

		// change color in tester link 
		var href = $('#test-glasses').attr("href");
		var hrefArr = href.split('-');
		var oldColor = hrefArr[ hrefArr.length - 1 ]; 
		var newColor = $(radio).val();
		var link = href.replace('-'+oldColor, '-'+newColor);
		$('#test-glasses').attr('href', link);

                if($(this).find('.colorInKioskIco').length) {
                        $('#article-preview-img .optiscontTrigger').css('display', 'block');
                } else {
                        $('#article-preview-img .optiscontTrigger').css('display', 'none');
                }
	});

});
