setInterval ('floatButton()', 100);

var drawerState = getCookie();
//var drawerState = 0;

if (document.images) {
	var folder = "";
	var bExt = 'gif';
	var cExt = 'gif'; 
	if(typeof(style) != "undefined") folder = style;
	if(typeof(bulletExt) != "undefined")	bExt = bulletExt;
	if(typeof(checkExt) != "undefined") 	cExt = checkExt;

	bulletOn		= new Image();
	bulletOn.src	= '/files/' + folder + 'bullet_on.' + bExt;
	bulletOff		= new Image();
	bulletOff.src	= '/files/' + folder + 'bullet_off.' + bExt;

	checkOn			= new Image();
	checkOn.src		= '/files/' + folder + 'check_on.' + cExt;
	checkOff		= new Image();
	checkOff.src	= '/files/' + folder + 'check_off.' + cExt;
	
	checkIconOn		= new Image();
	checkIconOn.src	= '/files/checkicon_on.gif';
	checkIconOff	= new Image();
	checkIconOff.src = '/files/checkicon_off.gif';
}

function changeBullet(bulletImage, onOff) {
	if (document.images) {
		if(document[bulletImage]){
			document[bulletImage].src = eval('bullet' + onOff + '.src');
		} else {	//must be an png image that was switched out
			toggleIEPng(bulletImage, onOff);
		}
	}
}

function changeCheck(checkImage, url, target) {
	if (document.images) {
		if(document[checkImage]){
			var checksrc = document[checkImage].src;
			if (checksrc.match(/check_off.gif$/) || checksrc.match(/check_off.png$/)) {
				document[checkImage].src = checkOn.src;
				drawerState = 1;
			}
			if (checksrc.match(/check_on.gif$/) || checksrc.match(/check_on.png$/)) {
				document[checkImage].src = checkOff.src;
			}
		} else {	//must be a png image that was switched out
			toggleIEPng(checkImage);
		}
	}
	
	if(url && target){
		document.getElementById(target).src = url;
	}

	initButton();
}

function toggleIEPng(image, onOff){
	if(!document.getElementById(image)){
		return;
	}

	var span = document.getElementById(image).outerHTML;
	
	//if onOff == null toggle else set to onOff
	if(onOff == null){
		if (span.match(/_off.png/i)) {
			span = span.replace(/_off.png/i,'_on.png');
			drawerState = 1;
		} else if (span.match(/_on.png/i)) {
			span = span.replace(/_on.png/i,'_off.png');
		}			
	} else {
		if(onOff.match(/off/i)){
			span = span.replace(/_on.png/i, '_off.png');
		} else if (onOff.match(/on/i)){
			span = span.replace(/_off.png/i, '_on.png');
		}
	}
	
	document.getElementById(image).outerHTML = span;
}

function changeCheck2(imageId, url, target) {
	var checkImage = "check" + imageId;
	if (document.images) {
		if(document[checkImage]){
			var checksrc = document[checkImage].src;
			if (checksrc.match(/check_off.gif$/ || checksrc.match(/check_off.png$/))) {
				document[checkImage].src = checkOn.src;
				drawerState = 1;
			}
			if (checksrc.match(/check_on.gif$/) || checksrc.match(/check_on.png$/)) {
				document[checkImage].src = checkOff.src;
			}
		} else {	//must be a png image that was switched out
			toggleIEPng(checkImage);
		}
	}
	
	if(url && target){
		document.getElementById(target).src = url;
	}
	
	updateStrip(imageId);	
	initButton();
}

function updateStrip(id){
	var num = Math.round(Math.random() * 100000) + 1;
	document.getElementById("selections").src = "/selections/?select=" + id + "&" + num;
}

function floatButton () {
	if (document.all && document.all.topButton != null) {
		if(document.all.topButton.style != null)
			document.all.topButton.style.pixelTop = (document.body.scrollTop + document.body.clientHeight - 130);
	} else if (document.layers && document.topButton != null) {
		document.topButton.top = (window.pageYOffset + document.body.clientHeight - 130);
	} else if (document.getElementById && document.getElementById('topButton') != null) {
		if(document.getElementById('topButton').style != null)
			document.getElementById('topButton').style.top = (window.pageYOffset + window.innerHeight - 130) + 'px';
//			document.getElementById('topButton').style.top = (window.pageYOffset + document.body.clientHeight - 130) + 'px';
	}
}

function openClose() {
	if (drawerState == 1) {
		drawerState = 0;
		initButton();
	} else {
		drawerState = 1;
		initButton();
	}
}

function openDrawer() {
	if (document.all) {
		document.all.topButton.style.pixelLeft = 0;
	} else if (document.layers) {
		document.topButton.left = 0;
	} else if (document.getElementById) {
		document.getElementById('topButton').style.left = 0 + 'px';
	}
}

function initButton() {
	var drawerHoriz = -630;

	if (drawerState == 1) {
		drawerHoriz = 0;
	}

	document.cookie = "drawerState=" + drawerState;

//	alert(drawerState);

	if (document.all) {
		document.all.topButton.style.pixelLeft = drawerHoriz;
		document.all.topButton.style.pixelTop = (document.body.scrollTop + document.body.clientHeight - 130);
		document.all.topButton.style.visibility = 'visible';
	} else if (document.layers) {
		document.topButton.left = drawerHoriz;
		document.topButton.top = (window.pageYOffset + document.body.clientHeight - 130);
		document.topButton.visibility = 'show';
	} else if (document.getElementById) {
		document.getElementById('topButton').style.left = drawerHoriz + 'px';
//		document.getElementById('topButton').style.top = (window.pageYOffset + document.body.clientHeight - 130) + 'px';
		document.getElementById('topButton').style.top = (window.pageYOffset + window.innerHeight - 130) + 'px';
		document.getElementById('topButton').style.visibility = 'visible';
	}
}

function selectHandler(imageId) {
		if (document.imageForm) {
			var current = document.imageForm.current.value;
			eval('document.imageForm.left'	+ current + '.value = ""');
			eval('document.imageForm.top'	+ current + '.value = ""');
			eval('document.imageForm.image'	+ current + '.value = imageId');
			document.imageForm.submit();
		} else {
		        document.location = '/gallery/?select=' + imageId
		}
}

function scrollFilm(speed, horizontal, vertical) {
        filmScroller = setInterval("selections.scrollBy(" + horizontal + "," + vertical + ")", speed);
}

function stopFilm() {
	clearInterval(filmScroller);
}

function cleanUpFilmstrip(imageId) {
	if (document['check' + imageId]) {
		document['check' + imageId].src = checkOff.src;
	} else if (document.getElementById('check' + imageId)){
		toggleIEPng('check' + imageId, 'off');
	}
}

function cleanUpControls(on) {
	var checkRegex = new RegExp("^check")
	for (var i = 0; i < document.images.length; i++) {
		if (checkRegex.test(document.images[i].name)) {
			if (on) {
				document.images[i].src = checkOn.src
			} else {
				document.images[i].src = checkOff.src
			}
		}
	}
	var spans = document.getElementsByTagName("span");
	for (var i = 0; i < spans.length; i++) {
		if (checkRegex.test(spans[i].id)) {
			if (on) {
				toggleIEPng(spans[i].id, 'on');
			} else {
				toggleIEPng(spans[i].id, 'off');
			}
		}
	}
}

function changeColor(obj){
	document.imageForm.submit();
}

function right(e) {
	if (navigator.appName == 'Netscape' && (e.which == 2 || e.which == 3)) {
		alert('This image is copyright protected');
		return false;
	} else if (navigator.appName == 'Microsoft Internet Explorer' && (event.button==2 || event.button == 3)) {
		alert('This image is copyright protected');
		return false;
	}

	return true;
}

document.onmousedown=right;

if (document.layers) window.captureEvents(Event.MOUSEDOWN);

window.onmousedown=right;

function getCookie() {
  var dc = document.cookie;
//  alert("Cookie: " + dc);
  var prefix = "drawerState=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

function openKeywords(id, imageWidth, imageHeight){
    if(imageWidth == null) imageWidth = 0;
    if(imageHeight == null) imageHeight = 0;
//    window.open("/keywords/?id=" + id, "Keywords", "toolbar=no,location=no,directories=no,menubar=no,scrollbars=no,status=no,width=650,height=350");
    var height = 350;
    var width = 560;
    if(imageHeight > 125){
        height = 245 + imageHeight;
    }
    if(imageWidth > 125){
        width = 435 + imageWidth;
    }
	popup("/keywords/?id=" + id, "Keywords", width, height, "no", "center");
}

function openPackages(id){
    popup("/utils/?action=package&id=" + id, "Package", 400, 300, "no", "center");
}

function processPackages(obj, name, id){
	win.close();
	
	
//	var output = 'name=' + name + '&id=' + id;
	addHidden("packageForm", "name", name);
	addHidden("packageForm", "id", id);
	var counter = 0;
	for(var i = 0; i < obj.options.length; i++){
		if(obj.options[i].selected){
      		addHidden("packageForm", "id" + counter, obj.options[i].value); 
      		addHidden("packageForm", "name" + counter, obj.options[i].text);
//      		output += "&id" + counter + "=" + obj.options[i].value;
//      		output += "&name" + counter + "=" + obj.options[i].text;
      		counter++;
    	}
    }
    addHidden("packageForm", "count", counter);
    
//    output += "&count=" + counter;
//    alert(output);

	document.forms["packageForm"].submit();
}

function addHidden(form, id, value){
	var oInput = document.createElement("INPUT");
	oInput.name = id;
	oInput.type = "hidden";
	oInput.id = id;
	oInput.value = value;
	document.forms[form].appendChild(oInput);
}

function updateKeywords(id, keywords){
	if(document.getElementById('k' + id) != null){
		document.getElementById('k' + id).innerHTML = keywords;
	}
}

var win = null;
function popup(mypage, myname, w, h, scroll, pos){
    var LeftPosition = 0;
    var TopPosition = 0;
    if(pos == "random"){
	LeftPosition = (screen.width) ? Math.floor(Math.random() * (screen.width-w)) : 100;
	TopPosition = (screen.height) ? Math.floor(Math.random()  *((screen.height-h)-75)) : 100;
    }
    if(pos == "center"){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 100;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 100;
    } else if((pos != "center" && pos != "random") || pos == null) {
	LeftPosition = 0;
	TopPosition = 20;
    }
    settings = "width=" + w + ", height=" + h + ", top=" + TopPosition + ", left=" + LeftPosition + ", scrollbars=" + scroll +
                    ", location=no, directories=no, status=no, menubar=no, toolbar=no, resizable = no";
    win=window.open(mypage,myname,settings);
}

function positionDiv(div, position, topOffset, leftOffset){
	if(topOffset == null) topOffset = 0 ;
	if(leftOffset == null) leftOffset = 0;
	if(document.getElementById(div)){
		var divDim = getDivBounds(div);
		if(position == 'center'){
			document.getElementById(div).style.left = Math.round((getWindowWidth() - divDim.w) / 2) + leftOffset;
			document.getElementById(div).style.top = Math.round((getWindowHeight() - divDim.h) / 2) + topOffset;
			document.getElementById(div).style.visibility = 'visible';
		}
		if(position == 'offscreen'){
			document.getElementById(div).style.left = 0;
			document.getElementById(div).style.top = -(200 + divDim.h);
			document.getElementById(div).style.visibility = 'hidden';
		}
	}              
}

function getImageDims(image){
	return new Dimension(0, 0, image.width, image.height);
}

//helper dimension object constructor
function Dimension(x,y,w,h){
	this.w=w;
	this.h=h;
	this.x=x;
	this.y=y;
}

function getDivBounds(id){
	var d; var x; var y; var w; var h;
	if(document.layers){
		d=document[id];
		x=d.left;
		y=d.top;
		w=d.clip.width;
		h=d.clip.height;
	}

	if(document.all || browser.isNS4up || browser.isSafari || browser.isFireFox){
		if(document.getElementById(id)){
			d=document.getElementById(id);
			x=d.offsetLeft;
			y=d.offsetTop;
			w=d.offsetWidth;
			h=d.offsetHeight;
		}
	}
  	return new Dimension(x,y,w,h);
}

function getWindowWidth(){
    var fWidth = (browser.isNS4up || browser.isSafari) ? window.innerWidth: document.body.clientWidth; 
    return fWidth;
}

function getWindowHeight(){
    var fHeight = (browser.isNS4up || browser.isSafari) ? window.innerHeight: document.body.clientHeight;
    return fHeight;
}

function editDiv(div, text){
	var aLayer
	if(document.layers){
		//thisbrowser="NN4";
		aLayer = document.layers[div];
		if(aLayer != null){
			aLayer.document.open();
			aLayer.document.write(text);
			aLayer.document.close();
		}
	}
	if(document.all){
		//thisbrowser="ie"
		aLayer = document.all[div];
		if(aLayer != null){
			aLayer.innerHTML=text;
		}
	}
	if(!document.all && document.getElementById){
		//thisbrowser="NN6";
		aLayer = document.getElementById(div);
		if(aLayer != null){
			aLayer.innerHTML =text;
		}
	}	
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
// Browser Detect  v2.1.6
// documentation: http://www.dithered.com/javascript/browser_detect/index.html
// license: http://creativecommons.org/licenses/by/1.0/
// code by Chris Nott (chris[at]dithered[dot]com)
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

function BrowserDetect() {
   var ua = navigator.userAgent.toLowerCase(); 

   // browser engine name
   this.isGecko       = (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1);
   this.isAppleWebKit = (ua.indexOf('applewebkit') != -1);

   // browser name
   this.isKonqueror   = (ua.indexOf('konqueror') != -1); 
   this.isFireFox     = (ua.indexOf('firefox') != -1);
   this.isSafari      = (ua.indexOf('safari') != - 1);
   this.isOmniweb     = (ua.indexOf('omniweb') != - 1);
   this.isOpera       = (ua.indexOf('opera') != -1); 
   this.isIcab        = (ua.indexOf('icab') != -1); 
   this.isAol         = (ua.indexOf('aol') != -1); 
   this.isIE          = (ua.indexOf('msie') != -1 && !this.isOpera && (ua.indexOf('webtv') == -1) ); 
   this.isMozilla     = (this.isGecko && ua.indexOf('gecko/') + 14 == ua.length);
   this.isFirebird    = (ua.indexOf('firebird/') != -1);
   this.isNS          = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && !this.isOpera && !this.isSafari && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) );
   
   // spoofing and compatible browsers
   this.isIECompatible = ( (ua.indexOf('msie') != -1) && !this.isIE);
   this.isNSCompatible = ( (ua.indexOf('mozilla') != -1) && !this.isNS && !this.isMozilla);
   
   // rendering engine versions
   this.geckoVersion = ( (this.isGecko) ? ua.substring( (ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14) ) : -1 );
   this.equivalentMozilla = ( (this.isGecko) ? parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) ) : -1 );
   this.appleWebKitVersion = ( (this.isAppleWebKit) ? parseFloat( ua.substring( ua.indexOf('applewebkit/') + 12) ) : -1 );
   
   // browser version
   this.versionMinor = parseFloat(navigator.appVersion); 
   
   // correct version number
   if (this.isGecko && !this.isMozilla) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('/', ua.indexOf('gecko/') + 6) + 1 ) );
   }
   else if (this.isMozilla) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) );
   }
   else if (this.isIE && this.versionMinor >= 4) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
   }
   else if (this.isKonqueror) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('konqueror/') + 10 ) );
   }
   else if (this.isSafari) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('safari/') + 7 ) );
   }
   else if (this.isOmniweb) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('omniweb/') + 8 ) );
   }
   else if (this.isOpera) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera') + 6 ) );
   }
   else if (this.isIcab) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab') + 5 ) );
   }
   else if (this.isFireFox) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('firefox') + 8 ) );
   }
   
   this.versionMajor = parseInt(this.versionMinor); 
   
   // dom support
   this.isDOM1 = (document.getElementById);
   this.isDOM2Event = (document.addEventListener && document.removeEventListener);
   
   // css compatibility mode
   this.mode = document.compatMode ? document.compatMode : 'BackCompat';

   // platform
   this.isWin    = (ua.indexOf('win') != -1);
   this.isWin32  = (this.isWin && ( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1 || ua.indexOf('xp') != -1) );
   this.isMac    = (ua.indexOf('mac') != -1);
   this.isUnix   = (ua.indexOf('unix') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1)
   this.isLinux  = (ua.indexOf('linux') != -1);
   
   // specific browser shortcuts
   this.isNS4x = (this.isNS && this.versionMajor == 4);
   this.isNS40x = (this.isNS4x && this.versionMinor < 4.5);
   this.isNS47x = (this.isNS4x && this.versionMinor >= 4.7);
   this.isNS4up = (this.isNS && this.versionMinor >= 4);
   this.isNS6x = (this.isNS && this.versionMajor == 6);
   this.isNS6up = (this.isNS && this.versionMajor >= 6);
   this.isNS7x = (this.isNS && this.versionMajor == 7);
   this.isNS7up = (this.isNS && this.versionMajor >= 7);
   
   this.isIE4x = (this.isIE && this.versionMajor == 4);
   this.isIE4up = (this.isIE && this.versionMajor >= 4);
   this.isIE5x = (this.isIE && this.versionMajor == 5);
   this.isIE55 = (this.isIE && this.versionMinor == 5.5);
   this.isIE5up = (this.isIE && this.versionMajor >= 5);
   this.isIE6x = (this.isIE && this.versionMajor == 6);
   this.isIE6up = (this.isIE && this.versionMajor >= 6);
   
   this.isIE4xMac = (this.isIE4x && this.isMac);
}
var browser = new BrowserDetect();

/*  End of browser detect */




