$(document).ready(
	function () {
	
		$('a.viewCaravanRes').bind('click',function()
			{
				$('#contentBox3').css({visibility:'visible'}).DropInUp(300);
			}
		);
		$('#contentBox3').Draggable(
			{	
				handle:		'div.contentHeader',
				ghosting:	true,
				opacity:	0.5,
				fx:			400,
				zIndex:		1
			}
		);
	
	
		zelongueur = $("div").filter("[@id^=box]");
		zelongueurok = (zelongueur.length)-1;
		function openAllBoxes(indice) {
			$('#box'+indice).css({display: "block"}).hide().fadeIn(500,function(){
			if (indice < zelongueurok) {
				openAllBoxes(++indice);
			}else{
				setTimeout("$('#newsBox1').css({visibility: \"visible\"}).hide().DropInUp(2000);", 1000 );
				setTimeout("$('#newsBox2').css({visibility: \"visible\"}).hide().DropInUp(2000);", 2000 );
			}
			});
		}
		openAllBoxes(1);
		$('#boxContainer').Sortable(
			{
				accept : 		'boxTips',
				helperclass : 	'sorthelper',
				activeclass : 	'sortableactive',
				hoverclass : 	'sortablehover',
				opacity: 		0.5,
				revert:			true,
				floats:			true,
				tolerance:		'pointer'
			}
		)
		$('a.minimize').bind('click', toggleContent);
		$('div.popup').hide();
		$('a.closePopup').bind('click',function()
			{
				$(this.parentNode).hide();
			}
		);
		$('a.close').bind('click',function()
				{
					$(this.parentNode.parentNode.parentNode).hide();
				}
			);
		$('div.meerTipsBox').Draggable(
			{
				ghosting:	true,
				opacity:	0.5,
				fx:			400,
				zIndex:		1
			}
		);	
		$('div.popup').Draggable(
			{
				ghosting:	true,
				opacity:	0.5,
				fx:			400,
				zIndex:		1
			}
		);
	}
);
var toggleContent = function(e) {
	var targetContent = $('div.xtraContent', this.parentNode.parentNode.parentNode);
	if (targetContent.css('display') == 'none') {
		targetContent.slideDown(300);
	}else{
		targetContent.slideUp(300);
	}
	return false;
};
$("a").filter("[@class^=viewPage]").click(function() {	
	$('div.popup').hide();	
	var monId=$(this).attr("class");
	var Longueur = monId.length;
	var monId2 = monId.substring(8, Longueur)
	$('#popUp'+monId2+'').show().css({ position: "absolute", top: "120px", left: "405px" });
	$('#popUp'+monId2+'').DropInUp(300);
	return false;
});
$("a").filter("[@class^=addBox]").click(function() {
	var detectClicPositionX = findPosX(this.parentNode.parentNode)-150;
	var detectClicPositionY = findPosY(this.parentNode.parentNode)-50;
	var monId=$(this).attr("class");
	var Longueur = monId.length;
	var monId2 = monId.substring(6, Longueur)
	$('#meerTipsBox'+monId2+'').show().css({ position: "absolute", display: "block", top: detectClicPositionY+"px", left: detectClicPositionX+"px" });
	$('#meerTipsBox'+monId2+' div.xtraContent').css({display: "block"});
	$('#meerTipsBox'+monId2+'').DropInUp(300);
	return false;
});
