// JavaScript Document

function resizeBackgrounds() {
			var navWidth = $(window).width();
			var navHeight = $(window).height();
			var ImgRatio = 1.3333333;
			var newWidth = navHeight*ImgRatio;
//			alert(newWidth);
			var FullscreenrOptions = {  width: newWidth, height: $(window).height(), bgID: '#bgimg' };
			// This will activate the full screen background!
			jQuery.fn.fullscreenr(FullscreenrOptions);

};
resizeBackgrounds();
$(window).resize(function(){
	// gestion de la fenêtre
	resizeBackgrounds();
});

// Création de l'objet HTTP Request
function getE(id) {
	if(document.all){
		return document.all[id];
	}else{
		return document.getElementById(id);
	}
}

function getX(){
	if(document.all){ 
        //Internet Explorer 
        return new ActiveXObject("Microsoft.XMLHTTP") ; 
    }else{ 
        //Mozilla 
        return new XMLHttpRequest(); 
    }
}

//Fonction d'envoie des données
function sendData(act,url,data){
	var x = getX();
	var eImg='';
	// Ici tu peux changer le nom de la page
	x.open('GET', url+data);
	// Ici c'est l'ID du SPAN
	var eSpan = getE('retailers_details');
	// Ici c'est si tout es ok on renvoie les données
	x.onreadystatechange = function(){ 
        if(x.readyState == 4 && x.status == 200){
			
			eSpan.innerHTML=x.responseText;
		}
	}

	// On envoie le tout avec valeur null puisque par GET
	x.send(null);
}

$(document).ready(function() {
  if ( $.browser.opera ) {
    if ( $( 'div#menutop' ).length ) {
      $( 'div#menutop' ).find( 'a' ).each(function(){
        $( this ).children( 'span' ).html( '<img src="/images/spacer.gif" height="' + $( this ).height() + '" width="' + $( this ).width() + '">' ).css({ 'display': 'block' });
      });
    }
    if ( $( 'div#menuwatches' ).length ) {
      $( 'div#menuwatches' ).find( 'a' ).each(function(){
        $( this ).children( 'span' ).html( '<img src="/images/spacer.gif" height="' + $( this ).height() + '" width="' + $( this ).width() + '">' ).css({ 'display': 'block' });
      });
    }
    if ( $( 'div#menunews' ).length ) {
      $( 'div#menunews' ).find( 'a' ).each(function(){
        $( this ).children( 'span' ).html( '<img src="/images/spacer.gif" height="' + $( this ).height() + '" width="' + $( this ).width() + '">' ).css({ 'display': 'block' });
      });
    }
    if ( $( 'div#menuretailer' ).length ) {
      $( 'div#menuretailer' ).find( 'a' ).each(function(){
        $( this ).children( 'span' ).html( '<img src="/images/spacer.gif" height="' + $( this ).height() + '" width="' + $( this ).width() + '">' ).css({ 'display': 'block' });
      });
    }
  }
  
  /* retailers page */
  
  $( 'a.retailer_detail' ).click(function(){
    var retailer_detail_url = '/ajax/' + $( this ).attr( 'href' );
    
    $.ajax({
      url: retailer_detail_url,
      dataType: 'html',
      type: 'GET',
      success: function( data ) {
        $( 'div#retailers_details' ).html( data );
      }
    });
    
    return false;
  });
  
  
}); 
