// JavaScript Document

// ISF1.11 :: Image swap-fade 
// *****************************************************
// DOM scripting by brothercake -- http://www.brothercake.com/
//******************************************************
//global object
var isf = { 'clock' : null, 'fade' : true, 'count' : 1 }
//*******************************************************


//swapfade setup function
function swapfade()
{
	//if the timer is not already going
	if(isf.clock == null)
	{
		//copy the image object 
		isf.obj1 = arguments[0];
		isf.obj2 = arguments[2];
		isf.obj3 = arguments[4];
		
		//copy the image src argument 
		isf.src1 = arguments[1];
		isf.src2 = arguments[3];
		isf.src3 = arguments[5];
		
		isf.alt = arguments[6];
		
		//store the supported form of opacity on object 1 (they all support the same form opacity)
		if(typeof isf.obj1.style.opacity != 'undefined')
		{
			isf.type = 'w3c';
		}
		else if(typeof isf.obj1.style.MozOpacity != 'undefined')
		{
			isf.type = 'moz';
		}
		else if(typeof isf.obj1.style.KhtmlOpacity != 'undefined')
		{
			isf.type = 'khtml';
		}
		else if(typeof isf.obj1.filters == 'object')
		{
			//weed out win/ie5.0 by testing the length of the filters collection (where filters is an object with no data)
			//then weed out mac/ie5 by testing first the existence of the alpha object (to prevent errors in win/ie5.0)
			//then the returned value type, which should be a number, but in mac/ie5 is an empty string
			isf.type = (isf.obj1.filters.length > 0 && typeof isf.obj1.filters.alpha == 'object' && typeof isf.obj1.filters.alpha.opacity == 'number') ? 'ie' : 'none';
		}
		else
		{
			isf.type = 'none';
		}
		
		var my_navigator = navigator.appName
		if (my_navigator == "Microsoft Internet Explorer")
		{
			isf.type = 'ie6+';
		}
					
		//if any kind of opacity is supported
		if(isf.type != 'none')
		{
			//copy and convert fade duration argument 
			//the duration specifies the whole transition
			//but the swapfade is two distinct transitions
			isf.length = parseFloat(arguments[7], 10) * 500;
			
			//create fade resolution argument as 20 steps per transition
			//again, split for the two distrinct transitions
			isf.resolution = parseFloat(arguments[7], 10) * 10;
				

			//start the timer
			isf.clock = setInterval('isf.swapfade()', 5);
		}
		
		//otherwise if opacity is not supported
		else
		{
			//just do the image swap
			isf.obj1.src = isf.src1;
			isf.obj2.innerHTML = isf.src2;
			isf.obj3.innerHTML = isf.src3;
		}

	isf.obj1.alt = isf.alt;
		
	}
};


//swapfade timer function
isf.swapfade = function()
{
	//increase or reduce the counter on an exponential scale
	isf.count = (isf.fade) ? isf.count * 0.7 : (isf.count * (1/0.7)); 
	
	//if the counter has reached the bottom
	if(isf.count < (1 / isf.resolution))
	{
		//clear the timer
		clearInterval(isf.clock);
		isf.clock = null;

		//do the image swap
		isf.obj1.src = isf.src1;
		isf.obj2.innerHTML = isf.src2;
		isf.obj3.innerHTML = isf.src3;

		//reverse the fade direction flag
		isf.fade = false;
		
		//restart the timer
		isf.clock = setInterval('isf.swapfade()', isf.length/isf.resolution);

	}
	
	//if the counter has reached the top
	if(isf.count > (1 - (1 / isf.resolution)))
	{
		//clear the timer
		clearInterval(isf.clock);
		isf.clock = null;

		//reset the fade direction flag
		isf.fade = true;
		
		//reset the counter
		isf.count = 1;
	}

	//set new opacity value on element
	//using whatever method is supported
	switch(isf.type)
	{
		case 'ie' :
			isf.obj1.filters.alpha.opacity = isf.count * 100;
			isf.obj2.filters.alpha.opacity = isf.count * 100;
			isf.obj3.filters.alpha.opacity = isf.count * 100;
			break;
			
		case 'ie6+' :
			isf.obj1.style.filter = 'alpha(opacity=' + isf.count * 100 +')';
			isf.obj2.style.filter = 'alpha(opacity=' + isf.count * 100 +')';
			isf.obj3.style.filter = 'alpha(opacity=' + isf.count * 100 +')';
			break;
			
		case 'khtml' :
			isf.obj1.style.KhtmlOpacity = isf.count;
			isf.obj2.style.KhtmlOpacity = isf.count;
			isf.obj3.style.KhtmlOpacity = isf.count;
			break;
			
		case 'moz' : 
			//restrict max opacity to prevent a visual popping effect in firefox
			isf.obj1.style.MozOpacity = (isf.count == 1 ? 0.9999999 : isf.count);
			isf.obj2.style.MozOpacity = (isf.count == 1 ? 0.9999999 : isf.count);
			isf.obj3.style.MozOpacity = (isf.count == 1 ? 0.9999999 : isf.count);
			break;
			
		default : 
			//restrict max opacity to prevent a visual popping effect in firefox
			isf.obj1.style.opacity = (isf.count == 1 ? 0.9999999 : isf.count);
			isf.obj2.style.opacity = (isf.count == 1 ? 0.9999999 : isf.count);
			isf.obj3.style.opacity = (isf.count == 1 ? 0.9999999 : isf.count);
	}
};





//----------------------------------------------------------------------------------

function show_resized_random_image(){
var j = 0
var a = show_resized_random_image.arguments;
var p = a.length;
var size = a[0];
var orientation = a[1];
/*
var preBuffer = new Array()
for (i = 2; i < p; i++){
   preBuffer[i] = new Image();
   preBuffer[i].src = a[i];
}
*/
var whichImage = 2+Math.round(Math.random()*(p-3));
document.write('<img src="'+a[whichImage]+'" '+orientation+'="'+size+'%">');
}

function show_resized_dated_image(){
var j = 0
var a = show_resized_dated_image.arguments;
var p = a.length;
var size = a[0];
var orientation = a[1];
/*
var preBuffer = new Array()
for (i = 2; i < p; i++){
   preBuffer[i] = new Image();
   preBuffer[i].src = a[i];
}
*/
var imageNum = p-2
var imageFrequency = 10
var today = new Date();
var oneJan = new Date(today.getFullYear(),0,1);
var dayOfYear = Math.ceil((today - oneJan) / 86400000);
var whichImage = 2+Math.floor(dayOfYear/imageFrequency)-imageNum*Math.floor(Math.floor(dayOfYear/imageFrequency)/imageNum);
document.write('<img src="'+a[whichImage]+'" '+orientation+'="'+size+'%">');
}

function showfullrandomimage_old(){
var j = 0
var a = showfullrandomimage.arguments;
var p = a.length;
var preBuffer = new Array()
for (i = 0; i < p; i++){
   preBuffer[i] = new Image();
   preBuffer[i].src = a[i];
}
//var whichImage = Math.round(Math.random()*(p-1));
var imageNum = 4
var imageFrequency = 10
var today = new Date();
var oneJan = new Date(today.getFullYear(),0,1);
var dayOfYear = Math.ceil((today - oneJan) / 86400000);
var whichImage = 1+Math.floor(dayOfYear/imageFrequency)-imageNum*Math.floor(Math.floor(dayOfYear/imageFrequency)/imageNum);
document.write('<img src="'+a[whichImage]+'" height="100%">');
//document.write('<img src="'+a[4]+'" height="100%">');
}


// --------------------- Variables --------------------------
// Default values for image names of the images/text to expand and collapse the hidden text.
// ----------------------------------------------------------
var defaultExpandText = "Show More...";
var defaultCollapseText = "Show Less....";

// ---------------- setDefaultExpanderImages(...) ------------------
// Call this method to change the names of the images used for the "expand" and "collapse" buttons
// The parameters should be the actual image URLS for the images, which may be relative or absolute
// ----------------------------------------------------------
function setDefaultExpanderImages(expandImgName, collapseImgName) {
    expandImage = expandImgName;
		collapseImage = collapseImgName;
}

// ---------------- setDefaultExpanderText(...) ------------------
// Call this method to change the strings used for the "expand" and "collapse" links
// expandText = "Expand" or "Show More" or "Reveal Answer" etc.
// collapseText = "Hide" or "Show Less" or "Hide Answer" etc.
// ----------------------------------------------------------
function setDefaultExpanderText(expandText, collapseText) {
    defaultExpandText = expandText;
		defaultCollapseText = collapseText;
}

// ----------------- toggleBlockText(...) -------------------
// Method to show or hide a paragraph or other block or span of text. 
// Use this version for text links to show/hide, and custom link text
// Parameters:
// hiddenDivId - the ID attribute of div to show or hide
// expander - pass in a reference to the image tag for the expender
//     usually this will just be "this" (without any quotes)
// expandText - the text to show when the block of text is hidden (to show the text) OPTIONAL
// collapseText - the text to show when the block of text is showing (to hide the text) OPTIONAL
// ----------------------------------------------------------
function toggleBlockText (hiddenDivId, expander, expandText, collapseText) {
    if (document.getElementById) {
        if (document.getElementById(hiddenDivId).style.display == "none") {
            document.getElementById(hiddenDivId).style.display = "";
						expander.innerHTML = collapseText?collapseText:defaultCollapseText;
        } else {
            document.getElementById(hiddenDivId).style.display = "none";
						expander.innerHTML = expandText?expandText:defaultExpandText;
        }  
    }
}

// JavaScript Document
/***********************************************
* CMotion Image Gallery II- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* Visit http://www.dynamicDrive.com for source code
* Modified by jscheuer1 for vertical orientation, at http://www.dynamicDrive.com/forums
***********************************************/

var restarea=15 //1) width of the "neutral" area in the center of the gallery in px
var maxspeed=7 //2) top scroll speed in pixels. Script auto creates a range from 0 to top speed.
var endofgallerymsg="<span style='font-size: 11px'>End of Gallery</span>" //3) message to show at end of gallery. Enter "" to disable message.

////NO NEED TO EDIT BELOW THIS LINE////////////

var iedom=document.all||document.getElementById
var scrollspeed=0
var movestate=""

var actualheight=''
var cross_scroll
var loadedyes=0

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function creatediv(){
statusdiv=document.createElement("div")
statusdiv.setAttribute("id","statusdiv")
document.body.appendChild(statusdiv)
statusdiv=document.getElementById("statusdiv")
statusdiv.innerHTML=endofgallerymsg
}

function positiondiv(){
menuwidth=parseInt(crossmain.offsetWidth)
mainobjoffsetW=getposOffset(crossmain, "left")
statusdiv.style.left=mainobjoffsetW+(menuwidth/2)-(statusdiv.offsetWidth/2)+"px"
statusdiv.style.top=menu_height+mainobjoffset+10+"px"
}

function showhidediv(what){
if (endofgallerymsg!="")
statusdiv.style.visibility=what
}

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft: what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}


function moveup(){
if (loadedyes){
movestate="up"
if (iedom&&parseInt(cross_scroll.style.top)>(menu_height-actualheight)){
cross_scroll.style.top=parseInt(cross_scroll.style.top)-scrollspeed+"px"
showhidediv("hidden")
}
else
showhidediv("visible")
}
uptime=setTimeout("moveup()",10)
}

function movedown(){
if (loadedyes){
movestate="down"
if (iedom&&parseInt(cross_scroll.style.top)<0){
cross_scroll.style.top=parseInt(cross_scroll.style.top)+scrollspeed+"px"
showhidediv("hidden")
}
else
showhidediv("visible")
}
downtime=setTimeout("movedown()",10)
}

function motionengine(e){
var dsocx=(window.pageXOffset)? pageXOffset: ietruebody().scrollLeft;
var dsocy=(window.pageYOffset)? pageYOffset : ietruebody().scrollTop;
var curposy=window.event? event.clientY : e.clientY? e.clientY: ""
curposy-=mainobjoffset-dsocy
var leftbound=(menu_height-restarea)/2
var rightbound=(menu_height+restarea)/2

if (curposy>rightbound){
scrollspeed=(curposy-rightbound)/((menu_height-restarea)/2) * maxspeed
if (window.downtime) clearTimeout(downtime)
if (movestate!="up") moveup()
}
else if (curposy<leftbound){
scrollspeed=(leftbound-curposy)/((menu_height-restarea)/2) * maxspeed
if (window.uptime) clearTimeout(uptime)
if (movestate!="down") movedown()
}
else
scrollspeed=0
}

function contains_ns6(a, b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function stopmotion(e){
if ((window.event&&!crossmain.contains(event.toElement)) || (e && e.currentTarget && e.currentTarget!= e.relatedTarget && !contains_ns6(e.currentTarget, e.relatedTarget))){
if (window.downtime) clearTimeout(downtime)
if (window.uptime) clearTimeout(uptime)
movestate=""
}
}

function fillup(){
if (iedom){
crossmain=document.getElementById? document.getElementById("motioncontainer") : document.all.motioncontainer
//menu_height=parseInt(crossmain.style.height)
//alert(navigator.appName)
menu_height=crossmain.clientHeight
mainobjoffset=getposOffset(crossmain, "top")
cross_scroll=document.getElementById? document.getElementById("motiongallery") : document.all.motiongallery
actualheight=cross_scroll.offsetHeight

crossmain.onmousemove=function(e){
motionengine(e)
}

crossmain.onmouseout=function(e){
stopmotion(e)
showhidediv("hidden")
}
}
if (window.opera){
cross_scroll.style.top=menu_height-actualheight+'px'
setTimeout('cross_scroll.style.top=0', 10)
}
loadedyes=1
if (endofgallerymsg!=""){
creatediv()
positiondiv()
}
}
//window.onload=fillup

//----------------------------------------------------------------------------------------------
//------------------------------- photo and thumbs loading -------------------------------------
//----------------------------------------------------------------------------------------------
function prepareImageGallery() { //v3.0
  var d=document;
  // creation of the thumbnails scroller
  fillup()
  // preload of main images
  if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=prepareImageGallery.arguments;	
	for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

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_swapImage() { //v3.0
  var obj,i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; 
//  obj=document.getElementById(a[0])
//  obj.innerHTML=a[1]
//  obj=document.getElementById(a[2])
//  obj.innerHTML=a[3]
	swapfade(document.getElementById(a[4]), a[6], document.getElementById(a[0]), a[1].replace(/&quot/g,"\""),  document.getElementById(a[2]), a[3].replace(/&quot/g,"\""), a[7], '1')
//  for(i=4;i<(a.length-2);i+=3)
//   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function change_captions() { //v9.0
  var obj,args=change_captions.arguments;
  obj=document.getElementById(args[0])
  obj.innerHTML=args[1]
  obj=document.getElementById(args[2])
  obj.innerHTML=args[3]
}


