/* Copyright (c) 2009 Michael Manning (actingthemaggot.com) Dual licensed under the MIT (MIT-LICENSE.txt) and GPL (GPL-LICENSE.txt) licenses.*/
(function(A){A.fn.extend({currency:function(B){var C={s:",",d:".",c:2};C=A.extend({},C,B);return this.each(function(){var D=(C.n||A(this).text());D=(typeof D==="number")?D:((/\./.test(D))?parseFloat(D):parseInt(D)),s=D<0?"-":"",i=parseInt(D=Math.abs(+D||0).toFixed(C.c))+"",j=(j=i.length)>3?j%3:0;A(this).text(s+(j?i.substr(0,j)+C.s:"")+i.substr(j).replace(/(\d{3})(?=\d)/g,"$1"+C.s)+(C.c?C.d+Math.abs(D-i).toFixed(C.c).slice(2):""));return this})}})})(jQuery);jQuery.currency=function(){var A=jQuery("<span>").text(arguments[0]).currency(arguments[1]);return A.text()};

/* Pagescripts */
$(document).ready(function(){
	$('ul.active_menu li').hover(function() {
		$(this).addClass('active_sub_menu');
	}, function () {
		$(this).removeClass('active_sub_menu');
	});
});


$.fn.setContainerHeight = function() {
	return this.each(function(i, container) {
		var innerHeight = $(container).find('div:first').height() + 27;
		$(container).css('height', innerHeight);
		$(container).css('overflow', 'visible');
	});
}

$(function() {
	$('.contact_block_tabs').tabs();	
});


jQuery().ready(function(){
	// simple accordion
	/* jQuery('.plus_minus_list').accordion();*/
	jQuery('.plus_minus_list').accordion({
		autoheight: true
		/* animated: 'easeslide'*/
	});
});



$(document).ready(function() {

	$(".text_image_list").click(function() {
		window.location = $(this).find("li:first a:first").attr("href");
	});
	$(".text_image_list li").hover(
			function() {
				$(this).addClass("hover");
			},
			function() {
				$(this).removeClass("hover");
			}
	);
	$("#sidebar .text_images").click(function() {
		window.location = $(this).find(".content:first a:first").attr("href");
	});
	$("#sidebar .text_images .content").hover(
			function() {
				$(this).addClass("hover");
			},
			function() {
				$(this).removeClass("hover");
			}
	);
});



var closedLi=false;
$(document).ready(function () {
	/*$('LI.drawer .drawer-content').hide();*/
	$('H2.drawer-handle').click(function(){
		if(closedLi){
			$(this).next().show();
			$(this).addClass('open');
			closedLi=false;
		}else{
			$('LI.drawer .drawer-content:visible').hide();
			$('H2.open').removeClass('open');
			closedLi=true;
		}
	});
});




//For page: Step 1 - detail button
$(document).ready(function(){
	$(".content_table .details").parent().next().next('.full').hide();
	
    $(".content_table .details").click(function(){
        var button = $('.content_table .details');
        if( $(this).hasClass('open') ) {
            $(this).removeClass('open');
            $(this).addClass('closed');
            $(this).parent().next().next('.full').slideToggle();
        }
        else {
            $(this).removeClass('closed');
            $(this).addClass('open');
            $(this).parent().next().next('.full').slideToggle();
        }
        return false;
    });
});

// Hover image on training detail page
$(document).ready(function () {
	$(".file_list ul li img").hover(
		function() {
			$("#trainingDefaultImage").css("visibility","hidden");		
			$("#trainingDefaultImage").css("display","none");
			$("#"+$(this).attr("id")+"Large").css("visibility","visible");		
			$("#"+$(this).attr("id")+"Large").css("display","block");
		},
		function() {
			$("#"+$(this).attr("id")+"Large").css("visibility","hidden");		
			$("#"+$(this).attr("id")+"Large").css("display","none");
			$("#trainingDefaultImage").css("visibility","visible");		
			$("#trainingDefaultImage").css("display","block");
			
		}
	);
});

/*
 * blockItems
 */
(function($) {
	$.fn.resizeContainedBlockItems = function() {
		return this.each(function(i, blockContainer) {
			var contentContainers = $(blockContainer).find("div.blockItem");
			//contentContainers = contentContainers.find("div.content");
			var maxHeight = null;
			
			contentContainers.each(function(i ,contentContainer) {
				var height = $(contentContainer).height();
				
				if (height > maxHeight) {
					maxHeight = height;
				}
			});
			
			contentContainers.each(function(i, contentContainer) {
				$(contentContainer).height(maxHeight);
			});
		});
	};
	
	$.fn.fixContainedBlockItems = function() {
		return this.each(function(i, linkContainer) {
			var linkContainer = $(linkContainer);
			var originalContent = $.trim(linkContainer.html());
			var imgSrc = "../images/blok_driehoekje_rood.gif";
			var isGrey = linkContainer.parent("div.blockItem").hasClass("grey");
			
			if (!isGrey) {
				imgSrc = "../images/blok_driehoekje_wit.gif";
			}
			
			linkContainer.html('<span><img src="' + imgSrc + '" /></span>' + originalContent);
		});
	};
})(jQuery);

$(document).ready(function() {
	//if ($.browser.msie && $.browser.version < 8) {
	//	$("div.blockContainer div.link").fixContainedBlockItems();
	//}

	//$("div.blockContainer:not([class~='no-resize'])").resizeContainedBlockItems();
	//if ($.browser.msie && $.browser.version < 8) {
	//	$("div.container div.link").fixContainedBlockItems();
	//}

	$("div.mainContainer:not([class~='no-resize'])").resizeContainedBlockItems();	
});

function loadTraining() {
	var trcPrm = $.cookie('SN_FORM_TRAINING_trc');
	var tricPrm = $.cookie('SN_FORM_TRAINING_tric');
	if (trcPrm != '' && tricPrm != '') {
		var location = window.location.href;
		if (location.indexOf('?') > 0) location += '&trc=' + trcPrm;					
		else location += '?trc=' + trcPrm;
		location += '&tric=' + tricPrm;
		window.location.href = location;
	}		
}
function saveTraining(trc, tric) {
	$.cookie('SN_FORM_TRAINING_trc', trc, { expires: 1 });
	$.cookie('SN_FORM_TRAINING_tric', tric, { expires: 1 });
}

