var temporaire = new Image();
var pardessus, montrerSuivant, montrerPrecedent, thumbnail, gaucheActuel, hautActuel, largeurActuel, hauteurActuel, nouveauGauche, nouveauHaut, nouveauLargeur, nouveauHauteur, largeurThumbnail, hauteurThumbnail, titrePresent = false, navigateurIE = navigator.userAgent.toLowerCase().indexOf('msie') > -1? true : false;
var bcj = {
	
	bcjOptions: {

		dureeOuverture: 0.45,          
		dureeRedimensionnement: 0.45,       
		dureeChangement: 0.50,         
		
		sequenceAnimation: 'synchro',       //synchro , largeurHauteur , hauteurLargeur
		animationOuverture: 'rapprochement',    //rapprochement , apparaitre      
		assouplssementOuverture: 'ease-in-out', //'none' , 'ease-in' , 'ease-out' , 'ease-in-out' , 'bounce'
		assouplissementRedimensionnement: 'ease-in-out',  //'none' , 'ease-in' , 'ease-out' , 'ease-in-out' , 'bounce'
		compteurImages: 'default',  //default , skip
		gallerieContinue: false, 
		espacementDeVue: 20         
	},
	peau: {
		
		background: '#FFF',                
		
		title: {
			
			background: '#444',            
			color: '#FFF',                 
			font: 'Verdana'                
			
		},
		
		pngs: {
			
			close: 'images/fermer.png',  
			next: 'images/suivante.png',  
			prev: 'images/precedente.png'   
			
		}
		
	},


	boite: null,
	

	closeBtn: null,
	
	nextBtn: null,
	
	prevBtn: null,
	
	image: null,
	
	title: null,
	
	preloader: [],
	
	gallery: [],
	
	courante: -1,	
	
	cache: [],	
	
	regex: {
		
		rel: /(boitecj)/i,
	
		gallery: /(?:boitecj)\[(.*?)\]/i
		
	},
	
	init: function() {

		if(bcj.bcjOptions.sequenceAnimation != 'hauteurLargeur' && bcj.bcjOptions.sequenceAnimation != 'largeurHauteur' && bcj.bcjOptions.sequenceAnimation != 'synchro') {
			bcj.bcjOptions.sequenceAnimation = 'synchro';
		}
		
		if(bcj.bcjOptions.assouplssementOuverture != 'none' && bcj.bcjOptions.assouplssementOuverture != 'ease-in' && bcj.bcjOptions.assouplssementOuverture != 'ease-out' && bcj.bcjOptions.assouplssementOuverture != 'ease-in-out' && bcj.bcjOptions.assouplssementOuverture != 'bounce') {
			bcj.bcjOptions.assouplssementOuverture = 'ease-in-out';
		}	
		
		if(bcj.bcjOptions.assouplissementRedimensionnement != 'none' && bcj.bcjOptions.assouplissementRedimensionnement != 'ease-in' && bcj.bcjOptions.assouplissementRedimensionnement != 'ease-out' && bcj.bcjOptions.assouplissementRedimensionnement != 'ease-in-out' && bcj.bcjOptions.assouplissementRedimensionnement != 'bounce') {
			bcj.bcjOptions.assouplissementRedimensionnement = 'ease-in-out';
		}
		
		if(bcj.bcjOptions.animationOuverture != 'apparaitre' && bcj.bcjOptions.animationOuverture != 'rapprochement') {
			bcj.bcjOptions.animationOuverture = 'rapprochement';
		}			
		
		bcj.bcjOptions.dureeOuverture = (bcj.bcjOptions.dureeOuverture > 0)? Math.ceil(50*bcj.bcjOptions.dureeOuverture) : 18;
		bcj.bcjOptions.dureeRedimensionnement = (bcj.bcjOptions.dureeRedimensionnement > 0)? Math.ceil(50*bcj.bcjOptions.dureeRedimensionnement) : 18;
		bcj.bcjOptions.dureeChangement = (bcj.bcjOptions.dureeChangement > 0)? Math.ceil(50*bcj.bcjOptions.dureeChangement) : 20;	
		
		var imgs = document.getElementsByTagName('img'), rel;
		for(var i=0; i<imgs.length; i++) {	
			
			rel = imgs[i].getAttribute('rel');
			if(bcj.regex.rel.test(rel) && imgs[i].getAttribute('src')) {
				
				bcj.preloader[i] = new Image();
				if(imgs[i].getAttribute('href'))
					bcj.preloader[i].src = imgs[i].getAttribute('href');
				else
					bcj.preloader[i].src = imgs[i].getAttribute('src');
				
				imgs[i].style.cursor = "pointer";
				imgs[i].onclick = function() { bcj.open( this, true ); return false; }
				imgs[i].xid = i;
				if(bcj.regex.gallery.test(rel)) imgs[i].gallery = rel.match(bcj.regex.gallery)[1];
				bcj.cache.push(imgs[i]);
				
			}
			
		}
		
	},
	
	populateGallery: function( img ) {
		var n = 0;
		if(!img.gallery) {
			bcj.gallery = [img];
			bcj.courante = 0;
		} else {
			bcj.gallery = [];			
			for(var i=0; i<bcj.cache.length; i++) {
				if(bcj.cache[i].gallery && bcj.cache[i].gallery == img.gallery) {
					bcj.gallery.push(bcj.cache[i]);
					if(bcj.cache[i] == img) bcj.courante = n;
					n++;
				}
			}
		}
	},
	
	toggleNavigation: function() {
		if(thumbnail.gallery) {
			if(bcj.bcjOptions.gallerieContinue) {
				montrerSuivant = true;
				montrerPrecedent = true;
			} else {
				montrerSuivant = (bcj.gallery[bcj.courante+1])? true : false;
				montrerPrecedent = (bcj.gallery[bcj.courante-1])? true : false;
			}
			bcj.nextBtn.style.display = (montrerSuivant)? 'block' : 'none';
			bcj.prevBtn.style.display = (montrerPrecedent)? 'block' : 'none';
			bcj.nextBtn.style.width = nouveauLargeur/3 + 'px';
			bcj.prevBtn.style.width = nouveauLargeur/3 + 'px';
		} else {
			montrerSuivant = false;
			montrerPrecedent = false;
			bcj.nextBtn.style.display = 'none';
			bcj.prevBtn.style.display = 'none';
		}
	},
	
	jumpto: function( index ) {
		if( bcj.gallery[index] && !bcj.animating() ) {
			bcj.courante = index;
			bcj.open(bcj.gallery[bcj.courante], false);
		}
	},
	
	next: function() {
		if(bcj.bcjOptions.gallerieContinue) {
			if(bcj.courante == bcj.gallery.length-1) {
				bcj.jumpto(0);
			} else {
				bcj.jumpto(bcj.courante+1);
			}
		} else {
			if(bcj.courante < bcj.gallery.length) {
				bcj.jumpto(bcj.courante+1);
			}
		}
	},
	
	previous: function() {
		if(bcj.bcjOptions.gallerieContinue) {
			if(bcj.courante == 0) {
				bcj.jumpto(bcj.gallery.length-1);
			} else {
				bcj.jumpto(bcj.courante-1);
			}
		} else {
			if(bcj.courante > 0) {
				bcj.jumpto(bcj.courante-1);
			}
		}
	},	
	
	ease: function( start, end, total, courante, easing, rnd ) {
		var delta = end - start,
		value = start;
		
		switch(easing) {
			case 'ease-in':
				value = delta * (courante /= total) * courante + start;
				break;
				
			case 'ease-out':
				value = -delta * (courante /= total) * (courante - 2) + start;
				break;
				
			case 'ease-in-out':
				if ((courante /= total / 2) < 1) {
					value = delta / 2 * courante * courante + start;
				} else {
					value = -delta / 2 * ((--courante) * (courante - 2) - 1) + start;
				}
				break;
				
			case 'bounce':
				if ((courante /= total) < (1 / 2.75)) {
					value = delta * (7.5625 * courante * courante) + start;
				} else if (courante < (2 / 2.75)) {
					value = delta * (7.5625 * (courante -= (1.5 / 2.75)) * courante + .75) + start;
				} else if (courante < (2.5 / 2.75)) {
					value = delta * (7.5625 * (courante -= (2.25 / 2.75)) * courante + .9375) + start;
				} else {
					value = delta * (7.5625 * (courante -= (2.625 / 2.75)) * courante + .984375) + start;
				}
				break;
				
			default:
				value = delta * courante / total + start;
				break;
		}
		
		if(rnd) value = value.toFixed(0);
		
		return value;
	},	
	
	animation: {
		
		fade: function( el, type, cb ) {
			var step = 0,
			from = (type == 'in')? 0 : 1,
			to = (type == 'in')? 1 : 0;
			setOpacity(el, from);
			el.style.visibility = "visible";
			el.fade = setInterval(function() {
				setOpacity(el, bcj.ease(from, to, bcj.bcjOptions.dureeChangement, step, 'ease-in-out'));
				step++;
				if(step > bcj.bcjOptions.dureeChangement) {
					clearInterval(el.fade);
					el.fade = null;
					if(type != 'in') el.style.visibility = 'hidden';
					if(cb) cb();
				}					
			},20);
		},
		
		slide: function( el, p, to, cb ) {
			if(p != 'top' && p != 'right' && p != 'bottom' && p != 'left') p = 'top';
			var step = 0,
			from = parseFloat(el.style[p]);
			el.slide = setInterval(function() {
				el.style[p] = bcj.ease(from, to, 15, step, 'ease-out') + 'px';
				step++;
				if(step > 15) {
					clearInterval(el.slide);
					el.slide = null;
					if(cb) cb();
				}					
			},20);
		},
		
		resize: function(left, top, width, height, sequence, steps, easing, cb) {
			
			var step = 0, timer, timerW, timerH;
			
			switch(sequence) {
				case 'hauteurLargeur':
					if(hauteurActuel == height) {
						adjustWidth(cb);
					} else if(largeurActuel == width) {
						adjustHeight(cb);
					} else {
					adjustHeight(function() {adjustWidth(cb);});
					}
				break;
				case 'largeurHauteur':
					if(largeurActuel == width) {
						adjustHeight(cb);
					} else if(hauteurActuel == height) {
						adjustWidth(cb);
					} else {
					adjustWidth(function() {adjustHeight(cb);});
					}
				break;
				default:
					adjustBoth(cb);
				break;
			}
			
			function adjustWidth(Ncb) {
				bcj.boite.resize = true;
				timerW = setInterval(function() {
					bcj.setDimensions(bcj.ease(gaucheActuel, left, steps, step, easing), null, bcj.ease(largeurActuel, width, steps, step, easing), null);
					step++;
					if(step > steps) {
						step = 0;
						clearInterval(timerW);
						bcj.boite.resize = null;
						if(Ncb) Ncb();
					}					
				},20);				
			}
			
			function adjustHeight(Ncb) {
				bcj.boite.resize = true;
				timerH = setInterval(function() {
					bcj.setDimensions(null, bcj.ease(hautActuel, top, steps, step, easing), null, bcj.ease(hauteurActuel, height, steps, step, easing));
					step++;
					if(step > steps) {
						step = 0;
						clearInterval(timerH);
						bcj.boite.resize = null;
						if(Ncb) Ncb();
					}					
				},20);
			}
			
			function adjustBoth(Ncb) {
				bcj.boite.resize = true;
				timer = setInterval(function() {
					bcj.setDimensions(bcj.ease(gaucheActuel, left, steps, step, easing), bcj.ease(hautActuel, top, steps, step, easing), bcj.ease(largeurActuel, width, steps, step, easing), bcj.ease(hauteurActuel, height, steps, step, easing));
					step++;
					if(step > steps) {
						step = 0;
						clearInterval(timer);
						bcj.boite.resize = null;
						if(Ncb) Ncb();
					}					
				},20);
			}
			
		}

	},
	
	animating: function() {
		var anim = true;
		if(($('boitecj') && !bcj.boite.resize && !bcj.boite.fade && !bcj.image.fade && !bcj.title.slide && !bcj.closeBtn.fade) || !$('boitecj')) { anim = false; }
		return anim;
	},
	
	setTitle: function( newTitle ) {
		
		titrePresent = (newTitle)? true : false;
		
		if(thumbnail.gallery)
		{
				var margin = (newTitle)? "5px" : "2px", text;
				text = (newTitle)? newTitle : "";
				text += "<div style='font-weight:normal; font-size:11px; margin-top:"+margin+";'>";
				if(bcj.bcjOptions.compteurImages == 'skip') {
					text += "Gallery: ";
					for(var i=0; i<bcj.gallery.length; i++) {
						if(i == bcj.courante) {
							text += "<span style='margin:0 2px; font-weight:bold;'>" + (i+1) + "</span><wbr>";
						} else {
							text += "<a href='javascript:void(0);' onclick='bcj.jumpto(" + i + ")' style='margin:0 2px; color:" + bcj.peau.title.color + ";'>" + (i+1) + "</a><wbr>";
						}
					}
				} else {
					text += "Image " + (bcj.courante+1) + " of " + bcj.gallery.length;
				}
				text += "</div>";
				bcj.title.innerHTML = text;
				titrePresent = true;
		}
		else if(newTitle) {
			bcj.title.innerHTML = newTitle;
		}		
		
	},	
	
	setDimensions: function( l, t, w, h ) {
		
		if(l) bcj.boite.style.left = l + 'px';
		if(t) bcj.boite.style.top = t + 'px';
		if(w) bcj.boite.style.width = w + 'px';
		if(h) bcj.boite.style.height = h + 'px';		
		
	},
	
	create: function() {
			
		bcj.boite = document.createElement("div");
			bcj.boite.setAttribute("id", "boitecj");
			bcj.boite.style.background = bcj.peau.background;
			//bcj.boite.setAttribute("style","position:relative");
			
		bcj.image = document.createElement("img");
			bcj.image.setAttribute("id", "boitecj-image");
			
			//bcj.image.setAttribute("oncontextmenu", "javascript:return false;");
			bcj.image.oncontextmenu = function(){return false;}
			//bcj.image.setAttribute("onmousedown", "javascript:return false;");
			bcj.image.onmousedown = function(){return false;}
			bcj.image.ondragstart = function(){return false;}
			bcj.image.onselectstart = function(){return false;}
			bcj.image.setAttribute("class","boitecj");
			
		bcj.title = document.createElement("div");
			bcj.title.setAttribute("id", "boitecj-title");
			bcj.title.style.background = bcj.peau.title.background + " url('images/ombre-s.png') repeat-x";
			bcj.title.style.color = bcj.peau.title.color;
			bcj.title.style.fontFamily = bcj.peau.title.font;
			bcj.title.style.display = 'none';
			
			
		bcj.closeBtn = document.createElement("div");
			bcj.closeBtn.setAttribute("id", "boitecj-close");
			bcj.closeBtn.style.background = "url('" + bcj.peau.pngs.close + "') no-repeat";
			bcj.closeBtn.style.visibility = "hidden";
			bcj.closeBtn.onclick = bcj.close;

		bcj.nextBtn = document.createElement("div");
			bcj.nextBtn.setAttribute("id", "boitecj-next");
			bcj.nextBtn.bgOn = "url('" + bcj.peau.pngs.next + "') no-repeat right center";
			bcj.nextBtn.bgOff = "url('" + bcj.peau.pngs.next + "') no-repeat -500px -500px";
			bcj.nextBtn.style.background = bcj.nextBtn.bgOff;
			bcj.nextBtn.style.display = 'none';
			bcj.nextBtn.onclick = bcj.next;
			bcj.nextBtn.onmouseover = function() { this.style.background = this.bgOn; }
			bcj.nextBtn.onmouseout = function() {this.style.background = this.bgOff; }

		bcj.prevBtn = document.createElement("div");
			bcj.prevBtn.setAttribute("id", "boitecj-prev");
			bcj.prevBtn.bgOn = "url('" + bcj.peau.pngs.prev + "') no-repeat left center";
			bcj.prevBtn.bgOff = "url('" + bcj.peau.pngs.prev + "') no-repeat -500px -500px";
			bcj.prevBtn.style.background = bcj.prevBtn.bgOff;
			bcj.prevBtn.style.display = 'none';
			bcj.prevBtn.onclick = bcj.previous;
			bcj.prevBtn.onmouseover = function() {this.style.background = this.bgOn; }
			bcj.prevBtn.onmouseout = function() {this.style.background = this.bgOff; }		
			
		document.body.appendChild( bcj.boite );
			bcj.boite.appendChild( bcj.image );
			
			
			bcj.boite.appendChild( bcj.title );
			bcj.boite.appendChild( bcj.closeBtn );
			bcj.boite.appendChild( bcj.nextBtn );
			bcj.boite.appendChild( bcj.prevBtn );
			
		var shdwDirs = new Array("n","e","s","w","nw","ne","se","sw");
		var shdw;
		for(var i=0; i<8; i++) {
			shdw = document.createElement("div");
			shdw.className = "ombre ombre-"+shdwDirs[i];
			bcj.boite.appendChild( shdw );
		}
	},
	
	open: function( img, resetGallery ) {

		if(!bcj.animating()) {
			
			if(!pardessus) {
			pardessus = document.createElement("div");
			pardessus.setAttribute('id', 'boitecj-pardessus');
			document.body.appendChild( pardessus );
			}
			
			if(resetGallery) bcj.populateGallery(img);		
			
			temporaire = bcj.preloader[img.xid];
			nouveauLargeur = temporaire.width;
			nouveauHauteur = temporaire.height;
			
			if(nouveauLargeur > page.width()-(bcj.bcjOptions.espacementDeVue*2) || nouveauHauteur > page.height()-(bcj.bcjOptions.espacementDeVue*2)) {
				newSize = resizeProportions(nouveauLargeur, nouveauHauteur, page.width()-(bcj.bcjOptions.espacementDeVue*2), page.height()-(bcj.bcjOptions.espacementDeVue*2));
				nouveauLargeur = newSize[0];
				nouveauHauteur = newSize[1];
			}
			
			var thumbPos = getElementPosition( img );
			largeurThumbnail = img.width;
			hauteurThumbnail = img.height;
			
			thumbnail = img;			

		}
		
		if(!$('boitecj')) {
			
			bcj.create();
			
			bcj.setDimensions(thumbPos[0], thumbPos[1], largeurThumbnail, hauteurThumbnail);
			
			bcj.image.setAttribute("src", temporaire.src);
			
			bcj.setTitle(thumbnail.title);
			
			bcj.title.style.width = nouveauLargeur - 12 + "px";
			
			gaucheActuel = parseFloat(bcj.boite.style.left);
			hautActuel = parseFloat(bcj.boite.style.top);
			largeurActuel = parseFloat(bcj.boite.style.width);
			hauteurActuel = parseFloat(bcj.boite.style.height);			
			nouveauGauche = Math.max(Math.ceil((page.width()/2) - (nouveauLargeur/2) + page.scrollX()), bcj.bcjOptions.espacementDeVue);
			nouveauHaut = Math.max(Math.ceil((page.height()/2) - (nouveauHauteur/2) + page.scrollY()), bcj.bcjOptions.espacementDeVue);
			
			afterOpen = function() {
				
				if(navigateurIE) {
					bcj.closeBtn.style.visibility = "visible";
				} else {
					bcj.animation.fade(bcj.closeBtn, 'in');
				}
				bcj.title.style.display = 'block';
				bcj.title.style.top = nouveauHauteur - bcj.title.offsetHeight + "px";
				bcj.title.style.display = 'none';
				bcj.toggleNavigation();
				if(titrePresent) {
					bcj.title.style.display = 'block';
					bcj.animation.slide(bcj.title, 'top', nouveauHauteur);
				}
				
			}
			
			if(bcj.bcjOptions.animationOuverture == 'rapprochement') {
				
				bcj.animation.resize(nouveauGauche, nouveauHaut, nouveauLargeur, nouveauHauteur, 'synchro', bcj.bcjOptions.dureeOuverture, bcj.bcjOptions.assouplssementOuverture, afterOpen);							
				
			} else if(bcj.bcjOptions.animationOuverture == 'apparaitre') {
				
				bcj.setDimensions(nouveauGauche, nouveauHaut, nouveauLargeur, nouveauHauteur);
				bcj.animation.fade(bcj.boite, 'in', afterOpen);
				
			}
			
		} else {
			
			if(!bcj.animating()) {
				
				changeImage = function() {

					if(navigateurIE) {
						bcj.closeBtn.style.visibility = "hidden";
					} else {
						bcj.animation.fade( bcj.closeBtn, 'out' );
					}
					bcj.animation.fade( bcj.image, 'out', function() { bcj.change(temporaire.src, img.title); } );
					bcj.title.style.display = 'none';					
				}
				
				if(titrePresent) {
					
					bcj.animation.slide(bcj.title, 'top', parseFloat(bcj.title.style.top) - bcj.title.offsetHeight, changeImage);
					
				} else {
					
					changeImage();
					
				}
				
				bcj.nextBtn.style.display = "none";
				bcj.prevBtn.style.display = "none";
				
			}
			
		}
		
	},
	
	change: function(newSrc, newTitle) {
		
		if(!bcj.animating()) {
		
			bcj.setTitle(newTitle);
		
			var titleFunc = null;
			if(titrePresent) {
				titleFunc = function() {
					bcj.title.style.display = 'block';
					bcj.title.style.top = nouveauHauteur - bcj.title.offsetHeight + 'px';
					bcj.animation.slide(bcj.title, 'top', parseFloat(bcj.title.style.top)+bcj.title.offsetHeight);
				}
			}
			
			function afterChange() {
				bcj.image.setAttribute('src', newSrc);
				bcj.title.style.width = nouveauLargeur - 12 + 'px';
				if(navigateurIE) {
					bcj.closeBtn.style.visibility = "visible";
				} else {
					bcj.animation.fade( bcj.closeBtn, 'in' );
				}
				bcj.animation.fade( bcj.image,  'in', function() { titleFunc(); bcj.toggleNavigation(); });
			}
			
			gaucheActuel = parseFloat(bcj.boite.style.left);
			hautActuel = parseFloat(bcj.boite.style.top);
			largeurActuel = parseFloat(bcj.boite.style.width);
			hauteurActuel = parseFloat(bcj.boite.style.height);
			nouveauGauche = Math.max(Math.ceil((page.width()/2) - (nouveauLargeur/2) + page.scrollX()), bcj.bcjOptions.espacementDeVue);
			nouveauHaut = Math.max(Math.ceil((page.height()/2) - (nouveauHauteur/2) + page.scrollY()), bcj.bcjOptions.espacementDeVue);
			
			bcj.animation.resize(nouveauGauche, nouveauHaut, nouveauLargeur, nouveauHauteur, bcj.bcjOptions.sequenceAnimation, bcj.bcjOptions.dureeRedimensionnement, bcj.bcjOptions.assouplissementRedimensionnement, afterChange);
		}
	},
	
	close: function() {
		
		function doClose() {
			bcj.boite.removeChild(bcj.title);
			if(bcj.bcjOptions.animationOuverture == 'rapprochement') {
				bcj.animation.resize(nouveauGauche, nouveauHaut, nouveauLargeur, nouveauHauteur, 'synchro', bcj.bcjOptions.dureeOuverture, bcj.bcjOptions.assouplssementOuverture, function() {document.body.removeChild( bcj.boite );});
			} else if(bcj.bcjOptions.animationOuverture == 'apparaitre') {
				bcj.animation.fade(bcj.boite, 'out', function() {document.body.removeChild( bcj.boite );});			
			}
		}
			
		if(!bcj.animating()) {
		
			bcj.boite.removeChild(bcj.closeBtn);
			bcj.boite.removeChild(bcj.nextBtn);
			bcj.boite.removeChild(bcj.prevBtn);
			var pos = getElementPosition( thumbnail );
			
			gaucheActuel = parseFloat(bcj.boite.style.left);
			hautActuel = parseFloat(bcj.boite.style.top);
			largeurActuel = parseFloat(bcj.boite.style.width);
			hauteurActuel = parseFloat(bcj.boite.style.height);			
			nouveauGauche = pos[0];
			nouveauHaut = pos[1];
			nouveauLargeur = thumbnail.width;
			nouveauHauteur = thumbnail.height;
			
			if(titrePresent)
				bcj.animation.slide(bcj.title, 'top', parseFloat(bcj.title.style.top)-bcj.title.offsetHeight, doClose);
			else
				doClose();
			
		}
		
	}
	
	

};
var page = {
	
	scrollX: function() {
		var pos = 0;
		if(window.pageXOffset) { pos = window.pageXOffset; }
		else if(document.body.scrollLeft) { pos = document.body.scrollLeft; }
		else if(document.documentElement && document.documentElement.scrollLeft){ pos = document.documentElement.scrollLeft; }
		return pos;
	},
	
	scrollY: function() {
		var pos = 0;
		if(window.pageYOffset) { pos = window.pageYOffset; }
		else if(document.body.scrollTop) { pos = document.body.scrollTop; }
		else if(document.documentElement && document.documentElement.scrollTop){ pos = document.documentElement.scrollTop; }
		return pos;
	},
	
	width: function() {
		pardessus.style.display = 'block';
		var width = pardessus.offsetWidth;
		pardessus.style.display = 'none';
		return width;
	},
	
	height: function() {
		var height;
		if( typeof( window.innerHeight ) == 'number' ) { height = window.innerHeight; }
		else if(document.documentElement && document.documentElement.clientHeight) { height = document.documentElement.clientHeight; }
		else {
		pardessus.style.display = 'block';
		height = pardessus.offsetHeight;
		pardessus.style.display = 'none';
		}
		return height;
	}

};

function resizeProportions( recWidth, recHeight, boundWidth, boundHeight ) {
	var tempWidth = recWidth, tempHeight = recHeight;
	if(recWidth/boundWidth >= recHeight/boundHeight) {
		recWidth = Math.floor(boundWidth);
		recHeight = Math.floor(recHeight * (recWidth / tempWidth));
	} else {
		recHeight = Math.floor(boundHeight);
		recWidth = Math.floor(recWidth * (recHeight / tempHeight));
	}
	return [recWidth, recHeight];
}

function $( id ) { return document.getElementById( id ); }

function setOpacity( el, op ) {
	el.style.opacity = op;
	el.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(Opacity=' + op*100 + ')';
}

function getOpacity( el ) { 
	var op = 1;
	if(el.style.opacity) { op = el.style.opacity; } 
	else 
	if(el.style.filter) { op = el.style.filter; }
	return parseFloat(op);
}

function getElementPosition( el ) {
	var left = 0;
	var top = 0;
	if(el.offsetParent) {
		left = el.offsetLeft;
		top = el.offsetTop;
		while(el = el.offsetParent) {
			left += el.offsetLeft;
			top += el.offsetTop;
		}
	}
	return [left, top];
}

function addLoadEvent( func ) {	
	var oldLoad = window.onload;
	if(typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldLoad();
			func();
		}
	}
}

addLoadEvent( bcj.init );
