﻿document.documentElement.className +=" hasJS";


/*******
* Tabs
 *******/
var tabs = {
	init : function(elm) {
		elm = $(elm);
		if (!elm) return;
		var ul = elm.getElement('ul.tabs')
		if (!ul) return;
		$(ul).getElements("a").each(function(a) {
			if (!a.className.match(/nochange/))  {
				$(a.parentNode).addEvent('mouseover', function() {
					if (ul.current) ul.current.removeClass('current');
				});
				a.parentNode.onclick = function() {
					a.blur();
					tabs.change(this);
					ul.current = $(this);
				};
				a.onclick = function() {
					return false;
				};
				if (document.all && /MSIE [567]/.test(navigator.userAgent)) {
					a.onmouseenter = function() {this.className+=' hover';};
					a.onmouseleave = function() {this.className = this.className.replace(/\bhover\b/g,'');};
				}
			}
		})
		ul.addEvent('mouseenter', function() {
			if (!this.current) this.current = this.getElement('li.current');
			if(this.current) this.current.removeClass('current');
		});
		ul.addEvent('mouseleave', function() {
			if (this.current) this.current.addClass('current');
		});
	},
	
	change : function(elm) {
		var i, n, current=0,
		li = elm;
		var ul = li.parentNode;
		var tabs = ul.getElementsByTagName("li");
		var div = ul;
		while(!div.className.match(/blockTabs/i)) {
			div = div.parentNode;
		};
		for (i=0; i<tabs.length; i++) { // get the index of the new Tab and remove otherClass "current"
			if (tabs[i]==li) {
				current = i;
				$(li).addClass("current");
			} else
				$(tabs[i]).removeClass("current");
		}
		$(div).getElements(".body div.tabCtn").each(function(tabCtn, i) {
			$(tabCtn).removeClass("tabCurrent");
			$(tabCtn).getElements('.blockToggle').each(function(block) {
				block.closed = true;
				block.addClass('toggleClosed');
				block.content.style.height = 0;
			});
			if (i==current) {
				$(tabCtn).addClass("tabCurrent");
			}
		});
	}
}


/* ToggleBlock :  block qui s'ouvre et qui se ferme */
var toggleBlock = {
	init : function(elm) {
		elm = $(elm);
		var head =   elm.getElement('.head');
		if (head) {
			var a =  head.getElement('a');
			a.blockToggle = elm;
			if (a) {
				a.onclick = function() {
					toggleBlock.toggle(this);
					return false;
				}
				if (document.all && /MSIE [567]/.test(navigator.userAgent)) {
					a.onmouseenter = function() {this.className+=' hover';};
					a.onmouseleave = function() {this.className = this.className.replace(/\bhover\b/g,'');};
				}
			}
		}
		elm.body = $(elm).getElement('div.body');
		elm.content = new Element('div').setStyles({
			overflow:'hidden'
		}).injectBefore(elm.body);
		elm.body.injectInside(elm.content);
		if (elm.hasClass('toggleClosed')) {
			elm.closed = true;
			elm.content.style.height = 0;
		} else {
			elm.closed = false;
		}
	},
	// ajout les fonctionnalites du open/close (toggle);
	toggle : function(elm) {
		var scrollTop = document.body.scrollTop;
		var block = $(elm.blockToggle);
		
		if (block.closed) {
			block.removeClass('toggleClosed');
			new Fx.Tween(block.content, {
			}).start('height', block.content.scrollHeight);
		} else {
			new Fx.Tween(block.content, {
				onComplete : function() {
					block.addClass('toggleClosed');
				}
			}).start('height',0);
		}
		block.closed = !block.closed;
		
		document.body.scrollTop = scrollTop;
	}
	
 };

function gotoTabToggle(elm) {
	var hash = elm.href.substring(elm.href.indexOf('#')+1,elm.href.length).split('_');
	// execute tab click
	$(hash[0]).onclick();
	//execute toggle click
	$(hash[1]).getElement('.head a').onclick();
	document.location.hash = hash[1];
}
 
 

window.addEvent('load', function() {
	tabs.init('gemTabs');
	$$('div.blockToggle').each(function(block) {
	    toggleBlock.init(block)
	})
})





/**** columns resize ****/


/* FW.colResize */

var colResize = {
	colsId : ['nav_left_container', 'content_3_3'],
	colsIdInside : [], // tableau contenant les id des elements a l'interieur des colonnes si ceux-ci existent
	colsContainer : 'container_telecommunication',
	timer : 20, // temps entre deux verifications de hauteur
	heightStyle : document.all && /MSIE [56]/.test(navigator.userAgent) ? 'height' : 'minHeight',
	cols : [], //colonnes existantes dans la page
	colsInside : [], //elements a l'interieur des colonnes
	lastHeights : [], //derniere hauteur du conteneur central qui a été enregistree, cela permet de gagner du temps dans la verification de la modification de la hauteur
	init : function() {
		var self = this;
		this.colsContainer = document.getElementById(this.colsContainer); 
		if (!this.colsContainer) return;
		this.colsId.each(function(colId, i) {
			self.cols.push(colId!=null ? document.getElementById(colId) : null);
			self.colsInside.push(self.colsIdInside[i] ? document.getElementById(self.colsIdInside[i]) : null);
		});
		this.checker();		
		var timer = setInterval(function() {self.checker()},this.timer); 
	},
	checker : function() {
		if(this.resizing) return;
		var colsHeight = this.cols.map(function(col) {
			return col ? col.offsetHeight : 0;
		});
		if (this.lastHeights.join('')!=colsHeight.join('')) {
			this.resize();
			this.lastHeights=this.cols.map(function(col) {
				return col ? col.offsetHeight : 0;
			});
		}
	},
	resize : function() {
		this.resizing = true;
		var self = this;
		this.cols.each(function(col, idx) {
			if (col) {
				var elm = self.colsInside[idx] || col;
				elm.style.paddingBottom = '';
			}
		});
		var containerHeight = self.colsContainer.scrollHeight;
		this.cols.each(function(col, idx) {
			if (col) {
				var elm = self.colsInside[idx] || col;
				//
				if (col.offsetHeight!=containerHeight) {
					//elm.style[self.heightStyle] = elm.offsetHeight + containerHeight-col.offsetHeight - ( parseInt($(elm).getStyle('padding-bottom')) + parseInt($(elm).getStyle('padding-top')) ) + 'px';
					var sum = 0;
					['margin-top'].each(function(style) {
						sum += parseInt($(elm).getStyle(style));
					});
					elm.style.paddingBottom = containerHeight-col.offsetHeight - sum + parseInt($(elm).getStyle('padding-bottom')) + 'px';
				}
			}
		});
		this.resizing = false;
	}
};
window.addEvent('domready', function() {

	colResize.init();
})


function openVideo(vid, cue) {
		SqueezeBox.fromElement({handler:'iframe',size:{x:720,y:650},url:'pop.htm?video=' +vid+"&cue="+cue});
}


function closeVideo(url, target){
	parent.SqueezeBox.close("",url, "_parent");
}






