jQuery.noConflict();
jQuery(document).ready(function($){
	/* --------------- slideshow thumbs --------------- */
	//use pixastic image manipulation to desaturate one of the two thumbnails
	//using "normal" javascript because pixastic's jquery function wasn't working in Safari
	
	jQuery(".desat").each(function(){
		Pixastic.process($(this).get(0), "desaturate", {average : false});
	});
	

	//hides the desaturated thumbnail and shows the normal thumbnail
	thumbFocus=function(thumb){
		//make the argument a jquery object
		var t=$(thumb);

		//note: IE doesn't play nice with fading transparent PNGs, so we only enable this feature for other browsers.
		//see: http://stackoverflow.com/questions/1375646/jquery-animate-opacity-doesnt-work-properly-on-ie/1990728#1990728
		if(!$.browser.msie){
			t.find(".desat").fadeTo("normal",0);
			t.find(".normal").fadeTo("normal",1);
			t.find(".inner-shadow").fadeTo("normal",1);
		}
	};
	//hides the normal thumbnail and shows the desaturated thumbnail
	thumbBlur=function(thumb){
		var t=$(thumb);
		//if thumbnail is active, we never want to blur it
		if(!$.browser.msie && !t.hasClass("active")){
			t.find(".desat").fadeTo("normal",0.2);	
			t.find(".normal").fadeTo("normal",0);
			t.find(".inner-shadow").fadeTo("normal",1);
		}		
	};
	//call the focus & blur functions on hover in & out
	$(".slide-nav a").hover(
		function(){
			thumbFocus(this);
		},
		function(){
			thumbBlur(this);
		}
	);
/* --------------- jQuery Cycle --------------- */
	//define common "pagerAnchorBuilder" and "before" functions for both front page and project page sliders
	
	pagerFunction=function(idx, slide) { 
				//build the pager and add class "pagerAnchor" to all pager elements
				var id2=idx+1;
				var anchor='.pager li:eq(' + idx + ') a';
				$(anchor).addClass("pagerAnchor");
	     		//return selector string for existing anchor 
		        return anchor; 
			};
	var firstLoad=true;
	beforeFunction=function(current, next, options, flag){
				//we are using the callback function "before" because we want
				//the fading in & out to happen as soon as someone clicks
				//and not when the slide actually shows. Also, using "before" means
				//that the effect will work wheter the slide transition is the result of a click
				//by the user, or is automatically called after the timeout. 
				
				//don't execute the function if this is the first time
				if(firstLoad==true){
					firstLoad=false;
				}else{
				//first, get the index of the next slide
				var idx=$(".slider li").index($(next));
				
				//then use that index to find the correct thumbnail, give it class "active", and focus it
				$('.pager li:eq('+ idx +') a').addClass("active").each(function(){
					thumbFocus(this);
				});
				
				//find all the other thumbnails, remove class "active", and blur them. 
				$('.pager li:not(:eq('+ idx +')) a').removeClass("active").each(function(){
					thumbBlur(this);
				});
				
				//adjust size of frame if needed
				currentImgHeight=$(current).find("img").height();
				nextImgHeight=$(next).find("input").val();
				//remove 20 pixel for the top and bottom shadows
				borderHeight=nextImgHeight-20;
				if(currentImgHeight!=nextImgHeight){
					$('.large-container').animate({
					    height: nextImgHeight+'px'
				  	}, 200, function() {
				    // Animation complete.
				  	});
					$('.large-container .left, .large-container .right').animate({
					    height: borderHeight+'px'
				  	}, 200, function() {
				    // Animation complete.
				  	});
				}
				}
			};
});