
	var homepage = true;
	var section = 'homepage';
	var ems;
	var theHash ="inithash";
	var theHashBits
	//var hashChecker


		$(function() { 	
			hashChecker = setInterval(checkHash, 500);
		if(! $.cookie('data'))$.cookie('data', ['']);
		//$.cookie('data',[795,794,792,388,403])
		//$.cookie('data',[])
		$('dd.artists li a').bind('mouseover', function(e){showCats(e)});
		$('dd.artists li a').bind('mouseout', function(e){hideCats(e)});
		$('dd.specialties li a').bind('mouseover', function(e){showArtists(e)});
		$('dd.specialties li a').bind('mouseout', function(e){hideArtists(e)});
		
		$('dd.artists li a').bind('click', function(e){isCurrent(e)});
		$('dd.specialties li a').bind('click', function(e){isCurrent(e)});

		//SLIDEMENU FUNCITONS
		$('#slidebar .menu-trigger').bind('click', slideOut );
		$('#slidebar .menu-trigger span').hover(slideRollOver, slideRollOut);
		$('.em-menu dd.specialties ul').bind('mouseover',function(){hiliteSpecialty()});
		$('.em-menu dd.specialties ul').bind('mouseout',function(){dimSpecialty()});
		
		$('#imageViewer').bind('new-image', function(){newBigImage()});
		$('.lb-ui-print').bind('click', printLightBoxImage).hide();
		dimSpecialty();
		//overlay
		$('#boxclose').click(function(){hideShareBox()});
		
		$(".rollover").hover(function(){this.src = this.src.replace("-up","-over");},function(){ this.src = this.src.replace("-over","-up"); } );
		showLightBoxCount();
		clearInterval(hashChecker);
		hashChecker = setInterval(checkHash, 400);
	});
	

function isCurrent(e){
	theHashBits = theHash.substr(1).split('/');
	currentFilter = theHashBits[0]
	if(filterName(e.target.innerText)==currentFilter){
		slideOut();
	}
}


function newBigImage(){
	updateName();
	updateLightBoxUI();
}

function updateName(){
	switch(section){
		case'lightbox':
			image_id = $('#imageViewer').imageviewer.getCurrentPicArtist();
			setTitle(image_id);
			break;
	 	case'specialty':
	 	case'share':
			image_id = $('#imageViewer').imageviewer.getCurrentPicArtist();
			setTitle(image_id);
			break;
	}
	
}



/*HOMEPAGE SLIDESHOW INTERACTIONS
_____________________________________________*/
	function slideShowInterupt(e){
		items = $('dd.artists li a');
		name = filterName(e.target.text);
		//currentSlide = items.index(e.target);
		currentSlide =slide_index[name];
		$('#slideshow').emAutoSlideshow.pauseSlideShow();
		$('#slideshow').emAutoSlideshow.showSlideIndex(currentSlide);
		
	}
	function slideShowResume(e){
		 $('#slideshow').emAutoSlideshow.resumeSlideShow();
	}
	
	function hideSlideshow(){
		$('#slideshow').emAutoSlideshow.pauseSlideShow();
		$('#slideshow').hide();
		$('dd.artists li a').unbind('mouseover');
		$('dd.artists li a').unbind('mouseout');
		
	}
	
	function showSlideshow(){
		$('#image-area').css({'height':'700px'});
		$('#slideshow').show();
	}

	
	function setSlideshow(){
		$('#slidebar ').css({'border-color':'#fff'});
		ems = $('#slideshow').emAutoSlideshow({data:slides,width:867,height:700, autostart:true});
		$('#slideshow').emAutoSlideshow.resumeSlideShow();
		$('#slideshow').bind('new-title', function(e,n){setTitle(n);});
		//SLIDE interupts
		$('dd.artists li a').bind('mouseover', function(e){slideShowInterupt(e)});
		$('dd.artists li a').bind('mouseout' ,function(){if(homepage)slideShowResume();});
	
	
	
	}
	function resetSlideBar(){
			slideIn()
			$("#slidebar").removeClass('init');
			$('#slidebar ').css({'border-color':'#fff'});	
	}
	
	
	function hideGallery(){
		//console.log('hide');
		$('#imageViewer').hide();
		
	}

	function showGallery(){
		$('#imageViewer').show();
	}
	
	/*END HOMEPAGE SLIDESHOW INTERACTIONS */

/*SLIDEBAR
_____________________________________________*/
	function slideIn() {
		$("#slidebar").animate( { left:"0px" }, {duration:250, complete: function() {
     		$('#slidebar .menu-trigger').unbind();
			$('#slidebar .menu-trigger').bind('click', slideOut );
    	}
		})
		$('dd.artists li a').bind('mouseover', function(e){showCats(e)});
		$('dd.artists li a').bind('mouseout', function(e){hideCats(e)});
		$('.menu-arrow').attr('src','images/left-arrow-small.png');

	}
	function slideOut() {
		if(!$("#slidebar").hasClass('init'))$("#slidebar").addClass('init');
		hideAllCats();
		$("#slidebar").animate( { left:"-180px" }, {duration:250, complete: function() {
			$('#slidebar .menu-trigger').unbind();
			$('#slidebar .menu-trigger').bind('click', slideIn );
    	}
    	})
    	$('.menu-arrow').attr('src','images/right-arrow-small.png');
   }
	
	
	function slideRollOver(){
		$('#slidebar.init .menu-trigger span').css({'background-color':'#aaa'});
		$('#slidebar ').css({'border-color':'#aaa'});
	}
	
	function slideRollOut(){
		$('#slidebar.init .menu-trigger span').css({'background-color':'#e0c600'});
		$('#slidebar').css({'border-color':'#e0c600'});
	}
	
	
	function hiliteSpecialty(){
		$('#slidebar').css('background-position', 'left 170px');
		$('.em-menu dd.specialties').removeClass('dim');
		//$('.em-menu dt.specialties').removeClass('dim');
		$('.em-menu dd.artists').addClass('dim');
		//$('.em-menu dt.artists').addClass('dim');
	}
	function dimSpecialty(){
	$('#slidebar').css('background-position', 'left 10px')
		$('.em-menu dd.specialties').addClass('dim');
		//$('.em-menu dt.specialties').addClass('dim');
		$('.em-menu dd.artists').removeClass('dim');
		//$('.em-menu dt.artists').removeClass('dim');
	}
	
	
	

function checkHash(){
	//check to see if there is a hash in the URL.
	//If so, load that content.
	//trace(window.location.hash + ' '.theHash);
	if(window.location.hash != theHash){
		theHash =window.location.hash;
		theHashBits = theHash.substr(1).split('/');
		processHash();
	}
}


function processHash(){
	theHashBits = theHash.substr(1).split('/');
	top_level = theHashBits[0];
	var secondary = theHashBits[1];
	setSubTitle('');
	setTitle('');
	if(top_level=='LINKS'){
		section='links';
		homepage=false;
		$('#links').show();
		hideGallery();
		resetSlideBar()
	}else if(top_level=='ABOUT'){
		section='about';
		homepage=false;
		$('#about').show();
		hideGallery()
		resetSlideBar()
	}else if(top_level=='CONTACT'){
		section='contact';
		homepage=false;
		$('#contact').show();
		hideGallery()
		resetSlideBar()
	}else if(top_level=='LIGHTBOX'){
		setLightBox();
		section='lightbox';
		homepage=false;
	}else if(top_level=='SHARE'){
		setShare();
		section='share';
		homepage=false;
	}else if(artists[top_level] != undefined){
		setArtist();
		section='artist';
	 	homepage=false;
	 	
	}else if(specialties[top_level] != undefined){
		setSpecialty();
		section='specialty';
		homepage=false;	
	}else{
		section='homepage';
		homepage=true;
	 	setSlideshow();
	}
	
	if(homepage==true){
		hideGallery();
		$('#video').html('');
		$('#video').hide();
	 	showSlideshow();
	 	$("#slidebar").removeClass('init');
		slideIn();
		$('#lb-ui').css('display', 'none')
	}else{
		hideSlideshow();
	 	showGallery();
	 	if(secondary == "VIDEO" || secondary == "TEARSHEETS" ){
	 		$('#lb-ui').css('display', 'none')
	 	}else{
	 		$('#lb-ui').css('display', 'block')
		}
	}

	if(top_level !== 'CONTACT'){
		$('#contact').hide();
	}
	if(top_level !== 'ABOUT'){
		$('#about').hide();
	}
		if(top_level !== 'LINKS'){
		$('#links').hide();
	}
	

	if(top_level !== 'LIGHTBOX'){
		setSelected();
	}
}


function filterName(n){
	if(n==undefined)return;
	var filtered = n.replace('&amp;', 'AND');
	var filtered = n.replace('&', 'AND');
	filtered = filtered.replace('+', '');
	filtered =  filtered.replace(/\s+/g, '');
	return filtered.toUpperCase();
}


function setTitle(n){
		if(n=='' || n==undefined){
			$("#meta img").hide();
		}else{
			
			$("#meta img").attr('src', 'images/titles/' +filterName(n).toUpperCase() +'.png' ).show();//('<h1>' + n + '</h1>')
		}
	}
	
function setSubTitle(n){
		$("#meta2").html( n )
}
	
	

function setLightBox(){
	var artist = theHashBits[1];
	artist_id = (artists[artist] != undefined)?artists[artist]['id']:null;
	//var cookieArray = $.cookie('data').split(',');
	$('#sidemenu .em-menu .name').html('My Lightbox');	
	$('#sidemenu .em-menu .location').html('');	
	showLightBox(artist_id);
}

function setShare(){
	var artist = theHashBits[2];
	artist_id = (artists[artist] != undefined)?artists[artist]['id']:null;
	var cookieArray = $.cookie('data').split(',');
	$('#sidemenu .em-menu .name').html('Shared Pictures');	
	$('#sidemenu .em-menu .location').html('');	
	showShared(artist_id);
}



function setArtist(){
	var artist = theHashBits[0];
	var specialty = theHashBits[1]
	var artist_info = artists[artist];
	setTitle(artist_info['name']);
	
	specilaty_id = (specialties[specialty] != undefined)?specialties[specialty]['id']:null;
	
	if(specialty=="PORTFOLIO"){
	//	return;	
	}else if(specialty=="TEARSHEETS"){
		showTearsheet(artist_info['id']);
		//return;	
	}else if(specialty=="VIDEO"){
		showVideos(artist_info['id'])
		//	return;	
	}else{	
		showArtist(artist_info['id'], specilaty_id);
	}
	$('#sidemenu .em-menu .name').html(artist_info['name']);
	$('#sidemenu .em-menu .location').html(artist_info['loc']);
	//console.log(artist_info)
	var spec =artist_info['specialties'];
	var specialty_list ='<ul>';
	if(spec.length>1)specialty_list +='<li><a href="#'+ artist+'"  class="VIEWALL">View All</a></li>'; 
	for( var i in spec){
			var s_name= specialties[spec[i]].name;
			specialty_list +='<li><a class="' + filterName(s_name.toUpperCase()) +'" href="#'+ artist+'/' + filterName(s_name.toUpperCase()) +'">' + s_name + '</a></li>';
		}
	specialty_list += '</ul>';
	$('#sidemenu .em-menu .sub').html(specialty_list);
	
	var extras_count = 0;
	var extra_list= "";
	if(artist_info['tearsheet']!='' || artist_info['video']!='' || artist_info['url']!=''){
	extra_list += '<ul class="artist-extras">';
	if(artist_info['tearsheet']!='')	extra_list +='<li><a class="TEARSHEETS"  href="#'+ artist+'/TEARSHEETS">Tearsheets</a></li>';
	if(artist_info['bio']!='')	extra_list +='<li><a class="BIO"  href="javascript:showArtistBio(\''+ artist_info['name'] + '\',\''+ artist_info['bio'] + '\')">Artist Bio</a></li>';
	if(artist_info['video']!='')	extra_list +='<li><a class="VIDEO" href="#'+ artist+'/VIDEO">Videos</a></li>';
	if(artist_info['url']!='') extra_list +='<li><a class="WEBSITE"  href="http://'+ artist_info['url'] +'" target="_blank">Artist Website</a></li>'
	extra_list += '</ul>';
	}
	if(specialty!="VIDEO" && specialty!="TEARSHEETS"){
	
		extra_list += '<dt class="lb-options-title">lightbox options:</dt>';		
		extra_list += '<dd><ul class="lb-options">';
		extra_list += '<ul><li class="lb-ui-add"><a href="#">Add Image</a></li>';
		extra_list += '<li><a href="javascript:addAllImagesToLightBox()">ADD ALL</a></li>';
		extra_list += '<li><a href="javascript:emptyLightBox();">Remove All</a></li>';
		extra_list += '</ul>';
	}
	extra_list += '</dl>';
	$('#sidemenu .em-menu .artist-links').html(extra_list);
	//$(".portfolio-link").click(function () {
	//	$('.portfolio-link ul').toggle('fast')
	//});   

}

function setSpecialty(e){
	var specialty = theHashBits[0]
	var artist = theHashBits[1];
	var specilaty_info = specialties[specialty];
	artist_id = (artists[artist] != undefined)?artists[artist]['id']:null;
	showSpecialty(specilaty_info['id'], artist_id)
	setTitle(specilaty_info['name'])
	hideSlideshow();
	$('#sidemenu .em-menu .name').html(specilaty_info['name']);
	$('#sidemenu .em-menu .location').html('');
	var artist =specilaty_info['artists'];
	var artist_list ='<ul>'
	if(artist.length>1)artist_list +='<li><a href="#'+ specialty +'"  class="VIEWALL">View All</a></li>'; 
		for( var i in artist){
			var a_name=  artists[artist[i]].name
			artist_list +='<li><a class="' + filterName(a_name.toUpperCase()) + '" href="#'+ specialty + '/' + filterName(a_name.toUpperCase()) + '">' + a_name +'</a></li>';
		}
	
	extra_list = '</ul>';
	extra_list += '<dt class="lb-options-title">lightbox options:</dt>';		
	extra_list += '<dd><ul class="lb-options">';
	extra_list += '<ul><li class="lb-ui-add"><a href="#">Add Image</a></li>';
	extra_list += '<li><a href="javascript:addAllImagesToLightBox()">ADD ALL</a></li>';
	extra_list += '<li><a href="javascript:emptyLightBox();">Remove All</a></li>';
	extra_list += '</ul></dl>'
	$('#sidemenu .em-menu .sub').html(artist_list);
	$('#sidemenu .em-menu .artist-links').html(extra_list);
}
function getSpecialties(artist){
		var artist = filterName(artist);
		return artists[artist.toUpperCase()]['specialties'];
}
function getArtists(specialty){
	    var specialty = filterName(specialty);
		return specialties[specialty.toUpperCase()]['artists'];
}
function showCats(e){
	//alert($(e.target).text());
	var spec =getSpecialties($(e.target).text());
	//console.log('cats =>',  spec);
	for( var i in spec){
		$('.'+spec[i]).addClass('selected');
	}
}
function hideCats(e){
   var spec =getSpecialties($(e.target).text());
   for( var i in spec){
	   $('.'+spec[i]).removeClass('selected');
   }

}
function hideAllCats(){
 	$('dd.specialties li a').removeClass('selected');
}
function showArtists(e){
		var artists =getArtists($(e.target).text());
		for( var i in artists){
		 	$('.'+artists[i]).addClass('selected');
		}
	}
function hideArtists(e){
		var artists =getArtists($(e.target).text());
		for( var i in artists){
			$('.'+artists[i]).removeClass('selected');
		}
}
function showArtist(a_id, s_id){
		$('#image-area').css({'height':'590px'});
		$.getJSON('getArtistPics.php?',{artist:a_id,specialty:s_id}, parseResult);
		homepage=false;
		slideOut();
	}
function showSpecialty(s_id,a_id){
	$('#image-area').css({'height':'590px'});
	//console.log('showSpecialty')
	$.getJSON('getSpecialtyPics.php?',{artist:a_id,specialty:s_id}, parseResult);
	//$.getJSON('getSpecialtyPics.php?',{artist:a_id,specialty:s_id}, function(){console.log('done')});
	homepage=false;
	slideOut();
}	
function showLightBox(a_id){
	$('#image-area').css({'height':'590px'});
	$.getJSON('getLightBoxPics.php?',{artist:a_id}, parseLightBoxResult);
	homepage=false;
	slideOut();
}

function showShared(a_id){
	$('#image-area').css({'height':'590px'});
	var shareID = theHashBits[1];
	$.getJSON('getSharedPics.php?',{artist:a_id, shareID:shareID}, parseSharedResult);
	homepage=false;
	slideOut();
}


function showTearsheet(a_id){
//trace('TEARSHEET')
	$('#image-area').css({'height':'590px'});
	$.getJSON('getTearsheetPics.php?',{artist:a_id}, parseResult);
	homepage=false;
	slideOut();
}	
function showVideos(a_id){
	$('#image-area').css({'height':'590px'});
	$.getJSON('getVideos.php?',{artist:a_id}, parseVideoResult);
	homepage=false;
	slideOut();
}
function parseVideoResult(data){
		hideGallery();
		$('#video').show();
		$('#video').vimeobridge({width:849,height:552, data:data.images, backgroundcolor:'#e0c600', hilightcolor:'#323133', bordercolor:'#323133',   darkcolor:'#e0c600'});

	}
	
	function showArtistBio(name, bio){
		 $('#overlay').fadeIn('fast')
		$('.overlay-content').html('<h2>'+name+'</h2><p>'+bio+'</p>')

	}
	
/*###############################################
//##	LIGHTRBOX
/###############################################*/

/*	GENERAL LIGHTBOX
_____________________________________________*/

	function updateLightBoxUI(){
		
		$('.lb-ui-add').unbind();
		if(isInLightbox()){
			setLBUIToRemove();
		}else{
			setLBUIToAdd();
		}
		
	}
	
	function showLightBoxCount(){
		$('.lightbox-links a').html("VIEW LIGHTBOX ("+ getNumberOfPicsInLightBox() + ")" )
	}
	
	function setLBUIToRemove(){
		$('.lb-ui-add').html('<a href="javascript:removeFromLightBox()">Remove Image</a>');
		//$('#lb-ui .lb-ui-add').bind('click', function(e){removeFromLightBox()});
	
	}
	
	function setLBUIToAdd(){
		$('.lb-ui-add').html('<a href="javascript:addToLightBox()">Add Image</a>');

		//$('#lb-ui .lb-ui-add').html('<img src="images/plus.png" />  LIGHTBOX');
		//$('#lb-ui .lb-ui-add').bind('click', function(e){addToLightBox()});
	}
	
	function addToLightBox(){
		image_id = $('#imageViewer').imageviewer.getCurrentPic();
		if(! $.cookie('data')) $.cookie('data',[image_id])
		var cookieArray = $.cookie('data').split(',');
		if(getPos(image_id,cookieArray)==-1){
			cookieArray.push(image_id);
		}
		$.cookie('data', cookieArray);
		setLBUIToRemove()
		showLightBoxCount()
	}
		
	function addAllImagesToLightBox(){
		if($.cookie('data')==null){
			var cookieArray =[];
		}else{
			var cookieArray = $.cookie('data').split(',');
		}
		for(i in imageData){
			if(getPos(imageData[i].id,cookieArray)==-1){
				cookieArray.push(imageData[i].id);
			}
		}
		$.cookie('data', cookieArray);
		setLBUIToRemove()
		showLightBoxCount()
	}
	
	function isInLightbox(){
		if($.cookie('data')==null)return false;//for ie
		image_id = $('#imageViewer').imageviewer.getCurrentPic();
		var cookieArray = $.cookie('data').split(',');
		return(getPos(image_id,cookieArray)>=0)?true:false;
		//return(cookieArray.indexOf(image_id)>=0)?true:false;
		//return false;
	}
	
	function removeFromLightBox(){
		image_id = $('#imageViewer').imageviewer.getCurrentPic();
		var cookieArray = $.cookie('data').split(',');
		//var index = cookieArray.indexOf(image_id);
		var index = getPos(image_id,cookieArray);
		if(index!=-1){
			cookieArray.splice(index,1);
		}
		//console.log('cookieArray = ' +  cookieArray + ' length=> ' + cookieArray.length)
		$.cookie('data', cookieArray);
		if(section == 'lightbox'){
			if(cookieArray.length < 1)clearLightBoxUI();
			setLightBox()
		}else{
			setLBUIToAdd();
		}
		showLightBoxCount();
	}
	function getNumberOfPicsInLightBox(){
		if($.cookie('data')==null)return 0;//for ie
		var cookieArray = $.cookie('data').split(',');
	
		if(cookieArray[0]=='')cookieArray.pop();
		return cookieArray.length
	}
	
	function getNamesInLightBox(){
	//this is the longway... may make a lookup table 
	
	
	}
	
	
	function clearLightBox(){
		$.cookie('data',['']);
		showLightBoxCount();
		$('#sidemenu .em-menu .artist-links').html('');
		setLightBox();
		clearLightBoxUI()
	}
	
	
	function emptyLightBox(){
		$.cookie('data',[''])
		showLightBoxCount();
		updateLightBoxUI();
	}
	
	function clearLightBoxUI(){
		if(section == 'lightbox'){
			
			setSubTitle('');
			setTitle('');
			$('#lb-ui .lb-ui-add').hide();
			$('#lb-ui .lb-ui-print').hide();
			$('.print').hide();
			$('#lb-ui .lb-ui-add').unbind();
			
		}
	}

	
/*	PRINT LIGHTBOX
_____________________________________________*/

function printLightBoxImage(){
	//window.print();
	printElement = $('<div>');
	image = $('.iv-images img');
	out = '<img src="'+image.attr('src')+'" />';
	filename = image.attr('src').split('/')[image.attr('src').split('/').length-1]
	out += '<p style ="color:#333">&copy;' + $('#imageViewer').imageviewer.getCurrentPicArtist() +'</p>';
	out += '<p style ="color:#333;clear:both">LIZ BAUGHER	EMISSARYARTISTS.COM	773.489.9888</p>';
	printElement.html(out);
	printElement.printElement();

}

function printLightBox(size){
//console.log('size');
	if(size=="small"){
		$.getJSON('getLightBoxPicsForPrint.php?',{dummydata:100}, setUpAndPrintContact);
	}
	if(size=="large"){
		$.getJSON('getLightBoxPicsForPrint.php?',{dummydata:100}, setUpAndPrintLarge);
	}
}


function printSharedGallery(size,id){
//console.log('size');
	if(size=="small"){
		$.getJSON('getSharedPics.php?',{shareID:id}, setUpAndPrintContact);
	}
	if(size=="large"){
		$.getJSON('getSharedPics.php?',{shareID:id}, setUpAndPrintLarge);
	}
}


function setUpAndPrintContact(data){
	imageData = data.images;
	var out ="";
	printElement = $('<div>');
	for(var i in imageData){
		out += '<div style="float:left;margin:0 5px 5px 0px;color:#333;border:1px solid #ccc;padding:5px"><img src="'+imageData[i].large+' " width="200"  style="padding-bottom:5px" /><br />&copy;'+imageData[i].artist + '</div>';
	}
	out += '<div id="print-footer"><p style ="clear:both;color:#333">LIZ BAUGHER	EMISSARYARTISTS.COM	773.489.9888</p></div>';
	printElement.html(out);
	printElement.printElement();

}

function setUpAndPrintLarge(data){
	imageData = data.images;
	var out ="";
	printElement = $('<div>');
	for(var i in imageData){
		out += '<div class="print-page"><img src="'+imageData[i].large+'" /><br />&copy;'+imageData[i].artist;
		out += '<p style ="clear:both;color:#333">LIZ BAUGHER	EMISSARYARTISTS.COM	773.489.9888</p></div>';
	}
	
	printElement.html(out);
	printElement.printElement();

}



/*	SHARE LIGHTBOX
_____________________________________________*/
function showShareBox(){
	 $('#overlay').fadeIn('fast')
	$('.overlay-content').html('<h1>Share Your Lightbox</h1><div class="shareerror"></div><ul><li><label for="recipient">Recipient\'s Address:</label><input type="text" class="requiredField email" name="recipient" id="recipient" style="width:90%" /><p><em>Separate multiple email addresses with commas</em></p></li><li><label for="sender">Sender\'s Address:</label><input type="text" class="requiredField email" name="sender" id="sender" style="width:90%" /></li> <li><label for="message">Message:</label><textarea name="message" id="message" rows="5" cols="30" style="width:90%"></textarea></li> <li><input type="submit" value="share" onClick="submitShare()" /></li> </ul>')

}

function hideShareBox(){
	$('#overlay').fadeOut('fast'); 
}


function submitShare(){//when the form is submitted.
		//validate email
		hasError = false;
		hasEmailError = false;
		jQuery('.error').remove();
		
	$('.requiredField').each(function() {
			if(jQuery.trim(jQuery(this).val()) == '') {
				var labelText = jQuery(this).prev('label').text();
				jQuery(this).parent().append('<span class=\"error\">You forgot to enter your '+labelText+'.</span>');
				jQuery(this).addClass('inputError');
				hasError = true;
			} else if(jQuery(this).hasClass('email')) {
				var emails = jQuery(this).val().split(',');
				
				for(var email in emails){
					//console.log(emails[email])
					var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
					
					if(!emailReg.test(jQuery.trim(emails[email]))){
						hasEmailError = true;
					}
				}
				if(hasEmailError){
					hasError = true;
					var labelText = jQuery(this).prev('label').text();
					jQuery(this).parent().append('<span class=\"error\">The '+labelText+' contains an invalid email address.</span>');
					jQuery(this).addClass('inputError');
				}
			}
	});
	
	if(!hasError) {
		var recipient = $('.overlay-content #recipient').val();
		var sender = $('.overlay-content #sender').val();
		var message = $('.overlay-content #message').val();
		//console.log($.cookie('data'));
		$.getJSON('shareLightbox.php?',{recipient:recipient, sender:sender, message:message}, shareLightboxDone);
	}
	
}

function shareLightboxDone(){
	$('.overlay-content').html('<h1>Thanks</h1><a href="javascript:hideShareBox()">close</a>')

}

function parseSharedResult(data){
	
		parseResult(data);
		var shareID = theHashBits[1];
		//if(getNumberOfPicsInLightBox() >0){
		var lbImages = data.artists
		var aList = [];
		var artist_list = '<ul>';
		if(lbImages.length > 1){
			artist_list += '<li><a href="#SHARE/'+shareID+'/" class="VIEWALL">VIEW ALL</a></li>';
		}
		for(var i in lbImages){
			artistName = lbImages[i].artist;
			if(getPos(artistName,aList)==-1){
			//if(aList.indexOf(artistName)==-1){
				aList.push(artistName);
				artist_list += '<li><a class="' + filterName(artistName).toUpperCase() + '" href="#SHARE/'+shareID+'/'+ filterName(artistName).toUpperCase()+'">'+ artistName +'</a></li>';
			}
		}
		artist_list += '</ul>';
		
	extra_list = '</ul>';
	extra_list += '<dt class="lb-options-title">lightbox options:</dt>';		
	extra_list += '<dd><ul class="lb-options">';
	extra_list += '<ul><li class="lb-ui-add"><a href="#">Add Image</a></li>';
	extra_list += '<li><a href="javascript:addAllImagesToLightBox()">ADD ALL</a></li>';
	extra_list += '<li><a href="javascript:emptyLightBox();">Remove All</a></li>';
	
	
	extra_list += '<dt class="lb-options-title">printing options:</dt>';		
	extra_list += '<li><a href="javascript:printLightBoxImage();">Print Current Image</a></li>';
	extra_list += '<li><a href="javascript:printSharedGallery(\'large\',\''+ shareID +'\');">Print All</a></li>';
	extra_list += '<li><a href="javascript:printSharedGallery(\'small\',\''+ shareID +'\');">Print Contact Sheet</a></li>';

	
	extra_list += '</ul></dl>'
	$('#sidemenu .em-menu .sub').html(artist_list);
	$('#sidemenu .em-menu .artist-links').html(extra_list);
		
		//	$('#sidemenu .em-menu .sub').html(extra_list);
		//}else{
		//	$('#sidemenu .em-menu .sub').html('<ul><li>This shared lightbox contains no images</li></ul>');
		
		//}
		
		
	setSelected()
	}
	
	
	
	

function parseLightBoxResult(data){
	
		parseResult(data);
			$('#sidemenu .em-menu .artist-links').html('');
		if(getNumberOfPicsInLightBox() >0){
		var lbImages = data.artists
		var aList = [];
		var extra_list = '<ul>';
		if(lbImages.length > 1){
			extra_list += '<li><a href="#LIGHTBOX" class="VIEWALL">VIEW ALL</a></li>';
		}
		for(var i in lbImages){
			artistName = lbImages[i].artist;
			if(getPos(artistName,aList)==-1){
			//if(aList.indexOf(artistName)==-1){
				aList.push(artistName);
				extra_list += '<li><a class="' + filterName(artistName).toUpperCase() + '" href="#LIGHTBOX/'+ filterName(artistName).toUpperCase()+'">'+ artistName +'</a></li>';
			}
		}
			extra_list += '</ul>';
			$('#sidemenu .em-menu .sub').html(extra_list);
			var extra_list = '<dt>lightbox options:</dt>';		
			extra_list += '<dd><ul class="lb-options">';
			
			extra_list += '<li><a href="javascript:printLightBoxImage();">Print Current Image</a></li>';
			extra_list += '<li><a href="javascript:printLightBox(\'large\');">Print All</a></li>';
			extra_list += '<li><a href="javascript:printLightBox(\'small\');">Print Contact Sheet</a></li>';
			extra_list += '<li><a href="javascript:clearLightBox();">Remove All</a></li>';
			extra_list += '<li><a href="javascript:showShareBox();">Share</a></li></dd>';
			
			
			
			extra_list += '</ul>';
			$('#sidemenu .em-menu .artist-links').html(extra_list);
			setSelected()
		}else{
			$('#sidemenu .em-menu .sub').html('<ul><li>Your Lightbox Is Empty</li></ul>');
		
		}
	
	
	}
	
	
function parseResult(data) {
  		imageData = data.images;
  		initImageViewer();
	};
function initImageViewer(){
		$('#video').html('');
		$('#video').hide();
		//console.log('INITIMAGEVIWER')
		$('#imageViewer').html();
		$('#imageViewer').imageviewer({width:849,height:552, data:imageData, backgroundcolor:'#e0c600',hilightcolor:'#323133', bordercolor:'#262525',   darkcolor:'#e0c600', showUI:true});
	}
function setSelected(){
	
	$('#sidemenu a').removeClass('selected');
	$('#site-links a').removeClass('selected');
	var primary = theHashBits[0];
	
	if(primary =="SHARE"){
		var secondary = theHashBits[2];
	}else{
		var secondary = theHashBits[1];
	}
	
	
	if(primary!="" && $('#site-links a.' + primary).length > 0 ){
		$('#site-links a.' +primary).addClass('selected');
		if(primary=="LIGHTBOX"){
			if($('#sidemenu a.' +secondary ).length <1)$('#sidemenu a:first').addClass('selected');
			$('#sidemenu a.' +secondary ).addClass('selected');
		}
		
	}else{
		if($('#sidemenu a.' +secondary ).length <1)$('#sidemenu a:first').addClass('selected');
		$('#sidemenu a.' +secondary ).addClass('selected');
	}
}

/*	SIGNUP FOR RSS
_____________________________________________*/


function signup(){
	 $('#overlay').fadeIn('fast')
	$('.overlay-content').html('<h1>Sign up for Emissary Artists Updates.</h1><div class="shareerror"></div><ul><li><label for="name">Name:</label><input type="text" class="requiredField" name="name" id="name" /></li><li><label for="company">Company:</label><input type="text" class="company" name="company" id="company" /></li><li><label for="email">Email:</label><input type="text" class="requiredField email" name="email" id="email" /></li> <li><input type="submit" value="Sign Up" onClick="submitSignUp()" /></li> </ul>')

}


function submitSignUp(){//when the form is submitted.
		//validate email
		hasError = false;
		jQuery('.overlay-content .error').remove();
		
	$('.requiredField').each(function() {
			if(jQuery.trim(jQuery(this).val()) == '') {
				var labelText = jQuery(this).prev('label').text();
				jQuery(this).parent().append('<span class=\"error\">You forgot to enter your '+labelText+'.</span>');
				jQuery(this).addClass('inputError');
				hasError = true;
			} else if(jQuery(this).hasClass('email')) {
				var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
				if(!emailReg.test(jQuery.trim(jQuery(this).val()))) {
					var labelText = jQuery(this).prev('label').text();
					jQuery(this).parent().append('<span class=\"error\">The '+labelText+' is not a valid email address.</span>');
					jQuery(this).addClass('inputError');
					hasError = true;
				}
			}
	});
	
	if(!hasError) {
		var name = $('.overlay-content #name').val();
		var company = $('.overlay-content #company').val();
		var email = $('.overlay-content #email').val();
		///feedburner
		//var myDiv = $('<div></div>');
		//var htmlForm = '<form action="http://feedburner.google.com/fb/a/mailverify" method="post" target="popupwindow" onsubmit="window.open(\'http://feedburner.google.com/fb/a/mailverify?uri=emissaryartists/zTzY\', \'popupwindow\', \'scrollbars=yes,width=550,height=520\');return true"><input type="text" value="'+email+'" name="email"/><input type="hidden" value="emissaryartists/zTzY" name="uri"/><input type="hidden" name="loc" value="en_US"/></form>';
		//myDiv.html(htmlForm);
		//$('form', myDiv).submit();
		//console.log($.cookie('data'));
		$.getJSON('signup.php?',{name:name, company:company, email:email}, shareLightboxDone);
		$('.overlay-content').html('<h1>Thanks for signing up!</h1><a href="javascript:hideShareBox()">close</a>')

	}
	
}




function trace(m){
	if(console){
		console.log(m)
	}

}



