// JavaScript Document
// LEVEL G, LLC - http://www.levelg.com

// ** FLASH FUNCTIONS //
// USED WITH SWFOBJECT.JS //

// SET NAV SWF ITEM/SUB ITEM
function setNav(navSetting,subItem) {
	var so = new SWFObject("/flash/nav.swf", "nav", "350", "270", "8", "");
	so.addParam("wmode", "transparent");
	if(navSetting) so.addVariable("navSetting", navSetting); //nav setting params!
	if(subItem) so.addVariable("subItem", subItem); //add sub nav vars if any
	setFlashClass('flashContent2_html');//set print class
	so.write("flashContent2_swf");//write content
}

// SET LOGO SWF
function setLogo() {
	var so = new SWFObject("/flash/logo.swf", "logo", "462", "108", "8", "");
	so.addParam("wmode", "transparent");
	setFlashClass('flashContent_html');
	so.write("flashContent_swf");
}
// SET HOME PANO SWF
function setSlideshow() {
	var so = new SWFObject("/flash/home_slideshow.swf", "slideshow", "831", "213", "8", "");
	so.addParam("wmode", "transparent");
	setFlashClass('flashContent3_html');
	so.write("flashContent3_swf");
}
// SET HOME PANO SWF
function setPano2() {
	var so = new SWFObject("/flash/header2.swf", "pano", "831", "213", "8", "");
	so.addParam("wmode", "transparent");
	setFlashClass('flashContent3_html');
	so.write("flashContent3_swf");
}

// SWITCH CLASS IDS
function setFlashClass(divid) {
	document.getElementById(divid).className = "printAll";
}

function newWindow(url) {
	var newWin=window.open('','_blank');
	newWin.location=url;
}


// ** RETURN ARRAY OF CLASS MATCHES ELEMENTS FROM DOM
// USED BY THE SCROLLER FUNCTION AND VIEWOPTIONS.JS

function createElementArray(tag, targetClass) {
	var total = document.getElementsByTagName(tag).length;
 	var objectArray = new Array();
	objectArray = document.getElementsByTagName(tag);
  	var targetObjects = new Array();
  	for(var i=0; i<total; i++) {
		if(objectArray[i].className == targetClass) {
			targetObjects[targetObjects.length] = objectArray[i];
		}	
  	}
	return targetObjects;
}

// ** SCROLLER FUNCTIONS 
// USED WITH MOOTOOLS-SMOOTHSCROLL.JS
// SCROLL CONTAINER TO ELEMENT
function scrollIt(container, theElement) {
	var myFx = new Fx.Scroll(container).toElement(theElement);
}

// DETAILS PAGE GALLERY SCROLLING
// FINDS ALL ANCHOR TAGS AND SCROLLS TO THE PREVIOUS OR NEXT TAG
function displayWorksCounter() {
totalSets = createElementArray('a', 'tray');
totalSets = totalSets.length;
var displayString;
if(totalSets == 1) {
document.getElementById('sliderFooter').style.display = 'none';
} else if(totalSets != 1) {
document.getElementById('sliderFooter').style.display = 'inline';
}
//document.getElementById('worksCounter').innerHTML = thisSet+" / "+totalSets;
if (thisSet == 1) {
document.getElementById('prevArrow').style.display = 'none';
} else if(thisSet !=1) {
document.getElementById('prevArrow').style.display = 'inline';
}
if (thisSet==totalSets) {
document.getElementById('nextArrow').style.display = 'none';
} else if(thisSet!=totalSets) {
document.getElementById('nextArrow').style.display = 'inline';
}
}

var anchorElement = 0;
function scrollIt_increment(operator, totalClass, target) {
	var elementNames = createElementArray('a', totalClass);
	total=elementNames.length-1;
totalSets = total+1;
	if(operator=='next') {
		if(anchorElement<total) {
			anchorElement++;
			var thisElement = totalClass+"_"+anchorElement;
			scrollIt(target,thisElement);//find the next anchortag and scroll to it.
thisSet++;
		} 
	} else if(operator=='prev') {
		if(anchorElement<=total && anchorElement>0) { 
			anchorElement--;
			var thisElement = totalClass+"_"+anchorElement;
			scrollIt(target,thisElement);//find the previous anchortag and scroll to it.
thisSet--;
		}
	}
displayWorksCounter();
}

function viewAll() {
if(document.getElementById('view_button').innerHTML=='View All') {
document.getElementById('slideContainer').style.width = '493px';
document.getElementById('slideBox').style.overflow = 'visible';
document.getElementById('slideBox').style.height = '100%';
document.getElementById('view_button').innerHTML = 'Minimize';
document.getElementById('prevArrow').style.display = 'none';
document.getElementById('nextArrow').style.display = 'none';
document.getElementById('worksCounter').innerHTML = '';
} else if(document.getElementById('view_button').innerHTML=='Minimize') {
document.getElementById('view_button').innerHTML = 'View All';
document.getElementById('slideContainer').style.width = '20000px';
document.getElementById('slideBox').style.overflow = 'hidden';
document.getElementById('slideBox').style.height = '118px';
document.getElementById('prevArrow').style.display = 'inline';
document.getElementById('nextArrow').style.display = 'inline';
//displayWorksCounter();
}
}

function pastMenu(option) {
location.href="http://www.acagalleries.com/exhibitions/past/"+option;
}




// ** COOKIE FUNCTIONS //
// USED WITH STYLESWITCHER.JS AND VIEWOPTIONS.JS //

// CREATE COOKIE
function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else {
	  expires = "";
  }
  	document.cookie = name+"="+value+expires+"; path=/";
}

// READ COOKIE
function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) {
		return c.substring(nameEQ.length,c.length);
	}
  }
  	return null;
}


// ** SHADOWBOX FUNCTIONS //
// USED WITH SHADOWBOX.JS //

function openGallery(xmlURL,startFrom,displayImg) {
	xmlURL = "xmlURL="+xmlURL+"works.xml";
        if(startFrom!='none') {
		var temper = "&startFrom="+startFrom;
		xmlURL += temper;
	} else	if(displayImg!='none') {
		var temper = "&dispImage="+displayImg;
		xmlURL += temper;
	}
	Shadowbox.open({
          player:     'swf',
          content:    '/flash/gallery.swf',
	  theFlashVars: xmlURL,
          height:     595,
          width:      621
       });
}


// FLASH VIRTUAL TOUR LINK
function openShadowbox_video(video_url){
boxtitle('');
    var iframe = {
        player:     'iframe',
        content:    video_url,
        height:     400,
        width:      600
    };
    Shadowbox.open([iframe]);
};

function openShadowbox_tour(){
boxtitle('');
    var iframe = {
        player:     'iframe',
        content:    '/virtual-gallery.html',
        height:     800,
        width:      900
    };
    Shadowbox.open([iframe]);
};

var invite_referrer;
var invite_title;
var invite_url;
function openShadowbox_invite(referrer, thetitle, theurl){
boxtitle('');
invite_referrer = referrer;
invite_title = thetitle;
invite_url = theurl;
    var iframe = {
        player:     'iframe',
        content:    '/send-invitation.html',
        height:     216,
        width:      520
    };
    Shadowbox.open([iframe]);
};
// CLOSE SHADOWBOX WINDOW
function closeIt() {
	Shadowbox.close();	
}

// ** IMAGE PRELOAD
// USED BY THE ALPHABROWSER
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
  var i,j=d.MM_p.length,a=MM_preloadImages.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 i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;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];}
}