var mainSlide = '';

/*
Pre-load image functions
*/
function preloadBaseImages() {
	var imageArray = new Array('progress_dots.gif');

    preloadImages(imageArray, '/images/');	
}


function preloadImages(imageArray, dirPrefix) {
	for(i = 0; i < imageArray.length; i++) {
		var imageName = new Image();
        imageName.src = dirPrefix + imageArray[i];
	}
}


/*
Replaces text with by in string
*/
function replace(string, text, by) {
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}


/*
Trim a string from leading and trailing spaces
*/
function Trim(iString) {
  iString = iString.replace( /^\s+/g, "" );
  return iString.replace( /\s+$/g, "" );
}


/*
Find an object on the page
*/
function findObj(objName) {
	var theObj = document.getElementById(objName);
	
	if (!theObj) {
		//theObj = document.all[objName];
	}
	
	return theObj;
}


/*
Find an object that is contained within an object
*/
function findContainedObj(objName, objContainer) {
	var theObj = objContainer.elements[objName];
	
	if ((!theObj) && (objContainer.all)) {
		theObj = objContainer.all[objName];
	}
	
	// If no object found, search through layers
	if ((!theObj) && (objContainer.getElementsByTagName)) {
		var tmpObj = objContainer.getElementsByTagName("div");
		for (var i = 0; i < tmpObj.length; i++) {
			if ((tmpObj[i].name == objName) || (tmpObj[i].id == objName)) {
				theObj = tmpObj[i];
			}
		}
	}
	
	// If we still haven't found the object, look for table cells
	if ((!theObj) && (objContainer.getElementsByTagName)) {
		var tmpObj = objContainer.getElementsByTagName("td");		
		for (var i = 0; i < tmpObj.length; i++) {
			if ((tmpObj[i].name == objName) || (tmpObj[i].id == objName)) {
				theObj = tmpObj[i];
			}
		}
	}
		
	// If we still haven't found the object, look for spans
	if ((!theObj) && (objContainer.getElementsByTagName)) {
		var tmpObj = objContainer.getElementsByTagName("span");		
		for (var i = 0; i < tmpObj.length; i++) {
			if ((tmpObj[i].name == objName) || (tmpObj[i].id == objName)) {
				theObj = tmpObj[i];
			}
		}
	}	

	// If we still haven't found the object, look for tables
	if ((!theObj) && (objContainer.getElementsByTagName)) {
		var tmpObj = objContainer.getElementsByTagName("table");		
		for (var i = 0; i < tmpObj.length; i++) {
			if ((tmpObj[i].name == objName) || (tmpObj[i].id == objName)) {
				theObj = tmpObj[i];
			}
		}
	}
	
	return theObj;	
}


/*
Reload the current window after a set time
*/
function reloadWindowTimeout() {
	setTimeout('window.location.reload();', 250);
}


/*
Redirect the current window after a set time
*/
function redirectWindowTimeout(iLocation) {
	setTimeout('window.location.href=\'' + iLocation + '\'', 250);
}


/*
Init the slide panels
*/
function initSlide(iDefaultPage) {
	mainSlide = new noobSlide({
		box: $('containerDiv'),
		items: $$('#containerDiv h3'),
		size: 600,
		handles: $$('#bottomLink span'),
		addButtons: {previous: $('previous_btn'), next: $('next_btn') },
		onWalk: function(currentItem, currentHandle) {
			$$(this.handles).removeClass('active');
			$$(currentHandle).addClass('active');			
		}
	});

	if (iDefaultPage == 'ABOUT') { iDefaultPage = 1; }
	if (iDefaultPage == 'SERVICES') { iDefaultPage = 2; }
	if (iDefaultPage == 'PORTFOLIO') { iDefaultPage = 3; }
	if (iDefaultPage == 'STAFF') { iDefaultPage = 4; }
	if (iDefaultPage == 'CONTACT') { iDefaultPage = 5; }
		
	mainSlide.walk(iDefaultPage, false, true);	
}


/*
Init the porfolio panels
*/
function initPorfolio() {
	var itemDetails = [
		{title: 'Sony Gamer Advisory Panel (G.A.P.)', description: 'The Gamer Advisory Panel (or G.A.P.) is the most elite membership tier in the PlayStation&reg; Underground&trade;', link: 'http://gap.us.playstation.com'},	
		{title: 'MySMSBuddy', description: 'The web\'s first social networking site for cell phones', link: 'http://www.mysmsbuddy.com'},
		{title: 'CCAT Public Site', description: 'The public relations site for the<br>Connecticut Center for Advanced Technology, Inc.', link: 'http://www.ccat.us'},
		{title: 'CCAT Internal Portal', description: 'The Connecticut Center for Advanced Technology, Inc. internal portal tools, web apps and programs', link: 'http://portal.ccat.us'},
		{title: 'Connecticut Business Incubator Network', description: '"<i>Hatching new businesses throughout the state</i>"', link: 'http://www.connecticutincubators.org'},
		{title: 'SecuriTube', description: 'The premier resource for remote security camera recording, monitoring and alerts', link: 'http://www.securitube.net'},
		{title: 'BizTouches', description: 'BizTouches.com | Final touches for any business', link: 'http://www.biztouches.com'},
		
		{title: 'ShowMeThat', description: 'ShowMeThat is an online gospel music and<br>DVD store to help musicians improve their techniques', link: 'http://www.showmethat.com'},		
		{title: 'Killingly Internal Portal', description: 'Killingly Public School\'s internal portal tools,<br>web applications and programs', link: 'http://www.killinglyschools.org'}, 
		{title: 'Killingly Public Relations Site', description: 'The public relations site for Killingly Public Schools', link: 'http://www.killingly.k12.ct.us'},		
		{title: 'EDfinity', description: 'Web-based school administration tools that allow administrators and teachers to easily work with school data', link: 'http://www.edfinity.com'},
		{title: 'Night Life Alerts', description: 'Online SMS system sending information about the hottest nightclubs, concerts, comedy shows, theater and more', link: 'http://www.nightlifealerts.com'}, 
		{title: 'Pip Bloomfield', description: 'Photographic art by Pip Bloomfield, Santa Monica CA', link: 'http://www.pipbloomfield.com'}, 
		{title: '3DChicken', description: 'Open forum and broadcast service for<br>developing and sharing 3d videos', link: 'http://www.3dchicken.com'}
	];

	var porfolioSlide = new noobSlide({
		mode: 'vertical',
		box: $('portfolioDiv'),
		items: itemDetails,
		size: 180,
		handles: $$('#portfolio_left div').extend($$('#portfolio_right div')),
		handle_event: 'mouseenter',
		button_event: 'click',
		fxOptions: {
			duration: 500,
			//transition: Fx.Transitions.Back.easeOut,
			wait: false
		},
		onWalk: function(currentItem,currentHandle){
			this.handles.set('opacity', 0.3);
			currentHandle.set('opacity', 1);
			
			findObj('more_info').innerHTML = '<a href="' + currentItem.link + '" class="newWindowLink" target="_blank"><b>' + currentItem.title + '</b></a><br>' + currentItem.description;
		}
	});	
}


/*
Contact info has been submitted
*/
function contactConfirmed() {
	findObj('name_row').style.display = 'none';
	findObj('email_address_row').style.display = 'none';
	findObj('message_row').style.display = 'none';
	findObj('updateBtn').style.display = 'none';
	
	findObj('updateMsg').innerHTML = 'Thank you for submitting your contact info. Someone from Smithwick Design will respond shortly.';
}
