// Extra functions

function insertTakeOver(){

    //var pHeight = getElmHeight('container');
    var objTakeOver = document.createElement("div");
    var objContainer = document.getElementById("wrapper");
    var objBody = document.body;
    
    //var takeoverheight = pHeight > 0 ? pHeight + 110 + 15 : 0;
    //if(takeoverheight > 0 && takeoverheight < 1200) takeoverheight = 1200;
    
    //objBody.style.backgroundColor = '#fff';
    objBody.style.backgroundImage = "url('/images/banners/hm/mixitup_rasterized.jpg')";
    objBody.style.backgroundPosition = '50% 0px';
    objBody.style.backgroundRepeat = 'no-repeat';
    
    objContainer.style.zIndex = 2;
    objContainer.style.position = 'relative';
    
    objTakeOver.setAttribute('id','takeover');
    objTakeOver.style.zIndex = 0;
    objTakeOver.style.top = '0px';
    objTakeOver.style.left = 0 ;
    objTakeOver.style.position = 'absolute';
    //objTakeOver.style.height = takeoverheight > 0 ? takeoverheight + 110 + 15 + "px" : '100%';
    objTakeOver.style.height = 1200 + "px";
    
    objTakeOver.style.width = '100%';
    objTakeOver.style.cursor = 'pointer';
    objTakeOver.onclick = function () { window.open('http://bs.serving-sys.com/BurstingPipe/adServer.bs?cn=tf&c=20&mc=click&pli=1497716&PluID=0&ord=%25n'); return false; }
    document.body.appendChild(objTakeOver);
    
}

// document ready

$(document).ready(function(){
  
  $(function(){
      var min_height = 175;
      var header = $(".header_scalable");
      var header_height = $(header).height();
      if(header_height < min_height) $(header).height(min_height);
      
      var bannerdiv = $("div", header);
      var bannerwidth = $(bannerdiv).width();
      if(bannerwidth <= 750) {
          var homelink = $("<a>");
          $(homelink).attr({"href": "/", "title": "home fashionmix"}).addClass("homelink");
          //$(bannerdiv).before(homelink);
      }
  })
  
  $(".rollover").hover(function() {
    curr = $(this).attr("src");
    overlen = curr.length;
    over = curr.substr(0, overlen-4);
    over = over+'_over.jpg';
    $(this).attr({ src: over});
  }, function() {
    $(this).attr({ src: curr});
  });
  
  $(".rollover").each(function(i) {
    temp = this.src;
    prelen = temp.length;
    pre = temp.substr(0, prelen-4);
    pre = pre+'_over.jpg';
    $.preloadImages(pre);
  });
  
  $("dd.item").click(function(){
  	var target = $(this).find("a").attr("target");
  	var URL = $(this).find("a").attr("href");
  	if(target == '_blank') {
  	  window.open(URL, '_blank');
  	} else {
  	  document.location.href = URL;
  	}
    return false;	
  }).hover(function(){
    $(this).addClass("itemhover").show("slow");
  }, function(){
    $(this).removeClass("itemhover").show("slow");
  });
  
  $("dd.gallery").click(function(){
    var URL = $(this).find("a").attr("href");
    document.location.href = URL;
    return false;
  }).hover(function(){
    $(this).addClass("galleryhover").show("slow");
  }, function(){
    $(this).removeClass("galleryhover").show("slow");
  });
  
  // Body background
  $("body").addClass("bg").show();
    
  // IE main fix
  if($.browser.msie) $("div.main").addClass("h100pct").show();
  
  // Search 
  $("#item_search").focus(function(){
      if($(this).val() == $(this).attr("title")) {
          $(this).val("");
      }
  }).blur(function(){
      var defval = $(this).attr("title");
      var curval = $(this).val();
      if(curval.length == 0) {
          $(this).val(defval);
      }
  }).click(function(){
      $(this).focus();
  });
  
  // HM temp
  //$("body").addClass("hm").show();
  //insertTakeOver();
  
  // Header banner
  //$("div.header_scalable div").wrap("<table><tr><td></tr></table>");
  
});

function findPos(obj) {
  var curleft = obj.offsetLeft || 0;
  var curtop = obj.offsetTop || 0;
  while(obj = obj.offsetParent) {
    curleft += obj.offsetLeft
    curtop += obj.offsetTop
  }
  return {x:curleft,y:curtop};
}