/* IE6 Resize crash fix*/
var resizeTimeout = undefined;
var resizeInProgress = false;
var cwidth = undefined;
var cheight = undefined;

var goWidth = 900;
var resize_prod_go=true;
var MaxWidth = 900;
var MaxHeight = 500;

/* IE6 Resize crash fix*/
function resizeComplete(){
    clearTimeout(resizeTimeout);
    resizeInProgress = false;
}
function resetHandler(){
  if (isBrowser("IE") && resizeInProgress == false){
    if (resizeTimeout != undefined){
      clearTimeout(resizeTimeout);
    }
    resizeTimeout = setTimeout("resize();", 100);
  }
  else if (isBrowser("FF")){
    resize();
  } 
} 

function has_scrollbar(elem_id){
  elem = $(elem_id); 
  if (elem.clientHeight < elem.scrollHeight){ 
    //alert("The element has a vertical scrollbar!"); 
    return true;
  }
  //alert("The element doesn't have a vertical scrollbar."); 
  return false;
} 
function getSize(){
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return Array(myWidth,myHeight);
}

function getElementSize(el){
  var obj = $(el);
  myWidth = obj.clientWidth;
  myHeight = obj.clientHeight;	
  return Array(myWidth,myHeight);
}
function resizeMenuWidth(){
  sizes = getSize();
  var iWidth=sizes[0];
	if(iWidth > MaxWidth){
		if($("menu_categorie_container")){$("menu_categorie_container").style.width = (iWidth) + "px";}
    if($("language_back")){$("language_back").style.width = (iWidth) + "px";}
    if($("country_back")){$("country_back").style.width = (iWidth) + "px";}
    if($("language_switch_holder")){$("language_switch_holder").style.width = (iWidth) + "px";}
    if($("country_switch_holder")){$("country_switch_holder").style.width = (iWidth) + "px";}
    if($("menu")){
      $("menu").style.width="";
      var mWidth = iWidth-295;
      //alert(mWidth+" : "+$("menu").clientWidth);
      setMenuImages(28,75);
      $("menu").style.lineHeight="75px";
      if($("menu").clientWidth > mWidth){
        $("menu").style.width=(mWidth-30)+"px";
        if($("menu").clientHeight > 75){
          $("menu").style.lineHeight="37px";
          setMenuImages(9,37);
        }
      }
    }
	}else{
		if($("menu_categorie_container")){$("menu_categorie_container").style.width  = (MaxWidth) + "px";}
    if($("language_back")){$("language_back").style.width = (MaxWidth) + "px";}
    if($("country_back")){$("country_back").style.width = (MaxWidth) + "px";}
    if($("language_switch_holder")){$("language_switch_holder").style.width = (MaxWidth) + "px";}
    if($("country_switch_holder")){$("country_switch_holder").style.width = (MaxWidth) + "px";}
    if($("menu")){
      $("menu").style.width="";
      $("menu").style.lineHeight="75px";
      setMenuImages(28,75);
      if($("menu").clientWidth > 575){
        $("menu").style.width="575px";
        if($("menu").clientHeight > 75){
          $("menu").style.lineHeight="37px";
          setMenuImages(9,37);
        }
      }
    }
	}
}
function resizeAll(){
  sizes = getSize();
  myWidth=sizes[0];
  myHeight=sizes[1];
  var browser=navigator.appName;
  var b_version=navigator.appVersion;
  var version=parseFloat(b_version);
  iHeight = myHeight-2;
  cHeight = 2;
  if($("top_container")){cHeight=cHeight+$("top_container").clientHeight;}
  if($("menu_categorie_container")){
    if($("product_container")){
      cHeight=cHeight+$("menu_categorie_container").offsetHeight;
    }
  }
  if($("footer_container")){cHeight=cHeight+$("footer_container").clientHeight;}

	if (iHeight > MaxHeight){
		if($('body')){
      //alert(myHeight+" : "+$('body').offsetHeight);
      if(myHeight > $('body').offsetHeight){
      $('body').style.overflowY='hidden';
      }else{
        $('body').style.overflowY='';
      }
    }
		//var H = iHeight-125;
		Hc = iHeight-cHeight;
		var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
		if( IE6){
			Hc = Hc-9;
		}
		if($("content_container")){
      $("content_container").style.height = '';
      /*if(myHeight < $('content_container').offsetHeight){
        $("content_container").style.height = ($('content_container').offsetHeight) + "px";
      }*/
    }
    var footergo=true;
		if($("product_container")){$("product_container").style.height = ((Hc)-40) + "px";}
		if($("product_loader")){$("product_loader").style.height = ((Hc)-40) + "px";}
		//if($("product_loader_holder")){$("product_loader_holder").style.marginTop = (((Hc)-$("product_loader_holder").offsetHeight)/2) + "px";}
		if($("blocks")){$("blocks").style.height = ((Hc)-40) + "px";}
		if($("show_blocks")){$("show_blocks").style.height = ((Hc)-40) + "px";}
    if($("flashcontent")){$("flashcontent").style.height = (Hc) + "px";}
    if($("content_container")){
      if((cHeight+$("content_container").offsetHeight) > myHeight){
        footergo=false;
      }
    }
    if($("footer_container")){
      if(footergo){
      $("footer_container").style.position= 'absolute';
      if(myHeight < $('body').offsetHeight){
        $("footer_container").style.bottom= '';
      }else{
        $("footer_container").style.bottom= '0px';
      }
      }else{
        $("footer_container").style.position= 'static';
      }
    }
	} else {
		if($('body')){$('body').style.overflowY='visible';}
		/*if($("content_container")){      if(!$('pagecontent')){        $("content_container").style.height = 375 + "px";      }    }*/
		if($("blocks")){$("blocks").style.height = (375-40) + "px";}
		if($("show_blocks")){$("show_blocks").style.height = (375-40) + "px";}
		if($("product_loader")){$("product_loader").style.height = (375-40) + "px";}
		//if($("product_loader_holder")){$("product_loader_holder").style.marginTop = (((375)-$("product_loader_holder").offsetHeight)/2) + "px";}
		if($("product_container")){$("product_container").style.height = (375-40) + "px";}
		if($("flashcontent")){$("flashcontent").style.height = 375 + "px";}
    if($("footer_container")){
      $("footer_container").style.position= 'static';
      $("footer_container").style.bottom= '';
    }
	}
	iWidth = myWidth;
  goWidth = iWidth;
	if(iWidth > MaxWidth){
		if($('body')){$('body').style.overflowX='hidden';}
	} else{
    goWidth=MaxWidth;
		if($('body')){$('body').style.overflowX='visible';}
	}
  if($("content_container")){$("content_container").style.width  = goWidth + "px";}
  if($("product_loader")){$("product_loader").style.width  = goWidth + "px";}
  //if($("blocks")){$("blocks").style.width  = goWidth + "px";}
  if($("show_blocks")){$("show_blocks").style.width  = (goWidth-40) + "px";}
  if($("product_container")){$("product_container").style.width  = (goWidth-40) + "px";}
  if($("flashcontent")){$("flashcontent").style.width  = goWidth + "px";}
  if($("top_container")){$("top_container").style.width  =goWidth + "px";}
  if($("footer_container")){
    $("footer_container").style.width  = goWidth + "px";
    if($("footer").clientWidth > goWidth){
      $("footer").style.width=(goWidth-60)+"px";
      $("footer").style.lineHeight="50px";
    }
    if($("footer").clientHeight > 50){
        $("footer").style.lineHeight="25px";
    }
  }
  resizeMenuWidth();
}
function setMenuImages(size,height){
  var images = $('menu').select('img');
  for(var i=0;i<images.length;i++){
    images[i].parentNode.style.height=height+"px";
    images[i].style.marginTop=size+"px";
  }
}
function resize(){
  sizes = getSize();
  myWidth=sizes[0];
  myHeight=sizes[1];
  /* IE6 Resize crash fix*/
  if (isBrowser("IE")){
    if(cwidth == myWidth && cheight == myHeight){
      return false;
    }else{
      cwidth = myWidth;
      cheight = myHeight;
    }
  }

  resizeAll();
  if($('product_container')){
    orderSmallProducts();
  }
  resizeProdDetail();
  //alert(iWidth);
  if($("flashcontainer")){
    var so = new SWFObject("foto_resize.swf", "flashcontent", goWidth, Hc,"8" ,"#ffffff");
    so.addParam("wmode", "transparent");
    so.addVariable("fotourl","/foto.jpg");
    so.write("flashcontainer");
  }
  checkCountryToggle();
}

function resizeMenu(){
  resizeAll();
  checkCountryToggle();
}

function resizeContent(){
  resizeAll();
  sizes = getSize();
  myWidth=sizes[0];
  myHeight=sizes[1];
  bHeight = 2;
  if($("top_container")){bHeight=bHeight+$("top_container").clientHeight;}
  if($("footer_container")){bHeight=bHeight+$("footer_container").clientHeight;}
  iHeight = myHeight-bHeight;
  cHeight = $('content_container').clientHeight;
  if(cHeight < iHeight){
    $('content_container').style.height = iHeight+'px';
  }
  
  resizeMenuWidth();
  checkCountryToggle();
}
/* IE6 Resize crash fix*/
function isBrowser(which){
  var toCheck;
  switch (which){
    case "IE" : 
      toCheck = "MSIE";
      break;
    case "FF" : 
      toCheck = "Firefox";
      break;
  }
  if (undefined != toCheck){
    return (navigator.userAgent.indexOf(toCheck) != -1)
  }
  return false;
}