$(function() {

	//USE A SELECT BOX AS LINKS
		//used in sidebar of artist pages
	$(".select_box_links").change(function() {
	  document.location = this.value;
	});
	
	//BLOG - changes link for header on blog
	$('.blog #site-header a').attr('href','http://www.growinginalldirections.org/blog');
	
	//TOGGLE ADDITONAL INFO FOR EVENT ARCHIVE
	//improve from judys version
	$('#event_expand').click( function() {
		$('.event_expanded').slideToggle(400);
		return false;
	})

	//DONATE TAB
	$("#donate_tab a").fancybox({
		'transitionIn'	:	'fade',
		'transitionOut'	:	'fade',
		'speedIn'		:	200, 
		'speedOut'		:	200,
		'overlayOpacity' : .5,
		'titleShow' 	: false
	});
	
	//SEND US A MESSAGE LINK
	$("#contact_link a").fancybox({
		'titleShow' 	: false,
		'type' : 'inline'
	});

	//generic lightbox class, currently for single event pg
	$('.lightbox').fancybox({
		'titleShow' 	: false
	})

	//FARM IMAGE MAPS
	$('.farm-map area').tooltip();

	//JCYCLE ON HOME PAGE
	$('#home-gallery ul').cycle({ 
		fx: 'fade',
		speed: 200,
		timeout: 4000,
		random: 1
	});
	//home gallery is hidden in css, takes a while to load js, and select random, visibility comes on afterward (if not doing random just hide all except 1st with css)
	$('#home-gallery img').css('visibility','visible');
	
	//REMOVE TITLE LINKS FROM NAV
	$("#nav a").removeAttr("title");

	//FIXES IMAGES THAT ARE LINK, TO NOT HAVE UNDERLINED
	$('a').has('img').css('border-bottom', '0');

	//CREATES A BULLET FOR THE CURRENT PAGE IN THE NAV
	/* $('#nav .current_page_item a').prepend('<span class="current_marker">&raquo;</span>'); */

	//SHORTCUT TO LOGIN (use ` key)
	$(window).keypress(function(e) {
	  if (e.which == '96') {
	  	window.location = "http://www.growinginalldirections.org/wp/wp-admin";
	     e.preventDefault();
	   }
	});
	
	//FORM BLUR/FOCUS
	$('input[type=text]').each(function() {
	
		var default_value = this.value;
		$(this).css('color','#aaa');
		
		$(this).focus(function(){
			if(this.value == default_value) {
				this.value = '';
				$(this).css('color','#333');
			}
		});
		
		$(this).blur(function(){
			if(this.value == '') {
				this.value = default_value;
				$(this).css('color','#aaa');
			}
		});
	
	});
	
	//
	$('.today').append('<img class="todayimg" src="http://www.growinginalldirections.org/wp/wp-content/themes/projectgrow/lib/imgs/graphic-yamamoto.jpg" />')
	
	
	/* @ temp for artist inactive */
	$(".artist-album.inactive a").click(function () {
		return false;
	});
	$(".artist-album.inactive").hover(
		function() {
			$(this).append('<p>Artwork coming soon.</p>');
		}, 
		function () {
    		$(this).find("p:last").remove();
	});	
	
	/*****************************
		CROSS BROWSER FIXES
	******************************/
	
	//$(':last-child').css('marginRight', '0px'); //for ie7
	
	
	/*****************************
		SLIDESHOWS
	******************************/
	
	//JQUERY CYCLE - FRONT IMAGE
	$('#nowShowing').cycle({
		fx: 'fade',
		speed: 800, //transition speed
		timeout:  5000 //how long each shows
	});
	
	//ADDS HASH, DIRECT LINK TO IMAGES	
	var title = $('#slideshow .title').html();
	var index = 0, hash = window.location.hash;
	if (hash && title ) { // @@@ added title as well since if only hash, when use hash to anchor to ids, causes potential issues, title insures this only runs on pages w a slideshow (could still run into issues if a page had a slideshow and was utilizing an id anchor)
		index = /\d+/.exec(hash)[0];
		//index = /[^-]+$/.exec(hash)[0]; //this matches the numbers after the title and hyphen - probably not best regex possible, but seems to work
		index = (parseInt(index) || 1) - 1; // slides are zero-based
	}
	
	//JQUERY CICYLE - IMAGE GALLERIES
	$('#slideshow').cycle({
		fx:	 'fade',
		speed:  10,
		startingSlide: index,
	    prev:   '#prev', 
	    next:   '#next', 
		timeout: 0,
		containerResize: 0,
		after: onAfter
	});
	function onAfter(curr, next, opts) {
		//handles the hash
		window.location.hash = opts.currSlide + 1;
	   	//window.location.hash = title + '-' + (opts.currSlide + 1); //@ if want to keep title, use this and regex i started above 
	   	
	   	//handles states for next/prev buttons
	   	var index = opts.currSlide;
	    $('#prev')[opts.currSlide == 0 ? 'addClass' : 'removeClass']('inactive');
	    $('#next')[opts.currSlide == opts.slideCount - 1 ? 'addClass' : 'removeClass']('inactive');
	   	var caption = 'IMAGE ' + (opts.currSlide + 1) + ' / ' + opts.slideCount;
		$('#count').html(caption);
	}
	
	//ADD KEYBOARD NAVIGATION FOR SLIDESHOWS
	$(window).keydown(function(e){
		if(e.which == 37){ $('#prev').click();}
		else if(e.which == 39){ $('#next').click();}
	});	
	
	/* @experiments in creating thumbs */
	//just use this... http://jquery.malsup.com/cycle/pager2.html
	//$('.image img').clone().appendTo('#thumbs');
	
	
	//OPEN ART IN LIGHTBOX (@don't need first class anymore i believe)
	$(".gallery a, .enlarge").fancybox({
		'transitionIn'	:	'fade',
		'transitionOut'	:	'fade',
		'speedIn'		:	200, 
		'speedOut'		:	200,
		'overlayOpacity' : .5,
		'titleShow' 	: false
	});




	
	/*****************************
		SMALL PLUGINS
	******************************/

	/* BROWSER DETECTIONS
		more here... http://css-tricks.com/snippets/jquery/browser-detetction/
	*/

	$('html').removeClass('no-js');
	
	/*
	CSS Browser Selector v0.3.5 (Feb 05, 2010)
	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',o='opera',h=document.documentElement,b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3.5')?g+' ff3 ff3_5':is('firefox/3')?g+' ff3':is('gecko/')?g:is('opera')?o+(/version\/(\d+)/.test(ua)?' '+o+RegExp.$1:(/opera(\s|\/)(\d+)/.test(ua)?' '+o+RegExp.$2:'')):is('konqueror')?'konqueror':is('chrome')?w+' chrome':is('iron')?w+' iron':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);



}); /* end document ready */




