(function(){
	
	var site = window.site = {},
		undefined;
		
	
	site.pages = {};
	
	var $html, $body, $siteWrap, $siteHeader, $siteFooter, $sitePage;
	
	site.pages["common"] = new esf.site.Page({
		test:function(){return true;},
		init:function(){
			var P = this;
			$html = $("html");
			$body = $("body");
			$siteWrap = $("#siteWrap");
			$siteHeader = $("#siteHeader");
			$siteFooter = $("#siteFooter");
			$sitePage = $("#sitePage");
			
			
			$("button, input:submit").button();
			
			P.createSlideshow();
			P.createTestimonials();
			P.createVideoLinks();
			
			
			//make the daily verse link open in a new window
			$siteHeader.find(".daily-verse a").each(function(){
				this.target="_blank";
			});
		},
		
		createSlideshow:function(){
			var $slideshows = $(".slideshow"),
				$images = $slideshows.find(".images").each(function(e, el){
					var $imgs = $(el);
					$imgs.cycle({
						fx:'fade',
						timeout:5000,
						speed:3000,
						next:$imgs.closest(".slideshow").find(".next").css({opacity:.7}).button("option", {text:false, icons:{primary:"ui-icon-triangle-1-e"}}),
						prev:$imgs.closest(".slideshow").find(".prev").css({opacity:.7}).button("option", {text:false, icons:{primary:"ui-icon-triangle-1-w"}})
					});
				});
			return this;
		},
		
		createTestimonials:function(){
			$sitePage.find(".testimonials .testimonial").each(function(d, div){
				var $div = $(div),
					quote = $div.find("blockquote"),
					excerpt = quote.find(".excerpt"),
					cite = $div.find("cite"),
					teaser = $("<p class='teaser'>"+excerpt.html()+"</p>").prependTo($div),
					full = $("<div class='full'/>").insertAfter(teaser),
					toggleHideHtml = "<span class='ui-icon ui-icon-circle-minus'></span>Hide",
					toggleMoreHtml = "<span class='ui-icon ui-icon-circle-plus'></span>Full Quote",
					toggle = $("<a class='toggle' href='javascript:;'>"+toggleMoreHtml+"</a>").appendTo($div);
				
				full.append(quote);//.append(cite);
				
				full.css({height:full.height()}).hide();
				
				teaser.add(toggle).click(function(evt){
					if(!full.is(":visible")){
						full.slideDown();
						toggle.html(toggleHideHtml);
					}else{
						full.slideUp();
						toggle.html(toggleMoreHtml);
					}
				});
				
			});
			return this;
		},
		
		createVideoLinks:function(){
			var parents = $sitePage.find(".videos li:has(>ul)");
			parents.addClass("parent").each(function(l, li){
				var $li = $(li),
					$ul = $li.children("ul");	
								
				$li.wrapInner("<a href='javascript:;'/>");
				$li.append($ul);
				$ul.css({height:$ul.height()}).hide();

				$li.children("a").click(function(){

					if(!$ul.is(":visible")){
						$ul.slideDown();
					}else{
						$ul.slideUp();	
					}
				});
				
			});
			
			var links = $("a[rel='video']");
			links.click(function(evt){
				window.open(this.href, "video", "toolbar=0, scrollbars=0, statusbar=0, menubar=0, resizable=0 location=no, width=425, height=355");
				return false;
			});
		}
	});
	
	
	site.pages["home"] = new esf.site.Page({
		test:function(){return (/^(\/(index|index\-dev)\.php)?$/i).test(window.location.pathname);},
		init:function(){
				
		}
	});
	
})();
