/*
+-----------------------------------------------------------------------+
| SiSTeR Zoomer Javascript Code - draglayers.js    						|
+-----------------------------------------------------------------------+
| Copyright (c) 2003-2005 Silver Screen Tele-Reality, Inc.				|
+-----------------------------------------------------------------------+
| The contents of this source file are the sole property of				|
| Silver Screen Tele-Reality, Inc.										|
| Unauthorized duplication or access is prohibited.						|
+-----------------------------------------------------------------------+
*/
is_opera = (navigator.userAgent.toLowerCase().indexOf("opera") != -1);
var curObj = {"top":null,"left":null}
var bDrag = false;
var dx = 0;
var dy = 0;
var mox = 0;
var moy = 0;
var zoomer_width = 570;
var zoomer_height = 400;
var moveable_zoomer = true;

function locToNum(loc)
{
	var sLoc = String(loc);
	return new Number(sLoc.replace(/px/,''));
}

function numToLoc(num)
{
	if (document.all)
	{
		return num;	
	}
	//alert(locToNum(num) + 'px');
	return locToNum(num) + 'px';	
}

var autoplay = true;
var movietype = null;
var video_visible = false
var wm_visible = false;
var player_open = false;
var zoomer_y;
var mouseX;
var mouseY;

function checkMovePlayer(obj)
{
	var scroll = getScroll();
	
	if ( !isFinite(scroll) )
	{
		scroll = 0;	
	}
	
	var client_width = getWinWidth();
	
	var client_height = getWinHeight();
	
	//alert(client_height);
	
	var bIsVisible = false;
	
	var top = locToNum(obj.style.top);
	var left = locToNum(obj.style.left);
	var width = locToNum(obj.style.width);
	var height = locToNum(obj.style.height);

	var newYLoc = mouseY;
	var mX = mouseX;
	
	if ( mX == undefined || mX == null || !isFinite(mX) )
	{
		mX = 0;	
	}
	
	if ( newYLoc == undefined || newYLoc == null || !isFinite(newYLoc) )
	{
		newYLoc = 0;	
	}

	
	if ( document.all )
	{
		newYLoc = newYLoc + scroll;
	}
	
	if ( scroll < top && ( ( top + height) < (scroll + client_height) ) && left > 0 )
	{
		bIsVisible = true;
	} else {
		if ( (newYLoc + height) > ( scroll + client_height ) )
		{
			newYLoc = newYLoc - ( ( newYLoc + height ) - ( scroll + client_height ) ) - 5;
		}
	}

	if ( moveable_zoomer && !bIsVisible )
	{
		movePlayer(mX,newYLoc);
	}
}

function movePlayer(x, y)
{
	if(x!=null && x!=undefined && isFinite(x))
	{
		flashLayer.style.left=numToLoc(x);
		flashLayer.style.visibility = "visible";
	}
	if(y!=null && y!=undefined && isFinite(y))
	{
		flashLayer.style.top=numToLoc(y);
		
		zoomer_y = y;
		
		flashLayer.style.visibility = "visible";
	}
	
}

function checkPlayerScrolledOffView(y)
{
	var scrollY = getScroll();
	var winH = getWinHeight();
	var tooLow = winH - zoomer_height + 20;
	if (y < scrollY)
	{
		y = scrollY + 5;
	}else if (y-scrollY > tooLow){
		y = winH - zoomer_height - 5;
	}
	return y;
}

function getWinHeight()
{
	var winH;
	if(document.all)
	{
		if ( is_compat )
		{
		   winH = document.documentElement.clientHeight;
		} else {
		   winH = document.body.clientHeight;
		}
	}else{
		winH = window.innerHeight;
	}
	return winH;
}

function getWinWidth()
{
	if(document.all)
	{
		var winW = document.body.clientWidth;
	}else{
		var winW = window.innerWidth;
	}
	return winW;
}

if ( zoomer_width == null ) 
{
	var zoomer_width = 570;
}

if ( zoomer_height == null ) 
{
	var zoomer_height = 400;
}

function getScroll() 
{
	if (window.pageYOffset)
	{
		y = window.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {
		y = document.documentElement.scrollTop;
	} else if (document.body) {
		y = document.body.scrollTop;
	}
	
	return y;
}
//Code modified to have the seperate draglayer
function player_dragThis()
{
	if ( !moveable_zoomer ) return;

	if ( client_type == "WMV" )
	{
		dragLayer.style.zIndex = 0;
		dragGalleryLayer.style.zIndex = 0;
	} else {
		dragLayer.style.zIndex = 10000;
		if(client_type == "FLV" )
	  	{
			dragGalleryLayer.style.zIndex = 10000;
		}	
	}
	
		dragLayer.style.visibility = "visible";
		if( client_type == "WMV" || client_type == "FLV" )
	  	{
			if(fullsizegallery_layer.style.visibility == "visible")
			{
				//alert("I am Full Size Visible");
				dragGalleryLayer.style.visibility = "visible";
			}	
			else
			{
				//alert("I am Full Size INVISIBLE");
				dragGalleryLayer.style.visibility = "hidden";
			}
			dragGalleryLayer.style.top = fullsizegallery_layer.style.top;
			dragGalleryLayer.style.left = fullsizegallery_layer.style.left;
		 }	
	flashLayer.style.visibility = "visible";
	dragLayer.style.top = flashLayer.style.top;
	dragLayer.style.left = flashLayer.style.left;
	

   if(needtoDrag == "flashLayer")
   {
        
        dragLayer.style.visibility = "visible";
        if( client_type == "WMV" || client_type == "FLV" )
	{
        	dragGalleryLayer.style.visibility = "hidden";
        }	
   	//alert("NeedtoDrag"+needtoDrag);
   	var tmp;
	tmp = dragLayer.style;
   	curObj = tmp;
	var str = "";
	var i=0;
	str = tmp.left;
	i= (!is_opera) ? str.substr(0,str.length-2) : str;
	dx = mouseX - i;
	str = tmp.top;
	i= (!is_opera) ? str.substr(0,str.length-2) : str;
	dy = mouseY - i;
	
   }
   else
   {
	//For Moving Gallery Div
	if( client_type == "WMV" || client_type == "FLV" )
	  {
		dragLayer.style.visibility = "hidden";
		dragGalleryLayer.style.visibility = "visible";
		var tmpGallery;
		//alert("Dragging Gallery"+dragGalleryLayer);
		tmpGallery = dragGalleryLayer.style;
	    
	   	curObj = tmpGallery;
		var str = "";
		var i=0;
		str = tmpGallery.left;
		i= (!is_opera) ? str.substr(0,str.length-2) : str;
		dx = mouseX - i;
		str = tmpGallery.top;
		i= (!is_opera) ? str.substr(0,str.length-2) : str;
		dy = mouseY - i; 
		//alert("NeedtoDrag"+needtoDrag);
	    }	
    }		
}

function mouseMove(e)
{
   	mouseX = (document.all) ? event.clientX : e.pageX;
	mouseY = (document.all) ? event.clientY : e.pageY;
    if (curObj)
    {
        curObj.left= mouseX - dx + 'px';
        curObj.top = mouseY - dy + 'px';
    }
}

function mouseUp() 
{
	var scr = getScroll();
	var w = zoomer_width;
	var h = zoomer_height;
	var winW = getWinWidth();
	var winH = getWinHeight();
	curObj = {"top":null,"left":null}
	 	if(needtoDrag == "flashLayer")
	  	 {
   
			var y = locToNum(dragLayer.style.top);
			var x = locToNum(dragLayer.style.left);
			
			//alert("dragLayer.style.visibility " +dragLayer.style.visibility);
			if (dragLayer.style.visibility != "hidden")
				{
					if (y < 0)
					{
						flashLayer.style.top= 5 + 'px';
					} else if (y+50-scr>winH) {
						flashLayer.style.top=winH+scr-50 + 'px';
					}else{
						flashLayer.style.top=dragLayer.style.top;
										
					}
					
					if (x+50<0)
					{
						flashLayer.style.left = 5 + 'px';
						
					} else if (x > winW) {
						flashLayer.style.left = winW - 50 + 'px';
						
						
					}else{
						flashLayer.style.left=dragLayer.style.left;
						
					}
					
					dragLayer.style.zIndex = 0;
					dragLayer.style.visibility = "hidden";
					
				}
		 }	
		else
		{
			if( client_type == "WMV" || client_type == "FLV" )
	 		{
				var y = locToNum(dragGalleryLayer.style.top);
				var x = locToNum(dragGalleryLayer.style.left);

				if (dragGalleryLayer.style.visibility != "hidden")
					{
						if (y < 0)
						{
							fullsizegallery_layer.style.top= 15 + 'px';
						} else if (y+50-scr>winH) {

							fullsizegallery_layer.style.top=winH+scr-50 + 'px';
						}else{
							fullsizegallery_layer.style.top=dragGalleryLayer.style.top;

						}

						if (x+50<0)
						{

							fullsizegallery_layer.style.left = 15 + 'px';
						} else if (x > winW) {
							fullsizegallery_layer.style.left = winW - 50 + 'px';

						}else{

							fullsizegallery_layer.style.left=dragGalleryLayer.style.left;
						}


						dragGalleryLayer.style.zIndex = 0;
						dragGalleryLayer.style.visibility = "hidden";
			 		}
			     }		
		
		}
}

function attachMouseEvents()
{
	if (document.layers)
	{
		document.captureEvents(Event.MOUSEMOVE);
	}
	document.onmousemove=mouseMove;
	document.onmouseup=mouseUp;	
}