function topCarousel_buttonCallback(carousel) {

	$("#goToPrev-top").click(function(){
   
   		//Get the id of this clicked item
  		clickedItem = $(this).attr("id");
   		//alert(clickedItem);
		
   	});
	
	$("#goToNext-top").click(function(){
   
   		//Get the id of this clicked item
  		clickedItem = $(this).attr("id");
   		//alert(clickedItem);
		
   	});

}

//We use the initCallback callback to assign functionality to the controls
function topCarousel_initCallback(carousel, item, idx, state) {
	
	/*
	if(typeof clickedItem != "undefined") {
		alert("clickedItem: " + clickedItem);
	}
	*/
	
	if(typeof clickedItem == "undefined" || clickedItem == "goToNext-top") {
		
		//alert("next");
	
		if(typeof currSectionNum == 'undefined') {
			currSectionNum = 1;
		} else {
			currSectionNum = currSectionNum + 1;
		}
		
		if(currSectionNum > 3) {
			currSectionNum = 1;
		}
		if(currSectionNum < 1) {
			currSectionNum = 3;
		}
	
	} else if(clickedItem == "goToPrev-top") {
		
		//alert("prev");
		
		if(typeof currSectionNum == 'undefined') {
			currSectionNum = 1;
		} else {
			currSectionNum = currSectionNum - 1;
		}
		
		if(currSectionNum < 1) {
			currSectionNum = 3;
		}
		if(currSectionNum > 3) {
			currSectionNum = 1;
		}
		
	}
	
	jQuery('.goToNext-top').bind('click', function() {
		urlCall = "no";
		functionCall = "no";
		carousel.next();
		selectedGalleryNum = 1;
		selectedGallery = 1;
		currContentSet = 0;
		clickedItemSamples = "";
		currNum = 1;
		$('#sample-num').html(currNum);
        return false;
    });

    jQuery('.goToPrev-top').bind('click', function() {
		urlCall = "no";
		functionCall = "no";
		carousel.prev();
		selectedGalleryNum = 1;
		selectedGallery = 1;
		currContentSet = 0;
		clickedItemSamples = "";
		currNum = 1;
		$('#sample-num').html(currNum);
        return false;
    });
	
	//alert(currSectionNum);	
	
	jQuery('.goToItem-top').bind('click', function() {
		urlCall = "no";
		functionCall = "no";
		clickedItem = "goToItem-top";
		selectedGalleryNum = 1;
		selectedGallery = 1;
		currContentSet = 0;
		clickedItemSamples = "";
		firstItem = jQuery.jcarousel.intval(this.id);
		centeredItem = firstItem - 1;
		carousel.scroll(centeredItem);
		currNum = 1;
		$('#sample-num').html(currNum);
        return false;
    });
	
	jQuery('.goToItem-top-footer').bind('click', function() {
		urlCall = "no";
		functionCall = "no";
		clickedItem = "goToItem-top";
		/*
		selectedGalleryNum = 1;
		selectedGallery = 1;
		currContentSet = 0;
		*/
		currContentSet = selectedGalleryNum;
		clickedItemSamples = "";
		firstItem = jQuery.jcarousel.intval(this.id);
		centeredItem = firstItem - 1;
		carousel.scroll(centeredItem);
		currNum = 1;
		$('#sample-num').html(currNum);
        return false;
    });
	
	//alert(clickedItem);
	
	if(page == "jobs" || page == "admin") {
		
		// do nothing
		
	} else {
	
		if(typeof clickedItem == "undefined" || clickedItem == "goToPrev-top" || clickedItem == "goToNext-top") {
			
			// do nothing
			
		} else {
		
			if(centeredItem == 0) {
				centeredItem = 3;
			}
			
			if(centeredItem == 1) {
				centeredItem = "work";
				currSectionNum = 1;
			} else if(centeredItem == 2) {
				centeredItem = "people";
				currSectionNum = 2;
			} else if(centeredItem == 3) {
				centeredItem = "way";
				currSectionNum = 3;
			}
			
		}
		
		if(currSectionNum == 1) {
			centeredItem = "work";
		} else if(currSectionNum == 2) {
			centeredItem = "people";
		} else if(currSectionNum == 3) {
			centeredItem = "way";
		}
		
		//alert(centeredItem);
		//alert(currSectionNum);
		
		/*
		*/
		if(centeredItem == "work") {
			$('.our-work').replaceWith('<img src="images/btn-main-nav-our-work.png" width="195" height="27" alt="Our Work" class="our-work" />');
			$('.our-way').replaceWith('<img src="images/btn-main-nav-our-way-off.png" width="195" height="27" alt="Our Way" class="our-way" />');
			$('.our-people').replaceWith('<img src="images/btn-main-nav-our-people-off.png" width="195" height="27" alt="Our People" class="our-people" />');	
		} else if(centeredItem == "people") {
			$('.our-work').replaceWith('<img src="images/btn-main-nav-our-work-off.png" width="195" height="27" alt="Our Work" class="our-work" />');
			$('.our-way').replaceWith('<img src="images/btn-main-nav-our-way-off.png" width="195" height="27" alt="Our Way" class="our-way" />');
			$('.our-people').replaceWith('<img src="images/btn-main-nav-our-people.png" width="195" height="27" alt="Our People" class="our-people" />');	
		} else if(centeredItem == "way") {
			$('.our-work').replaceWith('<img src="images/btn-main-nav-our-work-off.png" width="195" height="27" alt="Our Work" class="our-work" />');
			$('.our-way').replaceWith('<img src="images/btn-main-nav-our-way.png" width="195" height="27" alt="Our Way" class="our-way" />');
			$('.our-people').replaceWith('<img src="images/btn-main-nav-our-people-off.png" width="195" height="27" alt="Our People" class="our-people" />');	
		}

	}
	
	closeFooterBar();
	
	//This function makes the section carousel load to the correct one as defined in jcarousel-init.js
	/*
	*/
	function onLoadSetSectionCarousel() {
		urlCall = "yes";
		functionCall = "no";
		clickedItem = "goToItem-top";
		//selectedGalleryNum = 1;
		//selectedGallery = 1;
		//currContentSet = 0;
		clickedItemSamples = "";
		//firstItem = jQuery.jcarousel.intval(this.id);
		centeredItem = carouselFirstItem;
		//alert(centeredItem);
		carousel.scroll(centeredItem);
		//currNum = 1;
		//$('#sample-num').html(currNum);
		setCarousel = 1;
		return false;
	}
	
	if(typeof setCarousel == "undefined" || setCarousel != 1) {
		onLoadSetSectionCarousel();
	}
	
};

//We use the initCallback callback to assign functionality to the controls
function sectionCarousel_initCallback(carousel) {
	
	jQuery('.goToNext-section').bind('click', function() {
		
		// START Set active carousel back to the Nav Carousel to make the nav buttons function on the correct carousel
		carousel = jQuery('#sectionCarousel').data('jcarousel');
        
		carousel.next();
		
		//clickedItem = "";
		urlCall = "no";
		functionCall = "no";
		clickedItemSamples = "";
		currNum = 1;
		//alert(currNum);
		// Set image counter current value
		$('#imgCurr').html(currNum);
		$('#sample-num').html(currNum);
		
		//alert(currContentSet);
		if(typeof currContentSet == 'undefined' || currContentSet == 0) {
			currContentSet = selectedGallery + 1;
		} else {
			if(currContentSet >= totalContentSets) {
				currContentSet = 1;
			} else {
				currContentSet = currContentSet + 1;	
			}
		}
		selectedGallery = currContentSet;
		//alert(currContentSet);
		if(selectedGallery > totalContentSets) {
			selectedGallery = 1;
		}
		//alert(selectedGallery);
		
		updateContent(currSectionName, selectedGallery, 'no');
		
		closeFooterBar();
		
        return false;
		
    });

    jQuery('.goToPrev-section').bind('click', function() {
		
		// START Set active carousel back to the Nav Carousel to make the nav buttons function on the correct carousel
		carousel = jQuery('#sectionCarousel').data('jcarousel');
        
		carousel.prev();
		
		//clickedItem = "";
		urlCall = "no";
		clickedItemSamples = "";
		currNum = 1;
		// Set image counter current value
		$('#imgCurr').html(currNum);
		$('#sample-num').html(currNum);
		
		//jQuery('#samplesCarousel').data('jcarousel').reset();
		if(typeof currContentSet == 'undefined' || currContentSet == 0) {
			currContentSet = selectedGallery - 1;
		} else {
			currContentSet = currContentSet - 1;
		}
		selectedGallery = currContentSet;
		//alert(currContentSet);
		if(selectedGallery <= 0) {
			selectedGallery = totalContentSets;
		}
		//alert(selectedGallery);
		
		updateContent(currSectionName, selectedGallery, 'no');
		
		closeFooterBar();
		
        return false;
		
    });
	
	jQuery('.goToItem-section').bind('click', function() {
		
    	//alert(jQuery.jcarousel.intval(this.id));
		carousel.scroll(jQuery.jcarousel.intval(this.id));		
		
		//clickedItem = "";
		urlCall = "no";
		clickedItemSamples = "";
		currNum = 1;
		// Set image counter current value
		$('#imgCurr').html(currNum);
		$('#sample-num').html(currNum);
		
		//jQuery('#samplesCarousel').data('jcarousel').reset();
		selectedGallery = jQuery.jcarousel.intval(this.id);
		currContentSet = selectedGallery;
		//alert(selectedGallery);
		
		updateContent(currSectionName, selectedGallery, 'no');
		
		closeFooterBar();
		
        return false;
		
    });
	
};

function samplesCarousel_initCallback(carousel) {
	
	// Set image counter total value
	$('#imgCount').html(total);
	
};


function samplesCarousel_itemLoadCallback(carousel) {	
	
	$("#goToPrev-samples, #goToPrev-samples-mask").click(function(){
   
   		//Get the id of this clicked item
  		clickedItemSamples = $(this).attr("id");
   		//alert(clickedItemSamples);
		
   	});
	
	$("#goToNext-samples, #goToNext-samples-mask").click(function(){
   
   		//Get the id of this clicked item
  		clickedItemSamples = $(this).attr("id");
   		//alert(clickedItemSamples);
		
   	});
	
	$("#goToItem-samples").click(function(){
   
   		//Get the id of this clicked item
  		clickedItemSamples = "goToItem-samples";
   		//alert(clickedItemSamples);
		
   	});
	
	if(clickedItemSamples != 'windowResize') {
	
		if(typeof clickedItemSamples == "undefined") {
			clickedItemSamples = "";
			currNum = 1;
		}
		
		if(clickedItemSamples == "goToNext-samples" || clickedItemSamples == "goToNext-samples-mask") {
			// Set image counter current value
			
			if(goToNextClick == "Yes") {
				//alert('test1a');
				currNum = currNum + 1;
				goToNextClick = "";
			} else if(goToItemClick == "Yes") {
				//alert('test2a');
				goToItemClick = "";
			}
			
			if(currNum > total) {
				currNum = 1;
			}
			
		} else if(clickedItemSamples == "goToPrev-samples" || clickedItemSamples == "goToPrev-samples-mask") {
			// Set image counter current value
			
			if(goToPrevClick == "Yes") {
				//alert('test1b');
				currNum = currNum - 1;
				goToPrevClick = "";
			} else if(goToItemClick == "Yes") {
				//alert('test2b');
				goToItemClick = "";
			}
			
			if(currNum <= 0) {
				currNum = total;
			}	
			
		}	
		
		selectedSectionName = $('#section-name').html();
		//alert("selectedSectionName: " + selectedSectionName + "\n" + "selectedGalleryName: " + selectedGalleryName);
		setContentCopyAndLinks(selectedSectionName, selectedGalleryName);
		
	}
	
	//alert(clickedItemSamples);
	//alert(currNum);

	jQuery('.goToNext-carousel').bind('click', function() {

		goToNextClick = "Yes";
		
		carousel.next();
		
		if(currNum == (total - 1)) {
			nextNum = '1';
		} else if(currNum == total) {
			nextNum = '2';
		}  else {
			nextNum = currNum + 2;
		}
		changeSampleOpacity(nextNum);
		
		if(currNum == total) {
			nextNum = '1';
		}  else {
			nextNum = currNum + 1;
		}
		$('#imgCurr').html(nextNum);
		$('#sample-num').html(nextNum);
		
		//alert(currNum);
		
        return false;
		
    });

    jQuery('.goToPrev-carousel').bind('click', function() {
		
		goToPrevClick = "Yes";
		
        carousel.prev();
		
		changeSampleOpacity(currNum);
		
		if(currNum == 1) {
			prevNum = total;
		}  else {
			prevNum = currNum - 1;
		}
		$('#imgCurr').html(prevNum);
		$('#sample-num').html(prevNum);
		
		//alert(currNum);

        return false;
		
    });
	
	/*
	jQuery('.goToItem-carousel').bind('click', function() {
		
		currNum = this.id - 1;
		carousel.scroll(jQuery.jcarousel.intval(currNum));
		changeSampleOpacity(currNum + 1);

        return false;
		
    });
	*/
	
	jQuery('.goToItem-carousel').bind('click', function() {
		
		goToItemClick = "Yes";
		
		currNum = parseFloat(this.id);
		carousel.scroll(jQuery.jcarousel.intval(currNum));
		$('#imgCurr').html(currNum);
		$('#sample-num').html(currNum);
		
		if(currNum == total) {
			changeSampleOpacity(1);
		} else {
			changeSampleOpacity(currNum + 1);
		}
		
		//alert(currNum);

        return false;
		
    });
	
	if(typeof goToPrevClick == "undefined") {
		goToPrevClick = "";
	}
	if(typeof goToNextClick == "undefined") {
		goToNextClick = "";
	}
	if(typeof goToItemClick == "undefined") {
		goToItemClick = "";
	}
	
	//alert("currNum: " + currNum + " - goToNextClick: " + goToNextClick + " - goToPrevClick: " + goToPrevClick + " - goToItemClick: " + goToItemClick);
	//alert("currNum: " + currNum);
	//alert(clickedItemSamples);
	
};

function samplesCarousel_itemAddCallback(carousel, first, last, xml) {
	
	// Set the size of the carousel
    carousel.size(parseInt(jQuery('total', xml).text()));
	total = carousel.size(parseInt(jQuery('total', xml).text()));
	//alert(total);
	
	$('#imgCount').html(total);
	
	jQuery('image', xml).each(function(i) {
		
		//alert(jQuery(this).text());
		carousel.add(first + i, samplesCarousel_getItemHTML(jQuery(this).text()));
		$('#samplesCarousel.jcarousel-container-horizontal .jcarousel-clip-horizontal').css('width', '1950px');
		
		changeSampleOpacity(2);
		
    });
	
	carousel.scroll(jQuery.jcarousel.intval(1));
	
	setTimeout('setURLCallItem()', 1000);
	
};

function setURLCallItem() {
		
	if(typeof urlCall != "undefined" && urlCall == "yes") {
		
		if(typeof sampNum != "undefined" && sampNum != 1) {
			
			//carousel = jQuery('#samplesCarousel').data('jcarousel');
			currNum = sampNum;
			//alert(currNum);
			carousel.scroll(jQuery.jcarousel.intval(currNum));
			if(currNum == total) {
				changeSampleOpacity(1);
			} else {
				changeSampleOpacity(currNum + 1);	
			}
			
		}
		
	}
	
}

function decodeHTMLEntities(str) {
	return String(str).replace('&amp;', /&/g).replace('&lt;', /</g).replace('&gt;', />/g).replace('&quot;', /"/g);
}

/* Item html creation helper */
function samplesCarousel_getItemHTML(url) {
	
	//alert(url);
	return decodeHTMLEntities(url);
	
};

jQuery(document).ready(function() {	
	
	jQuery("#topCarousel").jcarousel({
		scroll: 1,
		wrap: 'circular',
		//initCallback: topCarousel_initCallback,
		initCallback: topCarousel_buttonCallback,
		itemFirstInCallback: topCarousel_initCallback,
		// This tells jCarousel NOT to autobuild prev/next buttons
		buttonNextHTML: null,
		buttonPrevHTML: null
	});
	
	$("#showPath").click(function(){
		
		deepLinkContent = "<div id='deep-link-content-close'><img src='images/close-x.png' width='15' height='15' alt='Close' /></div>";
		
		if(typeof selectedSectionName == "undefined") {
			
			if(typeof jobID1 == "undefined") {
			
				deepLinkContent += "<strong>Please select a job posting to get the link to the specific job posting you choose.</strong>";
			
			} else {
			
				deepLinkContent += "<strong>To link to the specific job posting you are viewing currently, copy this URL:</strong><br><br><center>http://swirl.net/index.php?jobid=" + jobID1 + "</center>";
				
			}
		
		} else {
			deepLinkContent += "<strong>To link to the specific section, gallery and image that you are viewing currently, copy this URL:</strong><br><br><center>http://swirl.net/index.php?section=" + selectedSectionName + "&gallery=" + selectedGalleryNameAbr + "&sample=" + currNum + "</center>";
		}
		
		//alert(deepLinkContent);
		
		$('#deep-link-content').html(deepLinkContent);
		$('#deep-link-content').css('display', 'block');
		
		$("#deep-link-content-close").click(function(){
			$('#deep-link-content').css('display', 'none');
		});
		
   	});
		
});

function setUpGalleries(selectedSectionName, selectedGallery, functionCall){
	
	if(typeof firstLoad == "undefined") {
		
		firstLoad = 1;
		
		// Turn URL Parameter request in to a function call to go to specific content
		if(typeof secName != "undefined" && typeof galName != "undefined" && secName != "" && galName != "") {
			
			selectedSectionName = secName;
			selectedGallery = galName;
			sampleNum = sampNum;
			urlCall = "yes";
			
		}
		
	}
	
	jQuery(document).ready(function() {
		
		if(firstLoad > 1) {
			$('#galleriesContent').fadeOut(300);
		}
			
		if(selectedSectionName == "work") {
			selectedSectionName = "work";
			ajaxPage = "our-work.php?staging=" + staging;
		} else if(selectedSectionName == "people") {
			selectedSectionName = "people";
			ajaxPage = "our-people.php?staging=" + staging;
		} else if(selectedSectionName == "way") {
			selectedSectionName = "way";
			ajaxPage = "our-way.php?staging=" + staging;
		} else if(selectedSectionName == "prev") {
			if (centeredItem == "people") {
				selectedSectionName = "work";
				ajaxPage = "our-work.php?staging=" + staging;
			} else if (centeredItem == "way") {
				selectedSectionName = "people";
				ajaxPage = "our-people.php?staging=" + staging;
			} else if (centeredItem == "work") {
				selectedSectionName = "way";
				ajaxPage = "our-way.php?staging=" + staging;
			}
		} else if(selectedSectionName == "next") {
			if (centeredItem == "way") {
				selectedSectionName = "work";
				ajaxPage = "our-work.php?staging=" + staging;
			} else if (centeredItem == "work") {
				selectedSectionName = "people";
				ajaxPage = "our-people.php?staging=" + staging;
			} else if (centeredItem == "people") {
				selectedSectionName = "way";
				ajaxPage = "our-way.php?staging=" + staging;
			}
		}
		
		setContent(selectedSectionName, selectedGallery);
		//alert("selectedSectionName: " + selectedSectionName + "\n" + "selectedGallery: " + selectedGallery);
		
		currSectionName = selectedSectionName;
			
		$.get(ajaxPage, function(data){
			
			$('#galleriesContent').slideUp(500).fadeIn(400).html(data);
			firstLoad = firstLoad + 1;
				
			jQuery("#sectionCarousel").jcarousel({
				scroll: 1,
				wrap: 'circular',
				initCallback: sectionCarousel_initCallback,
				// This tells jCarousel NOT to autobuild prev/next buttons
				buttonNextHTML: null,
				buttonPrevHTML: null
			});
			
			jQuery('#samplesCarousel').jcarousel({
				scroll: 1,
				//start: 4,
				wrap: 'circular',
				// Uncomment the following option if you want items
				// which are outside the visible range to be removed
				// from the DOM.
				// Useful for carousels with MANY items.
				// itemVisibleOutCallback: {onAfterAnimation: function(carousel, item, i, state, evt) { carousel.remove(i); }},
				initCallback: samplesCarousel_initCallback,
				itemLoadCallback: samplesCarousel_itemLoadCallback,
				buttonNextHTML: null,
				buttonPrevHTML: null
			});
			
			// Run function to update content based on defined variables
			if(page == "jobs" || page == "admin") {
				
				// do nothing
				
			} else {
		
				updateContent(selectedSectionName, selectedGalleryNum, 'no');
				
				// Set the relative position of the gallery on page load
				//itemOffset = $('#gallery-controller-bar').offset();
				//mainContentOffset = $('#mainContent').offset();
				//windowWidth = $(window).width();
				//pageCenter = (windowWidth/2);
				//alert(pageCenter);
				//alert(itemOffset.left);
				//alert(mainContentOffset.left);
				//alert($(window).width());
				
				//galleryPos = itemOffset.left - 466 + "px";
				//galleryPos = "-370px";
				//$('#samplesCarousel.jcarousel-container-horizontal .jcarousel-clip-horizontal').css('margin-left', galleryPos);
				
				// Set the relative position of the gallery copy on window resize
				//galleryTitlePos = itemOffset.left + 200 + "px";
				//galleryTitlePos = itemOffset.left + -40 + "px";
				//$('#galleryCaption').css('margin-left', galleryTitlePos);
				
				// Set the relative position of the gallery copy on window resize
				//galleryLinkPos = itemOffset.left + 510 + "px";
				//galleryLinkPos = itemOffset.left + 270 + "px";
				//$('#galleryLink').css('margin-left', galleryLinkPos);
				
				// Set the relative position of the gallery copy on window resize
				//galleryCopyPos = itemOffset.left + 9 + "px";
				//galleryCopyPos = itemOffset.left + -231 + "px";
				//$('#galleryCopy').css('margin-left', galleryCopyPos);
				
				//windowHeight = $(window).height();
				//$('#mainContent').css('height', windowHeight - 40);
				
			}
			
		});
	
	});
	
}

function updateContent(selectedSectionName, selectedGalleryNum, functionCall) {
	
	$.get('inc/get-gallery-total.php?section=' + selectedSectionName + "&staging=" + staging, function(data0){
		
		// Set gallery controller copy
		galleryTotal = data0;
		//alert(galleryTotal);
		
		totalContentSets = galleryTotal;
			
	});
	
	//alert(selectedGallery);
	setContent(selectedSectionName, selectedGalleryNum);
	//alert("selectedSectionName: " + selectedSectionName + "\n" + "selectedGalleryName: " + selectedGalleryName);
	
	$('#section-name').html(selectedSectionName);
	$('#gallery-name').html(selectedGalleryName);
	$('#imgCurr').html(currNum);
	
	if(typeof sampNum != "undefined"  && typeof urlCall != "undefined" && urlCall != "no") {
		$('#sample-num').html(sampNum);
	} else {
		$('#sample-num').html(currNum);
	}
	
	if(selectedSectionName == "work" || selectedSectionName == "people") {
		
		$('#galleryCaption').css('display', 'block');
		$('#galleryLink').css('display', 'block');		
		
	} else {
	
		$('#galleryCaption').css('display', 'none');
		$('#galleryLink').css('display', 'none');
		
	}
	
	$('#samplesCarousel.jcarousel-container-horizontal .jcarousel-clip-horizontal').css('width', "3000%");
		
	jQuery('#samplesCarousel').data('jcarousel').reset();
	
	//alert(currSectionName);
	currSectionSet = selectedGalleryNum;
	//alert(currSectionSet);
	
	if(functionCall == "yes") {
		
		setUpGalleries(selectedSectionName, selectedGalleryNum);
		
		centeredItem = selectedSectionName;
		
		if(selectedSectionName == "work") {
			currSectionNum = 3;
		} else if(selectedSectionName == "people") {
			currSectionNum = 1;
		} else if(selectedSectionName == "way") {
			currSectionNum = 2;
		}
		
		if(selectedSectionName == "work") {
			centeredItemAlt = 1;
		} else if(selectedSectionName == "people") {
			centeredItemAlt = 2;
		} else if(selectedSectionName == "way") {
			centeredItemAlt = 3;
		}
		
		carousel = jQuery('#topCarousel').data('jcarousel');
		carousel.scroll(centeredItemAlt);
		
	} else {
		
		if(typeof urlCall != "undefined" && urlCall == "yes") {
			
			//alert("urlcall");
			
			if(selectedSectionName == "work") {
				currSectionNum = 3;
			} else if(selectedSectionName == "people") {
				currSectionNum = 1;
			} else if(selectedSectionName == "way") {
				currSectionNum = 2;
			}
			
			if(selectedSectionName == "work") {
				centeredItemAlt = 1;
			} else if(selectedSectionName == "people") {
				centeredItemAlt = 2;
			} else if(selectedSectionName == "way") {
				centeredItemAlt = 3;
			}
	
			currContentSet = selectedGalleryNum;
			
			carousel = jQuery('#topCarousel').data('jcarousel');
			carousel.scroll(centeredItemAlt);
			
		}
		
	}
	
	carousel = jQuery('#sectionCarousel').data('jcarousel');
	carousel.scroll(selectedGalleryNum);
	
	//alert("selectedSectionName: " + selectedSectionName + " - selectedGalleryNum: " + selectedGalleryNum);

	// START Set active carousel to the Content Carousel to change the content below
	carousel = jQuery('#samplesCarousel').data('jcarousel');
	
	//alert(selectedSectionName);
	//alert(selectedGallery);
	//alert(selectedGalleryName);
	//alert(selectedGalleryNum);
	
	jQuery.get(
		'inc/setup-gallery-imgs.php?section=' + selectedSectionName + '&gallery=' + selectedGalleryNameAbr + "&staging=" + staging,
		{
			first: carousel.first,
			last: carousel.last
		},
		function(xml) {
			samplesCarousel_itemAddCallback(carousel, carousel.first, carousel.last, xml);
		},
		'xml'
	);
	// END Set active carousel to the Content Carousel to change the content below
	
	//changeGalleryIconsOpacity(selectedGalleryNum);
	
	changeGalleryIconsColor();
	
	//Perform Google Anaylytics tracking
	//alert('_trackEvent - ' + 'Content Navigation - ' + ' Section: our ' + selectedSectionName + ' - Gallery: ' + selectedGalleryNameAbr);
	_gaq.push(['_trackEvent','Content Navigation','Section: our ' + selectedSectionName,'Gallery: ' + selectedGalleryNameAbr]);
	
}

function changeGalleryIconsColor() {
	
	//alert(selectedGalleryNum);
	
	$.get('inc/get-gallery-names.php?section=' + selectedSectionName + "&staging=" + staging, function(data10){
		
		// Set gallery controller copy
		galleryNames = data10;
	
		//alert(galleryNames);
		
		galleryNamesArray = galleryNames.split(',');
		
		//alert(galleryNamesArray[1]);
		//alert(galleryNamesArray.length);
		
		j = 1;
		for(var k in galleryNamesArray) {
			
			fileName = "images/nav-icon_" + galleryNamesArray[k] + "_bw.png";
			//alert(fileName);
			//alert("MM_swapImage('Image" + j + "','','images/nav-icon_" + galleryNamesArray[k] + "_bw.png',1)");
			//MM_swapImage('Image' + j,'',fileName,1);
			
			//$('a.goToItem-section.item' + j).css('border','1px solid red');
			
			//$('.switched_images.item a' + j).html("<a href='#' class='goToItem-section' id='" + j + "'><img src='images/nav-icon_" + galleryNamesArray[k] + "_bw.png' alt='" + galleryNamesArray[k] + "' width='140' height='140' border='0' class='des sec" + j + "' id='Image" + j + "' /></a>")
			
			//$('a.goToItem-section.item' + j).html("<img src='images/nav-icon_" + galleryNamesArray[k] + "_bw.png' alt='" + galleryNamesArray[k] + "' width='140' height='140' border='0' class='des sec" + j + "' id='Image" + j + "' />").fadeIn(2000);
			
			$('.des.sec' + j).css('display','none').fadeOut(600);
			$('.des.sec-bw' + j).css('display','block').fadeIn(600);
			
			j++;
			
		}
		
		//alert("MM_swapImage('Image" + selectedGalleryNum + "','','images/nav-icon_" + selectedGalleryNameAbr.toLowerCase() + ".png',1)");
		//MM_swapImage('Image' + selectedGalleryNum,'','images/nav-icon_' + selectedGalleryNameAbr.toLowerCase() + '.png',1);
		
		//$('.switched_images.item' + selectedGalleryNum).html("<a href='#' class='goToItem-section' id='" + selectedGalleryNum + "'><img src='images/nav-icon_" + selectedGalleryNameAbr.toLowerCase() + ".png' alt='" + selectedGalleryNameAbr.toLowerCase() + "' width='140' height='140' border='0' class='des sec" + selectedGalleryNum + "' id='Image" + selectedGalleryNum + "' /></a>")
		
		//$('a.goToItem-section.item' + selectedGalleryNum).html("<img src='images/nav-icon_" + selectedGalleryNameAbr.toLowerCase() + ".png' alt='" + selectedGalleryNameAbr.toLowerCase() + "' width='140' height='140' border='0' class='des sec" + selectedGalleryNum + "' id='Image" + selectedGalleryNum + "' />");
		
		$('.des.sec' + selectedGalleryNum).css('display','block').fadeIn(600);
		$('.des.sec-bw' + selectedGalleryNum).css('display','none').fadeOut(600);
		
	});
	
}

function changeGalleryIconsOpacity(selectedGalleryNum) {
	
	//alert(selectedGalleryNum);
	
	if(typeof totalContentSets == "undefined") {
		totalContentSets_Opacity = 50;
	} else {
		totalContentSets_Opacity = totalContentSets;	
	}
	
	//alert(totalContentSets_Opacity);
	
	for(i=1;i<=totalContentSets_Opacity;i++) {
		secID = 'sec' + i;
		//alert(secID);
		if(i != selectedGalleryNum) {
			$('.' + secID).css('opacity', '0.4');
			$('.' + secID).css('filter', 'alpha(opacity=40)');
		} else {
			$('.' + secID).css('opacity', '1.0');
			$('.' + secID).css('filter', 'alpha(opacity=100)');	
		}
	}
	
}

function changeSampleOpacity(id) {
	
	for(i=1;i<=total;i++) {
		imgID = 'img' + i;
		//alert(imgID);
		if(i != id) {
			$('.' + imgID).css('opacity', '0.3');
			$('.' + imgID).css('filter', 'alpha(opacity=30)');
		} else {
			$('.' + imgID).css('opacity', '1.0');
			$('.' + imgID).css('filter', 'alpha(opacity=100)');	
		}
	}
		
}

function setOpacityOn(id) {
	
	secID = id;
	$('.' + secID).css('opacity', '1.0');
	$('.' + secID).css('filter', 'alpha(opacity=100)');	

}
function setOpacityOff(id) {
	
	secID = id;
	$('.' + secID).css('opacity', '0.5');
	$('.' + secID).css('filter', 'alpha(opacity=50)');

}

// CONTENT REPLACED - SEE jcarousel-init.js

function setGalleryCopy(selectedSectionName, selectedGalleryName) {
		
	//alert(selectedGallery);
	$.get('inc/setup-gallery-copy.php?section=' + selectedSectionName + '&gallery=' + selectedGalleryNameAbr + "&staging=" + staging, function(data1){
		
		// Set gallery controller copy
		galleryCopyContent = data1;
		
		// Set gallery controller copy
		$('#galleryCopy').html(galleryCopyContent);	
			
	});
	
}

function setCaptionLinks(selectedSectionName, selectedGallery) {
		
	$.get('inc/setup-gallery-links.php?section=' + selectedSectionName + '&gallery=' + selectedGalleryNameAbr + "&staging=" + staging, function(data2){
		// Set links copy
		linksArray = data2;
	});
	
}

// Makes the copy and links below the photos work
function setContentCopyAndLinks(selectedSectionName, selectedGallery) {
	
	//alert(selectedSectionName + " - " + selectedGalleryName);
	
	$.get('inc/setup-gallery-img-caption.php?section=' + selectedSectionName + '&gallery=' + selectedGalleryNameAbr + "&staging=" + staging, function(data3){
		// Set links copy
		captionsArray = data3;
		//alert(selectedGalleryName);
		parsedCaptionsArray = captionsArray.split(',');
		
		if(currNum == total) {
			imgNum = 0;	
		} else {
			imgNum = currNum;
		}
		
		galleryImageCaption = parsedCaptionsArray[(imgNum)];
		$('#galleryCaption').html(galleryImageCaption.replace("%%",","));
	});
	
	$.get('inc/setup-gallery-img-link-text.php?section=' + selectedSectionName + '&gallery=' + selectedGalleryNameAbr + "&staging=" + staging, function(data4){
		// Set links copy
		linksTextArray = data4;
		//alert(parsedCaptionsArray[0]);
		parsedLinksTextArray = linksTextArray.split(',');
		
		if(currNum == total) {
			imgNum = 0;	
		} else {
			imgNum = currNum;
		}
		
		galleryLinkContent = '<a href="javascript:void(0);" onclick="$.prettyPhoto.open(' + linksArray + '); $.prettyPhoto.changePage(' + imgNum + ');">' + parsedLinksTextArray[(imgNum)] + ' >></a>';
		$('#galleryLink').html(galleryLinkContent);
	});
	
}

window.onresize = function(event) {
	
	clickedItemSamples = 'windowResize';
	
	// Set the relative position of the gallery on page load
	//itemOffset = $('#gallery-controller-bar').offset();
	//mainContentOffset = $(window).width();
	//alert(itemOffset.left);
	//alert(mainContentOffset.left);
	
	//galleryPos = itemOffset.left - 466 + "px";
	//$('#samplesCarousel.jcarousel-container-horizontal .jcarousel-clip-horizontal').css('margin-left', galleryPos);
	
	// Set the relative position of the gallery copy on window resize
	//galleryTitlePos = itemOffset.left + 200 + "px";
	//$('#galleryCaption').css('margin-left', galleryTitlePos);
	
	// Set the relative position of the gallery copy on window resize
	//galleryLinkPos = itemOffset.left + 510 + "px";
	//$('#galleryLink').css('margin-left', galleryLinkPos);
	
	// Set the relative position of the gallery copy on window resize
	//galleryCopyPos = itemOffset.left + 9 + "px";
	//$('#galleryCopy').css('margin-left', galleryCopyPos);
	if(page == "jobs" || page == "admin") {
		
		windowHeight = $('#jobsRightContent').css('height');
		windowHeight = windowHeight.replace("px", "");
		windowHeight = parseInt(windowHeight);
		mainContentHeight = windowHeight + 100 + "px";
		//alert(mainContentHeight);
		$('#mainContent').css('height', mainContentHeight);
		
	} else {
		
		//windowHeight = $(window).height() - 10;
		//windowBottom = $(window).height() + 40;
		//alert(windowBottom);
		//$('#mainContent').css('height', windowHeight + "px");
		//$('#footerContainer').css('top', windowBottom + "px");
		//alert($('#footerContainer').css('bottom'));
		
	}
	
}

function changeSections(id){ 
	
     ID = document.getElementById(id); 
     
     if(ID.style.display == "") {
          ID.style.display = "none"; 
	} else { 
          ID.style.display = ""; 
	}
	
}

// Get URL parameters to allow for specific name/set navigation
$.extend({
  getUrlVars: function(){
	var vars = [], hash;
	var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	for(var i = 0; i < hashes.length; i++)
	{
	  hash = hashes[i].split('=');
	  vars.push(hash[0]);
	  vars[hash[0]] = hash[1];
	}
	return vars;
  },
  getUrlVar: function(name){
	return $.getUrlVars()[name];
  }
});
staging = $.getUrlVar('staging');
secName = $.getUrlVar('section');
galName = $.getUrlVar('gallery');
sampNum = $.getUrlVar('sample');
if(typeof sampNum == "undefined") {
	sampNum = 1;
}
sampNum = parseFloat(sampNum);

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function closeFooterBar() {
	
	if ($('#footerContent1').is(':visible')) {
			
		for(i=1;i<=4;i++) {
			btnElement = 'footerButton' + i;
			document.getElementById(btnElement).style.backgroundColor = "";
		}
		
		$('#footerContent1').slideToggle(speed, function(){
			document.getElementById('footerBg').style.height = "";
			document.getElementById('footerArrowUp').style.display = 'block';
			document.getElementById('footerArrowDown').style.display = 'none';
			return false;
		});
		
	} else if ($('#footerContent2').is(':visible')) {
		
		for(i=1;i<=4;i++) {
			btnElement = 'footerButton' + i;
			document.getElementById(btnElement).style.backgroundColor = "";
		}
		
		$('#footerContent2').slideToggle(speed, function(){
			document.getElementById('footerBg').style.height = "";
			document.getElementById('footerArrowUp').style.display = 'block';
			document.getElementById('footerArrowDown').style.display = 'none';
			return false;
		});
		
	} else if ($('#footerContent3').is(':visible')) {
		
		for(i=1;i<=4;i++) {
			btnElement = 'footerButton' + i;
			document.getElementById(btnElement).style.backgroundColor = "";
		}
		
		$('#footerContent3').slideToggle(speed, function(){
			document.getElementById('footerBg').style.height = "";
			document.getElementById('footerArrowUp').style.display = 'block';
			document.getElementById('footerArrowDown').style.display = 'none';
			return false;
		});
		
	} else if ($('#footerContent4').is(':visible')) {
		
		for(i=1;i<=4;i++) {
			btnElement = 'footerButton' + i;
			document.getElementById(btnElement).style.backgroundColor = "";
		}
		
		$('#footerContent4').slideToggle(speed, function(){
			document.getElementById('footerBg').style.height = "";
			document.getElementById('footerArrowUp').style.display = 'block';
			document.getElementById('footerArrowDown').style.display = 'none';
			return false;
		});
		
	}

}
