// JavaScript Document
function getElementLeft(elm) 
{
    var x = 0;

    //set x to elm�s offsetLeft
    x = elm.offsetLeft;

    //set elm to its offsetParent
    elm = elm.offsetParent;

    //use while loop to check if elm is null
    // if not then add current elm�s offsetLeft to x
    //offsetTop to y and set elm to its offsetParent

    while(elm != null)
    {
        x = parseInt(x) + parseInt(elm.offsetLeft);
        elm = elm.offsetParent;
    }
    return x;
}

function getElementTop(elm) 
{
    var y = 0;

    //set x to elm�s offsetLeft
    y = elm.offsetTop;

    //set elm to its offsetParent
    elm = elm.offsetParent;

    //use while loop to check if elm is null
    // if not then add current elm�s offsetLeft to x
    //offsetTop to y and set elm to its offsetParent

    while(elm != null)
    {
        y = parseInt(y) + parseInt(elm.offsetTop);
        elm = elm.offsetParent;
    }

    return y;
}
function Large(obj, width, height)
{
    var imgbox=document.getElementById("imgbox");
    imgbox.style.visibility='visible';
    var img = document.createElement("img");
    img.src=obj.src.replace('_sml.jpg','.jpg')
    img.style.width=width+'px';
    img.style.height=height+'px';
    
    if(img.addEventListener){
        img.addEventListener('mouseout',Out,false);
    } else {
        img.attachEvent('onmouseout',Out);
    }             
    imgbox.innerHTML='';
    imgbox.appendChild(img);
    imgbox.style.left=(getElementLeft(obj)-50) +'px';
    imgbox.style.top=(getElementTop(obj)-50) + 'px';
    imgbox.style.width=width + 2 +'px';
    imgbox.style.height=height + 2 + 'px';
    imgbox.style.padding = '4px';

}
function Out()
{
    document.getElementById("imgbox").style.visibility='hidden';
}

function doShowHide(vid)
{
  var element1 = document.getElementById(vid);
  var div = document.getElementsByTagName('div');
  for (var i = 0; i < div.length; i++)
  {
       divId = div[i].id;
       if (divId != vid && divId.indexOf('_video')>0)
       {
        document.getElementById(divId).style.visibility = 'hidden';
        document.getElementById(divId).style.display = 'none';
       }
  }
  if (element1.style.visibility=='visible')
  {
    element1.style.visibility='hidden';
    element1.style.display='none';

  }
  else
  {
    element1.style.visibility='visible';
    element1.style.display='block';
    element1.style.marginLeft = '-' + parseInt(element1.offsetWidth / 2) + 'px';

  }

 }
  var thisWidth, thisHeight, thisScroll, thisScrollWidth, thisScrollHeight;
  var origleft = new Array(), origtop = new Array(), origshadowleft = new Array(), origshadowtop = new Array();
function doShowHide2(vid)
{
  var element1 = document.getElementById(vid);
  var element1_shadow = document.getElementById('vid_ShadowBox');

    if (origleft[vid]==undefined)
    {
      origleft[vid] = parseInt(element1.style.left)
      origtop[vid] = parseInt(element1.style.top);
    }
    if (origshadowleft['vid_ShadowBox']==undefined)
    {
      origshadowleft['vid_ShadowBox'] = parseInt(element1_shadow.style.left)
      origshadowtop['vid_ShadowBox'] = parseInt(element1_shadow.style.top);
    }
      // hide the other divs and the shadow
      var div = document.getElementsByTagName('div');
      for (var i = 0; i < div.length; i++)
      {
           divId = div[i].id;
           if (divId != vid && divId.indexOf('_video')>0)
           {
            document.getElementById(divId).style.visibility = 'hidden';
            document.getElementById(divId).style.display = 'none';
            if(origleft[divId]!=undefined)
            {
                document.getElementById(divId).style.left = origleft[divId] + 'px';
                document.getElementById(divId).style.top = origtop[divId] + 'px';
            }
           }
      }
      if(origshadowleft['vid_ShadowBox']!=undefined)
      {
        element1_shadow.style.left = origshadowleft['vid_ShadowBox'] + 'px';
        element1_shadow.style.top = origshadowtop['vid_ShadowBox'] + 'px';
      }

  // get the size of the window
  getThisSize();
  // get the new location for the video div
  thisleft = parseInt(parseInt(thisWidth /2) - (parseInt(element1_shadow.style.width) / 2));
  thistop = parseInt(parseInt(thisScroll) + origshadowtop['vid_ShadowBox']);
  // get the new location for the shadow div
  thisshadowleft = thisleft - (origleft[vid] - origshadowleft['vid_ShadowBox']);
  thisshadowtop = thistop - (origtop[vid] - origshadowtop['vid_ShadowBox']);

  if (element1.style.visibility=='visible')
  {
    element1.style.visibility='hidden';
    element1.style.display='none';
    element1_shadow.style.visibility='hidden';
    element1_shadow.style.display='none';

  }
  else
  {
    element1.style.visibility='visible';
    element1.style.display='block';
    element1.style.left = thisleft + 'px';
    element1.style.top = thistop + 'px';
    element1_shadow.style.visibility='visible';
    element1_shadow.style.display='block';
    element1_shadow.style.left = thisshadowleft + 'px';
    element1_shadow.style.top = thisshadowtop + 'px';

  }
 }

// Utility: Get the size of the window, and set myWidth and myHeight
// Credit to quirksmode.org

 function getThisSize() {

	// Window Size

	if (self.innerHeight) { // Everyone but IE
		thisWidth = window.innerWidth;
		thisHeight = window.innerHeight;
		thisScroll = window.pageYOffset;
	} else if (document.documentElement && document.documentElement.clientHeight) { // IE6 Strict
		thisWidth = document.documentElement.clientWidth;
		thisHeight = document.documentElement.clientHeight;
		thisScroll = document.documentElement.scrollTop;
	} else if (document.body) { // Other IE, such as IE7
		thisWidth = document.body.clientWidth;
		thisHeight = document.body.clientHeight;
		thisScroll = document.body.scrollTop;
	}

	// Page size w/offscreen areas

	if (window.innerHeight && window.scrollMaxY) {
		thisScrollWidth = document.body.scrollWidth;
		thisScrollHeight = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight) { // All but Explorer Mac
		thisScrollWidth = document.body.scrollWidth;
		thisScrollHeight = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		thisScrollWidth = document.body.offsetWidth;
		thisScrollHeight = document.body.offsetHeight;
	}
}
function fade(eid)
{
  var element = document.getElementById(eid);
  if(element == null)
    return;

  if(element.FadeState == null)
  {
    if(element.style.opacity == null
        || element.style.opacity == ''
        || element.style.opacity == '1')
    {
      element.FadeState = 2;
    }
    else
    {
      element.FadeState = -2;
    }
  }

  if(element.FadeState == 1 || element.FadeState == -1)
  {
    // if fading in or out change to the oposite and change the time
    //element.FadeState = element.FadeState == 1 ? -1 : 1;
    //element.FadeTimeLeft = TimeToFade - element.FadeTimeLeft;
    element.FadeTimeLeft = TimeToFade;
  }
  else
  {
    element.FadeState = element.FadeState == 2 ? -1 : 1;
    element.FadeTimeLeft = TimeToFade;
    timer = setTimeout("animateFade(" + new Date().getTime() + ",'" + eid + "')", 33);
  }
}
function animateFade(lastTick, eid)
{
  var curTick = new Date().getTime();
  var elapsedTicks = curTick - lastTick;

  var element = document.getElementById(eid);

  if(element.FadeTimeLeft <= elapsedTicks)
  {
    element.style.opacity = (element.FadeState == 1 ? '1' : '0');
    element.style.filter = 'alpha(opacity = '
        + (element.FadeState == 1 ? '100' : '0') + ')';
    element.FadeState = (element.FadeState == 1 ? 2 : -2);
    return;
  }

  element.FadeTimeLeft -= elapsedTicks;
  var newOpVal = element.FadeTimeLeft/TimeToFade;
  if(element.FadeState == 1)
    newOpVal = 1 - newOpVal;

  element.style.opacity = newOpVal;
  element.style.filter = 'alpha(opacity = ' + (newOpVal*100) + ')';

  timer = setTimeout("animateFade(" + curTick + ",'" + eid + "')", 33);
}
function __getIEVersion() {
    var rv = -1; // Return value assumes failure.
    if (navigator.appName == 'Microsoft Internet Explorer') {
        var ua = navigator.userAgent;
        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null)
            rv = parseFloat(RegExp.$1);
    }
    return rv;
}

function __getOperaVersion() {
    var rv = 0; // Default value
    if (window.opera) {
        var sver = window.opera.version();
        rv = parseFloat(sver);
    }
    return rv;
}

var __userAgent = navigator.userAgent;
var __isIE =  navigator.appVersion.match(/MSIE/) != null;
var __IEVersion = __getIEVersion();
var __isIENew = __isIE && __IEVersion >= 8;
var __isIEOld = __isIE && !__isIENew;

var __isFireFox = __userAgent.match(/firefox/i) != null;
var __isFireFoxOld = __isFireFox && ((__userAgent.match(/firefox\/2./i) != null) || (__userAgent.match(/firefox\/1./i) != null));
var __isFireFoxNew = __isFireFox && !__isFireFoxOld;

var __isWebKit =  navigator.appVersion.match(/WebKit/) != null;
var __isChrome =  navigator.appVersion.match(/Chrome/) != null;
var __isOpera =  window.opera != null;
var __operaVersion = __getOperaVersion();
var __isOperaOld = __isOpera && (__operaVersion < 10);

function __parseBorderWidth(width) {
    var res = 0;
    if (typeof(width) == "string" && width != null && width != "" ) {
        var p = width.indexOf("px");
        if (p >= 0) {
            res = parseInt(width.substring(0, p));
        }
        else {
     		//do not know how to calculate other values (such as 0.5em or 0.1cm) correctly now
    		//so just set the width to 1 pixel
            res = 1;
        }
    }
    return res;
}


//returns border width for some element
function __getBorderWidth(element) {
	var res = new Object();
	res.left = 0; res.top = 0; res.right = 0; res.bottom = 0;
	if (window.getComputedStyle) {
		//for Firefox
		var elStyle = window.getComputedStyle(element, null);
		res.left = parseInt(elStyle.borderLeftWidth.slice(0, -2));
		res.top = parseInt(elStyle.borderTopWidth.slice(0, -2));
		res.right = parseInt(elStyle.borderRightWidth.slice(0, -2));
		res.bottom = parseInt(elStyle.borderBottomWidth.slice(0, -2));
	}
	else {
		//for other browsers
		res.left = __parseBorderWidth(element.style.borderLeftWidth);
		res.top = __parseBorderWidth(element.style.borderTopWidth);
		res.right = __parseBorderWidth(element.style.borderRightWidth);
		res.bottom = __parseBorderWidth(element.style.borderBottomWidth);
	}

	return res;
}


//returns the absolute position of some element within document
function getElementAbsolutePos(elemID) {
	var element;
	if (typeof(elemID) == "string")	{
		element = document.getElementById(elemID);
	}
	else {
		element = elemID;
	}

	var res = new Object();
	res.x = 0; res.y = 0;
	if (element !== null) {
    	res.x = element.offsetLeft;

		var offsetParent = element.offsetParent;
		var offsetParentTagName = offsetParent != null ? offsetParent.tagName.toLowerCase() : "";

        if (__isIENew  && offsetParentTagName == 'td') {
		    res.y = element.scrollTop;
		}
		else {
		    res.y = element.offsetTop;
		}

		var parentNode = element.parentNode;
		var borderWidth = null;

		while (offsetParent != null) {
			res.x += offsetParent.offsetLeft;
			res.y += offsetParent.offsetTop;

			var parentTagName = offsetParent.tagName.toLowerCase();

			if ((__isIEOld && parentTagName != "table") || (__isFireFoxNew && parentTagName == "td")  || __isChrome) {
				borderWidth = __getBorderWidth(offsetParent);
				res.x += borderWidth.left;
				res.y += borderWidth.top;
			}

			if (offsetParent != document.body && offsetParent != document.documentElement) {
				res.x -= offsetParent.scrollLeft;
				res.y -= offsetParent.scrollTop;
			}


			//next lines are necessary to fix the problem with offsetParent
   			if (!__isIE && !__isOperaOld || __isIENew) {
    			while (offsetParent != parentNode && parentNode !== null) {
					res.x -= parentNode.scrollLeft;
					res.y -= parentNode.scrollTop;
					if (__isFireFoxOld || __isWebKit) {
						borderWidth = __getBorderWidth(parentNode);
						res.x += borderWidth.left;
						res.y += borderWidth.top;
					}
    				parentNode = parentNode.parentNode;
    			}
			}

   			parentNode = offsetParent.parentNode;
    		offsetParent = offsetParent.offsetParent;
		}
	}
    return res;
}

