// JavaScript Document

IE4 = (document.all) ? 1 : 0;
NS4 = (document.layers) ? 1 : 0;
ver4 = (IE4 || NS4) ? 1 : 0;
var agt=navigator.userAgent;
var bad=false;
var isMac = 0;
if ((agt.indexOf("Mac")!=-1)) {
  isMac = 1;
  if (IE4) {bad=true;}
}

function getObj(objectId)
{
// cross-browser function to get an object's style object given its id
    if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	this.obj = document.getElementById(objectId);
	this.style = document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	this.obj = document.all(objectId);
	this.style = document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this won't find nested layers
	this.obj = document.layers[objectId];
	this.style = document.layers[objectId];
    } else {
	return false;
    }
}

function writit(text,id) {
	if (document.getElementById)
	{
		x = document.getElementById(id);
		x.innerHTML = '';
		x.innerHTML = text;
	}
	else if (document.all)
	{
		x = document.all[id];
		x.innerHTML = text;
	}
}

function zoomImg(wID){
	myWindow=window.open('/popup_img.php?id='+wID+'','','status=yes,width=80,height=80,scrollbars=1');
	myWindow.focus();
}

function showGallery(){
	myWindow=window.open('/popup_gallery.php','','status=yes,width=728,height=643,scrollbars=0');
	myWindow.focus();
}

function getLayerHt(wLayerObj){
	if (document.layers) {
		contHt = wLayerObj.style.clip.bottom;
	} else if (document.getElementById || document.all) {
		contHt = wLayerObj.obj.offsetHeight;
	}
	return contHt;
}





function goToPage(wPage){
	setFlashVariables('mymovie','page='+wPage);
}

function fileLinks() {
	baseURL = document.domain;
    var fileLink;
    if (document.getElementsByTagName('a')) {
        for (var i = 0; (fileLink = document.getElementsByTagName('a')[i]); i++) {
			if (fileLink.name != "") {
				fileLink.id = fileLink.name;
			}
		
			currPage = document.location.href;
			
			if (currPage.indexOf('#') != -1) {
				currPage = currPage.substring(0, currPage.indexOf('#'));
			}
			if (currPage.indexOf('?a=') != -1) {
				currPage = currPage.substring(0, currPage.indexOf('?a='));
			}
			
			linkPage = fileLink.href;
			if (linkPage.indexOf('?') != -1) {
				linkPage = linkPage.substring(0, linkPage.indexOf('?'));
			}
			if (linkPage.indexOf('#') != -1) {
				linkPage = linkPage.substring(0, linkPage.indexOf('#'));
			}
			
			if (linkPage == currPage) {
				if (fileLink.href.indexOf('#') != -1) {
					anchorID = fileLink.href.substring(fileLink.href.indexOf('#')+1);
				} else {
					anchorID = fileLink.href.substring(fileLink.href.indexOf('?a=')+3);
				}
				if (anchorID != "") {
					fileLink.href = "#";
					fileLink.onclick = Function("dw_scrollObj.scrollToAnchor('"+anchorID+"', 'wn', 'lyr1'); return false;");
				}
			}
			
        }
    }
}




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;
}

function MM_validateForm() { //v4.0
	errors = "";
	var i,p,q,nm,test,num,min,max,args=MM_validateForm.arguments;
	for (i=0; i<(args.length-2); i+=3) { 
		test=args[i+2]; val=MM_findObj(args[i]); myName=args[i+1];
		if (val) { nm=val.name; if ((val=val.value)!="") {
			if (test.indexOf('isEmail')!=-1) { 
				p=val.indexOf('@');
				if (p<1 || p==(val.length-1)) errors+='- '+myName+' must contain an e-mail address.\n';
			} else if (test!='R') {
				num = parseFloat(val);
				if (isNaN(val)) errors+='- '+myName+' must contain a number.\n';
				if (test.indexOf('inRange') != -1) {
					p=test.indexOf(':');
					min=test.substring(8,p); max=test.substring(p+1);
					if (num<min || max<num) errors+='- '+myName+' must contain a number between '+min+' and '+max+'.\n';
				} 
			} 
		} else if (test.charAt(0) == 'R') errors += '- '+myName+' is required.\n'; 
		} 
	}
	if (errors) alert('The following error(s) occurred:\n'+errors);
	document.MM_returnValue = (errors == '');
}


function submitSubscribe(){
	MM_validateForm(
			'subEmail','Your email','RisEmail'
					);
	if (document.MM_returnValue == true) {
		var contHolder = $('subCont');
		contHolder.innerHTML = '<p>Sending...</p>';
		postData = 'name=&email='+urlencode(document.subForm.subEmail.value);
		
		var httpReq = getNewHTTPrequest('POST');
		if (!httpReq) {
			alert('Giving up :( Cannot create an XMLHTTP instance');
			return false;
		}
		
		httpReq.onreadystatechange = function() { doneSubscribe(httpReq); };
		httpReq.open('POST', 'http://'+document.domain+'/subscribe.php', true);
		
		httpReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		httpReq.setRequestHeader("Content-length", postData.length);
		httpReq.setRequestHeader("Connection", "close");
		
		httpReq.send(postData);
	} else {
		return false;
	}
}
function doneSubscribe(httpRequest){
	if (httpRequest.readyState == 4) {
		var contHolder = $('subCont');
		if (httpRequest.status == 200) {
			contHolder.innerHTML = '<p>'+ httpRequest.responseText +'</p>';
		} else {
			contHolder.innerHTML = '<p>There was a problem with the sending of your subscription.</p>';
		}
	}
}







$(document).ready(
	function(){
		$(window).resize(function() {
			sizeContent();
		});
		sizeContent();
	}
);

var createdScroll = 0;

function initScrollPane(){
	$('.scrollable').jScrollPane({showArrows:true, scrollbarWidth:13, scrollbarMargin:0});
	createdScroll = 1;
}

function sizeContent(){
	if (createdScroll == 1) {
		$('.scrollable').jScrollPaneRemove();
	}

	$(".scrollable, #hold, #hold2").css({
		"height" : 1
	});
	
	arrPageSizes = ___getPageSize();
	var pageHeight = arrPageSizes[1];
	var windowHeight = arrPageSizes[3];
	
	$(".scrollable, #hold, #hold2").css({
		"height" : Math.max(440, (windowHeight - 235))
	});
	
	initScrollPane();
}






/*
 THIRD FUNCTION
 getPageSize() by quirksmode.com
 
 return Array Return an array with page width, height and window width, height
*/
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){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
};

/*
 THIRD FUNCTION
 getPageSize() by quirksmode.com
 
 return Array Return an array with page width, height and window width, height
*/
function ___getPageScroll() {
	var xScroll, yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}
	arrayPageScroll = new Array(xScroll,yScroll);
	return arrayPageScroll;
};



