$(window).load(function() {
	$('#loading').fadeOut(250, function(){
		$('#loading').remove();
			$('#container').fadeIn(250);
			$('#intro').fadeIn(2500).animate({opacity: 1.0}, 1000).fadeOut(650, function(){
				 $('#initialcycle').fadeIn(1000);
				 $('#initialcycle').cycle({ 
					fx:	'fade',
					speed:	1000,
					sync:	0, 
					timeout:	2300,
					delay: 500,
					autostop:	1,
					end:	function() {  
						$('#initialcycle').fadeOut(250, function(){
							$('#introcontainer').remove();
						});
						$('#homecontainer').animate({opacity: 1.0}, 1000).fadeIn(2000);
						$('#right').cycle({																	// cycle right images on main page
							speed:	2000,
							next:   '#right',
							timeout: 16000
						});
					}
					});
				});									 	
			});
});

jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
	if ((t/=d/2) < 1) return c/2*t*t + b;
	return -c/2 * ((--t)*(t-2) - 1) + b;
};

$(document).ready(function(){
		
		// general
		
		$('.introskip').click(function(){
										$('#intro').stop();
										$('#initialcycle').stop().fadeOut(250, function(){
																								 $('#introcontainer').remove();
																								 });
										$('#homecontainer').animate({opacity: 1.0}, 1000).fadeIn(2000);
										$('#right').cycle({																	// cycle right images on main page
															speed:	2000,
															next:   '#right',
															timeout: 16000
															});
										});
		
		$('#intro').hide();
		$('#initialcycle').hide();
		
		$("a").focus(function() {	$(this).blur();	});										// blur links on click
	
		$('#menu li img:not(active)').css('opacity', 0.6);									// set menu to 0.6 opacity on ready
		
		$('#menu li img:not(active)').hover(function() {									// fade menu item opacity up on hover
		$(this).stop().animate({opacity: 1.0}, 100);
			}, function() {
		$(this).stop().animate({opacity: 0.6}, 100);
		});
		
//		$('#menu li img:(active)').rm('a').
	
			
		// biography page
		
		$('.next').click(function(){ 														// cycle bio pages forward on .next link click
								$(this).parent().parent().fadeOut(500,function(){
																$(this).next('div').fadeIn(500);
																});
								return false;
								});
		
		$('.prev').click(function(){ 														// cycle bio pages backward on .prev link click
								$(this).parent().parent().fadeOut(500,function(){
																$(this).prev('div').fadeIn(500);
																});
								return false;
								});
		$('.medialist').click(function(){													// media list popup
										$('#container').css('opacity', 1).animate({opacity:0.35}, 750);
									 	$('#medialist').fadeIn(750);
										$('#medialistclose').fadeIn(750);
										return false;
									   });
		
		$('.closemedialist').click(function(){
												$('#container').animate({opacity:1}, 750);
												$('#medialist').fadeOut(750);
												$('#medialistclose').fadeOut(750);
												return false;
												});
	
		// links page
		
		$('#linkscontent li img').css('opacity', 0.6);
		
		$('#linkscontent li img').hover(function() {									// fade menu item opacity up on hover
		$(this).stop().animate({opacity: 1.0}, 100);
			}, function() {
		$(this).stop().animate({opacity: 0.6}, 100);
		});
		
		
		// portfolio and media pages
		
		var $thumbprev = $('a.thumbprev'),	//prev button
			$thumbnext = $('a.thumbnext'),	//next button
			$mainprev = $('a.mainprev'),	//prev button
			$mainnext= $('a.mainnext');		//next button

		// portfolio items
		
		$("div#thumbnail img[name='blanco']").click(function(){
			$('#mainimage').trigger( 'goto', [ 0 ] , function(){
				$('#mainimage').fadeOut(250, function(){
					$('#mainimage').html('<ul><li class="scrollable"><img src="images/blanco1.jpg" width="294" height="294" /></li><li class="scrollable"><img src="images/blanco2.jpg" width="294" height="294" /></li><li class="scrollable"><img src="images/blanco3.jpg" width="294" height="294" class="lastimage" /></li></ul>').animate({opacity: 1.0}, 250).fadeIn(250);
				});
			});
		});	
		$("div#thumbnail img[name='wyndfieldwest']").click(function(){
			$('#mainimage').trigger( 'goto', [ 0 ] , function(){
				$('#mainimage').fadeOut(250, function(){
					$('#mainimage').html('<ul><li><img src="images/wyndfieldwest1.jpg" width="294" height="294" class="scrollable" /></li><li><img src="images/wyndfieldwest2.jpg" width="294" height="294" class="scrollable" /></li><li><img src="images/wyndfieldwest3.jpg" width="294" height="294" class="scrollable" /></li><li><img src="images/wyndfieldwest4.jpg" width="294" height="294" class="scrollable lastimage" /></li></ul>').animate({opacity: 1.0}, 250).fadeIn(250);
				});
			});
		});	
		$("div#thumbnail img[name='76glenroad']").click(function(){
			$('#mainimage').trigger( 'goto', [ 0 ] , function(){
				$('#mainimage').fadeOut(250, function(){
					$('#mainimage').html('<ul><li class="scrollable"><img src="images/76glenroad1.jpg" width="294" height="294" /></li><li class="scrollable"><img src="images/76glenroad2.jpg" width="294" height="294" class="lastimage" /></li></ul>').animate({opacity: 1.0}, 250).fadeIn(250);
				});
			});
		});	
		$("div#thumbnail img[name='123SpruceH&H']").click(function(){
			$('#mainimage').trigger( 'goto', [ 0 ] , function(){
				$('#mainimage').fadeOut(250, function(){
					$('#mainimage').html('<ul><li class="scrollable"><img src="images/123SpruceH&H1.jpg" width="294" height="294" /></li><li class="scrollable"><img src="images/123SpruceH&H2.jpg" width="294" height="294" /></li><li class="scrollable"><img src="images/123SpruceH&H3.jpg" width="294" height="294" /></li><li class="scrollable"><img src="images/123SpruceH&H4.jpg" width="294" height="294" /></li><li class="scrollable"><img src="images/123SpruceH&H5.jpg" width="294" height="294" /></li><li class="scrollable"><img src="images/123SpruceH&H6.jpg" width="294" height="294" /></li><li class="scrollable"><img src="images/123SpruceH&H7.jpg" width="294" height="294" /></li><li class="scrollable"><img src="images/123SpruceH&H8.jpg" width="294" height="294" /></li><li class="scrollable"><img src="images/123SpruceH&H9.jpg" width="294" height="294" class="lastimage" /></li></ul>').animate({opacity: 1.0}, 250).fadeIn(250);
				});
			});
		});	
		$("div#thumbnail img[name='whitekitchen']").click(function(){
			$('#mainimage').trigger( 'goto', [ 0 ] , function(){
				$('#mainimage').fadeOut(250, function(){
					$('#mainimage').html('<ul><li class="scrollable"><img src="images/whitekitchen1.jpg" width="294" height="294" class="lastimage" /></li></ul>').animate({opacity: 1.0}, 250).fadeIn(250);
				});
			});
		});
		$("div#thumbnail img[name='260doris']").click(function(){
			$('#mainimage').trigger( 'goto', [ 0 ] , function(){
				$('#mainimage').fadeOut(250, function(){
					$('#mainimage').html('<ul><li class="scrollable"><img src="images/260doris1.jpg" width="294" height="294" /></li><li class="scrollable"><img src="images/260doris2.jpg" width="294" height="294" class="lastimage" /></li></ul>').animate({opacity: 1.0}, 250).fadeIn(250);
				});
			});
		});		
		$("div#thumbnail img[name='266erskine']").click(function(){
			$('#mainimage').trigger( 'goto', [ 0 ] , function(){
				$('#mainimage').fadeOut(250, function(){
					$('#mainimage').html('<ul><li class="scrollable"><img src="images/266erskine1.jpg" width="294" height="294" /></li><li class="scrollable"><img src="images/266erskine2.jpg" width="294" height="294" /></li><li class="scrollable"><img src="images/266erskine3.jpg" width="294" height="294" class="lastimage" /></li></ul>').animate({opacity: 1.0}, 250).fadeIn(250);
				});
			});
		});	
		$("div#thumbnail img[name='401qqw']").click(function(){
			$('#mainimage').trigger( 'goto', [ 0 ] , function(){
				$('#mainimage').fadeOut(250, function(){
					$('#mainimage').html('<ul><li class="scrollable"><img src="images/401qqw1.jpg" width="294" height="294" /></li><li class="scrollable"><img src="images/401qqw2.jpg" width="294" height="294" /></li><li class="scrollable"><img src="images/401qqw3.jpg" width="294" height="294" /></li><li class="scrollable"><img src="images/401qqw4.jpg" width="294" height="294" /></li><li class="scrollable"><img src="images/401qqw5.jpg" width="294" height="294" /></li><li class="scrollable"><img src="images/401qqw6.jpg" width="294" height="294" /></li><li class="scrollable"><img src="images/401qqw7.jpg" width="294" height="294" /></li><li class="scrollable"><img src="images/401qqw8.jpg" width="294" height="294" /></li><li class="scrollable"><img src="images/401qqw9.jpg" width="294" height="294" /></li><li class="scrollable"><img src="images/401qqw10.jpg" width="294" height="294" class="lastimage" /></li></ul>').animate({opacity: 1.0}, 250).fadeIn(250);
				});
			});
		});		
		$("div#thumbnail img[name='bartleybullparkway']").click(function(){
			$('#mainimage').trigger( 'goto', [ 0 ] , function(){
				$('#mainimage').fadeOut(250, function(){
					$('#mainimage').html('<ul><li class="scrollable"><img src="images/bartleybullparkway1.jpg" width="294" height="294" /></li><li class="scrollable"><img src="images/bartleybullparkway2.jpg" width="294" height="294" class="lastimage" /></li></ul>').animate({opacity: 1.0}, 250).fadeIn(250);
				});
			});
		});	
		$("div#thumbnail img[name='corporateoffice']").click(function(){
			$('#mainimage').trigger( 'goto', [ 0 ] , function(){
				$('#mainimage').fadeOut(250, function(){
					$('#mainimage').html('<ul><li class="scrollable"><img src="images/corporateoffice1.jpg" width="294" height="294" /></li><li class="scrollable"><img src="images/corporateoffice2.jpg" width="294" height="294" class="lastimage" /></li></ul>').animate({opacity: 1.0}, 250).fadeIn(250);
				});
			});
		});
		$("div#thumbnail img[name='risingchefs']").click(function(){
			$('#mainimage').trigger( 'goto', [ 0 ] , function(){
				$('#mainimage').fadeOut(250, function(){
					$('#mainimage').html('<ul><li class="scrollable"><img src="images/risingchefs1.jpg" width="294" height="294" /></li><li class="scrollable"><img src="images/risingchefs2.jpg" width="294" height="294" /></li><li class="scrollable"><img src="images/risingchefs3.jpg" width="294" height="294" class="lastimage" /></li></ul>').animate({opacity: 1.0}, 250).fadeIn(250);
				});
			});
		});		
		$("div#thumbnail img[name='fishoutofwater']").click(function(){
			$('#mainimage').trigger( 'goto', [ 0 ] , function(){
				$('#mainimage').fadeOut(250, function(){
					$('#mainimage').html('<ul><li><img src="images/fishoutofwater1.jpg" width="294" height="294" class="lastimage" /></li></ul>').animate({opacity: 1.0}, 250).fadeIn(250);
				});
			});
		});		
		$("div#thumbnail img[name='ridpaths']").click(function(){
			$('#mainimage').trigger( 'goto', [ 0 ] , function(){
				$('#mainimage').fadeOut(250, function(){
					$('#mainimage').html('<ul><li><img src="images/ridpaths1.jpg" width="294" height="294" class="scrollable" /></li><li><img src="images/ridpaths2.jpg" width="294" height="294" class="scrollable" /></li><li><img src="images/ridpaths3.jpg" width="294" height="294" class="scrollable" /></li><li><img src="images/ridpaths4.jpg" width="294" height="294" class="scrollable" /></li><li><img src="images/ridpaths5.jpg" width="294" height="294" class="scrollable lastimage" /></li></ul>').animate({opacity: 1.0}, 250).fadeIn(250);
				});
			});
		});	
		$("div#thumbnail img[name='028']").click(function(){
			$('#mainimage').trigger( 'goto', [ 0 ] , function(){
				$('#mainimage').fadeOut(250, function(){
					$('#mainimage').html('<ul><li><img src="images/0281.jpg" width="294" height="294" /></li></ul>').animate({opacity: 1.0}, 250).fadeIn(250);
				});
			});
		});
		$("div#thumbnail img[name='sunroom']").click(function(){
			$('#mainimage').trigger( 'goto', [ 0 ] , function(){
				$('#mainimage').fadeOut(250, function(){
					$('#mainimage').html('<ul><li><img src="images/sunroom1.jpg" width="294" height="294" class="scrollable" /></li><li><img src="images/sunroom2.jpg" width="294" height="294" class="scrollable" /></li></ul>').animate({opacity: 1.0}, 250).fadeIn(250);
				});
			});
		});	
		
		// media items

		$("div#thumbnail img[name='blancoidsmovie']").click(function(){
			$('#mainmovie').fadeOut(250, function(){
				$('#mainmovie').html('<object width="320" height="294"><param name="movie" value="http://www.youtube.com/v/dgEQf_k2yK0c&autoplay=1&rel=0&fs=1&color1=0x666666&color2=0x666666&border=0&loop=0"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/dgEQf_k2yK0&autoplay=1&rel=0&fs=1&color1=0x666666&color2=0x666666&border=0&loop=0" type="application/x-shockwave-flash" allowfullscreen="true" width="320" height="294"></embed></object>').animate({opacity: 1.0}, 250).fadeIn(250);
			});
		});	
		$("div#thumbnail img[name='pcmovie']").click(function(){
			$('#mainmovie').fadeOut(250, function(){
				$('#mainmovie').html('<object width="320" height="294"><param name="movie" value="http://www.youtube.com/v/LJpx6Hjqq1c&autoplay=1&rel=0&fs=1&color1=0x666666&color2=0x666666&border=0&loop=0"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/LJpx6Hjqq1c&autoplay=1&rel=0&fs=1&color1=0x666666&color2=0x666666&border=0&loop=0" type="application/x-shockwave-flash" allowfullscreen="true" width="320" height="294"></embed></object>').animate({opacity: 1.0}, 250).fadeIn(250);
			});
		});	
		$("div#thumbnail img[name='ids2009movie']").click(function(){
			$('#mainmovie').fadeOut(250, function(){
				$('#mainmovie').html('<object width="320" height="294"><param name="movie" value="http://www.youtube.com/v/UF7btM3mn_o&autoplay=1&rel=0&fs=1&color1=0x666666&color2=0x666666&border=0&loop=0"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/UF7btM3mn_o&autoplay=1&rel=0&fs=1&color1=0x666666&color2=0x666666&border=0&loop=0" type="application/x-shockwave-flash" allowfullscreen="true" width="320" height="294"></embed></object>').animate({opacity: 1.0}, 250).fadeIn(250);
			});
		});	
		$("div#thumbnail img[name='philipsmovie']").click(function(){
			$('#mainmovie').fadeOut(250, function(){
				$('#mainmovie').html('<object width="320" height="294"><param name="movie" value="http://www.youtube.com/v/6KbTLQbcDYo&autoplay=0&rel=0&fs=1&color1=0x666666&color2=0x666666&border=0&loop=0"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/6KbTLQbcDYo&autoplay=1&rel=0&fs=1&color1=0x666666&color2=0x666666&border=0&loop=0" type="application/x-shockwave-flash" allowfullscreen="true" width="320" height="294"></embed></object>').animate({opacity: 1.0}, 250).fadeIn(250);
			});
		});			
		$("div#thumbnail img[name='blancomovie']").click(function(){
			$('#mainmovie').fadeOut(250, function(){
				$('#mainmovie').html('<object width="320" height="294"><param name="movie" value="http://www.youtube.com/v/8xT9Shg0F5o&autoplay=0&rel=0&fs=1&color1=0x666666&color2=0x666666&border=0&loop=0"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/8xT9Shg0F5o&autoplay=1&rel=0&fs=1&color1=0x666666&color2=0x666666&border=0&loop=0" type="application/x-shockwave-flash" allowfullscreen="true" width="320" height="294"></embed></object>').animate({opacity: 1.0}, 250).fadeIn(250);
			});
		});
		$("div#thumbnail img[name='leezamovie']").click(function(){
			$('#mainmovie').fadeOut(250, function(){
				$('#mainmovie').html('<object width="320" height="294"><param name="movie" value="http://www.youtube.com/v/PfrGICZIYc0&autoplay=0&rel=0&fs=1&color1=0x666666&color2=0x666666&border=0&loop=0"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/PfrGICZIYc0&autoplay=1&rel=0&fs=1&color1=0x666666&color2=0x666666&border=0&loop=0" type="application/x-shockwave-flash" allowfullscreen="true" width="320" height="294"></embed></object>').animate({opacity: 1.0}, 250).fadeIn(250);
			});
		});	
		$("div#thumbnail img[name='venmarmovie']").click(function(){
			$('#mainmovie').fadeOut(250, function(){
				$('#mainmovie').html('<object width="320" height="294"><param name="movie" value="http://www.youtube.com/v/xa3J1V5Vd9k&autoplay=0&rel=0&fs=1&color1=0x666666&color2=0x666666&border=0&loop=0"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/xa3J1V5Vd9k&autoplay=1&rel=0&fs=1&color1=0x666666&color2=0x666666&border=0&loop=0" type="application/x-shockwave-flash" allowfullscreen="true" width="320" height="294"></embed></object>').animate({opacity: 1.0}, 250).fadeIn(250);
			});
		});		
		$("div#thumbnail img[name='torlysmovie']").click(function(){
			$('#mainmovie').fadeOut(250, function(){
				$('#mainmovie').html('<object width="320" height="294"><param name="movie" value="http://www.youtube.com/v/ifLeuX-yQEs&autoplay=0&rel=0&fs=1&color1=0x666666&color2=0x666666&border=0&loop=0"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/ifLeuX-yQEs&autoplay=1&rel=0&fs=1&color1=0x666666&color2=0x666666&border=0&loop=0" type="application/x-shockwave-flash" allowfullscreen="true" width="320" height="294"></embed></object>').animate({opacity: 1.0}, 250).fadeIn(250);
			});
		});	
		$("div#thumbnail img[name='123sprucemovie']").click(function(){
			$('#mainmovie').fadeOut(250, function(){
				$('#mainmovie').html('<object width="320" height="294"><param name="movie" value="http://www.youtube.com/v/kWgt8TwnBTU&autoplay=0&rel=0&fs=1&color1=0x666666&color2=0x666666&border=0&loop=0"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/kWgt8TwnBTU&autoplay=1&rel=0&fs=1&color1=0x666666&color2=0x666666&border=0&loop=0" type="application/x-shockwave-flash" allowfullscreen="true" width="320" height="294"></embed></object>').animate({opacity: 1.0}, 250).fadeIn(250);
			});
		});
		
		$('#thumbnail').serialScroll({															// scrolling porfolio items
									items:'.scrollable',
									prev:'a.thumbprev',
									next:'a.thumbnext',
									duration:750,
									force:true,
									stop:true,
									lock:false,
									cycle:false, 											// don't pull back once you reach the end
									jump: false, 
									easing:'easeOutQuart',
									onBefore:function( e, elem, $pane, $items, pos ){
																					$thumbprev.add($thumbnext).fadeIn();
																					if( pos == 0 )
																						$thumbprev.fadeOut();
																					else if( pos == $items.length-1 )
																						$thumbnext.fadeOut(); }
									});
		
		$('#mainimage').serialScroll({															// scrolling porfolio items
									items:'.scrollable',
									prev:'a.mainprev',
									next:'a.mainnext',
									constant:false,
									duration:750,
									force:true,
									stop:true,
									lock:false,
									cycle:false, 
									lazy: true,
									jump: false, 
									easing:'easeOutQuart',
									onBefore:function( e, elem, $pane, $items, pos ){
																					$mainprev.add($mainnext).fadeIn();
																					if( pos == 0 )
																						$mainprev.fadeOut();
																					else if( pos == $items.length-1 )
																						$mainnext.fadeOut(); }
									});
		
		$('.arrow').css('opacity', 0.6);									// set menu to 0.6 opacity on ready
		
		$('.arrow').hover(function() {									// fade menu item opacity up on hover
		$(this).stop().animate({opacity: 1.0}, 100);
			}, function() {
		$(this).stop().animate({opacity: 0.6}, 100);
		});

		
		

});