﻿/*
AJAX - style Switch sections by name (tabs)
*/

function switchSection(sectionName, trackingName) {
	// enables trackingName to override sectionName for purposes of analytics tracking
	if (trackingName==null) trackingName=sectionName;
	
	var sectionObj=findSectionByName(sectionName);
	//alert ('switchSection('+sectionName+')   '+sectionObj);
	
	// first, hide all sections
	for (var i in sections) {
		setSelectedSection(sections[i], false);
	}
	setSelectedSection(sectionObj, true);

	//Track this page in Google Analytics 
	trackPage(trackingName)
}

function setSelectedSection(sectionObj, b) {

	// if b is true, set this section to true
	
	var sectionName=sectionObj[0];
	var sectionButtonStyle=sectionObj[1];
	var sectionButtonSelectedStyle=sectionObj[2];	

	// switch section

	if ( ( section = document.getElementById(sectionName+'_div')) ) {
		if ( b && section.style.display == 'none') {
			section.className= 'sectionSelected';
			section.style.display = '';
		} else {
			section.className= 'section';
			section.style.display = 'none';
		}
	}
	
	// update button style
	if (button = document.getElementById(sectionName+'_btn')) {
		if (b) {
			button.className=sectionButtonSelectedStyle;
		} else {
			button.className=sectionButtonStyle;
		}
	}
}


function findSectionByName(sectionName) {
	for (var i in sections) {
		//alert ('findSectionByName'+sectionName+"    "+sections[i][0]);
		if (sectionName==sections[i][0]) {
			return sections[i];
		}
	}
}


// GOOGLE ANALYTICS

function trackPage(pageName) {
	//Track this page in Google Analytics 
	// pageName can be any unique string
	pageTracker._trackPageview(pageName);
	//alert ('trackPage:'+pageName);
}

function trackZoeViewEvent(type, path, name, comment) {
	/*
	Use to integrate with analytics via javascript bridge 
	usage: canvas.trackZoeViewEvent ('ITEM_DETAIL_LOADED', 'server/images/201.jpg', '201.jpg', 'Item # 201'); 
	eventTypes: GALLERY_LOADED, GALLERY_LIST_LOADED, ITEM_DETAIL_LOADED
	pagePath is the full path of the event, if applicable
	pageName is usually a UID of the event, which will be tracked by an analytics item of the same name
	comment can be anything, e.g. the title of the item
	*/
	var eventType='';
	switch (type) {
		case 'GALLERY_LIST_LOADED' : eventType+='GalleryList'; break;
		case 'GALLERY_LOADED' : eventType+='Gallery'; break;
		case 'ITEM_LOADED' : eventType+='Item'; break;
		case 'ITEM_DETAIL_LOADED' : eventType+='Detail'; break;
		default:eventType+='UnknownEvent'
	}
	var pageName=eventType+'|'+name+'|'+comment;
	trackPage(pageName);
}