
$(function(){

	$("#proimg > img").error(function(){
		$(this).attr("src", website_url+"mod/laptopsvergelijken/nopicture2.gif");
	});

	if ($("#product_big_images_list").length) {

		$("#product_big_images_list").hide();
		$("#product_big_images_list").before("<a href=\"#\" id=\"big_images_link\"></a>");
		$("#big_images_link").html("<img src=\""+website_url+"/mod/laptopsvergelijken/action_icon.gif\" /> Meer afbeeldingen");
		
		
		$("#proimg a.product_big_images").fancybox({'titlePosition':'inside','padding':'30'});
		$("#proimg>img, #big_images_link").css({cursor:'pointer'}).click(function() {
			$("#proimg a.product_big_images:first").click();
			return false;
		});
	
	}
	
	$("#reviewformbuttons a.review").click(function(){
		
		$("#reviewformbuttons a.comment").removeClass('ui-state-hover2');
		$("#reviewform #reviewformintro").html('<b>Plaats een review</b><br />Geef uw mening! Waarom deze laptop? Wat bevalt u aan deze laptop? Wat valt u tegen?');
		$("#reviewform input[type=submit]").attr('value', 'Plaats review');
		$("#reviewprosandcons").show();
		
		$(this).toggleClass('ui-state-hover2');
		
		if ($("#reviewform input[name=comment_type]").val() == 'review') {
			$("#reviewform").toggle();
		} else {
			$("#reviewform").show();	
		}
		
		$("#reviewform input[name=comment_type]").val('review');
		
		return false;
	});
	
	$("#reviewformbuttons a.comment").click(function(){
		
		$("#reviewformbuttons a.review").removeClass('ui-state-hover2');
		$("#reviewform #reviewformintro").html('<b>Plaats een reactie</b>');
		$("#reviewform input[type=submit]").attr('value', 'Plaats reactie');
		$("#reviewprosandcons").hide();
		
		$(this).toggleClass('ui-state-hover2');
		
		if ($("#reviewform input[name=comment_type]").val() == 'comment') {
			$("#reviewform").toggle();
		} else {
			$("#reviewform").show();
		}
		
		$("#reviewform input[name=comment_type]").val('comment');
		
		return false;
	});
	
	if ($("#reviewformerrors").length) {
		
		if ($("#reviewform input[name=comment_type]").val() == 'review') {
			$("#reviewformbuttons a.review").trigger('click');
		} else if ($("#reviewform input[name=comment_type]").val() == 'comment') {
			$("#reviewformbuttons a.comment").trigger('click');
		}
		
	}
	
	$("#longdesc").each(function(){
		
		var newtxt, 
		    elm = $(this), 
		    elm_html = elm.html(),
			elm_txt = elm.text(),
		    elm_txt_length = (elm_txt+'').length;
				
		if (elm_txt_length > 400) {
			newtxt = elm_txt.substr(0,400);	
			newtxt = newtxt.replace(/\w+$/, '');
			newtxt = newtxt+'... <span class="exp" href="#">Lees verder... </span>';		
		} 
		
		elm.data('originalhtml',elm_html);
		elm.html(newtxt);
		elm.find('span.exp').css({cursor:'pointer', textDecoration:'underline'}).click(function(){
			var p = $(this).parent();
			p.html(p.data('originalhtml'));
		});
		
	});
	
});
	
