
function ClientSniffer() { 
  this.ua = navigator.userAgent.toLowerCase(); 
  this.major = parseInt(navigator.appVersion); 
  this.minor = parseFloat(navigator.appVersion); 
  this.nav = ( (this.ua.indexOf('mozilla')!=-1) && ((this.ua.indexOf('spoofer')==-1) && (this.ua.indexOf('compatible') == -1)) ); 
  this.nav2 = (this.nav && (this.major == 2));
  this.nav3 = (this.nav && (this.major == 3)); 
  this.nav4 = (this.nav && (this.major == 4)); 
  this.nav4up = (this.nav && (this.major >= 4)); 
  this.nav5 = (this.nav && (this.major == 5)); 
  this.nav5up = (this.nav && (this.major >= 5)); 
  this.ie = (this.ua.indexOf("msie") != -1); 
  this.ie3 = (this.ie && (this.major == 2)); 
  this.ie4 = ( this.ie && (this.major == 4) && (this.ua.indexOf("msie 5.0")==-1) ); 
  this.ie4up = (this.ie && (this.major >= 4)); 
  this.ie5 = ( this.ie && (this.major == 4) && (this.ua.indexOf("msie 5.0")!=-1) ); 
  this.ie5up = (this.ie && !this.ie3 && !this.ie4); 
  this.opera = (this.ua.indexOf("opera") != -1); 
  this.webtv = (this.ua.indexOf("webtv") != -1); 
} 

var is = new ClientSniffer();

function myOnLoad() {
  // set up the mouse tracking
  if (is.nav4up) { 
    document.captureEvents(Event.MOUSEMOVE); 
  } 
//  document.onmousemove=mtrack;
  $('#dvSeating').hover(function(){$(this).show();},function(){$(this).hide();});
  $('#dvBeds').hover(function(){$(this).show();},function(){$(this).hide();});
  $('#dvTables').hover(function(){$(this).show();},function(){$(this).hide();});
  $('#dvContainers').hover(function(){$(this).show();},function(){$(this).hide();});
  $('#dvAccessories').hover(function(){$(this).show();},function(){$(this).hide();});
  $('#dvPortfolio').hover(function(){$(this).show();},function(){$(this).hide();});

  // preload rollover images
  preloadImages();
}

function mtrack(e) {
    var divs = Array("dvSeating","dvBeds","dvTables","dvContainers","dvAccessories","dvPortfolio");
    var width = 127;
    var y,x;
    if (is.nav4up) {
      y = e.pageY;
      x = e.pageX;
    }
    else {
      y = window.event.clientY;
      x = window.event.clientX;
    }

    // added by DC to fix bug, the following requires jquery and dimension plug-in,
    // please see header.html for included files
    var red_region_width = 762; // see first <TABLE ...> in header.html
    var offset = Math.round(($(document).width() - red_region_width) / 2);
    x = x - offset;
    //alert($(document).width());
    //alert(($(document).width() - red_region_width));
    //alert(offset);
    // ----------------------------------------------------------------------------

    if ( y < 76 ) {
      // hide the subnav if mouse is above or below threshold
      showHideLayers('dvBeds','','hide','dvSeating','','hide','dvTables','','hide','dvContainers','','hide','dvAccessories','','hide','dvPortfolio','','hide');
    }
    else {
      for ( var i=(divs.length-1);i>=0;i-- ) {
        if ( x > (i)*width ) {
      if ( (obj = document.getElementById(divs[i])) !=null ) {
        var height = 76+Number(obj.style.height.substr(0,obj.style.height.length-2));
        //alert(obj.id);
        if ( y > height ) {
        for ( n=0;n<divs.length;n++ ) {
          showHideLayers(divs[n],'','hide');
        }
        //showHideLayers('dvBeds','','hide','dvSeating','','hide','dvTables','','hide','dvContainers','','hide','dvAccessories','','hide','dvPortfolio','','hide');
        }
      }
      break;
    }
      }
    }
}

function newImage(arg) {
    if (document.images) {
        rslt = new Image();
        rslt.src = arg;
        return rslt;
    }
}

function changeImages() {
    if (document.images && (preloadFlag == true)) {
        for (var i=0; i<changeImages.arguments.length; i+=2) {
                        obj = findObj(changeImages.arguments[i]);
            obj.src = changeImages.arguments[i+1];
        }
    }
}

var preloadFlag = false;

function preloadImages() {
    if (document.images) {
        ddc_news_wishlist_over = newImage("images/ddc_news-over.gif");
        wishlist_over = newImage("images/wishlist-over.gif");
        ordering_over = newImage("images/ordering-over.gif");
        contact_us_over = newImage("images/contact_us-over.gif");
        seating_over = newImage("images/seating-over.gif");
        beds_over = newImage("images/beds-over.gif");
        tables_over = newImage("images/tables-over.gif");
        containers_over = newImage("images/containers-over.gif");
        portfolio_over = newImage("images/portfolio-over.gif");
        benches_over = newImage("images/benches-over.gif");
        accessories_over = newImage("images/accessories_over.gif");
        cocktail_tables_over = newImage("images/cocktail_tablesov.gif");
        consoles_over = newImage("images/consoles-over.gif");
        lighting_over = newImage("images/lighting-over.gif");
        ddc_projects_over = newImage("images/ddc_projects-over.gif");
        chairs_over = newImage("images/chairs-over.gif");
        bedroom_furniture_over = newImage("images/bedroom_furniture.gif");
        end_tables_over = newImage("images/end_tables-over.gif");
        home_theater_over = newImage("images/home_theater-over.gif");
        mirrors_over = newImage("images/mirrors-over.gif");
        ddc_model_rooms_over = newImage("images/ddc_model_roomsov.gif");
        club_chairs_over = newImage("images/club_chairs-over.gif");
        beds_beds_over = newImage("images/beds_beds-over.gif");
        extension_tables_over = newImage("images/extension_tables-over.gif");
        library_over = newImage("images/library-over.gif");
        rugs_over = newImage("images/rugs-over.gif");
        contract_projects_over = newImage("images/contract_projects.gif");
        ottomans_over = newImage("images/ottomans-over.gif");
        linens_over = newImage("images/linens-over.gif");
        desks_over = newImage("images/desks-over.gif");
        wall_units_over = newImage("images/wall_units-over.gif");
        accessories_other_over = newImage("images/accessories_other.gif");
        sectionals_over = newImage("images/sectionals-over.gif");
        mattresses_over = newImage("images/mattresses-over.gif");
        tables_other_over = newImage("images/tables_other-over.gif");
        containers_other_over = newImage("images/containers_other-over.gif");
        sofas_over = newImage("images/sofas-over.gif");
        stools_over = newImage("images/stools-over.gif");
        preloadFlag = true;
    }
}

function reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.pgW=innerWidth; document.pgH=innerHeight; onresize=reloadPage; }}
  else if (innerWidth!=document.pgW || innerHeight!=document.pgH) location.reload();
}
reloadPage(true);

function findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function showHideLayers() { //v6.0
  var i,p,v,obj,args=showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v;
		if (v=='visible') obj.display='block';
		if (v=='hidden') obj.display='none';
    }
}

function popup(loc,w,h) {
  w = ((w>0)?(w):(620));
  h = ((h>0)?(h):(650));
  var win = window.open(loc,'popup',"width="+w+",height="+h+",scrollbars=no,resize=no");
  win.focus();
}

function popupImage(loc,w,h) {
  w = ((w>0)?(w):(244));
  h = ((h>0)?(h):(162));
  var win = window.open('image_popup.php?url='+loc,'popup',"width="+w+",height="+h+",scrollbars=no,resize=no");
  win.focus();
}

function doSearch() {
  var search = document.forms.searchForm.search.value;
  if ( search.length > 0 ) {
    self.location = "products.php?search="+search;
  }
}

function popupFullCat() {
	var winFullCat = window.open('http://www.v-showroom.com/8200255/','showroom','width=780,height=465');
	winFullCat.focus();
}

function showFullCat() {
	if ($('#full-cat').length==0) {
		$('#header-con table:first tr:last').hide();
		$('input.searchbox').hide();
		$('#searchbutton').hide();
		if ($('#frontpage_image').length==1) {
			$('#frontpage_image').hide();
		} else {
			$('#site-wrapper').next('table').hide();
		}
		insertFullCatIFrame();
	} else {
		loadFullCatIUrl();
	}
}

function insertFullCatIFrame() {
	$('#site-wrapper').after('<div id="ful-cat-con" style="width:800px;height:500px;position:relative;"><iframe id="full-cat" width="800" height="500" border="0" frameborder="no"></iframe><div id="full-cat-loading" style="position:absolute;text-align: center;background: #000000;color: #ffffff; opacity:0.4;filter:alpha(opacity=40); width:762px;height:450px;top: 0;left:0;margin-left:19px;padding-top:50px;font-family:sans-serif;font-size:11px;"><img src="images/ajax-loader.gif"><br /><br />loading...</div></div>');
	loadFullCatIUrl();
	$('iframe#full-cat').load(function() {
		$('#full-cat-loading').hide();
	});
}

function loadFullCatIUrl() {
    $('iframe#full-cat').attr('src', 'http://www.v-showroom.com/8200255/productgroup/');
}
