  /* * * * * * * * * * * * *
   *  MEDIA VIEWER CLASS   *
   * * * * * * * * * * * * */

  function MediaItem(url, thump, text, mime, alternate,width,height,thumbnailwidth,thumbnailheight,prodmediapopup,prodmediapopupwidth,prodmediapopupheight)
  {
    this.Url       = url;
    this.Thump     = thump;
    this.Text      = text;
    this.Mime      = mime;
    this.Alternate = alternate;
    this.Width	   = width;
    this.Height	   = height;
    this.ThumbnailWidth	 = thumbnailwidth;
    this.ThumbnailHeight = thumbnailheight;
    this.ProdMediaPopup			= prodmediapopup;
    this.ProdMediaPopupWidth	= prodmediapopupwidth;
    this.ProdMediaPopupHeight	= prodmediapopupheight;
    this.ProdMediaPopupScroll	= "no"
    
    // Change popup size to fit window if screen size is smaller than image dimentions
    var ScreenW = screen.width; 
    var ScreenH = screen.height; 
    
    if(ScreenW < prodmediapopupwidth)
    {
		this.ProdMediaPopupWidth = ScreenW - 150;
		this.ProdMediaPopupScroll	= "yes"
    }
    
    if(ScreenH < prodmediapopupheight)
    {
		this.ProdMediaPopupHeight = ScreenH - 150;
		this.ProdMediaPopupScroll	= "yes"
    }
    
    
    
  }


  function MediaViewer()
  {
    
    if (!document.MediaViewers) document.MediaViewers = new Array();
    this.ID = document.MediaViewers.length;
    document.MediaViewers.push(this);

    this.MediaList = new Array();

    this.Width  = 0; 
    this.Height = 0;
    this.ThumbWidth  = 0; 
    this.ThumbHeight = 0;

    this.PictureProtection  = false; 
    this.PictureProtectionMessage = "";

    this.NavPrevText = "";
    this.NavNextText = "";


    this.Canvas   = "";
    this.Selector ="";
    this.NumItemsInRow = -1;
    
    this.NavigationStyle = "Thumbnail"; 
    this.Transition = "";
    this.PopupEnabled = true;
    
    this.MouseBehaviour = "Change";    
    this.AutoRotate = false;
    this.RotateInterval = 5000;
    this.RotationID = -1;
    
    this.StartRotation = MediaViewer_StartRotation;
    this.StopRotation = MediaViewer_StopRotation;
    
    this.AddMedia   = MediaViewer_AddMedia;
    this.Select     = MediaViewer_Select;
    this.Render     = MediaViewer_Render;
    this.Popup		= MediaViewer_Popup;
    this.PopupItem  = MediaViewer_PopupItem;
    this.Next		= MediaViewer_Next;
    this.Prev		= MediaViewer_Prev;
    
    this.MediaItemMouseOver = MediaViewer_MediaItemMouseOver;
    this.MediaItemMouseOut  = MediaViewer_MediaItemMouseOut;
    this.MediaItemMouseDown	= MediaViewer_MediaItemMouseDown;
    this.MediaItemClick     = MediaViewer_MediaItemClick;
    this.MediaBarMouseOver	= MediaViewer_MediaBarMouseOver;
    this.MediaBarMouseOut	= MediaViewer_MediaBarMouseOut;
    	
    this.SelectedIndex		= -1;
    
    
  }   

  function MediaViewer_AddMedia(item)
  {
    this.MediaList.push(item);
    if (parseInt(item.Width) > this.Width) {this.Width = parseInt(item.Width)}
    if (parseInt(item.Height) > this.Height) {this.Height = parseInt(item.Height)}
    if (item.ThumbnailWidth > this.ThumbWidth) {this.ThumbWidth = item.ThumbnailWidth}
    if (item.ThumbnailHeight > this.ThumbHeight) {this.ThumbHeight = item.ThumbnailHeight}
  }

  function MediaViewer_StartRotation()
  {
    this.RotationID = window.setInterval("document.MediaViewers["+this.ID+"].Next()", this.RotateInterval);  
  }

  function MediaViewer_StopRotation()
  {
    clearInterval(this.RotationID);
  }

  function MediaViewer_Select(index)
  {
    Can = document.getElementById(this.Canvas);
    Sel = document.getElementById(this.Selector);
    
    if(window.addEventListener){ // Mozilla, Netscape, Firefox
    Can.firstChild.style.position = 'relative';
    } else { // IE
    Can.firstChild.style.position = 'absolute';
    }
    
    
    
    try {Can.firstChild.filters[0].Apply();}catch(e) {}
    
    Can.firstChild.innerHTML = "<IMG Title=\""+ this.MediaList[index].Alternate + "\" SRC=\""+this.MediaList[index].Url+"\" OnClick=\"document.MediaViewers["+this.ID+"].Popup()\" OnMouseDown=\"document.MediaViewers["+this.ID+"].MediaItemMouseDown()\">";
   
    try {Can.firstChild.filters[0].Play();}catch(e) {}
    
    this.SelectedIndex		= index;

    
    switch (this.NavigationStyle)
    {
		case "Thumbnail" :
		    for (image in this.MediaList)
			{
				node = document.getElementById("Medias"+document.MediaViewers["+this.ID+"] + image);
							
				if (image == this.SelectedIndex)
				{
					node.className = "MediaLinkSelected_ProductInfo";
				}
				else
				{
					node.className = "MediaLink_ProductInfo";
				}
			}
			break;
		case "Textlinks" :
		    for (image in this.MediaList)
			{
				node = document.getElementById("Medias"+document.MediaViewers["+this.ID+"] + image);
							
				if (image == this.SelectedIndex)
				{
					node.className = "MediaLinkSelected_ProductInfo";
				}
				else
				{
					node.className = "MediaLink_ProductInfo";
				}
			}
			break;
		case "NavBar" :
		    document.getElementById("MediaViewLabel"+this.ID).innerHTML = this.MediaList[this.SelectedIndex].Text;
			break;
		default:
			break
	}	
    
  }

  function MediaViewer_Popup()
  {
    this.PopupItem(this.SelectedIndex);
  }

 function MediaViewer_PopupItem(index)
 {
    if (this.PopupEnabled == true)
    {
        var picprotectmsg = "";

        if (this.PictureProtection) {
            picprotectmsg = this.PictureProtectionMessage
        }

        var popupurl = "/shop/ImagePopup.asp?Title=" + escape(this.MediaList[index].Text) + "&Image=" + this.MediaList[index].ProdMediaPopup + "&ProtectMessage=" + picprotectmsg;
        PopupWindow = window.open(popupurl, "PopupI" + this.ID + "P" + index, "displayWindow,width=" + (this.MediaList[index].ProdMediaPopupWidth) + ",height=" + (this.MediaList[index].ProdMediaPopupHeight) + ",scrollbars=" + (this.MediaList[index].ProdMediaPopupScroll) + ",status=no,resizable=yes");
		//PopupWindow.document.write("<HEAD><TITLE>"+this.MediaList[index].Text+"</TITLE><META HTTP-EQUIV=\"imagetoolbar\" CONTENT=\"no\"></HEAD><BODY LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0><IMG SRC=\""+ this.MediaList[index].ProdMediaPopup +"\" Onmousedown=\"window.close()\" style=\"cursor:pointer;\"></BODY>");
		//PopupWindow.document.close();
    }
 }

  function MediaViewer_MediaItemClick(index,obj)
  {
		switch (this.MouseBehaviour)
		{
			case "Change" :
				this.Select(index);
			break;
			case "Popup"  :
				this.PopupItem(index);
			break;
		}
  }

  function MediaViewer_MediaItemMouseOver(index,obj)
  {
  		switch (this.MouseBehaviour)
		{
			case "Change" :
			    if (obj) obj.className = "MediaLinkHover_ProductInfo"
				if (index == this.SelectedIndex) obj.className = "MediaLinkSelected_ProductInfo"
			break;
			case "Popup"  :
				this.Select(index);
			break;
		}
  }

  function MediaViewer_MediaItemMouseOut(index,obj)
  {
    if (obj) obj.className = "MediaLink_ProductInfo"
    if (index == this.SelectedIndex) obj.className = "MediaLinkSelected_ProductInfo"    
  }

  function MediaViewer_MediaBarMouseOver(obj)
  {

	if ('MediaViewerSelectorNavBarLeft MediaLink_ProductInfo')
	{
		obj.className = 'MediaViewerSelectorNavBarLeft MediaLinkHover_ProductInfo'
	}
	if ('MediaViewerSelectorNavBarCenter MediaLink_ProductInfo')
	{
		obj.className = 'MediaViewerSelectorNavBarCenter MediaLinkHover_ProductInfo'
	}
	if ('MediaViewerSelectorNavBarRight MediaLink_ProductInfo')
	{
		obj.className = 'MediaViewerSelectorNavBarRight MediaLinkHover_ProductInfo'
	}

  }

  function MediaViewer_MediaBarMouseOut(obj)
  {
	if ('MediaViewerSelectorNavBarLeft MediaLinkHover_ProductInfo')
	{
		obj.className = 'MediaViewerSelectorNavBarLeft MediaLink_ProductInfo'
	}
	if ('MediaViewerSelectorNavBarCenter MediaLinkHover_ProductInfo')
	{
		obj.className = 'MediaViewerSelectorNavBarCenter MediaLink_ProductInfo'
	}
	if ('MediaViewerSelectorNavBarRight MediaLinkHover_ProductInfo')
	{
		obj.className = 'MediaViewerSelectorNavBarRight MediaLink_ProductInfo'
	}
  }


  function MediaViewer_MediaItemMouseDown()
  {
	if (this.PictureProtection == true) 
	{
		var browser = navigator.appName.substring ( 0, 9 );
		var event_number = 0;
		if (browser=="Microsoft")
			event_number = event.button;
		else if (browser=="Netscape")
			event_number = e.which;

		if ( event_number==2 || event_number==3 ) {
			alert (this.PictureProtectionMessage);
			return (false);
		}
		return (true);
	}
  }

  function MediaViewer_Next()
  {
    NewIndex = this.SelectedIndex +1;
    if (NewIndex > this.MediaList.length -1) NewIndex = 0
    this.Select(NewIndex);
  }

  function MediaViewer_Prev()
  {
    NewIndex = this.SelectedIndex -1;
    if (NewIndex < 0) NewIndex = this.MediaList.length -1;
    this.Select(NewIndex);
  }


  function MediaViewer_Render()
  {
  
    Can = document.getElementById(this.Canvas);
    
    Can.style.width = this.Width;
    Can.style.height = this.Height;
    
    Can.OnClick = this.Popup;
    
    Can.innerHTML = "<DIV STYLE=\"" + this.Transition + "\"></DIV>";

    Sel = document.getElementById(this.Selector);
    Sel.innerHTML = ""
    
    
    switch (this.NavigationStyle)
    {
		case "Thumbnail" :
		    for (image in this.MediaList)
			{
				if ((image % this.NumItemsInRow == 0) && (image > 0) && (this.NumItemsInRow > 0)) Sel.innerHTML += "<BR>"
				Sel.innerHTML += "<IMG ID=\"Medias"+document.MediaViewers["+this.ID+"] + image +"\" CLASS=\"MediaLink_ProductInfo\" ALT=\"" + this.MediaList[image].Alternate + "\" SRC=\"" + this.MediaList[image].Thump + "\" OnClick=\"document.MediaViewers["+this.ID+"].MediaItemClick("+image+",this)\" OnMouseOver=\"document.MediaViewers["+this.ID+"].MediaItemMouseOver("+image+",this)\" OnMouseOut=\"document.MediaViewers["+this.ID+"].MediaItemMouseOut("+image+",this)\">";
			}
			break;
		case "Textlinks" :
		    for (image in this.MediaList)
			{
				if ((image % this.NumItemsInRow == 0) && (image > 0) && (this.NumItemsInRow > 0)) Sel.innerHTML += "<BR>"
				Sel.innerHTML += "<SPAN ID=\"Medias"+document.MediaViewers["+this.ID+"] + image +"\" CLASS=\"MediaLink_ProductInfo\" OnClick=\"document.MediaViewers["+this.ID+"].MediaItemClick("+image+",this)\" OnMouseOver=\"document.MediaViewers["+this.ID+"].MediaItemMouseOver("+image+",this)\" OnMouseOut=\"document.MediaViewers["+this.ID+"].MediaItemMouseOut("+image+",this)\">" + this.MediaList[image].Text + "</SPAN>&nbsp;";
			}
			break;
		case "NavBar" :
		
				if (this.NavPrevText.indexOf('.gif') > -1 || this.NavPrevText.indexOf('.jpg') > -1)
				{
					nPrevText = "<IMG SRC=\""+this.NavPrevText+"\" BORDER=\"0\">"
				}
				else
				{
					nPrevText = this.NavPrevText;
				}
				
				if (this.NavNextText.indexOf('.gif') > -1 || this.NavNextText.indexOf('.jpg') > -1)
				{
					nNextText = "<IMG SRC=\""+this.NavNextText+"\" BORDER=\"0\">"
				}
				else
				{
					nNextText = this.NavNextText;
				}

				
		        x = ""
				x += "<TABLE CLASS=\"MediaViewerSelectorNavBar\" WIDTH=\"100%\" CELLSPACING=\"0\" CELLPADDING=\"0\" BORDER=\"0\">";
				x += "  <TR>";
				x += "    <TD CLASS=\"MediaViewerSelectorNavBarLeft MediaLink_ProductInfo\" WIDTH=\"10\" ALIGN=\"LEFT\" OnClick=\"document.MediaViewers["+this.ID+"].Prev()\" OnMouseOver=\"document.MediaViewers["+this.ID+"].MediaBarMouseOver(this)\" OnMouseOut=\"document.MediaViewers["+this.ID+"].MediaBarMouseOut(this)\">"+nPrevText+"</TD>";
				x += "    <TD CLASS=\"MediaViewerSelectorNavBarCenter MediaLink_ProductInfo\" ALIGN=\"CENTER\" OnMouseOver=\"document.MediaViewers["+this.ID+"].MediaBarMouseOver(this)\" OnMouseOut=\"document.MediaViewers["+this.ID+"].MediaBarMouseOut(this)\"><SPAN CLASS=\"MediaViewerSelectorNavBarText\" ID=\"MediaViewLabel"+this.ID+"\"></SPAN></TD>";
				x += "    <TD CLASS=\"MediaViewerSelectorNavBarRight MediaLink_ProductInfo\" WIDTH=\"10\" ALIGN=\"RIGHT\" OnClick=\"document.MediaViewers["+this.ID+"].Next()\" OnMouseOver=\"document.MediaViewers["+this.ID+"].MediaBarMouseOver(this)\" OnMouseOut=\"document.MediaViewers["+this.ID+"].MediaBarMouseOut(this)\">"+nNextText+"</TD>";
				x += "  </TR>";
				x += "</TABLE>";
				Sel.innerHTML += x;
			break;
			
		default:
			break
	}	
    

    this.Select(0);

    if (this.AutoRotate) this.StartRotation();
  }
