/*
CSS Browser Selector v0.3.2
Rafael Lima (http://rafael.adm.br)
http://rafael.adm.br/css_browser_selector
License: http://creativecommons.org/licenses/by/2.5/
Contributors: http://rafael.adm.br/css_browser_selector#contributors
*/
function css_browser_selector(u){var ua = u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1;},g='gecko',w='webkit',s='safari',h=document.getElementsByTagName('html')[0],b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3')?g+' ff3':is('gecko/')?g:/opera(\s|\/)(\d+)/.test(ua)?'opera opera'+RegExp.$2:is('konqueror')?'konqueror':is('chrome')?w+' chrome':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?'mobile':is('iphone')?'iphone':is('ipod')?'ipod':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win':is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; css_browser_selector(navigator.userAgent);



//========================
// General functions
//========================

function toggleVisibleElement(object) {
	$("#"+object).toggle();
}


function rdStat() {
	ls="/log____image.gif?summarylog&je="+navigator.javaEnabled()+"&sw="+screen.width+"&sh="+screen.height;

	if (screen.pixelDepth) ls+="&sd="+screen.pixelDepth;
	else if (screen.colorDepth) ls+="&sd="+screen.colorDepth;

	if (navigator.language) ls+="&la="+navigator.language;
	else if (navigator.userLanguage) ls+="&la="+navigator.userLanguage;

	var cookieEnabled = (navigator.cookieEnabled) ? true : false;
	if (typeof navigator.cookieEnabled == "undefined" && !cookieEnabled)
	{ 
		document.cookie="log____cc=1;path=/;";
		cookieEnabled = (document.cookie.indexOf("log____cc") != -1) ? true : false;
	}
	ls+="&co="+cookieEnabled;

	if (window.innerWidth) {
		ls+="&ww="+window.innerWidth;
		ls+="&wh="+window.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientWidth) {
		ls+="&ww="+document.documentElement.clientWidth;
		ls+="&wh="+document.documentElement.clientHeight;
	}
	else if (document.body && document.body.clientWidth) {
		ls+="&ww="+document.body.clientWidth;
		ls+="&wh="+document.body.clientHeight;
	}

	li=new Image();
	li.src=ls;
}


function getVisiblePageSize() {
	// borrowed from 
	// jQuery Lightbox
	// Version 0.5 - 11/29/2007
	// @author Warren Krewenki
	
	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;
	}
}



//========================
// Site Specific functions
//========================

function viewdetail(theURL) {
	window.open(theURL, 'DetailView', 'scrollbars=yes,status=no,toolbar=no,location=no,menubar=no,resizable=yes,height=580,width=750');
}


function confirmSubmit(theAction) {
	var agree = confirm("Are you sure you wish to "+theAction+"?");
	if (agree) {
		return true ;
	}
	else {
		return false ;
	}
}


function goTo(s, session)
	{
	o = $(s).val();
	window.location.href=(o + session);
	}
	
	
function showpic(whichPic) {
	$("div.thumbnail").removeClass("currentthumbnail");
	$("div.picture").css("display","none");
	$("#pic"+whichPic).css("display","block");
	$("#img"+whichPic).css("display","block");
	$("#tn"+whichPic).addClass("currentthumbnail");
}


function showpicwithside(whichPic) {
	$(".thumbnail").removeClass("currentthumbnail");
	$("a.curwork").removeClass("curwork");
	$(".picture").css("display","none");
	$("#pic"+whichPic).css("display","block");
	$("#img"+whichPic).css("display","block");
	$("#tn"+whichPic).addClass("currentthumbnail");
	$("#wl"+whichPic).addClass("curwork");
}


function setupSlideshow(slideshow) {
	$(slideshow).cycle({
		fx:			'fade',
		speed:		1600,
		timeout:	9000,
		pause:		1,
		sync:		0,
		direction:	'left',
		slideExpr:	'div.slide'
	});
}


function setupSlideshowNav(slideshow, fx, speed, delay, direction) {
	var fx = (fx == null) ? "fade" : fx;
	var speed = (speed == null) ? 1600 : speed;
	var delay = (delay == null) ? 8000 : delay;
	var direction = (direction == null) ? "down" : direction;
	$(slideshow).cycle({
		fx:			fx,
		speed:		speed,
		timeout:	delay,
		pause:		1,
		sync:		1,
		direction:	direction,
		slideExpr:	'img'
	});
}


function prepExtLinks() { 
	$("a[href^='http']").not("[href*='internationalartcentre.co.nz']").attr('target', '_blank').addClass("extlink");
}


function zoompic(z) {
	if (z == 'zoomin') {
		if (zoomfactor < maxzoom) {
			zoomfactor++;
		}
		else {
			return false;
		}
	}
	else if (z == 'zoomout') {
		if (zoomfactor > 0) {
			zoomfactor--;
		}
		else {
//			return false;
		}
	}

	if (zoomfactor == 0) {
		$('#zoomout').addClass('disabled');
	}
	else {
		$('#zoomout').removeClass('disabled');
	}

	if (zoomfactor == maxzoom) {
		$('#zoomin').addClass('disabled');
	}
	else {
		$('#zoomin').removeClass('disabled');
	}

	if (zoomfactor == 0) {
		$('#zoompic').removeClass('zoomin');
		$('#zoompic').removeClass('zoomin2');
		$('#zoompic').addClass('zoomout');
	}
	else if (zoomfactor == 1) {
		$('#zoompic').removeClass('zoomin2');
		$('#zoompic').removeClass('zoomout');
		$('#zoompic').addClass('zoomin');
	}
	else if (zoomfactor == 2) {
		$('#zoompic').removeClass('zoomin');
		$('#zoompic').removeClass('zoomout');
		$('#zoompic').addClass('zoomin2');
	}
}


function showDescription(o) {
	$(o).parent().css("display", "none");
	$(o).css("display", "none");
	$(o).parent().css("height", "auto");
	$(o).parent().fadeIn(800);
}


function showPreview(o, server) {
	var thumbnailPath = server + $(o).attr("href").replace(/-L.jpg/g, "-S.gif");
	var thumbnailAlt = $(o).attr("title").replace(/ \| /g, "<br />");

	$("#preview").attr({ src: thumbnailPath });

	$("div.title").html(thumbnailAlt);
	return false;
}


function hidePreview(o) {
	var thumbnailPath = "/_images/blank.gif";
	var thumbnailAlt = "&nbsp;";

	$("#preview").attr({ src: thumbnailPath });

	$("div.title").html(thumbnailAlt);
	return false;
}
