jQuery.fn.fadeIn = function(speed, callback) { 
    return this.animate({opacity: 'show'}, speed, function() { 
        if (jQuery.browser.msie)  
            this.style.removeAttribute('filter');  
        if (jQuery.isFunction(callback)) 
            callback();  
    }); 
}; 
 
jQuery.fn.fadeOut = function(speed, callback) { 
    return this.animate({opacity: 'hide'}, speed, function() { 
        if (jQuery.browser.msie)  
            this.style.removeAttribute('filter');  
        if (jQuery.isFunction(callback)) 
            callback();  
    }); 
}; 
 
jQuery.fn.fadeTo = function(speed,to,callback) { 
    return this.animate({opacity: to}, speed, function() { 
        if (to == 1 && jQuery.browser.msie)  
            this.style.removeAttribute('filter');  
        if (jQuery.isFunction(callback)) 
            callback();  
    }); 
}; 


$(document).ready(function() {

	//var loaded = 0;
	//$('img').attr('title', 'preview_start').load(function () {
		//loaded++; 
		//if(loaded == 4){ 
			$('.slideshow_preview1').delay(0).css({'display':'block'}).cycle({
				fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
				timeout: 6000, // milliseconds between slide transitions (0 to disable auto advance) 
				speed: 3000, // speed of the transition (any valid fx speed value) 
				delay: 0 // additional delay (in ms) for first transition (hint: can be negative) 
			});
			$('.slideshow_preview2').delay(3000).css({'display':'block'}).cycle({
				fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
				timeout: 6000, // milliseconds between slide transitions (0 to disable auto advance) 
				speed: 3000, // speed of the transition (any valid fx speed value) 
				delay: 3000 // additional delay (in ms) for first transition (hint: can be negative)
			});
			$('.slideshow_preview3').delay(6000).css({'display':'block'}).cycle({
				fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
				timeout: 6000, // milliseconds between slide transitions (0 to disable auto advance) 
				speed: 3000, // speed of the transition (any valid fx speed value) 
				delay: 6000 // additional delay (in ms) for first transition (hint: can be negative)
			});
			$('.slideshow_preview4').delay(9000).css({'display':'block'}).cycle({
				fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
				timeout: 6000, // milliseconds between slide transitions (0 to disable auto advance) 
				speed: 3000, // speed of the transition (any valid fx speed value) 
				delay: 9000 // additional delay (in ms) for first transition (hint: can be negative) 
			});
		//} 
	//});

	
	$('#project_images').css({'display':'none'});
	
	/*$('#nav a.portfolio').each(function(index) {
		$(this).onload(function() {*/
			
			//$('#warren_web').trigger('click');
			
			/*alert($('li').innerHTML);
			$('#project_items a:first').trigger('click');*/
			/*return false;*/
		/*});
	});*/
});
	
$(document).ready(function() {
	$('#project_items a').each(function(index) {
		$(this).click(function() {
			$start = true; //identify first slide loaded
			$('.slideshow').cycle('destroy');
			$('.active-item').removeClass();
			$('#project_instructions').css({'display':'none'});
			
			var $item = $(this).attr('id');
			var $folder = $(this).attr('section');
			$('#project_details').css({'opacity':'0'});
			$('#project_images').css({'display':'block'});
			$('#project_images').css({'opacity':'0'});
			
			$(this).addClass('active-item');
			//$('#project_details').animate({opacity:1},'slow').load($folder+'/'+$item+'_details.php');
			$('#project_details').fadeTo('slow',1).load($folder+'/'+$item+'_details.php');
			$('#project_images').delay('slow').animate({opacity:1},'slow').load(
			  $folder+'/'+$item+'_images.php',
				function() { 
				  $('.slideshow').delay('slow').cycle({
  		      fx: 'wipe', // name of transition effect (or comma separated names, ex: 'fade,scrollUp,shuffle') 
						  /* choose your transition type: blindX, blindY, blindZ, cover, curtainX, curtainY, 
						  fade, fadeZoom, growX, growY, none, scrollUp, scrollDown, scrollLeft, scrollRight, 
							scrollHorz, scrollVert, shuffle, slideX, slideY, toss, turnUp, turnDown, 
							turnLeft, turnRight, uncover, wipe, zoom */
						// override these globally if you like (they are all optional) 
						activePagerClass: 'activeSlide', // class name used for the active pager link 
						after: onAfter, // null, // transition callback (scope set to element that was shown):  function(currSlideElement, nextSlideElement, options, forwardFlag) 
						allowPagerClickBubble: false, // allows or prevents click event on pager anchors from bubbling 
						animIn: null, // properties that define how the slide animates in 
						animOut: null, // properties that define how the slide animates out 
						autostop: 0, // true to end slideshow after X transitions (where X == slide count) 
						autostopCount: 0, // number of transitions (optionally used with autostop to define X) 
						backwards: false, // true to start slideshow at last slide and move backwards through the stack 
						before:  onBefore, //null, // transition callback (scope set to element to be shown):     function(currSlideElement, nextSlideElement, options, forwardFlag) 
						cleartype: !$.support.opacity, // true if clearType corrections should be applied (for IE) 
						cleartypeNoBg: false, // set to true to disable extra cleartype fixing (leave false to force background color setting on slides) 
						containerResize: 0, //1, // resize container to fit largest slide 
						continuous: 0, // true to start next transition immediately after current one completes 
						cssAfter: null,//{ opacity:0 }, //null, // properties that defined the state of the slide after transitioning out 
						cssBefore: null, // properties that define the initial state of the slide before transitioning in 
						delay: 0, // additional delay (in ms) for first transition (hint: can be negative) 
						easeIn: null, // easing for "in" transition 
						easeOut: null, // easing for "out" transition 
						easing: null, // easing method for both in and out transitions 
						end: null, // callback invoked when the slideshow terminates (use with autostop or nowrap options): function(options) 
						fastOnEvent: 0, // force fast transitions when triggered manually (via pager or prev/next); value == time in ms 
						fit: true, //0, // force slides to fit container 
						fxFn: null, // function used to control the transition: function(currSlideElement, nextSlideElement, options, afterCalback, forwardFlag) 
						height: 'auto', // container height 
						manualTrump: true, // causes manual transition to stop an active transition instead of being ignored 
						next: '#next2', // null, // selector for element to use as event trigger for next slide 
						nowrap: 0, // true to prevent slideshow from wrapping 
						onPagerEvent: null, // callback fn for pager events: function(zeroBasedSlideIndex, slideElement) 
						onPrevNextEvent: null, // callback fn for prev/next events: function(isNext, zeroBasedSlideIndex, slideElement) 
						pager: '#spages', //null, // selector for element to use as pager container 
						pagerAnchorBuilder: onPagerAnchorBuilder, //null, // callback fn for building anchor links:  function(index, DOMelement) 
						pagerEvent: 'click.cycle', // name of event which drives the pager navigation 
						pause: true, // true to enable "pause on hover" 
						pauseOnPagerHover: true, // true to pause when hovering over pager link 
						prev: '#prev2', // null, // selector for element to use as event trigger for previous slide 
						prevNextEvent: 'click.cycle', // event which drives the manual transition to the previous or next slide 
						random: false, // true for random, false for sequence (not applicable to shuffle fx) 
						randomizeEffects: 1, // valid when multiple effects are used; true to make the effect sequence random 
						requeueOnImageNotLoaded: true, // requeue the slideshow if any image slides are not yet loaded 
						requeueTimeout: 250, // ms delay for requeue 
						rev: 0, // causes animations to transition in reverse (for effects that support it such as scrollHorz/scrollVert/shuffle) 
						shuffle: null, // coords for shuffle animation, ex: { top:15, left: 200 } 
						slideExpr: null, // expression for selecting slides (if something other than all children is required) 
						slideResize: 1, // force slide width/height to fixed size before every transition 
						speed: 1000, // speed of the transition (any valid fx speed value) 
						speedIn: null, // speed of the 'in' transition 
						speedOut: null, // speed of the 'out' transition 
						startingSlide: 0, // zero-based index of the first slide to be displayed 
						sync: 1, // true if in/out transitions should occur simultaneously 
						timeout: 4000, // milliseconds between slide transitions (0 to disable auto advance) 
						timeoutFn: null, // callback for determining per-slide timeout value:  function(currSlideElement, nextSlideElement, options, forwardFlag) 
						updateActivePagerLink: null // callback fn invoked to update the active pager link (adds/removes activePagerClass style) 
					});
			  }
			);
			return false;
		});
	});	
});


function onBefore(curr,next,opts) { 
	//alert($start);
	if (opts.slideCount != 1) {
		if ($start) {
			$start = false;
		} else {
			$(curr).delay('slow').animate({opacity:0},'slow');
		}
	}
	/*var $slide = $(next); 
	var w = $slide.outerWidth(); 
	$slide.css({ 
		marginLeft: (350 - w) / 2, 
	}); */
	//alert(w);
}; 

function onAfter(curr,next,opts) {
	//alert($(next).attr('title'));
	//alert($(next).attr('src'));
	var t = '';
	var t = $("img", next).attr('title');
	if (t != ''){
		$('#caption').html(t);
	}
	if (opts.slideCount == 1) {		
		$('#prev2').css({'display':'none'});
		$('#next2').css({'display':'none'});
		$('#spagesSection').css({'margin-left':'35px'});
		//$('#controls').css({'display':'none'});
	}
	
	/*var caption = 'Image ' + (opts.currSlide + 1) + ' of ' + opts.slideCount;
	$('#caption').html(caption);*/
}

function onPagerAnchorBuilder(idx, slide) { 
	var i = idx + 1;
	return '<li><a href="#">' + i + '</a></li>';
} 


/*$(document).ready(function() {
    $('.slideshow').cycle({
		fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
	});
});*/

//$('#slideshow').cycle('command');
	//The following command strings are supported: 
	//'pause'   // pauses the slideshow, slideshow can be resumed with 'resume' command 
	//'resume'  // resumes a paused slideshow 
	//'toggle'  // toggles the pause/resume state of the slideshow 
	//'next'    // advances slideshow to next slide 
	//'prev'    // advances slideshow to previous slide 
	//'stop'    // stops the slideshow 
	//'destroy' // stops the slideshow and unbinds all events 
