if(document.images) {
	site1 = new Image();site1.src = "/images/bg-tile.jpg";
	site2 = new Image();site2.src = "/images/nav-bg.png";
	site3 = new Image();site3.src = "/images/content-t.png";
	site4 = new Image();site4.src = "/images/content-bg.png";
	site5 = new Image();site5.src = "/images/content-t-corners.png";
	nav1 = new Image();nav1.src = "/images/nav-logo-over.png";
	nav2 = new Image();nav2.src = "/images/nav-wedding-over.png";
	nav3 = new Image();nav3.src = "/images/nav-family-over.png";
	nav4 = new Image();nav4.src = "/images/nav-recentwork-over.png";
	nav5 = new Image();nav5.src = "/images/nav-commercial-over.png";
	nav6 = new Image();nav6.src = "/images/nav-contact-over.png";
	nav7 = new Image();nav7.src = "/images/nav-search-over.png";
}
function nav(imgName, state) {
	document.images[imgName].src = "/images/nav-" + imgName + "-" + state + ".png";
}
var siteWidth = 980;
function getWidth() {
	var n_win = window.innerWidth ? window.innerWidth : 0;
	var n_docel = document.documentElement ? document.documentElement.clientWidth : 0;
	var n_body = document.body ? document.body.clientWidth : 0;
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	var currentWidth = n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
	if(currentWidth < siteWidth)
		return siteWidth;
	else
		return currentWidth;
}
var old_index = 0;
var timeout_id;
function clear_timeouts() {
	if(document.getElementById) {
		if(timeout_id != null)
			self.clearTimeout(timeout_id);
	}
}
function popupon(index, leftPx) {
	if(document.getElementById) {
		clear_timeouts();
		if(old_index != 0) {
			if(document.getElementById(old_index + "Sub"))
				document.getElementById(old_index + "Sub").style.display = "none";
			nav(old_index, "off");
		}
		if(document.getElementById(index + "Sub")) {
			document.getElementById(index + "Sub").style.top = 37;
			document.getElementById(index + "Sub").style.left = ((getWidth() - siteWidth) / 2) + leftPx; 
			document.getElementById(index + "Sub").style.display = "inline";
		}
		nav(index, "over");
		old_index = index;
	}
}
function popupoff() {
	if(document.getElementById) {
		if(old_index != 0)
			timeout_id = setTimeout("if(document.getElementById(old_index + 'Sub'))document.getElementById(old_index + 'Sub').style.display = 'none';nav(old_index, 'off');", 100);
	}
}
function addComment(postID) {
	if(document.getElementById("commentDiv" + postID).style.display == "none")
		document.getElementById("commentDiv" + postID).style.display = "inline";
	var commentWin = window.open("/comments_add.cfm?postID=" + postID, "commentWin", "width=600,height=400,scrollbars=yes,resizable=yes");
	commentWin.focus();
}
function openGallery(galleryID) {
	var galleryWin = window.open("/portfolio.cfm?galleryID=" + galleryID, "galleryWin", "width=940,height=720,scrollbars=yes,resizable=yes");
	galleryWin.focus();
}
function emailSignup() {
	var emailSignup = window.open("/email_signup.cfm", "emailSignup", "width=600,height=400,scrollbars=yes,resizable=yes");
	emailSignup.focus();
}

$(function() {
	// page headers
	if($('#headerpic div').length > 1) {
		$('#headerpic').after('<div id="headerpic-nav">').cycle({
			fx: 'fade',
			speed: 'slow',
			timeout: 7000,
			pager: '#headerpic-nav'
		});
		$("#headerpic-nav a").click(function() {
			$('#headerpic').cycle('pause');
		});
	}
	// videos
	$('a.videolink').fancybox({
		'type': 'iframe',
		'padding' : 0,
		'width' : 800,
		'height' : 450,
		'autoScale' : false,
		'scrolling' : 'no',
		'overlayOpacity' : '0.8',
		'overlayColor' : '#000'
	});
	// galleries
	$('"a[href^="/portfolio.cfm"]').fancybox({
		'type': 'iframe',
		'padding' : 0,
		'width' : 920,
		'height' : 700,
		'autoScale' : false,
		'scrolling' : 'no',
		'overlayOpacity' : '0.8',
		'overlayColor' : '#000'
	});
	// testimonials
	if($('#testimonials table').length > 1) {
		$('#testimonials').before('<div id="testimonials-nav">').cycle({
			fx: 'fade',
			speed: 'slow',
			timeout: 12000,
			pager: '#testimonials-nav'
		});
		$("#testimonials-nav a").click(function() {
			$('#testimonials').cycle('pause');
		});
	}
	// FAQs
	$("a.question").click(function(){
		$(this).next().slideToggle(400);
		return false;
	});
	$("a.answer-close").click(function(){
		$(this).parent().slideToggle(400);
		return false;
	});
	
});

// adds flash object to the page
function loadFlash(flashMovie, width, height) {
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + width + '" height="' + height + '" align="middle"><param name="allowScriptAccess" value="sameDomain"><param name="wmode" value="transparent"><param name="movie" value="' + flashMovie + '"><param name="quality" value="high"><embed src="' + flashMovie + '" quality="high" width="' + width + '" height="' + height + '" align="middle" allowScriptAccess="sameDomain" wmode="transparent" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></object>');
}

