// JavaScript Document

 $(document).ready(function(){ 
		$variables = new Array(); // Array to hold global vars
		$variables['menuLinks'] = $("#nav_523026 .selected ul").html();
	//	$("#nav_523026 .selected ul").hide().slideDown();


/* ------ CHECK TO SEE IF WE NEED TO SHOW BACK TO TOP LINK ------ */
	/*
		if($('#main').height() > $(window).height()) {
		$('#back').show();
		} else {
		$('#back').hide();
		}

	  */

					
		/* ------ SHOW SUBMENU IF WE ARE IN THE RIGHT SELECTION ------ */

		$('.photoGallery .photos span:first').show();	
		
		/* ------ JQUERY FOR WORK GALLERY PREVIEWER ------ */
	
		
		$variables['viewing'] = false; //set inital states (not viewing info, 1st picture showing)
		$variables['currentPhoto'] = '#photo1';
		$("#infoBox").removeClass('plain_info').addClass('information');

		/* ------ JQUERY TO RESTORE SUBNAV + SET ACTIVE STATE ------ */
			$variables['photoExists'] = $('.photoGallery');
			if($variables['photoExists'].length !== 0) {
				$('#nav_523026').find('a').each(function() {
				if($(this).attr('href') == '/what.html') {
					$(this).parent('li').addClass('selected');
				}
			});
			
				
			
			$('#nav_523026').find('a').each(function() {
				if($(this).html().substr(0,3) == $(".photoGallery .classifications").html().substr(0,3)) {
					$(this).parent('li').addClass('selected');
				}
			});	

			$('.overview').find('a').each( function() {
				if($(this).html() == $('.photoGallery h3').html()) {
					$(this).parent('li').addClass('selected');
			}
			});

			}

		$variables['numPhotos'] = $('.photoGallery span img').length;
		if($variables['numPhotos'] == 1) {
			$('.imageButton').hide();
		} 
		if ($variables['numPhotos'] == 2) {
			//$('.photoGallery .navigation')[3].hide();
			$('.photoGallery .navigation li:gt(2)').hide();
		} 

		
		$('#infoButton').click(function(event) { //function for info button
			event.preventDefault();
		if($variables['viewing'] === false) { //if not currently in view state

		/*	$(".photoGallery .information").animate(
				{ top: "0px"  }, { duration : 750, easing : 'easeInOutCirc'} );	*/
$(".photoGallery .information").fadeTo("fast", 1.0);
			
			$('.photoGallery li a').each( function() { // for all navigation links at the top
				$(this).fadeTo("fast", 0.33); //fade out
				$(this).addClass('fadedOut'); //add class fadedOut which removes hover states
			});
			$variables['viewing'] = true; // set viewing state to true
			$variables['imageSelection'] = '#photo1'; // set new photo  selection
		}

		});

	$('#close_button').click(function(event) { // when we press the close button animate the info box back up.
		event.preventDefault();
		if($variables['viewing'] === true) {
	$(".photoGallery .information").fadeTo("fast", 0.0);
		
			$('.photoGallery li a').each( function() { // fade the navigation buttons back in
		$(this).fadeTo("fast", 1.0);
		$(this).removeClass('fadedOut'); // restore hover states

		});
		$variables['viewing'] = false; //set viewing state to false

		}
	});
	
	$(".imageButton").click(function(event){
											 

	event.preventDefault();
		if(($variables['viewing'] === false) && ($variables['currentPhoto'] != $(this).attr('href'))) {
			//make sure we only show a new image if we aren't showing the info box AND not already 
			// looking at that picture
	$('.photoGallery li a').each( function() {
		$(this).removeClass('on');	
		});
		
		$(this).addClass('on');
		
		$variables['imageSelection'] = $(this).attr('href');
		$($variables['currentPhoto']).fadeOut('fast', function() {
			$($variables['imageSelection']).fadeIn('fast');
			$variables['currentPhoto'] = $variables['imageSelection'];
															   
															   });
		}
	});


		/* ------ JQUERY FOR INDEX PAGE ------ */
	$('#param').find('img').each( function() {
			$variables['linkRef'] = $(this).attr('src');
			$(this).before($variables['linkRef'] );
			$(this).remove();
			});
	$variables['flashvars'] = $('#param').html();
	//$('#param').remove();

	

/* ------ ADD IMAGE ROLLOVERS ------ */


if (!($.browser.msie && $.browser.version.substr(0,1)<7)) {


			$('.workDiv a img, .workDiv2 a img').each( function() {
				$variables['imageHeight'] = $(this).height();
				$variables['imageWidth'] = $(this).width();
				$(this).before("<div class='imageRollOver'></div>");
				$('.imageRollOver').css({height: $variables['imageHeight'], width: $variables['imageWidth'], display: 'block', opacity:'0.0'});});
			
		$('#footer .flickr_badge_image img').each( function() {
				$variables['imageHeight'] = $(this).height();
				$variables['imageWidth'] = $(this).width();
				$(this).before("<div class='imageRollOverFlickr'></div>");
				$('.imageRollOverFlickr').css({height: $variables['imageHeight'], width: $variables['imageWidth'], display: 'block', opacity:'0.0'});
		});
		
		$('#footer .teaser img').each ( function() {
				$variables['imageHeight'] = $(this).height()+1;
				$variables['imageWidth'] = $(this).width()+1;
		$(this).before("<div class='imageRollOverLatest'></div>");
		$('.imageRollOverLatest').css({height: $variables['imageHeight'], width: $variables['imageWidth'], display: 'block', opacity:'0.0'});
		});
		
		
		$('.imageRollOver, .imageRollOverFlickr, .imageRollOverLatest').hover(function() {
					$(this).fadeTo(100, .3);
				}, function() { 
					$(this).fadeTo(100, .0);
				//	$(this).css({opacity:'0.0'});
				});
		
}

if ($("#featureDiv").length > 0){
	flasher();
}
$("p.home-content-main").find('.tooltip').each(function() {
$variables.tooltipVar = $(this).attr('title');
$(this).append("<span class='toolover'>"+$variables.tooltipVar+"<span>");
});

$('span.tooltip').hover(function() {
$(this).find('.toolover').fadeIn();
}, function() { 
$(this).find('.toolover').fadeOut(100);
});


/*  ---------------------- This is for the secret garden part page at /super-secret-gallery.html

// ------------------ */



//*
$.getJSON("http://api.flickr.com/services/rest/?&method=flickr.people.getPublicPhotos&api_key=acfcc10feb710fa774fdae3810a0de55&user_id=42834093@N06&format=json&jsoncallback=?", 
function(data){
	
$.each(data.photos.photo, function(i,item){
//http://farm{farm-id}.static.flickr.com/{server-id}/{id}_{secret}.jpg

	$variables.smallLink = "http://farm"+ item.farm +".static.flickr.com/"+ item.server + "/" + item.id + "_" + item.secret +"_s.jpg";
	$variables.smallRetrieve = "http://www.flickr.com/photos/frontendbunker/"+ item.id+"/";

	//$("<img/>").attr("src", smallLink).appendTo("#secret").wrap("<a href='" + smallRetrieve + "'></a>").fadeIn();

	var  img = new Image();
	  // image onload
	$(img).load(function () {
		  // hide first
		
	
		$(this).css('display','none'); // since .hide() failed in safari
		  //
	//	$(this).wrap("<a href='" + $variables.smallRetrieve + "'></a>").appendTo("#secret");
//	$(this);
	 $(this).appendTo("#secret").fadeIn();
	  }).error(function () {
		  $(el).remove();
	  }).attr('src', $variables.smallLink);
		//img.wrap("<a href='" + $variables.smallRetrieve + "'></a>");	


 });

});
 // */



});

flasher = function() {
		var par = $variables['flashvars'];
swfobject.embedSWF("/homepage.swf", "featureDiv", "650", "340", "8.0.0", "expressInstall.swf", {passed:par}, {wmode: "transparent"},{});

};


