$(function(){
	//$(".tabs").tabs();

	$("#showGuides").click(function(){
		if ($(this).hasClass('show')) {
			$(".container, .g1, .g2, .g3, .g4, .g5, .g6, .g7, .g8, .g9, .g10, .g11, .g12, .p05 , .p10 , .p15 , .p20 , .p25 , .p30 , .p35 , .p40 , .p45 , .p50 , .p55 , .p60 , .p70 , .p75 , .p80 , .p85 , .p90 , .p95").removeClass('guide');
			$(this).removeClass('show');
		} else {

			$(".container, .g1, .g2, .g3, .g4, .g5, .g6, .g7, .g8, .g9, .g10, .g11, .g12, .p05 , .p10 , .p15 , .p20 , .p25 , .p30 , .p35 , .p40 , .p45 , .p50 , .p55 , .p60 , .p70 , .p75 , .p80 , .p85 , .p90 , .p95").addClass('guide');
			$(this).addClass('show');
		}
	});
/*
	// format numbers
	$('.formatPrice, .buyNow .current strong, .buyNow .value strong, .dealPriceInfo .value strong strong,  .dealPriceInfo .current strong strong').each(function(){
		var t = $(this);
		if(!isNaN(t.html())){
			var decimal = t.html().split(".");

			t.parent('.current').addClass("length_" + decimal[0].length);
			if (decimal[1]) {
				if (decimal[1] == '00') {t.html($().number_format(parseInt($(this).html())));} else if (decimal[1].substring(1,2) == '0') {t.html($().number_format($(this).html(),{numberOfDecimals:1}));
				}
			}
		}
	});
*/
	// substring text
	$('[class*="substring_"]').each(function(){
		var t = $(this);
		var c = t.attr('class').split(" ");
		for (var i in c) {
			if (c[i].indexOf("substring_") != -1) {
				var chars = parseInt(c[i].split("_")[1]);
				//alert(chars + " y tiene: " + );
				if (t.html().length > chars) {
					t.attr('title',t.html())
						.html(t.html().substring(0, chars) + "...");
				}
			}
		}
	});

	// toogle panels
	$('.toggle_trigger').click(function(e){
		e.preventDefault();
		var t = $(this);
		var tg_p = $(t.attr('href'));
		var txt = t.attr('rel').split("|");
		var wrap = t.parent();


		if (tg_p.is(':visible')){
			tg_p.slideUp("slow")
				.removeClass('toggle_opened');

			t.html(t.html().replace(txt[1],txt[0]));
		} else {
			wrap.find('.toggle_opened').slideUp("slow");
			tg_p.slideDown("slow")
				.addClass('toggle_opened')
				.removeClass('hidden');

			t.html(t.html().replace(txt[0],txt[1]));
		}
	});

	// show highlight
	$('.multiPic .showMore').each(function(e){
		substringContent(this,'.content', 400)
	});
	$('.onePic .showMore').each(function(e){
		substringContent(this,'.content', 180)
	});
	$('.showMore .showMoreLink').live('click',function(e){
		var trigger = "<a href='javascript:void(0)' class='showLessLink'>Minder informatie</a>";
		var par = $(this).parents('.showMore');

		par.find('.lessContent').hide();
		if ($('.showLessLink').size()==0) {par.find('.content').append(trigger);}
		par.find('.content').show()
	});
	$('.showMore .showLessLink').live('click',function(e){
		var par = $(this).parents('.showMore');

		par.find('.content').hide();
		par.find('.lessContent').show();
	});

	$('input').placeholder();

	

})

function substringContent(parent, contentWrap, chars){
	var t = $(parent).find(contentWrap);
	var trigger = "<a href='javascript:void(0)' class='showMoreLink'>Meer informatie</a>";

	if (t.html().length > chars) {
		t.hide().after("<div class='lessContent'>" + t.html().substring(0, chars) + "... " + trigger + "</div>");
	}
}
/*
function formatPrice() {
	$('.formatPrice').each(function(){
		var t = $(this);
		if(!isNaN(t.html())){
			var decimal = t.html().split(".");
			if (decimal[1]) {
				if (decimal[1] == '00') {t.html($().number_format(parseInt($(this).html())));} else if (decimal[1].substring(1,2) == '0') {t.html($().number_format($(this).html(),{numberOfDecimals:1}));
				}
			} else {t.html($().number_format($(this).html(),{numberOfDecimals:0}));
			}
		}
	});
}
*/

