var mx=0;
var my=0;

//alert("load overlay");

jQuery(document).ready(function(){
   $(document).mousemove(function(e){
      mx=e.pageY;
      //console.log(mx);
   }); 
})

function setPopPlace(){
    $('.div_ft .window').css("top",(mx)+"px");
    $('.div_ft #window').css("top",(mx)+"px");
}

$(function(){
 $(".div_ft").find("a").each(function () {
          //alert($(this).attr("href"));
            if ($(this).attr("href")=="#"){
              //alert(this.onclick);
              //this.onclick = null;
              //this.click = null;
              
              $(this).click(function(){
                //alert($(this).scrollTop());
                //alert($(this).css("top"));
                setPopPlace();
                
                
                return false
                });
            }
          }
)
})



var w3c=document.getElementById && !document.all;
var ie=document.all;

if (ie||w3c) {
 // déclaration des variables uniquement pour IE vive microsoft ?!!
 var overlay;
 var my_window;
}


function affiche_overlay_window(image_fond_overlay,adresse_page){
	// creation de l'overlay et affichage de l'image
	montreoverlay("");
	// creation de la fenętre
	montrefenetre(adresse_page);
//	adapt("short");
        
	//parent.document.getElementById('window').style.height="405px";
	h=$("body").css("height");
	if (h<2000) h=3000;
        parent.document.getElementById('overlay').style.height=h;
        return false;
}

function adapt(type){
        
	if (type=="short"){
		parent.document.getElementById('window').style.width="532px";
		parent.document.getElementById('window').style.height="405px";
		parent.document.getElementById('overlay').style.height="1820px";
	}
	else {
		parent.document.getElementById('window').style.width="532px";
		parent.document.getElementById('window').style.height="886px";
		parent.document.getElementById('overlay').style.height="1820px";
	}
	
}
function montreoverlay(text) {
  if (w3c||ie){
  //alert("montre overlay");
    overlay = document.all ? document.all["overlay"] : document.getElementById ? document.getElementById("overlay") : ""
	overlay.innerHTML = text; // fixe le code HTML dans l'overlay balise (div)
    overlay.style.visibility = "visible"; // modification du style
    /*$("#overlay").css("width","2000px");
    $("#overlay").css("height","2000px");
    $("#overlay").css("background","white");*/
    $(overlay).bind("click",function(){cachetout()});
  }
}

var tt="\
<script type='text/javascript' language='javascript1.1'> \
        alert ('ok');\
        window.document.cachetout=function() { \
        alert ('ok2');\
	if (w3c||ie){ \
        my_window = parent.document.getElementById('window');\
	my_window.style.visibility = 'hidden'; \
        my_window = parent.document.getElementById('contempwindow');\
	my_window.style.visibility = 'hidden';\
        my_window = document.all ? parent.document.all['overlay'] : parent.document.getElementById ? parent.document.getElementById('overlay') : '';\
	my_window.style.visibility = 'hidden';\
        }} \
</script>\
";


function doIframe(){
	o = document.getElementsByTagName('iframe');
	for(i=0;i<o.length;i++){
		if (/\bautoHeight\b/.test(o[i].className)){
			setHeight(o[i]);
			addEvent(o[i],'load', doIframe);
		}
	}
}

function setHeight(e){
	if(e.contentDocument){
		e.height = e.contentDocument.body.offsetHeight + 34;
	} else {
		e.height = e.contentWindow.document.body.scrollHeight;
	}
}

function addEvent(obj, evType, fn){
	if(obj.addEventListener)
	{
	obj.addEventListener(evType, fn,false);
	return true;
	} else if (obj.attachEvent){
	var r = obj.attachEvent("on"+evType, fn);
	return r;
	} else {
	return false;
	}
}

/*if (document.getElementById && document.createTextNode){
 addEvent(window,'load', doIframe);	
}*/


function adaptFrame(){
  
}
var adaptloaded=0;

function montrefenetre(html) {
//alert("inside montre");
  if (w3c||ie){
  //alert("inside condition");
    //affichage de la fenetre
	my_window = document.all ? document.all['window'] : document.getElementById ? document.getElementById('window') : ""
    my_window.style.visibility = "visible";

	// affichage du corps de la fenętre (balise iframe)
    my_window = document.all ? document.all['contempwindow'] : document.getElementById ? document.getElementById('contempwindow') : ""
    my_window.style.visibility = "visible";
    $(frames['contempwindow']).html("");
    $('.div_ft iframe').html("");
    
    //$('.div_ft iframe').css("height","0px");
    
    //$('.div_ft .window').css("position","fixed");
    //$('.div_ft .window').css("top","20px");
    //$('.div_ft .window').css("position","relative");
    
    frames['contempwindow'].location.href= html ; 
//alert("ok");
    if (!adaptloaded)
    $('.div_ft iframe').load(function() {
        //alert("frame loaded");
        /*if(this.contentDocument){
                if (this.contentDocument.document && this.contentDocument.document.body) {
		h=this.contentDocument.document.body.offsetHeight+35;
                w=this.contentDocument.document.body.offsetWidth;
                }
	} else {
	if (this.contentWindow.document && this.contentWindow.document.body) {
		h=this.contentWindow.document.body.offsetHeight;
                w=this.contentWindow.document.body.offsetWidth;
                }
	}
        
        //alert(w+"x"+h);
        
        h1=h;w1=w;
        if (w<530) w=531;
        if (w>570) w=531;
        
        if (h<200) h=400;
        */
        $('.div_ft #overlay').css("display","block");
        //$('.div_ft #overlay').css("width",this.document.body.offsetWidth+"px");
        //$('.div_ft #overlay').css("height",this.document.body.offsetHeight+"px");
        
        try{
        $('.div_ft #overlay').css("width",$(document).width()+"px");
        $('.div_ft #overlay').css("height",$(document).height()+"px");
        } catch (err){}
        
        $('.div_ft #overlay').css("z-index","1000");
        //if (h<300) h=600;
        //if (w>600) w=534;
        //alert($(frames['contempwindow'],"body").height());
        //w=533;
        
       
        /*$('.div_ft iframe').css("height",  h + 'px');
        $('.div_ft iframe').css("width",  w + 'px');
        $('.div_ft #window').css("height",  h + 'px');
        $('.div_ft #window').css("width",  w + 'px');*/
        
        //alert ("set "+w1+"x"+h1);
        //$(this.contentWindow.document.body).append("test1"+tt+"test2");
        //$('iframe').style.width = w + 'px';
        
        var script = this.contentWindow.document.createElement("script");
        script.src = "http://www.rezonance.ch/images/Rezonance/Restricted/adapt.js";
        script.onload = script.onreadystatechange = function(){ 
          //alert($(".div_ft iframe").contents().html());
         
          $(".div_ft iframe").contents().find("a").each(function () {
            //console.log($(this).attr("href"));
            if ($(this).attr("href")!="#" && 
              
              $(this).attr("href")!="http://www.rezonance.ch/images/Rezonance/Premium/Comparatif_short.html" && 
              $(this).attr("href")!="http://www.rezonance.ch/images/Rezonance/Premium/Comparatif_long.html" && 
              $(this).attr("href")!=""){
            $(this).attr("target","_BLANK")
            this.onclick = null;
            this.click = null;
            $(this).click(function(){cachetout();return true;});
            }else
            if ($(this).attr("href")!="http://www.rezonance.ch/images/Rezonance/Premium/Comparatif_long.html"&&$(this).attr("href")!="http://www.rezonance.ch/images/Rezonance/Premium/Comparatif_short.html")
              {
              $(this).attr("href","");
              $(this).attr("target","");
              $(this).click(function(){cachetout();return false;});
            }
          });
          
          adaptloaded=1;
          
          
           //alert($(".div_ft iframe").contents().height());
          //$(".div_ft iframe").contents().find("a").each(function(){$(this).unbind()});
          //$(".div_ft iframe").unbind("click");
          //$(".div_ft iframe").contents().find("a").attr("target","_BLANK");
          /*$(".div_ft iframe").contents().find("a").unbind("click");
          $(".div_ft iframe").contents().find("a").unbind();
          $(".div_ft iframe").contents().find("a").unbind("onclick");
          $(".div_ft iframe").contents().find("a").attr("onclick","");
          $(".div_ft iframe").contents().find("a").attr("click","");*/
          //$(".div_ft iframe").contents().find("a").after("target setted");
          //$(".div_ft iframe").contents().find("a").click(function(){cachetout();return true;});
          //$("a").attr("target","_blank");
          //$("a").click(function(){alert('a clicked');cachetout();return false;});
          //alert($("body").html());
          };
        this.contentWindow.document.body.appendChild( script );

        
    }
    );
  }
}

//"<script src='http://www.rezonance.ch/images/Rezonance/Restricted/adapt.js'></script>"
function cachetout() {
	if (w3c||ie){

	// masque la fenetre (balise div [window] )
	my_window = parent.document.getElementById('window');
	my_window.style.visibility = "hidden";

	// masque le contenu (balise iframe [contempwindow])
	my_window = parent.document.getElementById('contempwindow');
	my_window.style.visibility = "hidden";

	// masque l'overlay (balise div [overlay])
	my_window = document.all ? parent.document.all['overlay'] : parent.document.getElementById ? parent.document.getElementById('overlay') : ""
	my_window.style.visibility = "hidden";
$(".div_ft #window", top.document).css("height",  0 + 'px');
        $(".div_ft iframe", top.document).css("height",  0 + 'px');  
	}


}



/* "*/
