var layout={
  favoriteArr:[],
  bottomBannerArr:[],
  init:function(){
    window.onresize=function(){layout.adjustContentWrapperHeight();}
    if(!$('#pageWrapper').length) return;
    this.navigationHeight=112;
    this.layoutHeight = 920;
    this.layoutWidth=1120;
    this.wrapperObj=$("#pageWrapper");
    this.contentWrapperObj=$("#contentWrapper");
    /*contentWrapper's height is set to 672px*/
    this.navigationHolderDivObj=$("#navigationHolder").length?document.getElementById("navigationHolder"):false;
    this.processing=false;
    if(typeof(window.innerWidth)=='number'){
      this.innerWidth=window.innerWidth;
      this.innerHeigh=window.innerHeight;
    }else if(document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight)){
      this.innerWidth=document.documentElement.clientWidth;
      this.innerHeight=document.documentElement.clientHeight;
    }else if(document.body&&(document.body.clientWidth||document.body.clientHeight)){
      this.innerWidth=document.body.clientWidth;
      this.innerHeight=document.body.clientHeight;
    }
    this.innerHeight=isUndefined(this.innerHeight)?0:this.innerHeight;
    this.innerWidth=isUndefined(this.innerWidth)?0:this.innerWidth;
    this.layoutLeftPosition=(this.innerWidth-this.layoutWidth)/2;

    if( isGuest ){
      this.hideCustomerFunctions();
    }else{
      this.hideGuestFunctions();
      this.debitorNo = getCookie( 'cookiesVar_debitorNo' );
      if( this.debitorNo ){
        $('#rememberMe').attr('checked',true);
      }else{
        $('#rememberMeHolder').hide();
        $('#rememberMe').attr('disabled',true);
      }
    }
    if(this.favoriteArr.length){
      this.showFavorites();
      this.populateFavorites();
      this.hideCatalogues();
    }

    $('#bottomBanner').corner();
    this.bottomBannerArr = $('#bottomBanner').children();
    this.bannerRotator(1);
    $('#menu').corner();

    $('#searchFunction').corner();
    $('#Basket').corner();
    $('#QuickShopping').corner();
    $('#Catalogues').corner();
    $('#shopIndexHeader').corner('top');
    if( !$.browser.msie ) $('.menuHeaderFrame').corner();
    $('#address').corner();
    this.adjustContentWrapperHeight();
  },

  bannerRotator:function(bannerindex){
    if( $("#bb" + bannerindex ).length == 0 ) bannerindex=1;
    //hideAll
    for(var key = 1; key <= this.bottomBannerArr.length; key++){
      if( $("#bb" + key ).length ) $("#bb" + key ).hide();
    }
    //show the designated banner
    if( $("#bb" + bannerindex ).length ){
      $('#bottomBanner').css({backgroundColor:$("#bb"+bannerindex).css('background-color')});
      $("#bb"+bannerindex).show();
    }
    //10 seconds pause
    setTimeout("layout.bannerRotator("+ ++bannerindex +")",20000);
  },
  setShoppingBasketSubtotal:function(subtotal){
    $('#basketSubTotal').html( subtotal + " " + sessionObj.currencyName );
    sessionObj.subtotal = subtotal;
  },
  setShoppingBasketNumberOfItems:function(numberOfItems){
    $('#basketNumberOfItems').html( numberOfItems + " items" );
    sessionObj.numberOfItems = numberOfItems;
  },
  shoppingBasketBlink:function(actionid){
    if( !empty(actionid) ){
      //flash('Your basket is Updated');
    }
  },
  hideCatalogues:function(){hideLayer('Catalogues');},
  hideBrands:function(){hideLayer('Brands');},
  hideSubgroups:function(){hideLayer('Subgroups');},
  showSubgroups:function(){showLayer('Subgroups');},
  hideBottomBanner:function(){hideLayer('bottomBanner');},
  showBottomBanner:function(){showLayer('bottomBanner');},
  hideGuestFunctions:function(){hideLayer('guestFunctions');},
  hideCustomerFunctions:function(){hideLayer('customerFunctions');},
  hideRememberMe:function(){hideLayer('rememberMeHolder');},
  showRememberMe:function(){showLayer('rememberMeHolder');},
  showFavorites:function(){showLayer('favorites');},
  hideFavorites:function(){hideLayer('favorites');},
  hideShopIndex:function(){hideLayer('shopIndex');},
  showShopIndex:function(){showLayer('shopIndex');},
  showShopIndexDropdown:function(){showLayer('shopIndexDropdown');},
  hideShopIndexDropdown:function(){hideLayer('shopIndexDropdown');},
  hideSuperOffer:function(){hideLayer('superOffer');},
  showSuperOffer:function(){showLayer('superOffer');},
  showAntTrack:function(){showLayer('antTrack');},
  hideShopIndexRollout:function(){hideLayer('SHOP_INDEX_ROLLOUT');},
  showShopIndexRollout:function(){showLayer('SHOP_INDEX_ROLLOUT');},
  hideShopIndexRollback:function(){hideLayer('SHOP_INDEX_ROLLBACK');},
  showShopIndexRollback:function(){showLayer('SHOP_INDEX_ROLLBACK');},
  showCurrency:function(){$('#currency').show();},
  hideCurrency:function(){$('#currency').hide();},
  showShoppingBasketMessages:function(){showLayer('shoppingBasketMessages');},
  hideShoppingBasketMessages:function(){hideLayer('shoppingBasketMessages');},
  toggleShopIndex:function(){this.hideShopIndexDropdown();this.showShopIndex();this.showShopindexBoxes(1,32);},
  toggleBordersOn:function(objid){
    $("#"+objid).css({borderTop:"2px solid blue",borderLeft:"2px solid blue",borderRight:"2px solid blue",borderBottom:"2px solid white"});
  },
  toggleBordersOff:function(objid){
    $("#"+objid).css({borderTop:"2px solid white",borderLeft:"2px solid white",borderRight:"2px solid white",borderBottom:"2px solid blue"});
  },
  hideShopindexBoxes:function(from,to){
    for(var i = from ; i <= to ; i++) //setTimeout("hideLayer('SHOP_INDEX_"+i+"')", i*75 );
      hideLayer('SHOP_INDEX_'+i);
  },
  showShopindexBoxes:function(from,to){
    for(var i = from ; i <= to ; i++) setTimeout("showLayer('SHOP_INDEX_"+i+"')", i*75 );
  },
  populateFavorites:function(){
    var HTML = "<div class=boxHeaderRight style='background-color:#009933;height:25px;line-height:25px;font-weight:bold;'>Your favorites</div>";
    for( var key = 0; (key < 5 && key < layout.favoriteArr.length ) ; key++ ){
      HTML += "<div class=fItem><!-- <div class=fItemNumber>" + layout.favoriteArr[key][0] + "</div> -->";
      HTML += "<div class=fItemText>" + textCutter( layout.favoriteArr[key][1] , 28 ) + "</div>";
      HTML += "<div class=fItemPrice>" + sessionObj.currencyName + " " + layout.favoriteArr[key][2] + " </div>";
      HTML += "<div class=fAddToBasket onClick='addToBasket(" + layout.favoriteArr[key][0] + ",\"fav"+key+"\")'>Add</div>";
      HTML += "<div class=fAddToBasket><input type=text value=1 id=fav"+key+" name=fav"+key+" onFocus='setFocus(this)' size=1 class=noBorder style='font-size:7pt;height:12px;margin-left:3px;margin-right:3px;' onBlur='setBlur(this)'></div>"; HTML += "<div class=fAddToBasket onClick='addToBasket(" + layout.favoriteArr[key][0] + ",\"fav"+key+"\")'>to basket</div></div>";
      HTML += "<div style='height:1px;'>&nbsp;</div>";
    }
    HTML += "<div class=boxFooterRight>&nbsp;</div>";
    $('#favorites').html( HTML );
  },
  setShoppingBasketMessages:function(shoppingBasketMessages){if(!empty(shoppingBasketMessages)){this.showShoppingBasketMessages();$('#shoppingBasketMessagesText').html(shoppingBasketMessages);}},
  initLogon:function(){document.login.deb.focus();this.hideSuperOffer();},
  initUSC:function(){this.hideBottomBanner();},
  //visibleAreaHeight:function(){alert($(window).height()); return ( $(window).height() - this.navigationHeight ) > 709 ? 800 : ( $(window).height() - this.navigationHeight + 80 );},
  visibleAreaHeight:function(){return $(window).height();},
  initSearch:function(){this.hideShopindexBoxes(2,32);this.showShopIndexRollout();},
  initFp:function(){this.hideShopIndexRollout();},
  setPageContent:function(content){$('#pageContent').html(content);},
  adjustContentWrapperHeight:function(){$('#contentWrapper').css({height:"100%"});},
  populateLastSteps:function(step){
    var HTML = "\
    <div id=LS0>Shopping Basket</div>\
    <div id=LS1>Payment &amp; Delivery</div>\
    <div id=LS2>Freight Options</div>\
    <div id=LS3>Final Approval</div>\
    ";
    $('#LAST_STEPS').html(HTML).show();
    $('#LS0').css({background:'#E8EEF7',color:'#1150AC'});
    $('#LS1').css({background:'#C5D3E9',color:'#265ABD'});
    $('#LS2').css({background:'#6797DD',color:'#FFFFFF'});
    $('#LS3').css({background:'#265ABD',color:'#FFFFFF'});

    for( var i = 0 ; i < 4 ; i++ ){
      if( i < step ){
        $('#LS'+i).corner().hide((i+1)*500,function(){$(this).remove()});
      }else $('#LS'+i).corner();
    }
  },
  setShoppingBasketData:function( totalcurrency, totalnumberordered ){
    layout.setShoppingBasketSubtotal(totalcurrency);
    layout.setShoppingBasketNumberOfItems(totalnumberordered);
  }, // end setShoppingBasketData
  toggleLeftColomn:function(){
    $('#leftColomn').toggle();
  },
  toggleBasket:function(){
    $('#Basket').toggle();
  },
  toggleBottomBanner:function(){
    $('#bottomBanner').toggle();
  }
};
