     ////////////////////////////////////////////
    //   mnartists.org javascript             //
   //    december 2004                       // 
  //    updated spring  2009				//
 //     walker art center | eric williams  //  yo and justin heideman too!
////////////////////////////////////////////

var nowWork = 0;
var nowTour = 0;
var thisTime = null;
var swapOn = true;
var autoSwap = 0;
var shortUrl ='';

jQuery.noConflict();
jQuery(document).ready(function(){
	
	//overrides for jquery media
	//jQuery.fn.media.mapFormat('mp3','quicktime');  //reasign mpeg audio to quicktime
	//jQuery.fn.media.mapFormat('mpga','quicktime');  //reasign mpeg audio to quicktime
	
	
	//navigation
	jQuery("li.hasSub").hoverIntent(showSub,hideSub);
	
	//update login status
	checkStatus();
	//homepage rotators
	if (jQuery(".featuredWork.works").length > 0){
		jQuery('.featuredWork.works').cycle({ 
		    fx:     'fade', 
		    speed:   300, 
		    timeout: 4000, 
		    pause:   1,
		    next:   '#workRight',  
		    prev:   '#workLeft',
			cleartype: 1
		});
	}
	if (jQuery(".featuredWork.tours div.tourSlide").length > 1){
		jQuery('.featuredWork.tours').cycle({ 
		    fx:     'fade', 
		    speed:   300, 
		    timeout: 4000, 
		    pause:   1,
		    next:   '#collectRight',  
		    prev:   '#collectLeft',
			cleartype: 1,
			delay: 1500  //start delay on this one
		});
	} else {
		if (jQuery(".featuredWork.tours div.tourSlide").length == 1){
			jQuery(".featuredWork.tours div.tourSlide:hidden").show();
			jQuery('#collectLeft, #collectRight').hide();
			jQuery('div#feature-two div.slideShowTitle').css('borderWidth', '1px');
		}
	}


//for article image galleries
	if (jQuery("#articleImageGallery").length > 0){
		var artGalHeight = 0;
		var articleGal = jQuery('#articleImageGallery');
		

		articleGal.cycle({ 
   			fx:  'fade', 
		    speed:   800, 
		    timeout: 5000, 
			delay: 2000,
		    pause:   0,
		    next:   '#articleImageGalleryNext',  
		    prev:   '#articleImageGalleryPrev',
			containerResize: 0,
			cleartype: 1
		});
		articleGal.cycle('pause');
		articleGal.css('height',150);
	
		
		var articleImageGalleryStart = (function(){
			jQuery('#articleImageGalleryClose').addClass('active');
			jQuery('#articleImageGalleryStop').addClass('active');
				
			articleGal.animate({'height':artGalHeight},400);
			jQuery('#articleImageGalleryNav h2').html('Article Image Gallery');
			jQuery('#articleGalleryStart').hide();
			articleGal.cycle('resume');
			
		});
		
		
		var articleImageGalleryClose = (function(){
			articleGal.animate({'height':150},400,'linear',function(){jQuery('#articleGalleryStart').show()});
			jQuery('#articleImageGalleryStop').removeClass('active');
			jQuery('#articleImageGalleryClose').removeClass('active');
			articleGal.cycle('pause');
		});
		
		var articleImageGalleryStop = (function(){
			articleGal.cycle('pause');
			jQuery('#articleImageGalleryStop').removeClass('active');
		});
		
		

		jQuery("#articleImageGallery div.articleImageSub").each(function(){
			h = jQuery(this).height();
			if (h > artGalHeight){	artGalHeight = h;	}
		});
		
		var a = jQuery("<a></a>").attr({
				'href':'#',
				'id': 'articleGalleryStart'
			}).html("<span>Expand slideshow</span>").bind("click",articleImageGalleryStart );		
		articleGal.prepend(a);
		
		
		jQuery('#articleImageGalleryNav h2 a').bind("click",articleImageGalleryStart );
		
		//add extra function to close/stop/next/prev buttons
		jQuery('#articleImageGalleryStop').bind("click", articleImageGalleryStop);
		jQuery('#articleImageGalleryPrev').bind("click", articleImageGalleryStart);
		jQuery('#articleImageGalleryNext').bind("click", articleImageGalleryStart);
		jQuery('#articleImageGalleryClose').bind("click", articleImageGalleryClose);
	
	}
	


	
});


function mnShareThis(image,desc){
	//facebook
	jQuery('#share_facebook').bind('click',function(){
		u=location.href;
		t=document.title;
		window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),
		'sharer','toolbar=0,status=0,width=626,height=436');
		return false;
	});
	
	//myspace
	jQuery('#share_myspace').bind('click',function(){
		t=document.title;
		c='<img src="'+image+'" /><br />'+desc;
		u=location.href;
		window.open('http://www.myspace.com/index.cfm?fuseaction=postto&u='+encodeURIComponent(u)+
			'&t='+encodeURIComponent(t)+'&c='+encodeURIComponent(c)+'&l=3');
		return false;
	});
	
	
	//twitter
	jQuery('#share_twitter').bind('click',function(){
		if (shortUrl != ''){
			if (document.title.indexOf("mnartists.org | ") == 0){
				theTitle =  document.title.substr(16);
			} else {
				theTitle = document.title;
			}
			
			message = theTitle + " @mnartistsdotorg - " + shortUrl;
			window.open('http://twitter.com/home/?status='+encodeURIComponent(message));
			return false;
		}
	});
	
	//delicious
	jQuery('#share_delicious').bind('click',function(e){
		window.open('http://delicious.com/save?jump=yes&url='+
			encodeURIComponent(window.location)+'&title='+encodeURIComponent(document.title));
		return false;
	});
	
	//google bookrmakrs
	jQuery('#share_google').bind('click',function(e){
		window.open('http://www.google.com/bookmarks/mark?op=edit&bkmk='+
			encodeURIComponent(window.location)+'&title='+encodeURIComponent(document.title));
		return false;
	});
	
	
	//yahoo bookrmakrs
	jQuery('#share_yahoo').bind('click',function(e){
		window.open('http://bookmarks.yahoo.com/toolbar/savebm?u='+
			encodeURIComponent(window.location)+'&t='+encodeURIComponent(document.title)+"&opener=bm&ei=UTF-8",
			'sharer','toolbar=0,status=0,resizable=1,scrollbars=1,width=450,height=480');
		return false;
	});
	
	
	
	if (shortUrl == ''){
		jQuery.getJSON("http://api.bit.ly/shorten?login=mnartists&apiKey=R_f655bf7855d88031921da64773a99305&format=json&version=2.0.1&callback=?", 
			{longUrl: location.href},
			function(data){
				for (var r in data.results) {	first_result = data.results[r]; break;}     
				if (first_result){	
					shortUrl = first_result.shortUrl; 
				}
			}
		);
	}
	
}



function showSub(){ //shows subnav
	jQuery(this).children('.inner').fadeIn('fast');
}
function hideSub(){ //hides subnav
	jQuery(this).children('.inner').fadeOut('fast');
}



function openWin(path, height, width, scroll) {
	var props = "width=" + width + ",height=" + height + ",toolbar=no,scrollbars=" + scroll + ",resizable=no,menubar=no,status=no,directories=no,location=no";
	theWin=open(path,'theWin', props);
	if (theWin.focus) theWin.focus();
}

/* Added following JS */

function popRefresh(place) {
	window.opener.document.location = place;
	self.close();
}




function ticketBox() {
	if (jQuery("#ticketBox").css('display') == "none") {
		jQuery("#ticketBox").slideDown(); // = "block";
		jQuery("#ticketInfo").text("Hide Ticket Info");
	}
	else {
		jQuery("#ticketBox").slideUp(); //style.display = "none";
		jQuery("#ticketInfo").text("Ticket Info");
	}
}


function checkStatus() {
		jQuery.get( 'servlet/status', {}, showStatus, "xml" )
}


function showStatus(xmlHttpRequest, responseHeader) {
	
	//console.log(xmlHttpRequest, responseHeader);
	
    // Process HTTP response and update input form
	//var xmlDoc = xmlHttpRequest.responseXML;
	var xmlDoc = xmlHttpRequest;
	
	var items = xmlDoc.documentElement.getElementsByTagName("loggedin");
	var htmlOut = "";
	login = jQuery('#loginlink');
	join = jQuery('#joinlink');
	if (items.length > 0) {
		// logged in!
		login.html('<html:link forward="callLogoff">Log Off</html:link>');
		join.html('<html:link forward="callUserHome">My Account</html:link>');
	} else {
		// logged out!
		login.html('<html:link forward="callLogin">Log In</html:link>');
		join.html('<html:link forward="callJoin">Join / Subscribe</html:link>');
	}
	
	items = xmlDoc.documentElement.getElementsByTagName("isAdmin");
	optionsList = jQuery('#articleEditOptionList');
	if (items.length > 0 && optionsList.length > 0) {
		// logged in admin!
		var rid = articleRID;
		optionsList.prepend('<li style="margin-left:0px;"><a href="/editArticle.do?action=edit&currentOnly=true&activeOnly=false&sortBy=7&sortOrder=false&rid='+rid+'&rtype=-1">+ Edit This Article</a></li>');
	}
}
