function RUtils() {
}

RUtils.KEYCODE_ESCAPE = 27;

RUtils.getDims = function() {
	var dims = {width:$("html").outerWidth(true), height:$("html").outerHeight(true)};
	//console.log("Screen dims: " + dims.width + "x" + dims.height);
	return dims;
}

RUtils.SHOW_TEXT = "Show details";
RUtils.HIDE_TEXT = "Hide details";

RUtils.toggleDetails = function() {
	//var titleHeight = $("#detailContainer p.title").outerHeight(true);
	//var locHeight = $("#detailContainer p.location").outerHeight(true);
	//var detailHeight = $("#detailContainer div.project").outerHeight(true);
	//console.log("title height: " + titleHeight + ", loc height: , " + locHeight + ", title height: " + detailHeight);
	//console.log($("#detailContainer div.details").outerHeight(true));
	var d = $("#detailContainer div.details");
	var dl = $("#detailContainer #detailLink");
	if (d.is(":visible")) {
		d.slideUp();
		dl.html(RUtils.SHOW_TEXT);
	}
	else {
		d.slideDown();
		dl.html(RUtils.HIDE_TEXT);
	}
	return;
}

RUtils.rbg = $("#rBackground");
RUtils.rbgm = $("#rMask");
RUtils.rml = $("#rMaskLogo");
RUtils.img = $("#rBackground img");
RUtils.mc = $("#mapContainer");
RUtils.rh = $("#header");
RUtils.maskDelay = 5000;
RUtils.bgDelay = 1000;
RUtils.FADE_TIME = 1000;
RUtils.maskTimer = null;
RUtils.swapDelay = 1000;
RUtils.currentImage = 0;

RUtils.swapBackground = function() {
	if (RUtils.currentImage == RUtils.bgUrls.length - 1) {
		RUtils.currentImage = 0;
	}
	else {
		RUtils.currentImage++;
	}
	var img = '<img class="new" src="' + RUtils.bgUrls[RUtils.currentImage] + '" />';
	RUtils.rbg.append(img);
}

RUtils.setBackground = function(hasMap) {
	if (hasMap) {
		var dims = RUtils.getDims();
		//console.log("Image: " + img);
		//console.log("Image native dims: " + RUtils.img.width() + "x" + RUtils.img.height());
		var cf = dims.width/RUtils.img.width();
		//console.log("Conversion factor: " + cf);
		var w = Math.floor(RUtils.img.width()*cf);
		var h = Math.floor(RUtils.img.height()*cf);
		//console.log("Image scaled dims: " + w + "x" + h);
		RUtils.img.width(w);
		RUtils.img.height(h);
		RUtils.rbg.css("top", -1 * (RUtils.img.height() - dims.height)/2);
	}
	RUtils.rbgm.fadeOut(500, function() {
		RUtils.mc.css("z-index", "0");
	});
}

RUtils.fadeMask = function() {
	//console.log("Fading mask...");
	clearTimeout(RUtils.maskTimer);
	RUtils.rml.fadeOut(RUtils.FADE_TIME);
	RUtils.rbgm.fadeOut(RUtils.FADE_TIME);
	RUtils.rc.fadeIn(RUtils.FADE_TIME);
	RUtils.rh.fadeIn(RUtils.FADE_TIME);
	//setInterval(RUtils.swapBackground, RUtils.swapDelay);

}

RUtils.fadeBG = function() {
	//console.log("Fading BG...");
	RUtils.rbg.fadeIn(RUtils.FADE_TIME);
}

RUtils.rc = $("#rContainer")
RUtils.sc = $("#scrollContainer");
RUtils.si = $("#scrollItems");
RUtils.nav = {left:$("#prevButton"), right:$("#nextButton")};
RUtils.DETAIL_WIDTH = 228;
RUtils.NAV_OFFSET = 96;
RUtils.numItems = $("#scrollItems div.detailBox").length;

RUtils.initScrollItems = function() {
	var scrollListItems = $("#scrollList p");
	for (var i = 0; i < scrollListItems.length; i++) {
		$(scrollListItems[i]).bind('click', {id:i}, RUtils.scrollToItem);
		//$(scrollListItems[i]).bind('mouseenter', {id:i}, RUtils.addHighlight);
		//$(scrollListItems[i]).bind('mouseleave', {id:i}, RUtils.removeHighlight);
	}
	// Get approximate effective screen width (width - scrollbars)
	// Allows to easily categorize screen size
	var w = RUtils.getDims().width - 40;
	//console.log("Working with screen width of: " + w + "...");
	
	/*
	// Larger than 1920 resolution
	if (w > 1920) {
		//console.log("Adjusting to 1920+ resolution");
		//RUtils.si.css("left", "100px");
		//RUtils.si.css("width", "684px");
		return;
	}
	*/
	// 1920 resolution
	if (w > 1680 && w <= 1920) {
		//console.log("Adjusting to 1920 resolution");
		// Predetermined number of details to show at a given resolution
		RUtils.visibleItems = 7;
		// Set the new width to the number of detail elements times the detail element width
		var w = RUtils.visibleItems*RUtils.DETAIL_WIDTH + "px"
		RUtils.sc.css("width", w);
		// Set the positioning according to the number of detail elements relative to the original container
		var l = (RUtils.rc.width()-RUtils.visibleItems*RUtils.DETAIL_WIDTH)/2 + "px";
		RUtils.sc.css("left", l);
		
		// Set the nav offset positioning, in the 1024 grid there are 96px betwee the details and nav, maintain that space
		var no = -1 * ((RUtils.visibleItems - 3) * RUtils.NAV_OFFSET) + "px";
		RUtils.nav.left.css("left", no);
		RUtils.nav.right.css("right", no);
		
		// Show the nav items
		for (element in RUtils.nav) {
			RUtils.nav[element].show();
		}
		return;
	}
	// 1680 resolution
	if (w > 1440 && w <= 1680) {
		//console.log("Adjusting to 1680 resolution");
		// Predetermined number of details to show at a given resolution
		RUtils.visibleItems = 6;
		// Set the new width to the number of detail elements times the detail element width
		var w = RUtils.visibleItems*RUtils.DETAIL_WIDTH + "px"
		RUtils.sc.css("width", w);
		// Set the positioning according to the number of detail elements relative to the original container
		var l = (RUtils.rc.width()-RUtils.visibleItems*RUtils.DETAIL_WIDTH)/2 + "px";
		RUtils.sc.css("left", l);
		
		// Set the nav offset positioning, in the 1024 grid there are 96px betwee the details and nav, maintain that space
		var no = -1 * ((RUtils.visibleItems - 3) * RUtils.NAV_OFFSET) + "px";
		RUtils.nav.left.css("left", no);
		RUtils.nav.right.css("right", no);
		
		// Show the nav items
		for (element in RUtils.nav) {
			RUtils.nav[element].show();
		}
		return;
	}
	// 1440 resolution
	if (w > 1280 && w <= 1440) {
		//console.log("Adjusting to 1440 resolution");
		// Predetermined number of details to show at a given resolution
		RUtils.visibleItems = 5;
		// Set the new width to the number of detail elements times the detail element width
		var w = RUtils.visibleItems*RUtils.DETAIL_WIDTH + "px"
		RUtils.sc.css("width", w);
		// Set the positioning according to the number of detail elements relative to the original container
		var l = (RUtils.rc.width()-RUtils.visibleItems*RUtils.DETAIL_WIDTH)/2 + "px";
		RUtils.sc.css("left", l);
		
		// Set the nav offset positioning, in the 1024 grid there are 96px betwee the details and nav, maintain that space
		var no = -1 * ((RUtils.visibleItems - 3) * RUtils.NAV_OFFSET) + "px";
		RUtils.nav.left.css("left", no);
		RUtils.nav.right.css("right", no);
		
		// Show the nav items
		for (element in RUtils.nav) {
			RUtils.nav[element].show();
		}
		return;
	}
	// 1280 and 13xx resolution
	if (w > 1024 && w <= 1280) {
		//console.log("Adjusting to 1280 resolution");
		// Predetermined number of details to show at a given resolution
		RUtils.visibleItems = 4;
		// Set the new width to the number of detail elements times the detail element width
		var w = RUtils.visibleItems*RUtils.DETAIL_WIDTH + "px"
		RUtils.sc.css("width", w);
		// Set the positioning according to the number of detail elements relative to the original container
		var l = (RUtils.rc.width()-RUtils.visibleItems*RUtils.DETAIL_WIDTH)/2 + "px";
		RUtils.sc.css("left", l);
		
		// Set the nav offset positioning, in the 1024 grid there are 96px betwee the details and nav, maintain that space
		var no = -1 * ((RUtils.visibleItems - 3) * RUtils.NAV_OFFSET) + "px";
		RUtils.nav.left.css("left", no);
		RUtils.nav.right.css("right", no);
		
		// Show the nav items
		for (element in RUtils.nav) {
			RUtils.nav[element].show();
		}
		return;
	}
	if (w < 1024 ) {
		//console.log("Adjusting to 1024 resolution");
		// Predetermined number of details to show at a given resolution
		RUtils.visibleItems = 3;
		// Set the new width to the number of detail elements times the detail element width
		var w = RUtils.visibleItems*RUtils.DETAIL_WIDTH + "px"
		RUtils.sc.css("width", w);
		// Set the positioning according to the number of detail elements relative to the original container
		var l = (RUtils.rc.width()-RUtils.visibleItems*RUtils.DETAIL_WIDTH)/2 + "px";
		RUtils.sc.css("left", l);
		
		// Set the nav offset positioning, in the 1024 grid there are 96px betwee the details and nav, maintain that space
		var no = -1 * ((RUtils.visibleItems - 3) * RUtils.NAV_OFFSET) + "px";
		RUtils.nav.left.css("left", no);
		RUtils.nav.right.css("right", no);
		
		// Show the nav items
		for (element in RUtils.nav) {
			RUtils.nav[element].show();
		}
		return;
	}
}

RUtils.SCROLL_TIME = 500;
// 204 wide + 8px left/right padding + 8px margin one side
RUtils.SCROLL_DISTANCE = 204 + 8 + 8 + 8;
RUtils.sw = RUtils.SCROLL_DISTANCE * RUtils.numItems;
RUtils.currentItem = 0;

RUtils.scrollItem = function(event) {
	var direction = event.data.direction;
	
	//console.log(direction + " button pressed, scrollItems [" + RUtils.currentItem + " of " + RUtils.numItems + ", " + RUtils.visibleItems + " visible] width: " + RUtils.sw + "...");
	if (direction == 'previous') {
		RUtils.prevItem();
	}
	else {
		RUtils.nextItem();
	}
}

RUtils.prevItem = function() {
	//console.log("Previous item pressed, scrollItems [" + RUtils.currentItem + " of " + RUtils.numItems + ", " + RUtils.visibleItems + " visible] width: " + RUtils.sw + "...");

	// Wrap when visible items are at the left edge, calculated in initScrollItems()
	var scrollOperator;

	if (RUtils.currentItem === 0) {
		//console.log("Wrapping to end...");
		scrollOperator = -1 * (RUtils.numItems - RUtils.visibleItems) * RUtils.SCROLL_DISTANCE;
		RUtils.currentItem = RUtils.numItems - RUtils.visibleItems;
	}
	else {
		scrollOperator = "+=" + RUtils.SCROLL_DISTANCE;
		RUtils.currentItem --;
	}
	
	RUtils.si.animate({left:scrollOperator}, RUtils.SCROLL_TIME, function() {})
}

RUtils.nextItem = function() {
	//console.log("Next item pressed, scrollItems [" + RUtils.currentItem + " of " + RUtils.numItems + ", " + RUtils.visibleItems + " visible] width: " + RUtils.sw + "...");
	
	// Wrap when visible items are at the left edge, calculated in initScrollItems()
	var scrollOperator;
	
	if (RUtils.currentItem == RUtils.numItems - RUtils.visibleItems) {
		//console.log("Wrapping to start...");
		scrollOperator = "0";
		RUtils.currentItem = 0;
	}
	else {
		scrollOperator = "-=" + RUtils.SCROLL_DISTANCE;
		RUtils.currentItem ++;
	}
	
	RUtils.si.animate({left:scrollOperator}, RUtils.SCROLL_TIME, function() {});
}

RUtils.scrollToItem = function(event) {
	var id = event.data.id;
	//console.log("Scrolling to: " + id);
	//console.log("Scrolling to: " + id + " [" + RUtils.currentItem + " of " + RUtils.numItems + ", " + RUtils.visibleItems + " visible]");
	var scrollOperator;
	var scrollItems;

	if (id > RUtils.currentItem) {
		// Ensure that we don't scroll past the end of the items
		if (id > RUtils.numItems - RUtils.visibleItems) {
			scrollOperator = -1 * RUtils.SCROLL_DISTANCE * (RUtils.numItems - RUtils.visibleItems);
		}
		else {
			scrollOperator = "-=" + (id - RUtils.currentItem) * RUtils.SCROLL_DISTANCE;
		}
		//console.log("Scrolling " + scrollOperator + " px to clicked item...");
		RUtils.si.animate({left:scrollOperator}, RUtils.SCROLL_TIME, function() {})
	}
	else {
		// Ensure that we don't scroll past the start of the items
		if (id <= RUtils.visibleItems - 1) {
			scrollOperator = 0;
		}
		else {
			scrollOperator = "+=" + (RUtils.currentItem - id) * RUtils.SCROLL_DISTANCE;
		}
		//console.log("Scrolling " + scrollOperator + " px to clicked item...");
		RUtils.si.animate({left:scrollOperator}, RUtils.SCROLL_TIME, function() {})
	}
	$('#db_' + RUtils.currentItem).removeClass('current');
	$('#db_' + id).removeClass('hover');
	RUtils.currentItem = id;
	//$('#db_' + id).addClass('current');
}

RUtils.slc = $("#scrollListContainer");
RUtils.scrollList = $("#scrollList");
RUtils.slt = $("#scrollListTab");
RUtils.directionsTab = $("#directionsTab");
RUtils.slWidth = 256;
RUtils.TAB_HIDDEN_CLASS = "hidden";

RUtils.toggleListTab = function() {
	//console.log("Tab toggling...");
	if (RUtils.slc.hasClass(RUtils.TAB_HIDDEN_CLASS)) {
		RUtils.slc.animate({left:"+=" + RUtils.slWidth}, RUtils.SCROLL_TIME, function() {});
	}
	else {
		RUtils.slc.animate({left:"-=" + RUtils.slWidth}, RUtils.SCROLL_TIME, function() {});
	}
	RUtils.slc.toggleClass(RUtils.TAB_HIDDEN_CLASS);
}

RUtils.toggleDirectionsTab = function() {
	if (RUtils.scrollList.css("display") == "block") {
		RUtils.scrollList.css("display", "none");
		RUtils.rtc.css("display", "block");
	}
	//console.log("Tab toggling...");
	if (RUtils.slc.hasClass(RUtils.TAB_HIDDEN_CLASS)) {
		RUtils.slc.animate({left:"+=" + RUtils.slWidth}, RUtils.SCROLL_TIME, function() {});
	}
	else {
		RUtils.slc.animate({left:"-=" + RUtils.slWidth}, RUtils.SCROLL_TIME, function() {});
	}
	RUtils.slc.toggleClass(RUtils.TAB_HIDDEN_CLASS);
}


RUtils.rtc = $("#routeContainer");

RUtils.toggleLocTab = function() {
	//console.log("Tab toggling...");
	if (RUtils.rtc.hasClass(RUtils.TAB_HIDDEN_CLASS)) {
		RUtils.rtc.animate({left:"+=" + RUtils.slWidth}, RUtils.SCROLL_TIME, function() {});
	}
	else {
		RUtils.rtc.animate({left:"-=" + RUtils.slWidth}, RUtils.SCROLL_TIME, function() {});
	}
	RUtils.rtc.toggleClass(RUtils.TAB_HIDDEN_CLASS);
}

RUtils.addHighlight = function(event) {
	var id = event.data.id;
	//console.log('Adding highlight to: ' + id);
	var div = $("#db_"+ id + " p.name");
		div.addClass('hover');
}

RUtils.removeHighlight = function(event) {
	var id = event.data.id;
	//console.log('Removing highlight from: ' + id);
	var div = $("#db_"+ id + " p.name");
		div.removeClass('hover');
}

RUtils.currentBG = 0;
RUtils.displayBG = $("#rBackground .display");
RUtils.transitionBG = $("#rBackground .transition");
// True if display class div is shown, false otherwise
RUtils.isDisplayShown = 1;

RUtils.bgImages = [];
RUtils.bgImages.push("img/REIMAR_Mac_BG_01_LOW.jpg");
RUtils.bgImages.push("img/REIMAR_Mac_BG_02_LOW.jpg");
RUtils.bgImages.push("img/REIMAR_Mac_BG_03_LOW.jpg");

RUtils.swapImage = function(event) {
	var id = event.data.id;
	
	if (id == RUtils.currentBG) {
		return;
	}
	//console.log('Image ' + id + ' clicked, starting transition...');
	

	if (RUtils.isDisplayShown) {
		RUtils.transitionBG.attr('src', RUtils.bgImages[id]);
		RUtils.displayBG.fadeOut(1000);
		RUtils.transitionBG.fadeIn(1000);
		RUtils.isDisplayShown = 0;
	}
	else {
		RUtils.displayBG.attr('src', RUtils.bgImages[id]);
		RUtils.displayBG.fadeIn(1000);
		RUtils.transitionBG.fadeOut(1000);
		RUtils.isDisplayShown = 1;
	}
	
	/*
	RUtils.displayBG.removeClass('display');
	RUtils.displayBG.addClass('transition');
	RUtils.transitionBG.removeClass('transition');
	RUtils.transitionBG.addClass('display');
	*/
	$('#rt_' + RUtils.currentBG).removeClass('current');
	RUtils.currentBG = id;
	$('#rt_' + id).addClass('current');
	
}

RUtils.projectImages = [];
RUtils.prevLink = $("#prevImageLink");
RUtils.nextLink = $("#nextImageLink");

RUtils.initThumbs = function(projectImageUrls) {
	RUtils.prevLink.bind("click", function() {
		RUtils.prevImage();
	});
	
	RUtils.nextLink.bind("click", function() {
		RUtils.nextImage();
	});
	
	//RUtils.projectImages = projectImages;
	var numThumbs = projectImageUrls.length;
	//console.log("Initializing thumbstrip with " + numThumbs + " thumbs...");
	
	for (var i = 0; i < numThumbs; i++) {
		
		var image = new Image();
		image.src = projectImageUrls[i];
		RUtils.projectImages.push(image);
		
		var html = [];
		html.push("<div class='thumb' id='rThumb_" + i + "'>");
		html.push("<img src='" + image.src + "' width='" + RUtils.THUMB_WIDTH + "px' height='" + RUtils.THUMB_HEIGHT + "px' />");
		html.push("</div>");
		RUtils.thumbs.append(html.join(""));
		
		$("#rThumb_" + i).bind("click", {id:i}, function(event) {
			//console.log(event);
			RUtils.showLightbox(event);
		});
		
	}
}

RUtils.rlbf = $("#rLightboxFade");
RUtils.rlbi = $("#rLightboxImage");
RUtils.currentGalleryImage = 0;

RUtils.LIGHTBOX_IMAGE_MARGIN = 20;

RUtils.showLightbox = function(event) {
	var id = event.data.id;
	RUtils.currentGalleryImage = id;
	var clientX = event.clientX;
	var clientY = event.clientY;
	var dims = RUtils.getDims();

	var image = RUtils.projectImages[id];
	
	//console.log("Image raw dims: " + image.width + "x" + image.height);
	
	var h = dims.height - 2*RUtils.LIGHTBOX_IMAGE_MARGIN;
	var w = dims.width - 2*RUtils.LIGHTBOX_IMAGE_MARGIN;
		
	var displayHeight = "";
	var displayWidth = "";
	var displayLeft = 0;
	var displayTop = 0;
	var ratio = 0;
	
	if (h <= image.height) {
		//console.log("Image height exceeds screen height of " + h + "...");
		displayHeight = h;
		ratio = h/image.height;
		displayWidth = image.width * ratio;
		//console.log("Resized image width to " + displayWidth + "...");
		displayTop = RUtils.LIGHTBOX_IMAGE_MARGIN;
		displayLeft = w/2 - displayWidth/2 + RUtils.LIGHTBOX_IMAGE_MARGIN;
		
		RUtils.rlbi.width(displayWidth);
		
		RUtils.prevLink.css({
												width:displayWidth/2,
												height:h
												});
		RUtils.nextLink.css({
												width:displayWidth/2,
												height:h,
												});
		
	}
	else {
		console.log("Image height fits screen height...");
		if (w <= image.width) {
			console.log("Image width exceeds screen width of " + w + "...");
			displayWidth = w;
			ratio = w/image.width;
			displayHeight = image.height * ratio;
			console.log("Resized image height to " + displayHeight + "...");
		}
	}
	
	RUtils.rlbi.css({
		left:displayLeft, 
		top:displayTop
	});
	
	var html = [];
	//html.push("<img id='galleryImage' src='" + src + "' height='" + (dims.height - 40) + "px' width='" + (dims.width - 40) + "px' />");
	html.push("<img style='' id='galleryImage' src='" + image.src + "' width='" + displayWidth + "' height='" + displayHeight + "px' />");
	RUtils.rlbi.append(html.join(""));
	
	RUtils.rlbi.fadeIn(RUtils.FADE_TIME);
	
	RUtils.rlbf.fadeIn(RUtils.FADE_TIME, function() {
		RUtils.rlbf.bind("click", function() {
			RUtils.hideLightbox();
		});
		
		$(document).bind('keyup', function(e) {
			if(e.keyCode == RUtils.KEYCODE_ESCAPE) {
				RUtils.rlbf.click();
			}
		});
	});
}

RUtils.hideLightbox = function() {
	RUtils.rlbf.unbind("click");
	$(document).unbind("keyup");
	RUtils.rlbi.fadeOut(RUtils.FADE_TIME, function() {
		$("#galleryImage").remove();
	});
	RUtils.rlbf.fadeOut(RUtils.FADE_TIME);
}

RUtils.prevImage = function() {
	console.log("Prev gallery image...");
	if (RUtils.currentGalleryImage !== 0) {
		RUtils.currentGalleryImage--;
	}
	else {
		RUtils.currentGalleryImage = RUtils.projectImages.length - 1;
	}
	console.log("New index: " + RUtils.currentGalleryImage);
	$("#galleryImage").attr("src", RUtils.projectImages[RUtils.currentGalleryImage].src);
}

RUtils.nextImage = function() {
	console.log("Prev gallery image...");
	if (RUtils.currentGalleryImage !== RUtils.projectImages.length - 1) {
		RUtils.currentGalleryImage++;
	}
	else {
		RUtils.currentGalleryImage = 0;
	}
	console.log("New index: " + RUtils.currentGalleryImage);
	$("#galleryImage").attr("src", RUtils.projectImages[RUtils.currentGalleryImage].src);
	}

// Contact JS
RUtils.directionsToHere = function() {
	//console.log("To here...");
	toHere = true;
	$("#toHere").addClass("bold");
	$("#fromHere").removeClass("bold");
	$("#toFromText").html("Starting point: ");
}

RUtils.directionsFromHere = function() {
	//console.log("From here...");
	toHere = false;
	$("#fromHere").addClass("bold");
	$("#toHere").removeClass("bold");
	$("#toFromText").html("Destination: ");
}

RUtils.THUMB_WIDTH = 127;
RUtils.THUMB_HEIGHT = 95;
RUtils.THUMB_MARGIN = 4;
RUtils.NUM_THUMBS_DISPLAYED = 6;
RUtils.thumbs = $("#thumbs");

RUtils.prevThumb = function() {
	//console.log("[" + RUtils.currentImage + "/" + RUtils.projectImages.length + "] Prev...");
	if (RUtils.currentImage > 0) {
		RUtils.currentImage--;
		RUtils.thumbs.animate({left:"+=" + (RUtils.THUMB_WIDTH + RUtils.THUMB_MARGIN)}, RUtils.SCROLL_TIME, function() {});
	}
}

RUtils.nextThumb = function() {
	//console.log("[" + RUtils.currentImage + "/" + RUtils.projectImages.length + "] Next...");
	if (RUtils.currentImage < RUtils.projectImages.length && RUtils.projectImages.length > RUtils.NUM_THUMBS_DISPLAYED) {
		RUtils.currentImage++;
		RUtils.thumbs.animate({left:"-=" + (RUtils.THUMB_WIDTH + RUtils.THUMB_MARGIN)}, RUtils.SCROLL_TIME, function() {});
	}
}

function init_home() {
	//console.log("Show fade? " + RUtils.getCookie("showFade"));
	//RUtils.setBackground();
	//RUtils.maskTimer = setTimeout(RUtils.fadeBG, RUtils.bgDelay);
	//RUtils.maskTimer = setTimeout(RUtils.fadeMask, RUtils.maskDelay);
	//$("#rMaskLogo").bind("click", RUtils.fadeMask);
	
	//RUtils.bgUrls = [];
	// Push initial image, then images from template
	//RUtils.bgUrls.push($("#rBackground > img").attr("src"));
	//RUtils.bgUrls.push("img/REIMAR_Mac_BG_02_LOW.jpg");
	//RUtils.bgUrls.push("img/REIMAR_Mac_BG_03_LOW.jpg");
	
	//console.log(RUtils.bgUrls);
	
	//setInterval(RUtils.swapBackground, RUtils.swapDelay);
	//RUtils.setCookie("showFade", "false", 14);
	//$("#contactFormSubmit").bind("click", RUtils.processContactForm);
}

function init_profiles() {
	RUtils.initScrollItems();
	$("#prevButton").bind("click", {direction:'previous'}, RUtils.scrollItem);
	$("#nextButton").bind("click", {direction:'next'}, RUtils.scrollItem);
	$("#scrollListTab").bind('click', RUtils.toggleListTab);
	RUtils.setBackground();
	$(window).resize(function() {
	  RUtils.initScrollItems();
		RUtils.setBackground();
	});
}

function init_projects() {
	RUtils.initScrollItems();
	$("#prevButton").bind("click", {direction:'previous'}, RUtils.scrollItem);
	$("#nextButton").bind("click", {direction:'next'}, RUtils.scrollItem);
	$("#scrollListTab").bind('click', RUtils.toggleListTab);
	RUtils.setBackground();
	$(window).resize(function() {
	  RUtils.initScrollItems();
		RUtils.setBackground();
	});
}

function init_locations() {
	RUtils.setBackground(true);
	initialize();
	$(window).resize(function() {
		RUtils.setBackground(true);
		map.panTo(new google.maps.LatLng(43.445916,-79.727862));
	});
	
	$("#togglePoints").bind('click', function() {
		togglePoints();
	});
	$("#scrollListTab").bind('click', RUtils.toggleListTab);
	$("#directionsTab").bind('click', RUtils.toggleDirectionsTab);
}

function init_documents() {
	RUtils.setBackground();
}

function init_project_detail(projectImages) {
	$("#rightThumbNav").bind("click", RUtils.nextThumb);
	$("#leftThumbNav").bind("click", RUtils.prevThumb);
	RUtils.initThumbs(projectImages);
	// Image URLs are in a variable called 'projectImages' created in footer.php
	//console.log("Initializing " + projectImages.length + " images...");
}

function init_contact() {
	initialize();
	infoWindow.open(map, reimarMarker);
}

function init_site_locator() {
	initialize();
}

RUtils.processContactForm = function() {
	$("#ss-form").submit();
	/*
	var name = $("#contactName").val();
	var email = $("#contactEmail").val();
	var message = $("#contactMessage").val();
	
	var error = false;
	
	if (name == "" || name == null) {
		console.log("Processing name...");
		error = true;
		$("#contactNameLabel").addClass("error");
	}
	else {
		$("#contactNameLabel").removeClass("error");
	}

	if (email == "" || email == null) {
		console.log("Processing email...");
		error = true;
		$("#contactEmailLabel").addClass("error");
	}
	else {
		$("#contactEmailLabel").removeClass("error");
	}

	if (message == "" || message == null) {
		console.log("Processing message...");
		error = true;
		$("#contactMessageLabel").addClass("error");
	}
	else {
		$("#contactMessageLabel").removeClass("error");
	}

	if (error === true) {
		$("#contactFeedback").html("Please complete the required fields.").show();
		return;
	}
	
	var timeStamp = new Date().getTime();
	console.log("Message from " + name + " [" + email + "]at " + timeStamp + ": " + message);

	$.ajax({
		type : 'POST',
		url : 'http://reimar.ca/wp-content/themes/reimar/php/contactForm.php',
		dataType : 'json',
		data: {
			name : name,
			email : email,
			message : message
		},
		success : function(data){
			if (data.error === true) {
				console.log("Error - " + data.msg);
				return;				
			}
			console.log("Success - " + data.msg);
			
		},
		error : function(XMLHttpRequest, textStatus, errorThrown) {
			console.log("Failed...");
		}
	});
	*/
}
