// JavaScript Document

var isIE = document.documentElement && document.documentElement.clientHeight;
var isIE6 = ((navigator.userAgent.indexOf("MSIE 6.") != -1) && (navigator.userAgent.indexOf("Opera") == -1));
function msnews_addZoomFunction(){
	
	linkedMedia = $$('img.zoomable');
	linkedMedia.each(function(e){
		e.onclick=function(){msnews_zoom(this);}
		e.style.cursor='pointer';
	});
}
function msnews_zoom(media){
	var oBody =document.getElementsByTagName("body")[0]; 
	var src = media.src;
	if (src.indexOf('/msnews_thumb')>1) {
		datas = src.split('/msnews_thumb/');
		src=datas[1];
	}
	var regexp = new RegExp("http:\/\/");
	if(regexp.test(src)){
		src = src.replace(regexp, "");
		q=src.indexOf('/')
		src=src.substring(q+1);
	}
	msnews_CreateBodyMask()
	style="position:absolute;left:50%;top:50%;width:auto;height:auto;border:#eee 0px solid;background-color:#eee;padding:30px;z-index:1000;";
	var d = new Element('div', { 'id': 'linkedMediaZoom', 'style':style });d.hide();
	d.setPosition=function(){}
	style="position:absolute;width:14px;height:8px;top:10px;right:10px;padding-bottom:8px;text-align:center;font-size:16px; text-decoration:none; font-family:arial; font-weight:bolg;color:#888;  border:1px solid #888;	opacity : 0.5;filter : alpha(opacity=50); ";
	var a = new Element('a', { 'class': 'close', 'href': 'javascript:msnews_zoomClose()','style':style, 'onmouseover':'msnews_zoomClose_over(this)','onmouseout':'msnews_zoomClose_out(this)' }).update('X');
	var i = new Element('img' );
	d.appendChild(a);
	d.appendChild(i);
	oBody.appendChild(d);
	oBody.style.cursor='wait';
	i.onload=function(){
		var d=$("linkedMediaZoom");
		var s = d.getDimensions();
		d.style.marginLeft = -(parseInt(s.width)  / 2) + "px";
		windowsHeight =msnews_getWindowHeight();
		d.style.marginTop =  -(parseInt(s.height)  /2) + document.documentElement.scrollTop +"px";  
		d.show();
		// d.style.display='block';
		oBody.style.cursor='default';
	}
	i.src = '/msnews_zoom/'+src;
}
function  msnews_zoomClose_over(obj){
	$(obj).setStyle({'opacity' : '1', 'filter' : 'alpha(opacity=100'});
}
function  msnews_zoomClose_out(obj){
	$(obj).setStyle({'opacity' : '0.5', 'filter' : 'alpha(opacity=50'});
}

function  msnews_zoomClose(){
	if ($("linkedMediaZoom")) document.getElementsByTagName("body")[0].removeChild($("linkedMediaZoom"));
	msnews_DestroyBodyMask()
}
function msnews_CreateBodyMask(){
	docSize = getDocumentSize();
	var mskWidth = Math.max(docSize[0], screen.width);
	var mskHeight = Math.max(docSize[1], screen.height);
	var e = new Element('div', {'id': 'msnewsBodyMask',"style" : "position:absolute; top=0px; left:0px; width:"+mskWidth+"px; height:"+mskHeight+"px;background-color:#505050; opacity:0.6;filter : alpha(opacity=60);z-index:1000" });
	// e.onmousemove = promptbox_mouser; // DRAG AN DROP
	
	document.getElementsByTagName("body")[0].appendChild(e);
	iframes = $$('iframe');	// masquage des iframes pour IE
	for (i=0; i<iframes.length; i++){
		if (iframes[i].style.display != "none") {
			msnews_HidenIFramesObject.push(iframes[i].style.display);
			msnews_HidenIFramesStyle.push(iframes[i]);
			iframes[i].style.display="none";
		}
	}
	
}
function msnews_DestroyBodyMask(){
	if ($("msnewsBodyMask")) document.getElementsByTagName("body")[0].removeChild($("msnewsBodyMask"));
	globalBodyMask = null;
	for (i=0; i<msnews_HidenIFramesObject.length; i++){
		msnews_HidenIFramesStyle[i].style.display=iePromptBoxHidenIFramesStyle[i];
	}
}
function msnews_getWindowHeight() {
		
 var windowHeight = 0;
   if (typeof(window.innerHeight) == 'number') {
        windowHeight = window.innerHeight;
   } else {
          if (document.body && document.body.clientHeight) {
            windowHeight = document.body.clientHeight;
			if (! isIE6) windowHeight = windowHeight - 400; else windowHeight = document.documentElement.clientHeight;
        }
        else {
          if (document.documentElement && document.documentElement.clientHeight) {
            windowHeight = document.documentElement.clientHeight;
          }
        }
   }
 return windowHeight;
}
var msnews_HidenIFramesObject = new Array();
var msnews_HidenIFramesStyle = new Array();
