﻿function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
};
var navigateur = {
	ie : document.all && navigator.appVersion.match("MSIE 7.0") ? true : false ,
	ie6 : document.all && !navigator.appVersion.match("MSIE 7.0") && window.ActiveXObject ? true : false ,
	moz : !document.all && document.getElementById ? true : false,
	firefox : !document.all && document.getElementById && navigator.userAgent.toLowerCase().match("gecko") ? true : false,
	mozmac : document.getElementById && navigator.userAgent.toLowerCase().indexOf('mac') + 1 && !navigator.userAgent.toLowerCase().indexOf('safari') + 1 ? true : false
};
var getPosition = {
	findPosX : function(obj) {
		    var curleft = 0;
		    if(obj.offsetParent)
		      	  while(1) {
		          	curleft += obj.offsetLeft;
		        	  if(!obj.offsetParent)
		            		break;
		          	obj = obj.offsetParent;
		        	}
		    else if(obj.x)
		       		 curleft += obj.x;
		    return curleft;
	},
	findPosY: function(obj){
		var curtop = 0;
		if(obj.offsetParent){
			while(1){
				curtop += obj.offsetTop;
				if(!obj.offsetParent) break;	
				obj = obj.offsetParent;
			}
		}else if(obj.y) curtop += obj.y;	
		return curtop;
	}
};
function popImage(chemin,nom,param){
	popupImage = window.open('',nom,param)
	html = '<HTML><HEAD><BODY LEFTMARGIN=0 MARGINWIDTH=0 TOPMARGIN=0 MARGINHEIGHT=0><IMG SRC="'+chemin+'" BORDER=0></BODY></HEAD></HTML>';
	popupImage.document.open();
	popupImage.document.write(html);
	popupImage.document.close();
};
function pop_(chemin,nom,param,el,type){ 

	var img = document.getElementById(el);
	var margin = img.style.margin;
	if(!document.all) var flt = img.style.cssFloat;
	if(document.all) var flt = img.style.styleFloat;

	var file = img.src;
	var legend = img.alt;
	var x = getPosition.findPosX(img);
 	var y = getPosition.findPosY(img);
	var w = img.offsetWidth;
	var h = img.offsetHeight;
	var newCadre = document.createElement('div');
	newCadre.style.backgroundColor = "#333";
	newCadre.style.padding = "5px";
	newCadre.style.position = "absolute";
	if(flt && flt == "left" && !type){
		newCadre.style.left = x+"px";
		newCadre.style.top = y+"px";
	}
	if(flt && flt == "right" && !type){
		newCadre.style.left = (x+w)-9+"px";
		newCadre.style.top = y+"px";
	}
	newCadre.style.zIndex = "50";
	newCadre.id = "bloc"+el;
	var newBloc = document.createElement('div');
	newBloc.id = "img"+el;
	newBloc.style.border = "solid 1px #000";
	newCadre.onclick = function(){ this.parentNode.removeChild(this);}
	newCadre.appendChild(newBloc);
	if(!type){  document.body.appendChild(newCadre); }else{ if(document.all){ newCadre.style.marginLeft = "-"+w-10+"px"; } img.parentNode.insertBefore(newCadre,img); }
	present.setMove(document.getElementById(newCadre.id),img,w,h,file,flt,chemin,nom,param,legend);
};

var present = {
	setMove : function(el,img,w,h,file,pos,chemin,nom,param,legend){
		this.el = el;
		this.img = img;
		this.w = 0;
		this.h = 0;
		this.file = file;
		this.pos = pos;
		this.chemin = chemin;
		this.nom = nom;
		this.param = param;
		this.legend = legend;
		
		this.k = w*2.2;
		this.p = this.k;		
		this.j = h*2.2;
		this.c = this.j;
		this.ratio = 30;
		
		this.pos1 = getPosition.findPosX(this.el);
		this.pos1b = this.k;
		this.pos2 = this.pos1-this.k;
		
		this.go = setInterval("present.move()",5);
	},
	move : function(){

		this.el.style.width = this.w+"px";
		this.el.style.height = this.h+"px";

		if(this.w >= this.k){
			clearInterval(this.go);
			this.el.style.opacity = "";
			this.el.style.backgroundColor = "#000";
			
			var leg = document.createElement('div');
			if(window.ActiveXObject) leg.style.setAttribute("cssText","position:absolute; top:0; color:#fff; background-color: #000; font-size: 90%; width: 180px; padding: 10px; cursor:pointer;left:"+(this.k+35)+"px;");
			if(window.XMLHttpRequest) leg.setAttribute("style","position:absolute; top:0; color:#fff; background-color: #333; border: solid 1px #000; font-size: 90%; width: 180px; padding: 10px;cursor:pointer;left:"+(this.k+35)+"px;");
			leg.innerHTML = this.legend;
			
			var plus = document.createElement('div');
			if(window.ActiveXObject) plus.style.setAttribute("cssText","position:absolute;top:0;color:#fff;cursor:pointer;left:"+(this.k+5)+"px;");
			if(window.XMLHttpRequest) plus.setAttribute("style","position:absolute; top:0; color:#fff; cursor:pointer;left:"+(this.k+5)+"px;");
			plus.innerHTML = "<img src='__image/zoom.png' title='Voir en taille réelle' alt='bouton aggrandissement' />";
			
			_file = this.file.replace("mini_","");
			_nom = this.nom;
			_param = this.param;
			plus.onclick = function(e){ 
				if (!e) var e = window.event;
				e.cancelBubble = true;
				if (e.stopPropagation) 
				e.stopPropagation();
				popImage(_file,_nom,_param);
			}
			var nImg = document.createElement('img');
			nImg.src = this.file.replace("mini_","");
			nImg.style.width = this.k+"px";
			nImg.style.height = this.j+"px";
			nImg.style.marginTop = "-2px";
			this.el.appendChild(nImg);
			this.el.appendChild(plus);
			if(this.legend!="") this.el.appendChild(leg);
		}
		
		this.w = Math.ceil(this.ratio*this.p/100);
		this.p = this.p-this.w;
		this.w = Math.ceil(this.k-this.p);
		
		this.h = Math.ceil(this.ratio*this.c/100);
		this.c = this.c-this.h;
		this.h = Math.ceil(this.j-this.c);
		
		if(this.pos=="right"){					
			this.pos1 = Math.ceil(28*this.pos1b/100);
			this.pos1b = this.pos1b-this.pos1;
			this.pos1 = Math.ceil(this.pos2+this.pos1b);		
			this.el.style.left = this.pos1+"px";			
		}
	}
};

function popVideo(chemin,nom,param,w,h){
	popupImage = window.open('',nom,param)
	html = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'+
		'<HTML>'+
			'<HEAD><title></title></HEAD>'+
			'<BODY LEFTMARGIN=0 MARGINWIDTH=0 TOPMARGIN=0 MARGINHEIGHT=0>'+
				'<object height="'+h+'" width="'+w+'"><embed flashvars="file='+chemin+'" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" src="flvplayer.swf" height="'+h+'" width="'+w+'"></object>'+
			'</BODY>'+
		'</HTML>';
	popupImage.document.open();
	popupImage.document.write(html);
	popupImage.document.close();
};

function print(bloc){
	var contenu = document.getElementById(bloc).innerHTML;
	popimprime = window.open('','','resizable=yes, location=no, width=500, height=500, menubar=no, status=no, scrollbars=yes');
	html = '<html><head><link rel="stylesheet" type="text/css" href="_css_/print.css"/></head><body><div id="printZone">'+contenu+'</div></body></html>';
	code = "<script type=\"text/javascript\">setTimeout(\"window.print()\",200)</script>";
	popimprime.document.open();
	popimprime.document.write(html+code);
	popimprime.document.close();
};

function increaseText(bloc){
	var bloc = document.getElementById(bloc);
	var perc = parseInt(bloc.style.fontSize.substr(0,bloc.style.fontSize.length-1));
	bloc.style.fontSize = perc+10+"%";
};

function decreaseText(bloc){
	var bloc = document.getElementById(bloc);
	var perc = parseInt(bloc.style.fontSize.substr(0,bloc.style.fontSize.length-1));
	bloc.style.fontSize = perc-10+"%";
};

function placeMovs(id){
	var mov = document.getElementById(id).getElementsByTagName('div');
	var so;
	for(i=0; i<mov.length; i++){
		if(mov[i].className == "video"){
			mov[i].removeChild(mov[i].firstChild);
			so = new SWFObject("flvplayer.swf", "movie", "440", "330", "7", "#336699");
			so.addVariable("file",mov[i].id.replace(/-/gi,"/"));
			so.addParam('allowscriptaccess','true');
			so.addVariable('displayheight','330');
			so.addVariable('height','330');
			so.addVariable('width','440');
			so.addParam("wmode", "transparent");
			so.write(mov[i]);
		}
		else if(mov[i].className == "son"){
			mov[i].removeChild(mov[i].firstChild);
			so = new SWFObject("flvplayer.swf", "movie", "320", "100", "7", "#ffffff");
			so.addParam("wmode", "transparent");
			so.addVariable("file",mov[i].id.replace(/-/gi,"/"));
			so.addVariable('screencolor','0xFFFFFF');
			so.addVariable('lightcolor','0xFFFFFF');
			so.addParam('allowfullscreen','true');
			so.addParam('allowscriptaccess','true');
			so.addVariable('height','100');
			so.addVariable('width','320');
			so.write(mov[i]);
		}
	}
};

function setLinks(bloc){
	var a = document.getElementById(bloc).getElementsByTagName('a');
	var m = new RegExp("[http://www.chateaudeboudry.ch]");
	for(i=0; i<a.length; i++){
		if(!a[i].href.match("http://")){
			//a[i].setAttribute("target","_blank");
		}
	}	
};
var imprimer = {
	fenetre : function(title,file,data,css){
		popupImage = window.open('','','width=800,height=400,scrollbars=no')
		html = '<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">'+
			'<html>'+
				'<head><title>'+title+'</title><link rel="stylesheet" type="text/css" href="'+css+'" />'+
				'<style>'+
				'html,body{overflow: auto}'+
				'body{background-image: none;}'+
				'</style>'+
				'</head>'+
				'<body>'+
				'<div style="background-color:#FFB340; font-size: 130%; padding: 5px;">'+
				'<input type="button" value="Imprimer" onclick="window.print()" style="float:right;" />'+
				'www.chateaudeboudry.ch / '+title+'</div>'+
				'<div id="zoneImpression" style="padding: 10px;">'+data+'</div></body>'+
			'</html>';
		popupImage.document.open();
		popupImage.document.write(html);
		popupImage.document.close();
	}
};
var pdf = {
	create : function(file,data,element){
		data = data.replace(/\n/gi,"")
		var popupImage = window.open(file,'pdfpopup','width=800,height=500,scrollbars=no')
		
		var pdfForm = document.createElement('form');
		var pdfInput = document.createElement('input');
		
		pdfForm.id = "pdfForm";
		pdfForm.name = "pdfForm";
		pdfForm.method = "post";
		pdfForm.action = file;
		pdfForm.style.display = "none";
		pdfForm.target = "pdfpopup";
		
		pdfInput.type = "text";
		pdfInput.name = "data";
		pdfInput.value = data;
		
		pdfForm.appendChild(pdfInput);
		document.getElementById(element).appendChild(pdfForm);
		document.getElementById('pdfForm').submit();
		document.getElementById(element).removeChild(document.getElementById('pdfForm'));
	}	
};

function preloadImage(){

}