function dsfitimage(target, upscale, maineffect){
boxH = target.parentNode.offsetHeight;
boxW = target.parentNode.offsetWidth;
imgH = target.offsetHeight;
imgW = target.offsetWidth;
imgOrient = imgW/imgH; 
//debug(boxH+'-'+boxW+':<img src="'+target.getAttribute('src')+'"/>');
if (imgW >= imgH){
  if (imgW > boxW) {
//debug('1:<img src="'+target.getAttribute('src')+'"/>');
    imgW = boxW; 
    imgH = boxW/imgOrient;
    target.style.left = '0px';
    target.style.top  = (boxH - imgH)/2 + 'px';
    target.style.width = imgW+'px';
    target.style.height= imgH+'px';
  } else
  if (imgW <= boxW){
//debug('2:<img src="'+target.getAttribute('src')+'"/>');
    if (upscale){
      imgW = boxW;
      imgH = boxW/imgOrient;
      if (imgH > boxH){
        imgH = boxH;
        imgW = boxH*imgOrient;
      }
      target.style.left = (boxW - imgW)/2 + 'px';
      target.style.top  = (boxH - imgH)/2 + 'px';
      target.style.width = imgW+'px';
      target.style.height= imgH+'px';
    } else {  
      target.style.left = imgW < boxW ? (boxW - imgW)/2 + 'px' : '0px';
      target.style.top  = (boxH - imgH)/2 + 'px';
    }
  }
} else {
  if (imgH > boxH) {
//debug('3:<img src="'+target.getAttribute('src')+'"/>');
    imgH = boxH; 
    imgW = boxH*imgOrient;
    target.style.left = (boxW - imgW)/2 + 'px';
    target.style.top  = '0px';
    target.style.width = imgW+'px';
    target.style.height= imgH+'px';
  } else
  if (imgH <= boxH){
//debug('4:<img src="'+target.getAttribute('src')+'"/>');
    if (upscale){
      imgH = boxH;
      imgW = boxH*imgOrient;
      if (imgW > boxW){
        imgW = boxW;
        imgH = boxW/imgOrient;
      }
      target.style.left = (boxW - imgW)/2 + 'px';
      target.style.top  = (boxH - imgH)/2 + 'px';
      target.style.width = imgW+'px';
      target.style.height= imgH+'px';      
    } else {
      target.style.left = (boxW - imgW)/2 + 'px';
      target.style.top  = imgH < boxH ? (boxH - imgH)/2 + 'px' : '0px';
    }
  }
}
if (maineffect == true){
$('dscontent').style.display = 'none';
target.style.visibility= 'visible';
$('dstitle').style.visibility = 'visible';
$('dscontent').appear({duration:1});
} else {
target.style.display = 'block';
target.style.visibility = 'visible';
//target.show();
}
};

function dsshowimage(target, medurl, ititle, idescr){
$('dstitle').style.visibility = 'hidden';
if (document.getElementById(target)){
$(target).innerHTML = "<img style='position:relative;top:0px; left:0px; visibility:hidden;' onload='dsfitimage(this, true, true);' src='"+medurl+"'/>";
}
//$('dstitle').innerHTML = ititle + " - " + idescr;
$('dstitle').innerHTML = idescr;
};

function dsshowsplash(medurl, ititle, idescr){
if ($('splashcontent')){
$('splashcontent').innerHTML = "<img style='position:relative;top:0px; left:0px; visibility:hidden;' onload='dsfitimage(this, true);' src='"+medurl+"'/>";
}
};

function fadeSplash(){
$('splash').fade();
};

function debug(string){
$("debug").innerHTML += string+'<br>';
};

function kickOff(){
try{
activateScroller();
}catch(err){alert(err);}
};

slider = null;
function activateScroller(){
scrollbox = $('dsstrip');
scrollH = scrollbox.scrollHeight;
boxH = scrollbox.offsetHeight;
diff = scrollH - boxH;
if (diff > 0){
dsbuttheight = (boxH - diff) <= 40 ? 40 : (boxH - diff);
$('dsbutton').style.height = dsbuttheight + 'px';
slider = new Control.Slider('dsbutton', 'dsscroll', {axis:'vertical', onSlide: function(v) { scrollVertical(v, scrollbox, slider); }, onchange: function(v) { scrollVertical(v, scrollbox, slider); }
});
} else {
$('dsbutton').style.display = 'none';
}
};

function scrollVertical(value, element, slider) {
element.scrollTop = Math.round(value/slider.maximum*(element.scrollHeight-element.offsetHeight));
};
