var concerto = function() {
	
	return {
		
		util : {
		
			/* FUNCTION: getQueryParamVal
			 * parses the querystring and returns the value of the passed parameter.
			 * example: var paramVal = concerto.util.getQueryParamVal("paramName")
			 */
			getQueryParamVal : function (paramName) {
				
				var query = window.location.search.substring(1);
				var vars = query.split("&");
				
				for (var i=0;i<vars.length;i++) {
					var pair = vars[i].split("=");
					if (pair[0] == paramName) {
						return pair[1];
					}
				}
				
				// if no match, return empty string
				return "";
			},
			
			getServicePath : function () {
				var url = window.location.href.split("venus/")[0];
				return 'http://www.tide.com/en-US/';
				//return url + 'en-US/';
				
			},
			
			getMediaPath : function (server) {
				var url = window.location.href.split("venus/")[0];
				return url.indexOf('tide.com') > -1 ? 'http://media.tide.com/venus/' : 'http://tidedev.digitas.com/venus/';
				//return url.indexOf('tide.com') > -1 ? 'http://media.tide.com/venus/' : '/Volumes/Users/Shared/WorkFiles/subversion/tideVenus/branches/tide-redesign-p2/TideWeb/WebContent/venus/';
			},			
			
			openPopup : function (pageToLoad, width, height, scroll, resize) {
				resizable = 0;
				resizable = resize;
				args = "width=" + width + ","     + "height=" + height + ","
				+ "location=1," + "menubar=1,"  + "resizable=" + resizable + "," + "scrollbars=" + scroll + ","
				+ "status=0,"   + "titlebar=1," + "toolbar=1," + "hotkeys=0";
				

				return window.open( pageToLoad,"newWin",args );
			}	
		},
		
		load : function () {
			
			var vId = concerto.util.getQueryParamVal("videoId");
			var gId = concerto.util.getQueryParamVal("galleryId");
			
			var server = concerto.util.getServicePath();
			var mediaServerURL = concerto.util.getMediaPath(server);
			
			var completeSwfPath = "./swf/";
			var completeAudioPath = mediaServerURL + "audio/";
			var completeFLVPath = mediaServerURL + "flv/";
			
			var flashvars = {
				indexPath:"./",
				swfPath:completeSwfPath, 
				xhtmlPath:"./",
				audioPath:completeAudioPath, 
				flvPath:completeFLVPath,
				servicePath:server,
				xmlPath:"xml/",
				playlistID:"D6D85D9B7776F5A2",
				videoId:vId,	
				galleryId:gId	
			};
			
			var params = {};
			params.bgcolor = "#FFFFFF";
			params.SeamlessTabbing = false;
			params.allowscriptaccess = "always";
			params.wmode = "transparent";
			params.scale = "noscale";
			params.quality = "high";
			params.menu = false;
			params.allowfullscreen = true;
			
			var attributes = {};
			attributes.align = "center";
			
			swfobject.embedSWF( "swf/venusLoader.swf", "flashDiv", "980", "624", "9.0.0", "swf/expressInstall.swf", flashvars, params, attributes );
		}	
	};
}();


$(document).ready(function() {
	
	concerto.load();
	
	$("a#rulesLink").click(function(e){
		e.preventDefault();
		concerto.util.openPopup("rules.html","820","820","1","1");
	});
	
	var initSlot1 = setTimeout ( function(){
		$("div#footer").fadeIn();	
	}, 2000 );
	
});

function trackPage(pageName){
	//alert("Tracking: " + pageName);
	pageTracker._trackPageview(pageName);
}

function trimWhiteSpace( aString )
{
	return (aString.replace(/^\W+/,'')).replace(/\W+$/,'');
}

function trackEvent(section, subsection, event){

	/* 
	for some reason the three arguements getting passed by flash are getting received
	as a comma delimited string in a single argument
	so if there is a comma split them apart and handle the array
	*/
	if( section.indexOf(",") >=0 )
	{
		var argArray = section.split(",");
		//
		section = trimWhiteSpace(argArray[0]);
		subsection = trimWhiteSpace(argArray[1]);
		event = trimWhiteSpace(argArray[2]);
	}

	if(section == undefined)
	section = "";
	if(subsection == undefined)
	subsection = "";
	if(event == undefined)
	event = "";
	
	
			//alert("Event:" + section + ":" + subsection + ":" + event);
	

	pageTracker._trackEvent(section, subsection, event);
}




