function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

var dragObject = null; 
var posXinsideSlider = 0;
var galleryPos = 0;

function initPage() { 
  
	var object = MM_findObj('view_container');
	if ( object ) {
		GALLERY_SPEED = 1;
		object.onmousemove = changeGalleryProcess;
		if (object.captureEvents) object.captureEvents(Event.MOUSEMOVE);
		var intervalID = setInterval('moveGallery()', 50);
		GALLERY_WIDTH = GALLERY_BASE_WIDTH;
	}
	
	SCROLLBARWIDTH = getScrollbarWidth();
	
}

function getScrollbarWidth() {
	document.body.style.overflow = 'hidden';
	var width = document.body.clientWidth;
	document.body.style.overflow = 'scroll';
	width -= document.body.clientWidth;
	if(!width) width = document.body.offsetWidth-document.body.clientWidth;
	document.body.style.overflow = '';
	return width;
}

function mouseCoords(ev){   
	if(ev.pageX || ev.pageY){   
		return {x:ev.pageX, y:ev.pageY};   
	}   
	return {   
		x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,   
		y:ev.clientY + document.body.scrollTop  - document.body.clientTop   
	};   
}   

var GALLERY_SPEED = 0;

function moveGallery() {
	var object = MM_findObj('view_container');
	if ( object ) {
		if ( object && GALLERY_ACTIVE && GALLERY_SPEED < 0 && (parseInt(object.style.left) - GALLERY_SPEED) <= 0 )
			object.style.left = (parseInt(object.style.left) - GALLERY_SPEED) + "px";
		else if ( object && GALLERY_ACTIVE && GALLERY_SPEED < 0 && parseInt(object.style.left) < 0 )
			object.style.left = "0px";
		else if ( object && GALLERY_ACTIVE && GALLERY_SPEED > 0 && ( ( -1 * parseInt(object.style.left)) + 742 ) < (GALLERY_WIDTH-GALLERY_SPEED) )
			object.style.left = (parseInt(object.style.left) - GALLERY_SPEED) + "px";
		else if ( object && GALLERY_ACTIVE && GALLERY_SPEED > 0 && ( ( -1 * parseInt(object.style.left)) + 742 ) < GALLERY_WIDTH ) 
			object.style.left = "-" + (GALLERY_WIDTH - 742) + "px";			
	}
}

function stopGallery(e) {
	GALLERY_SPEED = 0;
	GALLERY_ACTIVE = false;
}

function changeGalleryProcess(e) {
	var posx = 0;
	if (!e) var e = window.event;
	if (e.pageX) 	{
		posx = e.pageX;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
	}
	
	var wWidth = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		wWidth = window.innerWidth - SCROLLBARWIDTH;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		wWidth = document.documentElement.clientWidth;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		wWidth = document.body.clientWidth;
	}
	
	posx = posx - Math.round((wWidth-998)/2) - 242;
	
	var max = 3;
	var min = 0;
	if ( posx >= 371 && posx <= 372 )
		GALLERY_SPEED = 0;
	else if ( posx < 371 ) {
		GALLERY_SPEED = -1 * (max - Math.round(((max-min)/370)*posx)); 
	} else if ( posx > 372 ) {
		GALLERY_SPEED = min + Math.round(((max-min)/370)*(posx-372));
	}
			
	if ( dragObject )
		GALLERY_SPEED = 0; 
}