function getPageSize() {
  var xScroll,yScroll;
  if(window.innerHeight && window.scrollMaxY) {  
    xScroll=window.innerWidth+window.scrollMaxX;
    yScroll=window.innerHeight+window.scrollMaxY;
  }
  else if(document.body.scrollHeight>document.body.offsetHeight) {
    xScroll=document.body.scrollWidth;
    yScroll=document.body.scrollHeight;
  }
  else {
    xScroll=document.body.offsetWidth;
    yScroll=document.body.offsetHeight;
  }
  
  var windowWidth, windowHeight;
  if(self.innerHeight) {
    if(document.documentElement.clientWidth)
      windowWidth=document.documentElement.clientWidth; 
    else
      windowWidth=self.innerWidth;
    
    windowHeight=self.innerHeight;
  }
  else if(document.documentElement && document.documentElement.clientHeight) {
    windowWidth=document.documentElement.clientWidth;
    windowHeight=document.documentElement.clientHeight;
  }
  else if(document.body) {
    windowWidth=document.body.clientWidth;
    windowHeight=document.body.clientHeight;
  } 
  
  if(yScroll<windowHeight)
    pageHeight=windowHeight;
  else
    pageHeight=yScroll;

  if(xScroll<windowWidth)
    pageWidth=xScroll;    
  else
    pageWidth=windowWidth;

  arrayPageSize=new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
  return arrayPageSize;
}

function getPageScroll() {
  var xScroll,yScroll;
  if(self.pageYOffset) {
    yScroll=self.pageYOffset;
    xScroll=self.pageXOffset;
  }
  else if(document.documentElement && document.documentElement.scrollTop) {
    yScroll=document.documentElement.scrollTop;
    xScroll=document.documentElement.scrollLeft;
  }
  else if(document.body) {
    yScroll=document.body.scrollTop;
    xScroll=document.body.scrollLeft; 
  }
  
  arrayPageScroll=new Array(xScroll,yScroll) 
  return arrayPageScroll;
}

function addVideos() {
  $.getJSON("xml/videos.js",
    function(data) {
      $.each(data.items,function(i,item) {
        var src;
        if(i%2==0)
          src='<a href="javascript:playVideo(\''+item.src+'\',\''+item.title+'\',\''+item.width+'\',\''+item.height+'\')" class="video" style="margin-left:46px">';
        else
          src='<a href="javascript:playVideo(\''+item.src+'\',\''+item.title+'\',\''+item.width+'\',\''+item.height+'\')" class="video">';
        
        if(item.newVideo=="true")
          src+='<div class="new"><img src="images/new.png" alt=""/></div>';
        
        src+='<div class="thumb"><img src="images/videoThumbnails/'+item.img+'" alt=""/></div>';
        src+=item.title;
        
        src+='</a>';
        $(".main").append(src);
      });
    }
  );
}

function playVideo(src,title,width,height) {
  var pageSize=getPageSize();
  var vWidth=parseInt(width)+22;
  var vHeight=parseInt(height)+35;

  window.scrollTo(0,0);

  $("body *").fadeOut(300);
  $("body").prepend('<div class="overlay"></div>');
  $(".overlay").append('<div class="videoPlayer" style="width:'+vWidth+'px; height:'+vHeight+'px;"></div>');
  
  $(".overlay .videoPlayer").css({
    left:pageSize[0]/2-$(".overlay .videoPlayer").width()/2,
    top:100
  });
  
  $(".overlay .videoPlayer").append(
    '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" width="'+width+'" height="'+height+'">'+
    '<param name="src" value="videos/'+src+'">'+
    '<param name="autoplay" value="true">'+
    '<param name="type" value="video/quicktime" width="'+width+'" height="'+height+'">'+
    '<embed src="videos/'+src+'" width="'+width+'" height="'+height+'" autoplay="true" type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/">'+
    '</object>'+
    '<div class="title">'+title+'</div>'+
    '<a href="javascript:closeVideo()" class="exit">Back</a>'
  ).css({opacity:"0.0"}).animate({opacity:"1.0"});
}

function closeVideo() {
  $(".overlay").fadeOut(300,function() {
    $(".overlay").remove();
    $("body *").fadeIn();
  });
}