// JavaScript Document for Blyth

// functions for hide/display HTML element

var timerID = null;
var timerIDold = null;
var timerRunning = false;
var timerRunningold = false;
var itemidold = '';
var maxheightold = 0;

function stopclock(tim) {
  if (tim == 'timerID') {
    if (timerRunning) {
      clearInterval(timerID);
    }
    timerRunning = false;
  } else {
    if (timerRunningold) {
      clearInterval(timerIDold);
    }
    timerRunningold = false;
  }
}

function slowflipitem(itemid,maxheight) {
  var item = document.getElementById(itemid);
  var itemold = document.getElementById(itemidold);
  item.style.overflow = "hidden";
  stopclock('timerID');
  if (item.style.display == "none") {
    item.style.height = "1px";
    item.style.display = "block";
    if(itemidold!='') {
      timerIDold = setInterval("slowflipitemflip('"+itemidold+"',"+maxheightold+",'up','timerIDold')",20);
      timerRunningold = true;
    }
    itemidold = itemid;
    maxheightold = maxheight;
    timerID = setInterval("slowflipitemflip('"+itemid+"',"+maxheight+",'down','timerID')",50);
  } else {
    timerID = setInterval("slowflipitemflip('"+itemid+"',"+maxheight+",'up','timerID')",20);
    itemidold = '';
    maxheightold = 0;
  }
  timerRunning = true;
}

function slowflipitemflip(itemid,maxheight,how,tim) {
  var item = document.getElementById(itemid);
  if (how == 'down') {
    if (item.offsetHeight > (maxheight - 8)) {
      item.style.height = "auto";
      stopclock(tim);
    } else {
      item.style.height = (item.offsetHeight + 8)+"px";
    }
  } else {
    if (item.offsetHeight < 15) {
      stopclock(tim);
      item.style.display = "none";
    } else {
      item.style.height = (item.offsetHeight - 15)+"px";
    }
  }
}

function winOpen(soub,w,h)
{
  var start=window.open(soub + '&w='+ w +'&h='+ h,'open','width='+ w +',height=' + h +',top=20,left=20');
	start.focus();
}

function dejTopFlash(relLink,flash,flashimg)
{
  var flashcontainer = document.getElementById('flashcontainer');
  
  if(navigator.plugins)
  {
  	var x = navigator.plugins["Shockwave Flash"];
  	var y = navigator.plugins["Shockwave Flash 2.0"];
  		
  	if(x || y)
  	{
  	  flashcontainer.style.backgroundImage = flashimg;
  		flashcontainer.innerHTML = flash;
  	}
  }
  else if(navigator.mimeTypes)
  {
  	var x = navigator.mimeTypes['application/x-shockwave-flash'];
  	if(x && x.enabledPlugin)
  	{
  	  flashcontainer.style.backgroundImage = flashimg;
  		flashcontainer.innerHTML = flash;
  	}
  }
  //alert(flashcontainer);
}
