gallery = {
	c:null,
	t:null,
	i:null,
	a:1,
	init:function(){
		if($("#gallery_items li").length){
			gallery.c=$("#gallery_items li").eq(0).attr('id');
			gallery.i=0;
			$("#gallery_nav a").unbind().bind('click',function(){  gallery.btn.pause(); gallery.go(this); return false; });
			$("#gallery_items img").each(function(){ $(this).css({position:'absolute',top:'50%',left:'50%',marginTop:'-'+(this.height/2)+'px',marginLeft:'-'+(this.width/2)+'px'}); });
			var n=$("#gallery_items li").length-7;
			if(n>0){
				$("#gallery_nav_slider").slider({
					value:0,
					min:0,
					max:n,
					change:function(event,o){
						$("#gallery_nav_content").animate({marginLeft:'-'+Number(o.value*72)+'px'});
					},
					slide:function(event,o){
						$("#gallery_nav_content").animate({marginLeft:'-'+Number(o.value*72)+'px'});
					},
					animate:6000
				});
			}
			$("#gallery_items li:gt(0)").hide();
			var playpause=$("<div id=\"gallery_playpause\"><a id=\"gallery_playpause_btn\">Pause</a></div>");
			$("#gallery").append(playpause).addClass('js');
			$("#gallery_playpause_btn").button({icons:{primary:'ui-icon-pause'},text:false}).bind('click',function(){ gallery.btn.state(); return false; });
			gallery.t=window.setTimeout("gallery.auto()",6000);
			//$("#gallery_menu").css('opacity',0.3).hover(function(){ $("#gallery_menu").animate({'opacity':1}); },function(){ $("#gallery_menu").animate({'opacity':0.3}); })
		}
	},
	btn:{
		state:function(){
			if(gallery.a==1){
				gallery.btn.pause();
			}else{
				gallery.btn.play();
			}
		},
		play:function(){
			gallery.a=1;
			$("#gallery_playpause_btn").button('option',{label:'pause',icons:{primary:'ui-icon-pause'}});
			gallery.ctrl.play();
		},
		pause:function(){
			gallery.a=0;
			$("#gallery_playpause_btn").button('option',{label:'play',icons:{primary:'ui-icon-play'}});
			gallery.ctrl.pause();
		}
	},
	ctrl:{
		play:function(){
			gallery.t=window.setTimeout("gallery.auto()",6000);
		},
		pause:function(){
			window.clearTimeout(gallery.t);
		}
	},
	auto:function(){
		var c=Number($("#gallery_items li").filter("#"+gallery.c).index());
		var g=$("#gallery_items li");
		c=c+1;
		if(c>=g.length){ c=0; }
		var id=$("#gallery_items li").eq(c).attr('id');
		gallery.go($("#"+id+"_nav > a").get(0));
	},
	go:function(e){
		if(typeof(e.href)!=="undefined"){
			var href=String(e.href);
			var hash=href.indexOf('#');
			var end=href.length;
			var dest="";
			if(hash>0){
				dest=href.substring(hash+1,end);
				if(gallery.c!==dest){
					gallery.ctrl.pause();
					$("#gallery_nav a").unbind().bind('click',function(){ return false; });
					$("#gallery_nav li").removeClass('selected');
					$("#gallery_items li").filter("#"+gallery.c).fadeOut(500,function(){
						gallery.c=dest;
						gallery.i=$("#gallery_items li").filter("#"+gallery.c).index();
						var slide_pos=gallery.i-3;
						if(slide_pos<0){ slide_pos=0; }
						$("#gallery_nav_slider").slider("value",slide_pos);
						gallery.i=$("#gallery_items li").filter("#"+gallery.c).index();
						$("#gallery_items li").filter("#"+gallery.c).addClass('selected').fadeIn(500,function(){
							$("#gallery_nav a").bind('click',function(){ gallery.btn.pause(); gallery.go(this); return false; });
							$("#gallery_nav li").filter("#"+gallery.c+"_nav").addClass('selected');
							if(gallery.a==1){ gallery.ctrl.play(); }
						});			
					}).removeClass('selected');
				}
			}
		}
		return false;
	}
}

home_slide = {
		a:null,
		n:null,
		o:null,
		t:null,
		next:function(){
			home_slide.a = home_slide.o.filter('.active');
			if (home_slide.a.length == 0 ){ home_slide.a = home_slide.o.filter(':last'); }
			home_slide.n =  home_slide.a.next().length ? home_slide.a.next() : home_slide.o.filter(':first');
			home_slide.a.addClass('last-active').animate({opacity:0}, 0, function() {
				home_slide.n.css({opacity: 0.0}).addClass('active').animate({opacity:1}, 0, function() { home_slide.a.removeClass('active last-active'); });
			});
		},
		start:function(){
			var $o = $("#quotes > ul li");
			home_slide.o = $o;
			$("#quotes").hover(function(){ window.clearInterval(home_slide.t); },function(){ home_slide.t = window.setInterval("home_slide.next()", 6000 ); });
			home_slide.t = window.setInterval("home_slide.next()", 6000 );
		}
};



$(function() {
 	$("body").addClass("js")
 	
	if($.browser.msie && $.browser.version<7){
		var $pngs = $("img[src$='.png']");
		if($pngs.length>0){ $pngs.ifixpng(); }
		$("#navigation").hover(function(){ $(this).width(360); },function(){ $(this).width(150); });
	}

 	if($("#container").hasClass("home")){
 		$("#img_display").html("<div id=\"home_images\"><div id=\"home_images_swf\">&nbsp;</div></div>");
 		swfobject.embedSWF("js/images.swf", "home_images_swf", 770, 520, "9.0.0", null, {max:8,imgDir:encodeURIComponent("photos/homepage/"),imgName:"slide",imgSufx:"_l",imgStart:2,fadeTime:2,fadeDelay:6000,imgNamePad:1},{wmode:"transparent"});
 	}
 	
 
 	gallery.init();
 	home_slide.start();
 	
 	$("h1").each(function(){
		$t = $(this);
		var newid = "swftext"+$t.index()+Math.floor(Math.random()*100000);
		$t.append("<div id=\""+newid+"\"></div>");
		var w = 340; var h = 300;
		$t.css('textIndent',"-999em");
		var swfvars = { as:false, a:"left", w:w, h:h, c:"0xffffff", s:32, t:encodeURIComponent(String($t.text())) }
		swfobject.embedSWF("js/headings_ds.swf", newid, w, h, "9.0.0", null, swfvars,{wmode:"transparent"});
	});
 	
 	//swfobject.embedSWF("test.swf", "fish_mov_swf", 320, 210, "8.0.0", null, null,{wmode:"transparent"},null,function(){ $("#fish_mov_swf_bg").hide(); });
 	
	$("#navigation > ul").superfish({delay: 500, speed: 'fast', dropShadows: false });
 	
	$("div.photo a").each(function(){
		var newtitle = String($(this).attr('title')).substring(String("New Window: ").length);
		$(this).attr({'title':newtitle,'rel':'photo'});
	});
	$("div.photo a, a[rel='photo']").colorbox({transition:'fade',speed:500,slideshow:false});
	
	$("a[title^='New Window: ']").each(function(){
		var newtitle = String($(this).attr('title')).substring(String("New Window: ").length);
		$(this).attr('title',newtitle);
		$(this).click(function(){ window.open($(this).attr('href')); return false; });
	});
	
 })
