var isOpera = (navigator.userAgent.indexOf('Opera') != -1)? true : false;
var isIE = (document.all && !isOpera && navigator.platform == "Win32")? true : false;
var isIE6 = (navigator.userAgent.indexOf('MSIE 6') != -1)? true : false ;
var isIE7 = (navigator.userAgent.indexOf('MSIE 7') != -1)? true : false ;

function init(){
	if($('navTop')) var myNavTop = new NavTop();
	if (screen.width<=800 && screen.height<=600) new ManageOverflow();
	hackPng();
}

Event.observe(window, 'load',init);


/*** Permet de voir les png transparent sous ie6 ***/
function hackPng(){
  if (navigator.appVersion.indexOf("MSIE 6")!=-1)
    for (i = 0; i < document.images.length; i++)
      if (document.images[i].src.substring(document.images[i].src.length-3, document.images[i].src.length) == "png") 
      {
        document.images[i].style.height = document.images[i].height + "px";
        document.images[i].style.width = document.images[i].width + "px";
        document.images[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=" + document.images[i].src + ",sizingMethod='scale')";
       document.images[i].src = "/img/commun/pix.gif";
      }
}
 
function selectPart(url){
    try{
        if(document.getElementById("content")){
	        document.getElementById("content").selectPart(url);
	    }
	    else document.location.href = url;
    }
    catch(e){
        document.location.href = url;
        //alert(e+" -  "+url);
        
    }
}

function bsk_flash(num)
{
    if(num == "amfmsg_FRFantagameconfirmation"){
        bsk_img = new Image();
        bsk_img.src = 'http://view.atdmt.com/action/amfmsg_FRFantagameconfirmation100309_3';
    }
    else{
        bsk_img = new Image();
        bsk_img.src = 'http://s0b.bluestreak.com/ix.e?bb&t='+num;
    }
    
    return;
}

function onSelect(value){
	//alert("onLoadPart "+value)

}

function openPop(f,l,h,op) {
	var marginLeft = (screen.width/2) - (l/2); 
	window.open(f,'Fanta','width='+l+',height='+h+',left='+marginLeft+',top='+marginTop+',resizable=no,'+op+'');
	var marginTop = (screen.height/2) - (h/2); 
}

function openReglementGuitarhero() {
	openPop("reglement.htm",500,600,"scrollbars=yes");
}

function openHush() {
    window.open("http://www.myspace.com/hushpuppies");
}

function openGuitarHeroGame() {
    window.open("http://www.guitarherogame.fr");
}

function openSesam() {
    window.open("http://www.sesam.org");
}

function goMSNGame() {
    p4ql = new ActiveXObject('MSNMessenger.P4QuickLaunch');
    p4ql.LaunchApp(10361763, '');
}

function openVanneImg(HashKey,Download) {
    window.open("GetImage.aspx?HashKey="+HashKey+"&Download="+Download);
}
function openIFrame(url) {
    //$('frameref').src = url+".html"
}
function openReglementVanneGenerator() {
    openPop("reglement.htm",500,600,"scrollbars=yes");
}
function openLiveConnect(url) {
    window.open(livelogin);
}

function openPage(url) {
    window.open(url);
}

function selectNav(id){
   var o =  $('n'+id);
   
   if(!o) return;
   
   o.addClassName('select');
    
    var img = o.getElementsByTagName('img')[0];
	var src = img.src;
	var stat = 1;
	
    var finfin=src.substring(src.length-3,src.length);
    var fin=src.substring(src.length-5,src.length-4);

    src=src.substring(0,src.length-5);
    img.src=src+stat+"."+finfin;	
}

var Aheuh = {
	Version: '1.0',
	intialize: function () {}
}
Aheuh.intialize();

Aheuh.Axis = {
    initialize: function() {
        this.each( function(k,r){ this.base[k] = this.base[k]||this.keys(k); }.bind(this) );
    },
    base:{x:null,y:null},
    pos:{x:'Left',y:'Top'},
    scale:{x:'Width',y:'Height'},
    id:{x:0,y:1},
    keys: function(key){
         this[key] = this[key] ||
            {
                key:key,          
                min:key+'min',
                max:key+'max',
                axis:key+'axis',
                limit:key+'limit',
                factor:key+'factor',
                pos:this.pos[key].toLowerCase(),
                scale:this.scale[key].toLowerCase(),
                scrollpos:'scroll'+this.pos[key],
                scrollscale:'scroll'+this.scale[key],
                offsetpos:'offset'+this.pos[key],
                offsetscale:'offset'+this.scale[key],
                clientscale:'client'+this.scale[key],
				mouse:key+'mouse',
				pointer:'pointer'+key.toUpperCase()
            };
        return this[key];
    },
    from: function(o)
    {
        return {x:o[0],y:o[1]};
    },
    each: function(iterator,memo)
    {
        for(var key in this.base)
            memo = iterator((this[key]||key),memo);
        return memo;
    }
}
Aheuh.Axis.initialize();

var ManageOverflow = Class.create({
	
	initialize: function (o) {
		this._doc = (!this.Safari) ?document.documentElement :document.body;
		Event.observe(window,'resize',this._onWindowResize.bind(this));
		this._onWindowResize();
	},
	
	_onWindowResize: function () {
		[{ o:$('logo'), Left:0, Top:0 },{ o:$('navTop'), Left:0, Top:0 }].each(function (o){
			Aheuh.Axis.each( this._check.bind(this,o) );
		}.bind(this));
	},
	
	_getPageSize: function (k) {
		return (this._doc[k.scrollscale]<this._getWindowSize(k)) ?this._getWindowSize(k) :this._doc[k.scrollscale];
	},
	
	_getWindowSize: function (k) {
		return document.documentElement[k.clientscale];
	},
	
	_check: function (o,k) {
		
		if (
			Position.cumulativeOffset(o.o)[Aheuh.Axis.id[k.key]]<0 ||
			Position.cumulativeOffset(o.o)[Aheuh.Axis.id[k.key]] + o.offsetWidth>this._getPageSize(k)
		) {	
			o.o.style['margin'+Aheuh.Axis.pos[k.key]] = '0px';
			o.o.style[k.pos] = (0 + o[Aheuh.Axis.pos[k.key]]) + 'px';
		}
	}
	
});


/***** rescueFrame *****/
function rescueFrame(obj){
	//if(isIE && !isIE7){		
		if(!$('rescueFrame'+obj.id)){
			var rescueObj = document.createElement('iframe');
			var rescueElement = Element.up(obj).appendChild(rescueObj);
			
			
			rescueElement.id = 'rescueFrame'+obj.id;
			rescueElement.style.position = 'absolute';
			
			//rescueElement.style.top = "0px" //obj.offsetTop+'px'; 
			//rescueElement.style.left = "0px" //obj.offsetLeft+'px';
			
			rescueElement.style.width = "1200px" //obj.offsetWidth+'px'; 
			rescueElement.style.height = "200px" //obj.offsetHeight+'px'; 
			
			///alert(obj.offsetTop+" - "+obj.offsetLeft)
			//rescueElement.style.visibility = 'visible';
			//rescueElement.style.border = '10px';
			//rescueElement.style.filter = 'alpha(opacity=0);';
			rescueElement.style.zIndex = 10;
			
		}
	//}
}
function removeRescueFrame(obj){
	//if(isIE && !isIE7){
		if($('rescueFrame'+obj.id)){
			Element.up(obj).removeChild($('rescueFrame'+obj.id));
		}
	//}
}
/*****************************/