// JavaScript Document

//Set up background array
var arBackgrounds = [];

arBackgrounds.push("assets/images/backgrounds/cruce01.jpg");
arBackgrounds.push("assets/images/backgrounds/cruce02.jpg");
arBackgrounds.push("assets/images/backgrounds/panorama_c.jpg");
arBackgrounds.push("assets/images/backgrounds/cruce03.jpg");
arBackgrounds.push("assets/images/backgrounds/cruce04.jpg");
arBackgrounds.push("assets/images/backgrounds/cruce05.jpg");
arBackgrounds.push("assets/images/backgrounds/cruce06.jpg");
arBackgrounds.push("assets/images/backgrounds/cruce07.jpg");


function Testimonial(s) {
	this.blurb = s;
	this.display = function() {
		return s;	
	}
}
function ThumbNail(sThumbURL, sTargetURL) {
	this.urlThumb = sThumbURL;
	this.urlTarget = sTargetURL;
	
	this.click = function() {
		////alert('wow, nice');
	}
}
function SlideShow(o, int) {
	this.arItems = new Array();
	this.slideIndex = 0;
	this.slideInterval = int;
	this.oContainer = o;
	
	this.addSlide = function(strImagePath) {
		//adds a slideshow to the queue
		this.arItems.push(strImagePath);
	}
	this.startSlideShow = function() {
		//starts the slideshow	
		this.slideIndex = Math.floor(Math.random() * this.arItems.length); 
		var oImg = this.oContainer.children("img");
		
		//alert("trying to show " + this.slideIndex);
		oImg.attr("src",this.arItems[this.slideIndex]);
	}
	this.stopSlideShow = function() {
		//stops the slideshow
	}
	this.nextSlide = function(o) {
		var oImg = o.oContainer.children("img");
		
		o.slideIndex++;
		if (o.slideIndex >= o.arItems.length) {
			o.slideIndex = 0;
		}
		
		$(oImg).fadeOut(300,function() {
			//Animation complete
			$(this).attr("src",o.arItems[o.slideIndex]);
		});
	}
	this.listAllSlideshows = function(sOutput) {
		//just for testing - displays all testimonials
		var s="";
		
		for (var i=0; i < this.arItems.length; i++) {
			s += (s == "") ? this.arItems[i] : "\n" + this.arItems[i];	
		}
		switch (sOutput) {
			case "//alert" :
				//alert(s);
				break;
			case "document":
			default :s
				document.write("<pre>" + s + "</pre>");
				break;
		}
	}
}
function drawHeader() {
	document.write('<div id="logoBanner"><div id="logo"><div id="logoTagLine">design solutions</div></div><div id="pageHeader">' + pageHeader + '</div></div>');
}
function drawMainMenu() {
	document.write('<div id="mainMenu">');
    document.write('<div id="menuPortfolio" class="menuItem">Portfolio</div>');
    document.write('<div id="menu3DDesign" class="menuItem">3D Design</div>');
	document.write('<div id="menuServices" class="menuItem">Services</div>');
	document.write('<div id="menuBio" class="menuItem">Bio</div>');
	document.write('<div id="menuWorkingTogether" class="menuItem">Working Together</div>');
	document.write('<div id="menuContact" class="menuItem">Contact</div>');
    document.write('</div>');
}
function drawFooter() {
	document.write('<div id="divFooter">');
    document.write('<div class="divFooterContent"><a href="mailto:noa@noanoadesign.com">noa@noanoadesign.com</a></div>');
    document.write('<div class="divFooterContent">512.739.1267 ::</div>');
    document.write('<div class="divFooterContent">contact information :: </div>');
    document.write('</div>');
}
function setEventHandlers() {
	$("#logo").click(function() {
		document.location="index.php";
	});
	$("#menuPortfolio").click(function() {
		document.location="portfolio.php";						 
	});
	$("#menuServices").click(function() {
		document.location="services.html";						 
	});
	$("#menuBio").click(function() {
		document.location="bio.html";						 
	});
	$("#menuWorkingTogether").click(function() {
		document.location="working_together.html";						 
	});
	$("#menuContact").click(function() {
		document.location="contact.php";						 
	});
	
	//home page links
	$("#sbDeclutter").click(function() {
		document.location="declutter.php";
	});
	$("#sbDesign").click(function() {
		document.location="design.php";
	});
	$("#sbDecorate").click(function() {
		document.location="decorate.php";
	});
	$("#sbDIY").click(function() {
		document.location="diy.php";
	});
	$("#adminMenu").click(function(e) {
		document.location = "index.php?include=" + e.target.options[e.target.selectedIndex].value;
	});
	
	//portfolio links
	$(".pfBox").click(function(e) {
		document.location = "portfolio_" + e.target.id + ".php";
	});
	
	//***********************************************************
	//               IMAGE LOAD FUNCTIONS START
	//***********************************************************
	
	$('#largePortfolioImage').load(function() {
		$(this).fadeIn(300, function() {
			//animation complete
		});
	});
	
	$("#slideShowImage").load(function() {
		//alert("slide image loaded");
		$(this).fadeIn(300,function() {
			//Animation complete
			//alert("homeSlider.nextSlide: " + homeSlider.nextSlide);
			//alert("homeSlider.slideInterval: " + homeSlider.slideInterval);
			//alert("homeSlider: " + homeSlider);
			setTimeout(homeSlider.nextSlide,homeSlider.slideInterval,homeSlider);
		});
	});
	
	//***********************************************************
	//               IMAGE LOAD FUNCTIONS END
	//***********************************************************
}

function returnDocument() {
	var file_name = document.location.href;
    var end = (file_name.indexOf("?") == -1) ? file_name.length : file_name.indexOf("?");
	
    return file_name.substring(file_name.lastIndexOf("/")+1, end);
}

function startPageSpecificContentLaunchers() {
	var fileName = returnDocument();
	
	switch (fileName) {
		case "" : 
		case "index.php":
			//alert("home page detected");
			homeSlider = new SlideShow($("#slideshowBox"),5000);
			
			homeSlider.addSlide("assets/images/slideshow/pf_slideshow_01.jpg");
			homeSlider.addSlide("assets/images/slideshow/pf_slideshow_02.jpg");
			homeSlider.addSlide("assets/images/slideshow/pf_slideshow_03.jpg");
			homeSlider.addSlide("assets/images/slideshow/pf_slideshow_04.jpg");
			homeSlider.addSlide("assets/images/slideshow/pf_slideshow_05.jpg");
			homeSlider.addSlide("assets/images/slideshow/pf_slideshow_06.jpg");
			
			//alert("trying to start slide show");
			homeSlider.startSlideShow();	
			//oTestimonials.startSlideShow();
			break;
	}
}

function loadPortfolioImage(newImageURL) {
	$('#largePortfolioImage').fadeOut(300,function() {
		$('#largePortfolioImage').attr("src",newImageURL);
	});								  
}
function setBackground() {
	var sPath = arBackgrounds[Math.floor(Math.random()*arBackgrounds.length)];

	$("body").css("backgroundImage","url(" + sPath + ")")	
}
function pageLoad() {
	setEventHandlers();
	setBackground();
	
	//animate visual elements
	$("#contentContainerBackground").fadeTo(0,.8);
	
	$("#logoBanner").fadeTo('slow',.9,function() { 
		$("#pageHeader").fadeTo("slow",.8,function() { 
			$("#contentContainer").fadeTo("slow",1,function() { 
				startPageSpecificContentLaunchers();												
			});
		});
	});
}



$(pageLoad);
