
function webbyTrack(){
	pageTracker._trackPageview("/webbyClick/"); 
}
// ------------------------ GENERAL ----------------------------------------
var g_bNoVideo = false;

Candt = {}

Candt.initialize = function(p_sCookieName, p_sCookieDelimiter, p_nPlayerControlsHeight) {
	CandtGlobal.initialize(parseInt(p_nPlayerControlsHeight));
	CandtPlaylist.initialize(p_sCookieName, p_sCookieDelimiter);
	CandtWork.initialize();
	CandtCareers.initialize();
}

Candt.initializeForCareers = function(p_sCookieName, p_sCookieDelimiter, p_nPlayerControlsHeight, p_sCareerDiv) {
	CandtGlobal.initialize(parseInt(p_nPlayerControlsHeight));
	CandtPlaylist.initialize(p_sCookieName, p_sCookieDelimiter);
	CandtWork.initialize();
	CandtCareers.initializeWithCareerDiv(p_sCareerDiv);
}

// ------------------------ GLOBAL ----------------------------------------


CandtGlobal = {};

CandtGlobal._nPlayerControlsHeight = 0;
CandtGlobal._searchMax = 5;
CandtGlobal._sCurrentPlayerId = null;
CandtGlobal._nPlayerTransitionDelay = 30; // seconds

CandtGlobal._sPrevVideoId = null;
CandtGlobal._sPrevClient = null;
CandtGlobal._sPrevTitle = null;
CandtGlobal._sPrevUrl = null;
CandtGlobal._sNextVideoId = null;
CandtGlobal._sNextClient = null;
CandtGlobal._sNextTitle = null;
CandtGlobal._sNextUrl = null;

CandtGlobal.initialize = function(p_nPlayerControlsHeight) {
	CandtGlobal._nPlayerControlsHeight = p_nPlayerControlsHeight;

	CandtGlobal.setIconHovers();
	CandtGlobal.setNavHovers();
	CandtGlobal.setDefaultInputs();

	$('body').mouseup( function() {
		if ( $('#'+CandtGlobal._sCurrentPlayerId).html() != null ) {
			$('#'+CandtGlobal._sCurrentPlayerId)[0].mouseUpOutside();
		}
	} );
}

CandtGlobal.setCurrentVideo = function(p_sClient, p_sTitle, p_sUrl) {
	CandtGlobal._sClient = p_sClient;
	CandtGlobal._sTitle = p_sTitle;
	CandtGlobal._sUrl = p_sUrl;
}

CandtGlobal.setPrevVideo = function(p_sVideoId, p_sClient, p_sTitle, p_sUrl) {
	CandtGlobal._sPrevVideoId = p_sVideoId;
	CandtGlobal._sPrevClient = p_sClient;
	CandtGlobal._sPrevTitle = p_sTitle;
	CandtGlobal._sPrevUrl = p_sUrl;
}

CandtGlobal.setNextVideo = function(p_sVideoId, p_sClient, p_sTitle, p_sUrl) {
	CandtGlobal._sNextVideoId = p_sVideoId;
	CandtGlobal._sNextClient = p_sClient;
	CandtGlobal._sNextTitle = p_sTitle;
	CandtGlobal._sNextUrl = p_sUrl;
}

CandtGlobal.setIconHovers = function() {
	/*
    $(".icon_holder").hover(function(){
        $(this).addClass('icon_holder_hover');      
    },function(){
        $(this).removeClass('icon_holder_hover');
    });
	*/
}

CandtGlobal.setNavHovers = function() {
	$(".nav .icon").hover(function() {
		$('.nav .display').css('display','none');
		$(this).siblings('.display').css('display','block');
		// $(this).addClass('icon_hover');
	},function() {
		$(this).siblings('.display').css('display','none');
		// $(this).removeClass('icon_hover');
	});


	$('#header .linklist .nav').hover(function(){
		if( $(this).css('color') != 'rgb(255,255,255)' && $(this).css('color') != 'rgb(255, 255, 255)'&& $(this).css('color') != '#ffffff'  ) {
			$(this).attr('name','animating');
			$(this).attr('rev',9);
			$(this).parent().attr( 'class','color9' );
		}
		
	},function(){
		if($(this).attr('name')){
			$(this).attr('name','');
			CandtGlobal.colorMe ( $(this) );
		}
	});
}

CandtGlobal.colorMe = function(element){
	currentColor = $(element).attr('rev');
	
	if (currentColor < 1 ) return;
	
	if ( $(element).attr('name') == 'animating'  ) {
		$(element).parent().attr( 'class','color9' );
		$(element).attr('rev',9);
	} else {
		$(element).parent().attr( 'class','color'+(currentColor - 1) );
		$(element).attr('rev',currentColor - 1);
	}
	window.setTimeout(function() { CandtGlobal.colorMe( $(element) ); },050);
}

CandtGlobal.setDefaultInputs = function() {
	if (!document.getElementsByTagName) return true;

	ourForms = document.getElementsByTagName('form');

	// go through each form
	var numForms = ourForms.length;
	for (var i=0;i<numForms;i++) { 
		// go through each form element
		var numFormElements = ourForms[i].elements.length;
		for (var j=0;j<numFormElements;j++) {
			var el = ourForms[i].elements[j];
			// ignore submit buttons
			if (el.type == "submit") continue;

			// if we got a text type input
			if (el.type == "text") {
				// only populate if we want it to
				// note: might want title attribute but no pre-population of inputs
				var ourClassName = el.className;
				if (ourClassName.match('auto-select') || ourClassName.match('auto-clear') || ourClassName.match('populate')) {
					// only populate if empty
					if (el.value == '') el.value = el.title;
				}

				// add auto select if class contains auto-select
				// note: else if below so auto-select takes precedence (assuming select is better than clear)
				if (el.className.match('auto-select')) {
					el.onfocus = function () {
						if (this.value == this.title) this.select();
					}
					if (el.captureEvents) el.captureEvents(Event.FOCUS);
				}
				// add auto clear if class contains auto-clear
				else if (el.className.match('auto-clear')) {
					el.onfocus = function () {
						if (this.value == this.title) this.value = '';
					}
					if (el.captureEvents) el.captureEvents(Event.FOCUS);

					el.onblur = function () {
						if (this.value == '') this.value = this.title;
					}
					if (el.captureEvents) el.captureEvents(Event.BLUR);
				}
			}

			// if we got a textarea
			if (el.type == "textarea") {
				// only populate if we want it to
				// note: might want title attribute but no pre-population of inputs
				var ourClassName = el.className;
				if (ourClassName.match('auto-select') || ourClassName.match('auto-clear') || ourClassName.match('populate')) {
					// only populate if empty
					if (el.value == '') el.value = el.title;
				}

				// add auto select if class contains auto-select
				if (el.className.match('auto-select')) {
					el.onfocus = function () {
						if (this.value == this.title) this.select();
					}
					if (el.captureEvents) el.captureEvents(Event.FOCUS);
				}
				// add auto clear if class contains auto-clear
				else if (el.className.match('auto-clear')) {
					el.onfocus = function () {
						if (this.value == this.title) this.value = '';
					}
					if (el.captureEvents) el.captureEvents(Event.FOCUS);
					
					el.onblur = function () {
						if (this.value == '') this.value = this.title;
					}
					if (el.captureEvents) el.captureEvents(Event.BLUR);
				}
			}
		}
	}
}

CandtGlobal.changeSectionNav = function(p_sNewSec,p_sNewCat) {
	$('#sections_navlist p.span').removeClass('span').addClass('link');
	$('#sections_navlist #'+p_sNewCat+'In'+p_sNewSec).removeClass('link').addClass('span');
}

CandtGlobal.embedVideoMissingMessage = function(p_sVideoId, p_sDivId, p_nEmbedWidth, p_nEmbedHeight) {
	var l_sMissingMessageHtml = '<div style="background: #dddddd; width:'+p_nEmbedWidth+'px; height:'+p_nEmbedHeight+'px">The assets for project with id '+p_sVideoId+' are missing.</div>';
	$('#'+p_sDivId).html(l_sMissingMessageHtml);
}

CandtGlobal.pauseVideoPlayback = function() {
	$('#'+CandtGlobal._sCurrentPlayerId)[0].pausePlayback();
}

CandtGlobal.videoPlaybackStopped = function(p_sVideoId) {
	if ( CandtPlaylist._aPlaylistForNavigation != null && CandtPlaylist.getCurrentTransitionHolderIdSuffix != null ) {
		// we are on the playlist sequential page...

		var l_sCurrentDivSelector = '#content_transition_' + CandtPlaylist.getCurrentTransitionHolderIdSuffix();
		var l_sSlug = $(l_sCurrentDivSelector+ ' .nav_right .icon_click').attr('rel');
		//alert ( 'video stopped in playlist, changing to slug: ' + l_sSlug );
		if ( l_sSlug != null && l_sSlug != undefined ) {
			CandtAjax.changePlaylistPage(l_sSlug, 'right');
		}
	}
}

CandtGlobal.videoPlayed = function(p_sVideoId) {
	if ( CandtGlobal._sCurrentPlayerId != p_sVideoId ) {
		CandtGlobal.pauseVideoPlayback();
	}
	CandtGlobal._sCurrentPlayerId = p_sVideoId;
}

CandtGlobal.prepareVideoPlayerDiv = function(p_sVideoId, p_sDivId, p_nEmbedWidth, p_nEmbedHeight) {
	// $('#'+p_sDivId).css("height", (p_nEmbedHeight - CandtGlobal._nPlayerControlsHeight)+"px");
	// $('#'+p_sDivId).css("background", "url(/_site/asset/project/"+p_sVideoId+"_large.jpg) left top no-repeat");
}

CandtGlobal.embedVideoPlayer2 = function(p_sVideoId, p_sAutoplay, p_sDivId, p_nEmbedWidth, p_nEmbedHeight, p_bImageOnly){
	if ( p_sAutoplay ) {
		CandtGlobal._sCurrentPlayerId = p_sVideoId;
	}
	//alert('embedVideoPlayer2');
	var flashvars = {
		videoId: p_sVideoId,
		autoplay: p_sAutoplay,
		playbackStoppedJavascriptFunction : 'CandtGlobal.videoPlaybackStopped',
		playClickedJavascriptFunction : 'CandtGlobal.videoPlayed',
		imageOnly: p_bImageOnly,
		transitionDelay : 'CandtGlobal._nPlayerTransitionDelay'
	};
	
	var params = {
		menu: "false",
		wmode: "transparent",
		allowfullscreen: "true",
		allowScriptAccess: 'always'
	};

	swfobject.embedSWF("/_site/swf/VideoPlayer.swf", p_sDivId, p_nEmbedWidth, p_nEmbedHeight, "1", "/_site/swf/swfobject/expressinstall.swf",flashvars,params);
}

CandtGlobal.embedVideoPlayer = function(p_sVideoId, p_sAutoplay, p_sDivId, p_nEmbedWidth, p_nEmbedHeight, p_bImageOnly) {
	if ( p_sAutoplay ) {
		CandtGlobal._sCurrentPlayerId = p_sVideoId;
	}
	// alert('embedVideoPlayer : ' + p_sDivId + " => " + l_bIsIPad);
	var l_bShowIPadVideo = false;	var l_bShowIPhoneVideo = false;
	 
	if(l_bIsIPad == 1){
		
		var l_sMatcherDelimeter = '~';
		var l_sMatcher = l_sMatcherDelimeter + p_sVideoId + l_sMatcherDelimeter;
		if( (l_sMatcherDelimeter+l_aIPadIds.join(l_sMatcherDelimeter)+l_sMatcherDelimeter).match(l_sMatcher) ){
			l_bShowIPadVideo = true;	
		}
	}
	else if(l_bIsIPhone == 1){
		
		var l_sMatcherDelimeter = '~';
		var l_sMatcher = l_sMatcherDelimeter + p_sVideoId + l_sMatcherDelimeter;
		if( (l_sMatcherDelimeter+l_aIPhoneIds.join(l_sMatcherDelimeter)+l_sMatcherDelimeter).match(l_sMatcher) ){
			l_bShowIPhoneVideo = true;	
		}
	}
	
	if(l_bShowIPadVideo){
		var l_sHTML5 = '<video class="html5-video" src="http://www.codeandtheory.com/_site/asset/project/ipad/'+p_sVideoId+'_iPad.mp4" type=\'video/mp4; codecs="avc1.42E01E, mp4a.40.2"\' width="'+p_nEmbedWidth+'" height="'+p_nEmbedHeight+'" controls poster="/_site/asset/project/'+p_sVideoId+'_large.jpg"></video>';
		 $('#'+p_sDivId).html(l_sHTML5);

	}else if(l_bShowIPhoneVideo){
		var l_sHTML5 = '<video class="html5-video" src="http://www.codeandtheory.com/_site/asset/project/iphone/'+p_sVideoId+'_iPhone.mp4" type=\'video/mp4; codecs="avc1.42E01E, mp4a.40.2"\' width="'+p_nEmbedWidth+'" height="'+p_nEmbedHeight+'" controls poster="/_site/asset/project/'+p_sVideoId+'_large.jpg"></video>';
		 $('#'+p_sDivId).html(l_sHTML5);

	}else{
		
		$('#'+p_sDivId).append('<div id="ActualPlayer" style="float:left; margin:-'+p_nEmbedHeight+'px 0 0 0"><div id="ActualPlayer_'+p_sVideoId+'">&nbsp;</div>&nbsp;</div>');
		//return;
		var so = new SWFObject('/_site/swf/VideoPlayer.swf',p_sVideoId, p_nEmbedWidth, p_nEmbedHeight, '8', '#ffffff');
		so.useExpressInstall('/_site/swf/swfobject/expressinstall.swf');
		so.addParam('menu', 'false');            
		so.addParam('wmode', 'transparent');            
		so.addParam('allowfullscreen', 'true');
		so.addParam("allowScriptAccess", "always");
	
		var l_sFlashParams = 'videoId='+p_sVideoId+'&autoplay='+p_sAutoplay+'&playbackStoppedJavascriptFunction=CandtGlobal.videoPlaybackStopped&playClickedJavascriptFunction=CandtGlobal.videoPlayed&imageOnly='+p_bImageOnly+'&transitionDelay='+CandtGlobal._nPlayerTransitionDelay;
	
		if ( CandtPlaylist._aPlaylistForNavigation == null || CandtPlaylist.getCurrentTransitionHolderIdSuffix == null ) {
			// we are NOT on the playlist sequential page...
			l_sFlashParams+= '&client='+escape(CandtGlobal._sClient)+'&title='+escape(CandtGlobal._sTitle)+'&url='+escape(CandtGlobal._sUrl);
			if ( CandtGlobal._sPrevVideoId != null ) {
				l_sFlashParams+= '&prevVideoId='+CandtGlobal._sPrevVideoId+'&prevClient='+escape(CandtGlobal._sPrevClient)+'&prevTitle='+escape(CandtGlobal._sPrevTitle)+'&prevUrl='+escape(CandtGlobal._sPrevUrl);
			}
			if ( CandtGlobal._sNextVideoId != null ) {
				l_sFlashParams+= '&nextVideoId='+CandtGlobal._sNextVideoId+'&nextClient='+escape(CandtGlobal._sNextClient)+'&nextTitle='+escape(CandtGlobal._sNextTitle)+'&nextUrl='+escape(CandtGlobal._sNextUrl);
			}
		}
	
		so.addParam('flashvars', l_sFlashParams);
		so.write('ActualPlayer_'+p_sVideoId);
	}
	
	
	$('#'+p_sDivId).attr('rel',p_bImageOnly);
}

CandtGlobal.embedVideoPlayerPlaceHolder = function(p_sVideoId, p_sDivId, p_nEmbedWidth, p_nEmbedHeight, p_bImageOnly) {    
	//alert('embedVideoPlayerPlaceHolder');
	var l_nImageHeight = p_nEmbedHeight - CandtGlobal._nPlayerControlsHeight;
	var l_sPlaceHolderHtml = '<div style=\"float:left\"><img src=\"/_site/asset/project/'+p_sVideoId+'_large.jpg\" id=\"img_'+p_sVideoId+'\" width=\"'+p_nEmbedWidth+'\" height=\"'+l_nImageHeight+'\" rel=\"'+p_bImageOnly+'\"/><br/>';
	if ( !p_bImageOnly ) {
		l_sPlaceHolderHtml+= '<img src=\"/_site/images/fake_player_controls.jpg\" width=\"'+p_nEmbedWidth+'\" height=\"'+CandtGlobal._nPlayerControlsHeight+'\" />';
	}
	l_sPlaceHolderHtml+= '</div>';
	$('#'+p_sDivId).html(l_sPlaceHolderHtml);
}

CandtGlobal.replacePlayerWithPlaceHolder = function(p_sDivId) {
	//if(document._bIsMacFF){
		var l_xDiv = $('#'+p_sDivId);
		if($('#ActualPlayer').length > 0)
			$('#ActualPlayer').remove();
	//}
}

CandtGlobal.replacePlaceHolderWithPlayer = function(p_sDivId) {
	var l_xDiv = $('#'+p_sDivId);
	var l_xImg = l_xDiv.find('img:eq(0)');
	if ( l_xImg.html() != null ) { // if assets were missing...
		var l_sVideoId = l_xImg.attr('id').substring(4, l_xImg.attr('id').length);
		var l_nEmbedWidth = l_xImg.attr('width');
		var l_nEmbedHeight = parseInt(l_xImg.attr('height'))+parseInt(CandtGlobal._nPlayerControlsHeight);
		var l_bImageOnly = l_xImg.attr('rel');
		//alert ( 'replace place holder: ' + l_sVideoId + ' ' + l_nEmbedWidth + ' ' + l_nEmbedHeight );
		CandtGlobal.embedVideoPlayer(l_sVideoId, true, p_sDivId, l_nEmbedWidth, l_nEmbedHeight, l_bImageOnly);
	}
}


// ------------------------ PLAYLIST ----------------------------------------


function PlaylistItem(p_sId, p_sTitle, p_sSlug, p_nYear) {
	this._sId = p_sId;
	this._sTitle = p_sTitle;
	this._sSlug = p_sSlug;
	this._nYear = p_nYear;
}

PlaylistItem.prototype.getId = function() { return this._sId; }
PlaylistItem.prototype.getTitle = function() { return this._sTitle; }
PlaylistItem.prototype.getSlug = function() { return this._sSlug; }
PlaylistItem.prototype.getYear = function() { return this._nYear; }
PlaylistItem.prototype.getInternalLink = function() { return "/work/"+this._nYear+"/"+this._sSlug; }

CandtPlaylist = {};

CandtPlaylist._nTransitionSpeed = 500;
CandtPlaylist._nCookieExpiryInDays = 7;
CandtPlaylist._nDelayedHeaderCount = 0;

CandtPlaylist._bHeaderSortablesAdded = false;
CandtPlaylist._bEditSortablesAdded = false;
CandtPlaylist._sCurrentProjectSlug = null;
CandtPlaylist._aPlaylistForNavigation = null;
CandtPlaylist._sCurrentTransitionHolderIdSuffix = null;
CandtPlaylist._sTransitionDirection = null;
CandtPlaylist._bSessionPlaylist = false;
CandtPlaylist._bTransitionInProgress = false;
CandtPlaylist._sQueuedProjectSlug = null;
CandtPlaylist._sQueuedTransitionDirection = null;
CandtPlaylist._aNavDisableContent = null;

CandtPlaylist.initialize = function(p_sCookieName, p_sCookieDelimiter) {
	CandtPlaylist._sCookieName = p_sCookieName;
	CandtPlaylist._sCookieDelimeter = p_sCookieDelimiter;
	CandtPlaylist._sCurrentProjectSlug = null;
	CandtPlaylist._aPlaylistForNavigation = null;
	CandtPlaylist._sCurrentTransitionHolderIdSuffix = null;
	CandtPlaylist._sTransitionDirection = null;
	CandtPlaylist._bSessionPlaylist = false;
	CandtPlaylist._bTransitionInProgress = false;
	CandtPlaylist._sQueuedProjectSlug = null;
	CandtPlaylist._sQueuedTransitionDirection = null;
	CandtPlaylist._aNavDisableContent = null;

	CandtPlaylist.setEditPlaylist();
	CandtPlaylist.setHeaderPlaylist();
	CandtPlaylist.setPlaylistClose();
}

CandtPlaylist.reinitialize = function() {
	CandtPlaylist._sCurrentProjectSlug = null;
	CandtPlaylist._aPlaylistForNavigation = null;
	CandtPlaylist._sCurrentTransitionHolderIdSuffix = null;
	CandtPlaylist._sTransitionDirection = null;
	CandtPlaylist._bSessionPlaylist = false;
	CandtPlaylist._bTransitionInProgress = false;
	CandtPlaylist._sQueuedProjectSlug = null;
	CandtPlaylist._sQueuedTransitionDirection = null;
	CandtPlaylist._aNavDisableContent = null;

	CandtPlaylist.setEditPlaylist();
	CandtPlaylist.setHeaderPlaylist();
	CandtPlaylist.setPlaylistClose();
}

CandtPlaylist.setCurrentTransitionHolderIdSuffix = function(p_sTransitionIdSuffix) {
	CandtPlaylist._sCurrentTransitionHolderIdSuffix = p_sTransitionIdSuffix;
}

CandtPlaylist.getCurrentTransitionHolderIdSuffix = function() {
	return CandtPlaylist._sCurrentTransitionHolderIdSuffix;
}

CandtPlaylist.getOtherTransitionHolderIdSuffix = function() {
	if ( CandtPlaylist._sCurrentTransitionHolderIdSuffix == 'one' ) {
		return 'two';
	}
	else if ( CandtPlaylist._sCurrentTransitionHolderIdSuffix == 'two' ) {
		return 'one';
	}
	else {
		return null;
	}
}

CandtPlaylist.setCurrentProjectSlug = function(p_sProjectSlug) {
	CandtPlaylist._sCurrentProjectSlug = p_sProjectSlug;
}

CandtPlaylist.setSessionPlaylist = function(p_bSessionPlaylist) {
	CandtPlaylist._bSessionPlaylist = p_bSessionPlaylist;
}

CandtPlaylist.createCookie = function(p_sName, p_sValue, p_nDays) {
	if (p_nDays) {
		var l_xDate = new Date();
		l_xDate.setTime(l_xDate.getTime()+(p_nDays*24*60*60*1000));
		var l_sExpires = "; expires="+l_xDate.toGMTString();
	}
	else {
		var l_sExpires = "";
	}
	document.cookie = p_sName+"="+p_sValue+l_sExpires+"; path=/";
}

CandtPlaylist.readCookie = function(p_sName) {
	var l_sNameEQ = p_sName + "=";
	var l_aCookies = document.cookie.split(';');
	for(var i=0;i < l_aCookies.length;i++) {
		var l_sCookie = l_aCookies[i];
		while (l_sCookie.charAt(0)==' ') l_sCookie = l_sCookie.substring(1,l_sCookie.length);
		if (l_sCookie.indexOf(l_sNameEQ) == 0) return l_sCookie.substring(l_sNameEQ.length,l_sCookie.length);
	}
	return null;
}

CandtPlaylist.eraseCookie = function(p_sName) {
	CandtPlaylist.createCookie(p_sName,"",-1);
}

CandtPlaylist.getPlaylistFromCookieWithKey = function(p_sKey) {
	var l_sCookieValue = CandtPlaylist.readCookie(CandtPlaylist._sCookieName);
	var r_aPlaylist = new Array();
	if ( l_sCookieValue != null && l_sCookieValue.length > 0) {
		var l_aPlaylistData = l_sCookieValue.split(CandtPlaylist._sCookieDelimeter);
		for ( var i=0; i<l_aPlaylistData.length/4; i++ ) {
			var l_xPlaylistItem = new PlaylistItem(l_aPlaylistData[i*4], l_aPlaylistData[i*4+1], l_aPlaylistData[i*4+2], l_aPlaylistData[i*4+3]);
			if ( p_sKey == 'slug' ) {
				r_aPlaylist[l_xPlaylistItem.getSlug()] = l_xPlaylistItem;
			}
			else {
				r_aPlaylist[l_xPlaylistItem.getId()] = l_xPlaylistItem;
			}
		}
	}
	return r_aPlaylist;
}

CandtPlaylist.getPlaylistFromCookie = function() {
	return CandtPlaylist.getPlaylistFromCookieWithKey('id');
}

CandtPlaylist.getPlaylistFromCookieBySlug = function() {
	return CandtPlaylist.getPlaylistFromCookieWithKey('slug');
}

CandtPlaylist.createCookieFromPlaylist = function(p_aPlaylist) {
	var l_sCookieValue = '';
	var l_nCounter = 0;

	for ( var l_sId in p_aPlaylist ) {
		if ( l_nCounter != 0 ) {
			l_sCookieValue+= CandtPlaylist._sCookieDelimeter;
		}
		l_sCookieValue += p_aPlaylist[l_sId].getId() + CandtPlaylist._sCookieDelimeter + p_aPlaylist[l_sId].getTitle() + CandtPlaylist._sCookieDelimeter + p_aPlaylist[l_sId].getSlug() + CandtPlaylist._sCookieDelimeter + p_aPlaylist[l_sId].getYear();
		l_nCounter++; 
	}

CandtPlaylist.createCookie(CandtPlaylist._sCookieName, l_sCookieValue, CandtPlaylist._nCookieExpiryInDays);
}

CandtPlaylist.addProjectToPlaylist = function(p_sId, p_sTitle, p_sSlug, p_nYear) {
	var l_aPlaylist = CandtPlaylist.getPlaylistFromCookie();

	var l_xPlaylistItem = new PlaylistItem(p_sId, p_sTitle, p_sSlug, p_nYear);
	l_aPlaylist[l_xPlaylistItem.getId()] = l_xPlaylistItem;

	CandtPlaylist.createCookieFromPlaylist(l_aPlaylist);
	CandtPlaylist.showDropdown();
}

CandtPlaylist.removeProjectFromPlaylist = function(p_sId) {
	var l_aPlaylist = CandtPlaylist.getPlaylistFromCookie();

	var r_sRemovedSlug = null;

	if ( l_aPlaylist[p_sId] ) {
		r_sRemovedSlug = l_aPlaylist[p_sId].getSlug();
		delete l_aPlaylist[p_sId];
	}

	CandtPlaylist.createCookieFromPlaylist(l_aPlaylist);

	return r_sRemovedSlug;
}

CandtPlaylist.reorderProjectsInPlaylist = function(p_aIds) {
	var l_aPlaylist = CandtPlaylist.getPlaylistFromCookie();

	var l_aNewPlaylist = new Array();

	for ( var i=0; i<p_aIds.length; i++ ) {
		var l_sId = p_aIds[i];
		l_aNewPlaylist[l_sId] = l_aPlaylist[l_sId];
	}

	CandtPlaylist.createCookieFromPlaylist(l_aNewPlaylist);
}

CandtPlaylist.updateHeaderPlaylist = function() {
	CandtAjax.fixShareInput();
	if ( CandtPlaylist._bHeaderSortablesAdded == true ) {
		CandtPlaylist._bHeaderSortablesAdded = false;
		$('#the_selectlist').sortable( "destroy" );
	}
	$('#playlist_drop').removeClass('show');
	CandtPlaylist.setHeaderPlaylist();
	CandtPlaylist.setPlaylistClose(); //!!!!!
	//$('#playlist_drop').addClass('show');
}

CandtPlaylist.addHeaderEmptyMessageIfNecessary = function() {
	// FIXME - should replace this test for no children with something better
	if ( $('#the_selectlist').children('li').html() == null ) {
		$('#the_selectlist').append(
		'<li>No Items in Playlist</li>'
	);
		
	$('#playlist_drop').addClass('null');
		document.g_bEmpty = 1;
	}
}

CandtPlaylist.setHeaderPlaylist = function() {
	var l_aPlaylistItems = CandtPlaylist.getPlaylistFromCookie();

	$('#the_selectlist').empty();
	var l_nCounter = 0;
	if ( l_aPlaylistItems.length > 0 ) {
		for ( var l_nPlaylistId in l_aPlaylistItems ) {
			var l_xPlaylistItem = l_aPlaylistItems[l_nPlaylistId];
			$('#the_selectlist').append(
				'<li id="plheader_' + l_xPlaylistItem.getId() + '"><a rev="right" href="/#/'+l_xPlaylistItem.getInternalLink()+'" class="ajaxlink" rel="/'+l_xPlaylistItem.getInternalLink()+'">'+
				l_xPlaylistItem.getTitle() +
				'</a><div class="handle"></div>'+
				'<div class="close"></div>'+
				'</li>');
			l_nCounter++;
		}
	}
	else {
		CandtPlaylist.addHeaderEmptyMessageIfNecessary();
	}

	$('#plheader_count').html(''+l_nCounter);

	var l_bHover = 0;
	
	$('#playlist_select .playlist').click( function(){ 
		CandtPlaylist.playlistclicked = true;
		
		
		CandtPlaylist._nDelayedHeaderCount++;
		$('#playlist_select .playlist').addClass('original_drop')
		$('#playlist_drop').addClass('show');
		
	});
	
	$("#playlist_select").hover( function() {
		if(CandtPlaylist.playlistclicked){
			CandtPlaylist._nDelayedHeaderCount++;
			$('#playlist_select .playlist').addClass('original_drop')
			$('#playlist_drop').addClass('show');
		}
		else{
			$('#playlist_select .playlist').addClass('original_drop')
		}
	}, function() {
		if(CandtPlaylist.playlistclicked){
			CandtPlaylist.delayedHeaderClose(CandtPlaylist._nDelayedHeaderCount);
		}
		else{
			$('#playlist_select .playlist').removeClass('original_drop')	
		}
 });

	$("#playlist_select li").hover(function() {
		if (!l_bHover) $(this).addClass("hover");
	},function() {
		$(this).removeClass("hover");
	});

	newwidth= $('#playlist_drop').width();

	if (newwidth > 350) newwidth = 350;

	$('#the_selectlist li').width( newwidth-30 );

	CandtPlaylist.setSortable();

	setLinks('#the_selectlist');

}

CandtPlaylist.delayedHeaderClose = function(p_nDelayedHeaderCount) {
	window.setTimeout("CandtPlaylist.delayedHeaderCloseHelper("+CandtPlaylist._nDelayedHeaderCount+")",800);
}

CandtPlaylist.delayedHeaderCloseHelper = function(p_nDelayedHeaderCount) {
	if(p_nDelayedHeaderCount == CandtPlaylist._nDelayedHeaderCount){
		$('#playlist_drop').removeClass('show');
		$('#playlist_select .playlist').removeClass('original_drop');
		$('#the_selectlist  .hover').removeClass('hover');
		CandtPlaylist.playlistclicked = false;
		CandtAjax.fixShareInput();
	}
}

CandtPlaylist.setSortable = function() {
	var l_aPlaylistItems = CandtPlaylist.getPlaylistFromCookie();
	
	if ( l_aPlaylistItems.length > 0 ) {
		CandtPlaylist._bHeaderSortablesAdded = true;
		$('#the_selectlist').sortable(
			{
				handle: '.handle',
				items: 'li',
				placeholder:'helperclass',
				axis: 'v',
				containment: '#the_selectlist',
				start: function(e,ui) {
					l_bHover = 1;
				},
				stop: function(e,ui){
					l_bHover = 0;
				},
				update: function(e,ui){ CandtPlaylist.updateSortable('plheader', $(this).sortable("serialize")); }
			}
		);
	}
	else {
		CandtPlaylist._bHeaderSortablesAdded = false;
	}
}

CandtPlaylist.getPlaylistNumber = function(p_nNumber) {
	if ( p_nNumber < 10 ) {
		return '0'+p_nNumber;
	}
	else {
		return ''+p_nNumber;
	}
}

CandtPlaylist.updateEditPlaylist = function() {
	if ( CandtPlaylist._bHeaderSortablesAdded == true ) {
		CandtPlaylist._bHeaderSortablesAdded = false;
		$('#the_playlist').sortable( "destroy" );
	}
	CandtPlaylist.setEditPlaylist();
	CandtPlaylist.setPlaylistClose();
}

CandtPlaylist.setEditPlaylist = function() {
	var l_aPlaylistItems = CandtPlaylist.getPlaylistFromCookie();

	$('#pledit_holder').empty();
	var l_nCounter = 1;
	if ( l_aPlaylistItems.length > 0 ) {
		$('#playlist_edit .playlist_empty').hide();
		for ( var l_nPlaylistId in l_aPlaylistItems ) {
			var l_xPlaylistItem = l_aPlaylistItems[l_nPlaylistId];
			$('#pledit_holder').append(
				'<div class="playlist_row" id="pledit_' + l_xPlaylistItem.getId() + '">'+
				'<div class="imgholder">'+
				'<img src="/_site/asset/project/'+l_xPlaylistItem.getId()+'_thumb.jpg" width="72" height="68" alt="'+escape(l_xPlaylistItem.getTitle())+'" />'+
				'</div>'+
				'<div class="meta">'+
				'<p><span class="pledit_number">' + CandtPlaylist.getPlaylistNumber(l_nCounter++) + '</span>. ' + l_xPlaylistItem.getTitle() + '</p>'+
				'<div class="handle"></div>'+
				'<div class="close"></div>'+
				'</div>'+
				'<div class="clear"></div>'+
				'</div>');
		}
	}
	else {
		$('#playlist_edit .playlist_empty').show();
	}

	$('#plheader_count').html(''+(l_nCounter-1));

	$("#playlist_edit .playlist_row").hover(function() {
		$(this).addClass('hover');
	},function() {
		$(this).removeClass('hover');
	});

	if ( l_aPlaylistItems.length > 0 ) {
		CandtPlaylist._bHeaderSortablesAdded = true;
		$('#the_playlist').sortable(   
			{
				handle: '.handle',
				items: 'div.playlist_row',
				placeholder:'helperclass',
				axis: 'v',
				containment: '#the_playlist',
				stop: function(e,ui){ },
				update: function(e,ui){ CandtPlaylist.updateSortable('pledit', $(this).sortable("serialize")); }
			}
		);
	}
	else {
		CandtPlaylist._bHeaderSortablesAdded = false;
	}
}

CandtPlaylist.updateEditPlaylistNumbers = function() {
	var l_nNumber = 1;
	$('.pledit_number').each(function() {
		$(this).html(CandtPlaylist.getPlaylistNumber(l_nNumber++));
	});
}


CandtPlaylist.addToPlaylist = function(p_sId, p_sTitle, p_sSlug, p_nYear) {
	$('#playlist_drop').removeClass('null'); 
	CandtPlaylist.addProjectToPlaylist(p_sId, p_sTitle, p_sSlug, p_nYear);
	CandtPlaylist.updateHeaderPlaylist();
	CandtWork.updatePlaylistLink();
	CandtWork.checkButtons(); //!!!!!!
	CandtPlaylist.showDropdown(p_sId);
}

CandtPlaylist.showDropdown = function(p_sId){
	CandtPlaylist.playlistclicked = true;
	CandtPlaylist._nDelayedHeaderCount++;
	currentCount = CandtPlaylist._nDelayedHeaderCount;
	$('#playlist_select .playlist').addClass('original_drop')
	$('#playlist_drop').addClass('show');

	$('#the_selectlist  #plheader_'+p_sId).addClass('hover');
	$('#the_selectlist  #plheader_'+p_sId).animate({ opacity: '1.0' }, 0200,'',function() {
		$('#the_selectlist  #plheader_'+p_sId).removeClass('hover');
		$('#the_selectlist  #plheader_'+p_sId).animate({ opacity: '1.0' }, 0150,'',function() {
			$('#the_selectlist  #plheader_'+p_sId).addClass('hover');
			$('#the_selectlist  #plheader_'+p_sId).animate({ opacity: '1.0' }, 0200,'',function() {
				$('#the_selectlist  #plheader_'+p_sId).removeClass('hover');
				$('#the_selectlist  #plheader_'+p_sId).animate({ opacity: '1.0' }, 0150,'',function() {
					$('#the_selectlist  #plheader_'+p_sId).addClass('hover');
					window.setTimeout("CandtPlaylist.delayedHeaderCloseHelper("+currentCount+")",800);
				});
			});
		});
	});
}

CandtPlaylist.removeFromPlaylist = function(p_sId) {
	l_sRemovedSlug = CandtPlaylist.removeProjectFromPlaylist(p_sId);
	CandtPlaylist.updateHeaderPlaylist();
	CandtWork.updatePlaylistLink();
	CandtPlaylist.changePlaylistPageIfNecessary(p_sId);
	CandtPlaylist.setPlaylistForNavigationFromCookie();
	if ( CandtPlaylist.getCurrentTransitionHolderIdSuffix() != null ) {
		CandtPlaylist.updatePlaylistPageContent(CandtPlaylist.getCurrentTransitionHolderIdSuffix());
	}
	else {
		CandtPlaylist.removeFromPlaylistAll(l_sRemovedSlug);
	}
	CandtWork.checkButtons();
}

CandtPlaylist.updateSortable = function(p_sChangeSource, p_sSerialized) {

	CandtAjax.fixShareInput();

	if ( p_sChangeSource == 'pledit' ) {
		CandtPlaylist.reorderProjectsInPlaylist(CandtPlaylist.getPlaylistItemsIds(p_sChangeSource, p_sSerialized));
		CandtPlaylist.updateEditPlaylistNumbers();
		CandtPlaylist.updateHeaderPlaylist();
	}
	else if ( p_sChangeSource == 'plheader' ) {
		CandtPlaylist.reorderProjectsInPlaylist(CandtPlaylist.getPlaylistItemsIds(p_sChangeSource, p_sSerialized));
		CandtPlaylist.updateEditPlaylist();
		if ( !CandtPlaylist._bSessionPlaylist ) {
			CandtPlaylist.setPlaylistForNavigationFromCookie();
			if ( CandtPlaylist.getCurrentTransitionHolderIdSuffix() != null ) {
				CandtPlaylist.updatePlaylistPageContent(CandtPlaylist.getCurrentTransitionHolderIdSuffix());
			}
			else {
				CandtPlaylist.updatePlaylistAllOrder();
			}
		}
	}
}

CandtPlaylist.getPlaylistItemsIds = function(p_sIdPrefix, p_sSerialized) {
	var r_aIds = new Array();

	var l_aIdsToParse = p_sSerialized.split('&'); 
	for ( var i=0; i<l_aIdsToParse.length; i++ ) {
		var l_sIdToParse = l_aIdsToParse[i];
		r_aIds.push(l_sIdToParse.replace(p_sIdPrefix+'[]=', ''));
	}
	return r_aIds;
}

CandtPlaylist.removeSortable = function(p_sChangeSource, p_sRemovedId) {
	var l_sRemovedId = p_sRemovedId.replace(p_sChangeSource+'_', '');
	if ( p_sChangeSource == 'pledit' ) {
		CandtPlaylist.removeProjectFromPlaylist(l_sRemovedId);
		CandtPlaylist.updateEditPlaylistNumbers();
		CandtPlaylist.updateHeaderPlaylist();
		var l_aPlaylistItems = CandtPlaylist.getPlaylistFromCookie();
		if ( l_aPlaylistItems.length > 0 ) {
			$('#playlist_edit .playlist_empty').hide();
		}
		else {
			$('#playlist_edit .playlist_empty').show();
		}
	}
	else if ( p_sChangeSource == 'plheader' ) {
		l_sRemovedSlug = CandtPlaylist.removeProjectFromPlaylist(l_sRemovedId);
		CandtPlaylist.updateEditPlaylist();
		CandtWork.updatePlaylistLink();
		CandtPlaylist.addHeaderEmptyMessageIfNecessary();
		if ( !CandtPlaylist._bSessionPlaylist ) {
			CandtPlaylist.changePlaylistPageIfNecessary(l_sRemovedId);
			CandtPlaylist.setPlaylistForNavigationFromCookie();
			if ( CandtPlaylist.getCurrentTransitionHolderIdSuffix() != null ) {
				CandtPlaylist.updatePlaylistPageContent(CandtPlaylist.getCurrentTransitionHolderIdSuffix());
			}
			else {
				CandtPlaylist.removeFromPlaylistAll(l_sRemovedSlug);
			}
		}
	}
	
	CandtAjax.fixShareInput();
}

CandtPlaylist.setPlaylistClose = function() {
	$('#the_selectlist .close').click( function() { 
		var l_sRemovedId = $(this).parent('li').attr('id');
		$(this).parent('li').remove();
		CandtPlaylist.removeSortable('plheader', l_sRemovedId);
	}); 
	$('#the_playlist .close').click( function(){ 
		var l_sRemovedId = $(this).parent('div').parent('div').attr('id');
		$(this).parent('div').parent('div').remove();
		CandtPlaylist.removeSortable('pledit', l_sRemovedId);
	});
}

CandtPlaylist.setHiddenForm = function(){
	var l_aPlaylistItems = CandtPlaylist.getPlaylistFromCookie();

	var l_aActualPlaylist = new Array();
	if ( l_aPlaylistItems.length > 0 ) {
		for ( var l_nPlaylistId in l_aPlaylistItems ) {
			l_aActualPlaylist.push(l_nPlaylistId);
		}
	}

	var l_sActualPlaylist= l_aActualPlaylist.toString() ;
	$('#the_form .hidden_playlist').attr('value',l_sActualPlaylist);
}

CandtPlaylist.trim = function(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

CandtPlaylist.checkEmailField = function(p_sEmailField){
	var emailRegxp = /^[\+\w\.-]+@([\w-]+(\.))+(\w){2,5}$/; 
	l_sEmail = $(p_sEmailField).attr('value');
	l_sEmail = CandtPlaylist.trim(l_sEmail);
	
	if(emailRegxp.test( l_sEmail )){
		$(p_sEmailField).css('border-color','#B1B1B1');
		$('#error_div').html('');
		return false;
	}
	
	$(p_sEmailField).css('border-color','red');
	return true;
}

CandtPlaylist.submitFormFields = function(){

	if(document.g_bEmpty){
		
		return false;
	}

	l_bFormFlag=0;
	if( CandtPlaylist.checkEmailField('#the_form .my_email') ) {
		l_bFormFlag=1;
	}
	if( CandtPlaylist.checkEmailField('#the_form .rep_email') ) {
		l_bFormFlag=1;
	}

	if(l_bFormFlag){
		$('#error_div').html('Please correct the required fields');
		return false;
	}
	l_aFormFields = new Array();
	l_aFormFields['sender_name'] = $('#the_form .my_name').attr('value');
	l_aFormFields['sender_email'] = $('#the_form .my_email').attr('value');
	l_aFormFields['recip_name'] = $('#the_form .rep_name').attr('value');
	l_aFormFields['recip_email'] = $('#the_form .rep_email').attr('value');
	l_aFormFields['message'] = $('#the_form .comments').attr('value');
	if(l_aFormFields['message'] == $('#the_form .comments').attr('title')) {
		l_aFormFields['message'] = '';
	}
	var l_aPlaylist = CandtPlaylist.getPlaylistFromCookie();
	l_aActualPlaylist = new Array();
	var l_nCounter = 0;
	if ( l_aPlaylist.length > 0 ) {
		for ( var l_nPlaylistId in l_aPlaylist ) {
			l_aActualPlaylist[l_nCounter] = l_nPlaylistId;
			l_nCounter++;
		}
	}
	l_aFormFields['playlist']= l_aActualPlaylist.toString() ;
	CandtAjax.sendPlaylistEmail(l_aFormFields);

	$('#the_form .rep_name').attr('value', $('#the_form .rep_name').attr('title') );
	$('#the_form .rep_email').attr('value', $('#the_form .rep_email').attr('title') );	
}

CandtPlaylist.setOtherDivContentToCurrentDivContent = function(p_sCurrentDivSelector, p_sOtherDivSelector) {
	$(p_sOtherDivSelector).html($(p_sCurrentDivSelector).html());
}

CandtPlaylist.updateOtherDiv = function(p_sOtherDivSelector, p_sContent) {
	$(p_sOtherDivSelector).html(p_sContent);
}

CandtPlaylist.clearCurrentDiv = function() {
	var l_sCurrentDivSelector = '#content_transition_' + CandtPlaylist.getCurrentTransitionHolderIdSuffix();
	$(l_sCurrentDivSelector+' .nav .nav_left .icon').empty();
	$(l_sCurrentDivSelector+' .nav .nav_left .display span').html('None');
	$(l_sCurrentDivSelector+' .nav .nav_left .icon').append('<div class="icon_click"></div>');
	$(l_sCurrentDivSelector+' .nav .nav_right .icon').empty();
	$(l_sCurrentDivSelector+' .nav .nav_right .display span').html('None');
	$(l_sCurrentDivSelector+' .nav .nav_right .icon').append('<div class="icon_click"></div>');
	var l_sCurrentPlayerDivSelector = '#player_holder_' + CandtPlaylist.getCurrentTransitionHolderIdSuffix();
	$(l_sCurrentPlayerDivSelector).empty();
	var l_sCurrentDetailsDivSelector = '#playlist_work_details_'+CandtPlaylist.getCurrentTransitionHolderIdSuffix();
	$(l_sCurrentDetailsDivSelector).empty();
}

CandtPlaylist.disableNavIcons = function() {
	CandtPlaylist._aNavDisableContent = new Array();

	var l_sTransitionDivId = '#content_transition_one ';
	CandtPlaylist._aNavDisableContent['nav_one_left_tooltip'] = $(l_sTransitionDivId+'.nav .nav_left .display span').html();
	CandtPlaylist._aNavDisableContent['nav_one_left_click'] = $(l_sTransitionDivId+'.nav .nav_left .icon').html();
	CandtPlaylist._aNavDisableContent['nav_one_right_tooltip'] = $(l_sTransitionDivId+'.nav .nav_right .display span').html();
	CandtPlaylist._aNavDisableContent['nav_one_right_click'] = $(l_sTransitionDivId+'.nav .nav_right .icon').html();
	$(l_sTransitionDivId+'.nav .nav_left .display span').html('Loading');
	$(l_sTransitionDivId+'.nav .nav_left .icon').html('');
	$(l_sTransitionDivId+'.nav .nav_left .icon').addClass('none');
	$(l_sTransitionDivId+'.nav .nav_left').addClass('none');
	$(l_sTransitionDivId+'.nav .nav_right .display span').html('Loading');
	$(l_sTransitionDivId+'.nav .nav_right .icon').html('');
	$(l_sTransitionDivId+'.nav .nav_right .icon').addClass('none');
	$(l_sTransitionDivId+'.nav .nav_right').addClass('none');

	var l_sTransitionDivId = '#content_transition_two ';
	CandtPlaylist._aNavDisableContent['nav_two_left_tooltip'] = $(l_sTransitionDivId+'.nav .nav_left .display span').html();
	CandtPlaylist._aNavDisableContent['nav_two_left_click'] = $(l_sTransitionDivId+'.nav .nav_left .icon').html();
	CandtPlaylist._aNavDisableContent['nav_two_right_tooltip'] = $(l_sTransitionDivId+'.nav .nav_right .display span').html();
	CandtPlaylist._aNavDisableContent['nav_two_right_click'] = $(l_sTransitionDivId+'.nav .nav_right .icon').html();
	$(l_sTransitionDivId+'.nav .nav_left .display span').html('Loading');
	$(l_sTransitionDivId+'.nav .nav_left .icon').html('');
	$(l_sTransitionDivId+'.nav .nav_left .icon').addClass('none');
	$(l_sTransitionDivId+'.nav .nav_left').addClass('none');
	$(l_sTransitionDivId+'.nav .nav_right .display span').html('Loading');
	$(l_sTransitionDivId+'.nav .nav_right .icon').html('');
	$(l_sTransitionDivId+'.nav .nav_right .icon').addClass('none');
	$(l_sTransitionDivId+'.nav .nav_right').addClass('none');
}

CandtPlaylist.enableNavIcons = function() {
	var l_sTransitionDivId = '#content_transition_one ';
	$(l_sTransitionDivId+'.nav .nav_left .display span').html(CandtPlaylist._aNavDisableContent['nav_one_left_tooltip']); 
	$(l_sTransitionDivId+'.nav .nav_left .icon').html(CandtPlaylist._aNavDisableContent['nav_one_left_click']);
	if ( CandtPlaylist._aNavDisableContent['nav_one_left_tooltip'] != '' ) {
		$(l_sTransitionDivId+'.nav .nav_left .icon').removeClass('none');
		$(l_sTransitionDivId+'.nav .nav_left').removeClass('none');
	}
	$(l_sTransitionDivId+'.nav .nav_right .display span').html(CandtPlaylist._aNavDisableContent['nav_one_right_tooltip']);
	$(l_sTransitionDivId+'.nav .nav_right .icon').html(CandtPlaylist._aNavDisableContent['nav_one_right_click']);
	if ( CandtPlaylist._aNavDisableContent['nav_one_right_tooltip'] != '' ) {
		$(l_sTransitionDivId+'.nav .nav_right .icon').removeClass('none');
		$(l_sTransitionDivId+'.nav .nav_right').removeClass('none');
	}

	var l_sTransitionDivId = '#content_transition_two ';
	$(l_sTransitionDivId+'.nav .nav_left .display span').html(CandtPlaylist._aNavDisableContent['nav_two_left_tooltip']);
	$(l_sTransitionDivId+'.nav .nav_left .icon').html(CandtPlaylist._aNavDisableContent['nav_two_left_click']);
	if ( CandtPlaylist._aNavDisableContent['nav_two_left_tooltip'] != '' ) {
		$(l_sTransitionDivId+'.nav .nav_left .icon').removeClass('none');
		$(l_sTransitionDivId+'.nav .nav_left').removeClass('none');
	}
	$(l_sTransitionDivId+'.nav .nav_right .display span').html(CandtPlaylist._aNavDisableContent['nav_two_right_tooltip']);
	$(l_sTransitionDivId+'.nav .nav_right .icon').html(CandtPlaylist._aNavDisableContent['nav_two_right_click']);
	if ( CandtPlaylist._aNavDisableContent['nav_two_right_tooltip'] != '' ) {
		$(l_sTransitionDivId+'.nav .nav_right .icon').removeClass('none');
		$(l_sTransitionDivId+'.nav .nav_right').removeClass('none');
	}
	CandtPlaylist._aNavDisableContent = null;
	CandtGlobal.setNavHovers();
}

CandtPlaylist.transitionPlaylistPageContent = function() {
	CandtPlaylist.updatePlaylistPageContent(CandtPlaylist.getOtherTransitionHolderIdSuffix());

	var l_sCurrentDivSelector = '#content_transition_' + CandtPlaylist.getCurrentTransitionHolderIdSuffix();
	var l_sOtherDivSelector = '#content_transition_' + CandtPlaylist.getOtherTransitionHolderIdSuffix();
	var l_sOtherDivContent = $(l_sOtherDivSelector).html();

	CandtGlobal.replacePlayerWithPlaceHolder('player_holder_' + CandtPlaylist.getCurrentTransitionHolderIdSuffix());
	CandtPlaylist.disableNavIcons();

	var l_nCurrentDivIndex = $(l_sCurrentDivSelector).parent().children().index($(l_sCurrentDivSelector)[0]);
	var l_nOtherDivIndex = $(l_sCurrentDivSelector).parent().children().index($(l_sOtherDivSelector)[0]);
	
	if ( CandtPlaylist._sTransitionDirection == 'left' && l_nCurrentDivIndex < l_nOtherDivIndex ) {
		CandtPlaylist.setOtherDivContentToCurrentDivContent(l_sCurrentDivSelector, l_sOtherDivSelector);
		$(l_sCurrentDivSelector).next().insertBefore(l_sCurrentDivSelector);
		$('.content_transition_holder').stop().scrollTo( l_sCurrentDivSelector, {speed:0, axis:'x', onAfter: function() {
			CandtPlaylist.updateOtherDiv(l_sOtherDivSelector, l_sOtherDivContent);
			$('.content_transition_holder').scrollTo( l_sOtherDivSelector, {speed:CandtPlaylist._nTransitionSpeed, axis:'x', onAfter: CandtPlaylist.transitionComplete } );
			//CandtGlobal.setNavHovers();
		}} );
	
	}
	else if ( CandtPlaylist._sTransitionDirection == 'right' && l_nCurrentDivIndex > l_nOtherDivIndex ) {
		CandtPlaylist.setOtherDivContentToCurrentDivContent(l_sCurrentDivSelector, l_sOtherDivSelector);
		$(l_sCurrentDivSelector).prev().insertAfter(l_sCurrentDivSelector);
		$('.content_transition_holder').stop().scrollTo( l_sCurrentDivSelector, {speed:0, axis:'x', onAfter: function() {
			CandtPlaylist.updateOtherDiv(l_sOtherDivSelector, l_sOtherDivContent);
			$('.content_transition_holder').scrollTo( l_sOtherDivSelector, {speed:CandtPlaylist._nTransitionSpeed, axis:'x', onAfter: CandtPlaylist.transitionComplete } );
			//CandtGlobal.setNavHovers();
		}} );
	}
	else {
		//CandtPlaylist.updateOtherDiv(l_sOtherDivSelector, l_sOtherDivContent);
		$('.content_transition_holder').stop().scrollTo( l_sOtherDivSelector, {speed:CandtPlaylist._nTransitionSpeed, axis:'x', onAfter: CandtPlaylist.transitionComplete } );
	}
}

CandtPlaylist.transitionComplete = function() {
	CandtGlobal.replacePlaceHolderWithPlayer('player_holder_' +CandtPlaylist.getOtherTransitionHolderIdSuffix());
	CandtPlaylist.clearCurrentDiv();
	CandtPlaylist.setCurrentTransitionHolderIdSuffix(CandtPlaylist.getOtherTransitionHolderIdSuffix());
	if ( CandtPlaylist._sQueuedProjectSlug != null && CandtPlaylist._sQueuedTransitionDirection != null ) {
		CandtAjax.changePlaylistPageInternal(CandtPlaylist._sQueuedProjectSlug, CandtPlaylist._sQueuedTransitionDirection);
	}
	else {
		CandtPlaylist.enableNavIcons();
		CandtPlaylist._bTransitionInProgress = false;
	}
}

CandtPlaylist.updatePlaylistPageContent = function(p_sDivIdSuffix) {
	$('#playlist_content_ordered_list').empty();
	
	var l_nIndexOfCurrentSlug = -1;
	if ( CandtPlaylist._aPlaylistForNavigation.length > 0 ) {
		if ( $('#playlist .icons').css("display") == 'none' ) {
			$('#playlist .icons').show();
		}
		$('#playlist .playlist_empty').hide();
		$('#playlist .nav').show();

		for ( var l_nIndex=0; l_nIndex<CandtPlaylist._aPlaylistForNavigation.length; l_nIndex++ ) {
			if ( CandtPlaylist._aPlaylistForNavigation[l_nIndex].getSlug() == CandtPlaylist._sCurrentProjectSlug ) {
				l_nIndexOfCurrentSlug = l_nIndex;
			}
		}
		for ( var l_nIndex=0; l_nIndex<CandtPlaylist._aPlaylistForNavigation.length; l_nIndex++ ) {
			var l_sDirection = 'right';
			if ( l_nIndex < l_nIndexOfCurrentSlug ) {
				l_sDirection = 'left';
			}
			$('#playlist_content_ordered_list').append('<li><a href=\"javascript:void(0)\" onclick=\"CandtAjax.changePlaylistPage(\''+CandtPlaylist._aPlaylistForNavigation[l_nIndex].getSlug()+'\',\''+l_sDirection+'\')\" >'+CandtPlaylist._aPlaylistForNavigation[l_nIndex].getTitle()+'</a></li>');
		}
	}
	else {
		$('#playlist .icons').hide();
		$('#playlist .playlist_empty').show();
		$('#playlist .nav').hide();
		$('#playlist_work_details_one').html('');
		$('#playlist_work_details_two').html('');
		$('#player_holder_one').html('');
		$('#player_holder_two').html('');
	}
	if ( l_nIndexOfCurrentSlug != -1 ) {
		var l_sTransitionDivId = '#content_transition_'+p_sDivIdSuffix+' ';
		$(l_sTransitionDivId+'.nav .nav_left .icon').empty();
		if ( l_nIndexOfCurrentSlug > 0 ) {
			$(l_sTransitionDivId+'.nav .nav_left .display span').html(CandtPlaylist._aPlaylistForNavigation[l_nIndexOfCurrentSlug-1].getTitle());
			$(l_sTransitionDivId+'.nav .nav_left .icon').removeClass('none');
			$(l_sTransitionDivId+'.nav .nav_left').removeClass('none');
			$(l_sTransitionDivId+'.nav .nav_left .icon').append('<div class="icon_click" rel="'+CandtPlaylist._aPlaylistForNavigation[l_nIndexOfCurrentSlug-1].getSlug()+'" onclick="CandtAjax.changePlaylistPage(\'' + CandtPlaylist._aPlaylistForNavigation[l_nIndexOfCurrentSlug-1].getSlug() + '\',\'left\')"></div>');
		}
		else {
			$(l_sTransitionDivId+'.nav .nav_left .display span').html('');
			$(l_sTransitionDivId+'.nav .nav_left .icon').addClass('none');
			$(l_sTransitionDivId+'.nav .nav_left').addClass('none');
			$(l_sTransitionDivId+'.nav .nav_left .icon').append('<div class="icon_click"></div>');
		}
		$(l_sTransitionDivId+'.nav .nav_right .icon').empty();
		if ( l_nIndexOfCurrentSlug < CandtPlaylist._aPlaylistForNavigation.length -1 ) {
			$(l_sTransitionDivId+'.nav .nav_right .display span').html(CandtPlaylist._aPlaylistForNavigation[l_nIndexOfCurrentSlug+1].getTitle());
			$(l_sTransitionDivId+'.nav .nav_right .icon').removeClass('none');
			$(l_sTransitionDivId+'.nav .nav_right').removeClass('none');
			$(l_sTransitionDivId+'.nav .nav_right .icon').append('<div class="icon_click" rel="'+CandtPlaylist._aPlaylistForNavigation[l_nIndexOfCurrentSlug+1].getSlug()+'" onclick="CandtAjax.changePlaylistPage(\'' + CandtPlaylist._aPlaylistForNavigation[l_nIndexOfCurrentSlug+1].getSlug() + '\',\'right\')"></div>');
		}
		else {
			$(l_sTransitionDivId+'.nav .nav_right .display span').html('');
			$(l_sTransitionDivId+'.nav .nav_right .icon').addClass('none');
			$(l_sTransitionDivId+'.nav .nav_right').addClass('none');
			$(l_sTransitionDivId+'.nav .nav_right .icon').append('<div class="icon_click"></div>');
		}
	}
}

CandtPlaylist.changePlaylistPageIfNecessary = function(p_sRemovedId) {
	if(CandtPlaylist._aPlaylistForNavigation == null) {
		return;
	}
	var l_nIndexOfCurrentSlug = -1;
	for ( var l_nIndex=0; l_nIndex<CandtPlaylist._aPlaylistForNavigation.length; l_nIndex++ ) {
		if ( CandtPlaylist._aPlaylistForNavigation[l_nIndex].getId() == p_sRemovedId &&
			 (CandtPlaylist._aPlaylistForNavigation[l_nIndex].getSlug() == CandtPlaylist._sCurrentProjectSlug ||
			  CandtPlaylist._aPlaylistForNavigation[l_nIndex].getSlug() == CandtPlaylist._sQueuedProjectSlug) ) {
			l_nIndexOfCurrentSlug = l_nIndex;
			break;
		}
	}
	if ( l_nIndexOfCurrentSlug != -1 ) {
		if ( l_nIndexOfCurrentSlug < CandtPlaylist._aPlaylistForNavigation.length -1 ) {
			CandtAjax.changePlaylistPage(CandtPlaylist._aPlaylistForNavigation[l_nIndexOfCurrentSlug+1].getSlug(), 'right');
		}
		else if ( l_nIndexOfCurrentSlug > 0 ) {
			CandtAjax.changePlaylistPage(CandtPlaylist._aPlaylistForNavigation[l_nIndexOfCurrentSlug-1].getSlug(), 'left');
		}
		else {
			CandtPlaylist.playlistEmpty();
		}
	}
}

CandtPlaylist.playlistEmpty = function() {
	$('#playlist_work_details').html('No projects in playlist!');
	var l_sOtherDivSelector = '#content_transition_' + CandtPlaylist.getOtherTransitionHolderIdSuffix();
	$('.content_transition_holder').stop().scrollTo( l_sOtherDivSelector, {speed:0, axis:'x', onAfter: function() {
		CandtPlaylist.clearVideoPlayerDivs();
	} } );
}

CandtPlaylist.clearVideoPlayerDivs = function() {
	$('#player_holder_one').css('background', '');
	$('#player_holder_two').css('background', '');
}

CandtPlaylist.updatePlaylistAllOrder = function() {
	var l_aProjectDivs = new Array();
	$('.content_holder').children('.content_all').each(function(i){
		var $this = $(this);
		l_aProjectDivs[this.id] = $this.html();
	});
	
	$('#playlist_content_ordered_list').empty();
	
	for ( var l_nIndex=0; l_nIndex<CandtPlaylist._aPlaylistForNavigation.length; l_nIndex++ ) {
		$('#playlist_content_ordered_list').append('<li><a href=\"javascript:void(0)\" onclick=\"CandtPlaylist.showPlaylistItem(\''+CandtPlaylist._aPlaylistForNavigation[l_nIndex].getSlug()+'\')\" >'+CandtPlaylist._aPlaylistForNavigation[l_nIndex].getTitle()+'</a></li>');
	}
	
	if ( CandtGlobal._sCurrentPlayerId == null ) {
		$('#playlist .content_holder').empty();
		for ( var l_nIndex=0; l_nIndex<CandtPlaylist._aPlaylistForNavigation.length; l_nIndex++ ) {
			var l_sDivId = 'content_all_'+CandtPlaylist._aPlaylistForNavigation[l_nIndex].getSlug();
			$('#playlist .content_holder').append('<div id=\"'+l_sDivId+'\" class=\"content_all\"'+l_aProjectDivs[l_sDivId]+'</div>');
		}
	}
	else {
		var l_sPlayingDivId = $('#'+CandtGlobal._sCurrentPlayerId).parent().parent().attr('id');
		
		for ( var l_nIndex=0; l_nIndex<CandtPlaylist._aPlaylistForNavigation.length; l_nIndex++ ) {
			var l_sDivId = 'content_all_'+CandtPlaylist._aPlaylistForNavigation[l_nIndex].getSlug();
			if ( l_sDivId != l_sPlayingDivId ) {
				$('#'+l_sDivId).remove();
			}
		}
		
		var l_bBefore = true;
		
		var l_sBeforeContent = '';
		var l_sAfterContent = '';
		
		for ( var l_nIndex=0; l_nIndex<CandtPlaylist._aPlaylistForNavigation.length; l_nIndex++ ) {
			var l_sDivId = 'content_all_'+CandtPlaylist._aPlaylistForNavigation[l_nIndex].getSlug();
			if ( l_sDivId == l_sPlayingDivId ) {
				l_bBefore = false;
			}
			else if ( l_bBefore) {
				l_sBeforeContent+= '<div id=\"'+l_sDivId+'\" class=\"content_all\"'+l_aProjectDivs[l_sDivId]+'</div>';
			}
			else {
				l_sAfterContent+= '<div id=\"'+l_sDivId+'\" class=\"content_all\"'+l_aProjectDivs[l_sDivId]+'</div>';
			}
		}
		
		$('#playlist .content_holder').prepend(l_sBeforeContent);
		$('#playlist .content_holder').append(l_sAfterContent);
	}
}

CandtPlaylist.removeFromPlaylistAll = function(p_sRemovedSlug) {
	$('#playlist_content_ordered_list').empty();
	if ( CandtPlaylist._aPlaylistForNavigation.length > 0 ) {
		$('#playlist .playlist_empty').hide();
		$('#playlist .icons').show();
		for ( var l_nIndex=0; l_nIndex<CandtPlaylist._aPlaylistForNavigation.length; l_nIndex++ ) {
			$('#playlist_content_ordered_list').append('<li><a href=\"javascript:void(0)\" onclick=\"CandtPlaylist.showPlaylistItem(\''+CandtPlaylist._aPlaylistForNavigation[l_nIndex].getSlug()+'\')\" >'+CandtPlaylist._aPlaylistForNavigation[l_nIndex].getTitle()+'</a></li>');
		}
	}
	else {
		if ( $.browser.msie ) {
			$('#content_all_'+p_sRemovedSlug).hide();
		}
		$('#playlist .playlist_empty').show();
		$('#playlist .icons').hide();
	}

	if ( !$.browser.msie || CandtPlaylist._aPlaylistForNavigation.length > 0  ) {
		if( $('#playlist').html() )
			CandtGlobal.replacePlayerWithPlaceHolder('player_holder_'+p_sRemovedSlug); 
		$('#player_holder_'+p_sRemovedSlug).css('background', '');
		$('#content_all_'+p_sRemovedSlug).hide('slow');
	}
}

CandtPlaylist.showPlaylistItem = function(p_sSlug) {
	$.scrollTo('#content_all_'+p_sSlug, 500);
}

CandtPlaylist.clearPlaylistForNavigation = function() {
	CandtPlaylist._aPlaylistForNavigation = null;
}

CandtPlaylist.setPlaylistForNavigation = function(p_aPlaylistIds, p_aPlaylistTitles, p_aPlaylistSlugs, p_aPlaylistYears) {
	CandtPlaylist._aPlaylistForNavigation = new Array();
	for ( var i=0; i<p_aPlaylistIds.length; i++ ) {
		CandtPlaylist._aPlaylistForNavigation.push(new PlaylistItem(p_aPlaylistIds[i], p_aPlaylistTitles[i], p_aPlaylistSlugs[i], p_aPlaylistYears[i]));
	}
}

CandtPlaylist.setPlaylistForNavigationFromCookie = function() {
	var l_aPlaylist = CandtPlaylist.getPlaylistFromCookie();
	CandtPlaylist._aPlaylistForNavigation = new Array();
	if ( l_aPlaylist.length > 0 ) {
		for ( var l_sPlaylistId in l_aPlaylist ) {
			CandtPlaylist._aPlaylistForNavigation.push(l_aPlaylist[l_sPlaylistId]);
		}
	}
}


// ------------------------ WORK ----------------------------------------


CandtWork = {};

CandtWork._nDelayedDropCount = 0;
CandtWork._sCurrentProjectSlug = null;
CandtWork._sCurrentProjectDate = null;
CandtWork._searchCount = 0;
CandtWork._getHelp = 0;

CandtWork.initialize = function() {
	CandtWork._sCurrentProjectSlug = null;
	CandtWork.setDropboxHovers();
	CandtWork.setDropboxClicks();
	CandtWork.setWorklistHovers();
	CandtWork.fadeInChunks();
	CandtWork.checkButtons();
	CandtWork.setSearch();
}


CandtWork.viewDrop = function(viewing){
	$('#searchdropdown .searchterm_hover').removeClass('searchterm_hover');

	$('#searchdropdown .searchterm').eq(viewing-1).addClass('searchterm_hover');	
}

CandtWork.setSearch = function(){
	CandtWork._viewingDrop = 0;
	
	$('#livesearch').click(function(){ $(this).select() });
	
	if(! CandtWork._issearchset && $('#livesearch').attr('type')=='text'  ){
		
		$('#livesearch').keyup( function(event){ 
			if(event.keyCode == 38 ){
				if( CandtWork._viewingDrop > 0 ){
					CandtWork._viewingDrop--;
					CandtWork.viewDrop( CandtWork._viewingDrop );	
				}
			}
			else if(event.keyCode == 40 ){
				if( CandtWork._viewingDrop < CandtGlobal._searchMax  ){
					CandtWork._viewingDrop++;
					CandtWork.viewDrop( CandtWork._viewingDrop );	
				}
			}
			else if(event.keyCode == 13 ){
				if(CandtWork._viewingDrop){
					$('#livesearch').attr('value',  $('#searchdropdown .searchterm_hover').html() );
					$('#livesearch').blur();
					CandtWork._getHelp = 0;
					CandtWork.startSearch();				
				}
			}
			else{
				CandtWork._getHelp = 1;
				CandtWork.startSearch();
			}
		}); //@@@@@@@@@@@
		
		CandtWork._issearchset = 1;
		
	}
}
CandtWork.startSearch = function(){
		CandtWork._searchCount++; 
		var searchon = $('#livesearch').attr('value') ;
		if (searchon)
			searchon = searchon.toLowerCase();
		CandtWork.searchOn_helper(searchon, CandtWork._searchCount);	
}

CandtWork.searchOn_helper = function(p_sSearchOn, p_nSearchCount){
	window.setTimeout("CandtWork.searchOn('"+p_sSearchOn+"',"+p_nSearchCount+")",200)
}

CandtWork.setSearchTerms = function(){
	$('#searchdropdown .searchterm').mousedown(function(){
		
		$('#livesearch').attr('value',$(this).html() );
		CandtWork._getHelp = 0;
		CandtWork.startSearch();
		
	});
	
	$('#livesearch').blur(function(){
		$('#searchdropdown').empty();
		$('#searchdropdown').hide();
		CandtWork._showingDrop = false;
		CandtWork._viewingDrop = 0;
	});
}

CandtWork.searchOn = function(p_sSearchOn, p_nSearchCount){
	if(p_nSearchCount == CandtWork._searchCount){
		
		if(p_sSearchOn == 'undefined' || !p_sSearchOn){
			
			$('#custom-featured-holder').show();
			$('#workSectionLists').show();
			$('#workSectionResults').remove();
			$('#searchdropdown').empty();
			$('#searchdropdown').hide();
			CandtWork._showingDrop = false;
			CandtWork._viewingDrop = 0;
			return;
		}
		
		var regex = eval('/'+p_sSearchOn+'/i');
		
		if(CandtWork._getHelp){
			var startTitles = new Array;
			var matchTitles = new Array;
			var startTags = new Array;
			var matchTags = new Array;
			
			for( var j=0; j< searchdata.count ; j++){
				var position = searchdata.proj[j].title.search( regex ) ;
				if(position == 0){
					startTitles.push(searchdata.proj[j].title);
				}
				else if(position > 0){
					matchTitles.push(searchdata.proj[j].title);
				}
				
				position = searchdata.proj[j].name.search( regex ) ;
				if(position == 0){
					startTitles.push(searchdata.proj[j].name);
				}
				else if(position > 0){
					matchTitles.push(searchdata.proj[j].name);
				}
					
			}
			for(y in searchdata.tags ){
				var position = searchdata.tags[y].search( regex ) ;
				if(position == 0){
					startTags.push(searchdata.tags[y]);
				}
				else if(position > 0){
					matchTags.push(searchdata.tags[y]);
				}
				
			}
			
			
			var outputArray = '';
			var seperator = '~!~';
			
			for(z in startTitles){
				if(! eval('/'+seperator+startTitles[z]+seperator+'/i').test(outputArray) )
					outputArray += startTitles[z]+seperator;
			}
			for(z in startTags){
				if(! eval('/'+seperator+startTags[z]+seperator+'/i').test(outputArray) )
					outputArray += startTags[z]+seperator;
			}
			for(z in matchTitles){
				if(! eval('/'+seperator+matchTitles[z]+seperator+'/i').test(outputArray) )
					outputArray += matchTitles[z]+seperator;
			}
			for(z in matchTags){
				if(! eval('/'+seperator+matchTags[z]+seperator+'/i').test(outputArray) )
					outputArray += matchTags[z]+seperator;
			}
			
			outputArray = outputArray.split(seperator);
			
			var outputString = '';
			var outputStringCount = 0;
			for(z in outputArray){
				if(outputArray[z]){
					outputString += '<div class="searchterm">'+outputArray[z]+'</div>';
					outputStringCount++;
				}
				if(outputStringCount == CandtGlobal._searchMax)
					break;
			}
			if(outputString){
				$('#searchdropdown').html(outputString);
				$('#searchdropdown').show();
				CandtWork.setSearchTerms();
				CandtWork._showingDrop = outputStringCount;
				CandtWork._viewingDrop = 0;
			}
			else{
				$('#searchdropdown').html('');
				$('#searchdropdown').hide();	
				CandtWork._showingDrop = false;
				CandtWork._viewingDrop = 0;
			}
			
		}
		
		var lineCount = 0;
		
		var outputString = '<div id="workSectionResults"><h2>Results:</h2><ul class="work_list">';
		
		for( var i=0; i< searchdata.count ; i++){
			
			var tagFlag = 0;
			
			if(searchdata.proj[i].tags){
				for (x in searchdata.proj[i].tags){
					if( regex.test(searchdata.proj[i].tags[x]) ){
						tagFlag = 1;
					}
				}
			}
			
			
			if (tagFlag || regex.test(  searchdata.proj[i].title) || regex.test(searchdata.proj[i].name) ){
				
				var extraclass = '';
				var afterline = '';
				lineCount++;
				if(lineCount % 4 == 0){
					extraclass = 'last_item';
					afterline = '<div class="clear_noheight">&nbsp;</div>';
					
				}
				
				outputString += '<li class="'+extraclass+'"><a rev="right" class="ajaxlink" href="/#/work/'+searchdata.proj[i].date+'/'+searchdata.proj[i].slug+'" rel="/work/'+searchdata.proj[i].date+'/'+searchdata.proj[i].slug+'">'+
				'<div class="imgholder"><img src="/_site/asset/project/'+searchdata.proj[i].id+'_thumb.jpg" class="img_border" height="180"></div>'+
				'<p class="clientname">'+searchdata.proj[i].name+'</p>'+
				'<p class="byline">'+searchdata.proj[i].title+'</p>'+
				'</a></li>' + afterline;
				
			}
		}
		outputString += '</ul>';
		
		if(lineCount == 0)
			outputString += '<div class="spacer_45"></div><div class="spacer_45"></div><div class="spacer_45"></div>';
		
		outputString += '</div>';
		$('#custom-featured-holder').hide();
		$('#workSectionResults').remove();
		$('#workSectionLists').after(outputString);
		$('#workSectionLists').css('display','none');
		setLinks('#workSectionResults');
	}
}


CandtWork.setCurrentProjectSlug = function(p_sProjectSlug) {
	CandtWork._sCurrentProjectSlug = p_sProjectSlug;
	// CandtWork.updatePlaylistLink();  MOVED to fix ie6 bug
}

CandtWork.setCurrentProjectDate = function(p_sProjectDate) {
	CandtWork._sCurrentProjectDate = p_sProjectDate;
}

CandtWork.updatePlaylistLink = function() {
	l_aPlaylist = CandtPlaylist.getPlaylistFromCookieBySlug();
	
	//alert(l_aPlaylist);
	
	if ( CandtWork._sCurrentProjectSlug != null ) {
		if ( l_aPlaylist[CandtWork._sCurrentProjectSlug] ) {
			$('#work_single_playlist_add').css('display','none');
			$('#work_single_playlist_remove').css('display','block');
		}
		else {
			$('#work_single_playlist_remove').css('display','none');
			$('#work_single_playlist_add').css('display','block');
		}
	}
}
CandtWork.switchDescription = function(obj){
	
	newObj = $(obj).parents('.projdescription');
	
	$(newObj).children('.short').hide();
	$(newObj).children('.long').show();
	
	
	
}


CandtWork.setDropboxHovers = function() {
	$("#dropbox").hover( function() {
		CandtWork._nDelayedDropCount++;
		$('#dropbox .original').addClass('original_drop')
		$('#dropbox_selector').addClass('show');
	}, function(){
		CandtWork.delayedDropClose(CandtWork._nDelayedDropCount);
	});
	
	$("#dropbox_selector div").hover(function() {
		$(this).addClass("hover");
	},function() {
		$(this).removeClass("hover");
	});
	
}

CandtWork.delayedDropClose = function(p_nDelayedDropCount) {
	window.setTimeout("CandtWork.delayedDropCloseHelper("+p_nDelayedDropCount+")",800);
}

CandtWork.delayedDropCloseHelper = function(p_nDelayedDropCount) {
	if(p_nDelayedDropCount == CandtWork._nDelayedDropCount){
		$('#dropbox_selector').removeClass('show');
		$('#dropbox .original').removeClass('original_drop')
	}
}

CandtWork.setWorklistHovers = function() {
	/*
	$("#work_list li").hover(function(){
		$(this).addClass('hover');
		customFadeIn( $(this).children('.imgholder').children('div') ,200);
	},function(){
		$(this).removeClass('hover');
		customFadeOut( $(this).children('.imgholder').children('div') ,100);
	});
	*/
	CandtWork.checkButtons();
}

CandtWork.setArchiveHovers = function() {
	$("#workArchive li").hover(function(){
		$(this).addClass('hover');
		customFadeIn( $(this).children('.imgholder').children('div') ,200);
	},function(){
		$(this).removeClass('hover');
		customFadeOut( $(this).children('.imgholder').children('div') ,100);
	});
	
	CandtWork.fadeInArchiveChunks();
	setLinks('#workArchive');
}

CandtWork.setDropboxClicks = function() {
	$('#dropbox_selector div').click( function () {
		tmpName = $(this).html();

		$('#dropbox .original div span').html(tmpName);

		$('#dropbox_selector').removeClass('show');
		$('#dropbox .original').removeClass('original_drop');
	});
}

CandtWork.updateWorkContents = function() {
	CandtWork.setWorklistHovers();
	CandtWork.setArchiveHovers();
	CandtWork.fadeInChunks();
}

CandtWork.checkButtons = function(){
	var l_aPlaylistItems = CandtPlaylist.getPlaylistFromCookie();

	var l_aActualPlaylist = new Array();
	if ( l_aPlaylistItems.length > 0 ) {
		for ( var l_nPlaylistId in l_aPlaylistItems ) {
			l_aActualPlaylist.push(l_nPlaylistId);
		}
	}

	$('#work_contents .dispRemove').each(function(){
		l_nId = $(this).attr('id');
		l_nId = l_nId.slice(5);
		if( (jQuery.inArray(l_nId, l_aActualPlaylist)) < 0){
			$(this).removeClass('dispRemove');
		}
	});

	$('#work_contents li').each(function(){  
		l_nId = $(this).attr('id');
		l_nId = l_nId.slice(5);
		
		if( (jQuery.inArray(l_nId, l_aActualPlaylist)) >= 0)
			$(this).addClass('dispRemove');
	});
}


CandtWork.fadeInArchiveChunks = function(){
	
	var l_aIds = new Array;
	
	$('#workArchive .chunk_cover').each( function(){ 
		tmpId = $(this).attr('id');
		thisId = tmpId.slice(6);
		$(this).height( $('#content_'+thisId ).height() );
		$('#content_'+thisId ).removeClass('hideMe');
		
		l_aIds.push( tmpId );
	});
	
	l_aIds = l_aIds.reverse();
	
	$('#ajaxhelper').animate({ opacity: .9999}, 501, '', function() { 
		CandtWork.fadeInChunksAction(l_aIds);
	 });
	
}

CandtWork.fadeInChunks = function(){
	
	var l_aIds = new Array;
	var l_nLimit = 2;
	
	$('#work_contents .chunk_cover').each( function(){ 
		tmpId = $(this).attr('id');
		thisId = tmpId.slice(6);
		if(!CandtAjax._nofade)
			$(this).height( $('#content_'+thisId ).height() );
		
		$('#content_'+thisId ).removeClass('hideMe');
		
		l_aIds.push( tmpId );
	});
	
	l_aIds = l_aIds.reverse();
	
	$('#footer').animate({ opacity: .9999}, 501, '', function() { 
		CandtWork.fadeInChunksAction(l_aIds,0,l_nLimit);
	 });
	
}

CandtWork.fadeInChunksAction = function (p_aIds, p_nCount,p_nLimit){
	
	if(p_nCount == p_nLimit){
		tmpId = p_aIds.pop();
		while(tmpId){
			$('#'+tmpId).hide();
			tmpId = p_aIds.pop();
		}
	}
	else{
		tmpId = p_aIds.pop();
		
		if(tmpId){
			$('#'+tmpId).fadeOut(0700, function(){
				CandtWork.fadeInChunksAction(p_aIds, p_nCount+1 ,p_nLimit);						   
			});
		}
	}
}

CandtWork.fadeInContent = function(){
	
	$('#work_single_cover').height( $('#work_single_content').height() );
	
	$('#ajaxhelper').animate({ opacity: .9999}, 0001, '', function() { 
		$('#work_single_content').removeClass('hideMe');
		
		$('#ajaxhelper').animate({ opacity: .9999}, 0001, '', function() { 
			
			$('#work_single_cover').fadeOut(400);
			CandtWork.updatePlaylistLink();
		});
		
	});
	
}


// ------------------------ CAREERS ----------------------------------------


CandtCareers = {};

CandtCareers._sOldCareerDiv = '';
CandtCareers._sTargetCareerDiv = null;

CandtCareers.initialize = function() {
	CandtCareers._sTargetCareerDiv = null;
	// CandtCareers.setCareerPage();
}

CandtCareers.initializeWithCareerDiv = function(p_sCareerDiv) {
	CandtCareers._sTargetCareerDiv = p_sCareerDiv;
	CandtCareers.setCareerPage();
}

CandtCareers.setCareerPage = function() {
	if(CandtCareers._sTargetCareerDiv)
		CandtCareers.switchCareerDiv( CandtCareers._sTargetCareerDiv );
	else
		CandtCareers.switchCareerDiv( $('#careers .career:nth-child(1)').attr('id')   );

	$('#careers .navlist a').click( function() {
	//  switchCareerDiv($(this).attr('class'));     
	//  return false;
	});
}

CandtCareers.switchCareerDiv = function(p_sCareerDiv) {
	if (CandtCareers._sOldCareerDiv){
		$('#'+CandtCareers._sOldCareerDiv).css('display','none');      
		$('#careers .navlist .'+CandtCareers._sOldCareerDiv).siblings('span').css('display','none');
		$('#careers .navlist .'+CandtCareers._sOldCareerDiv).css('display','inline');
	}

	$('#'+p_sCareerDiv).css('display','block');
	CandtCareers._sOldCareerDiv = p_sCareerDiv;

	$('#careers .navlist .'+p_sCareerDiv).siblings('span').css('display','inline');
	$('#careers .navlist .'+p_sCareerDiv).css('display','none');
}

CandtCareers.fadeInPage = function() {

	$('#sections_cover').height( $('#real_sections_content').height() );
	
	$('#ajaxhelper').animate({ opacity: .9999}, 0001, '', function() { 
		$('#real_sections_content').removeClass('hideMe');
		
		$('#ajaxhelper').animate({ opacity: .9999}, 0001, '', function() { 
			
			$('#sections_cover').fadeOut(300);
			
		});
		
	});
	
}

// ------------------------ HOME ANIMATIONS ---------------------------------------


CandtHome = {}

CandtHome.initialize = function(){
	
	setLinks('#home'); 

	$("#footer").addClass("home");
	
	if($.browser.msie || homecount == 1){
		
		CandtHome.animating = true;
		
		//alert( $('body').height() );
		$('body').height('auto');
		//alert( $('body').height() );
		
	//	$('#p1').animate({ opacity: 0.0}, 0001, '', function() { 
	//		$(this).css('z-index',100);
		
			$('#home_content').animate({ opacity: 0.0}, 0001, '', function() { 
				$(this).css('z-index',100);
				
	//			$('#icon_holder2').animate({ opacity: 0.0}, 0001, '', function() { 
	//				$(this).css('z-index',100);
					
					$('#fakeheader #header').animate({ opacity: 0.0}, 0001, '', function() { 
						$(this).css('visibility','visible');
						$(this).css('z-index',200);
						
						$('#homeborder').animate({ opacity: 0.0}, 0001, '', function() { 
							$(this).css('visibility','visible');
							$(this).css('z-index',100);
							
							$('#homeborder').animate({ opacity: 0.0}, 0001, '', function() { 
								$(this).css('z-index',100);
								
								$('#footer').animate({ opacity: 0.0}, 0001, '', function() { 
									$(this).css('z-index',100);
									
							//		$('#news').animate({ opacity: 0.0}, 0001, '', function() { 
							//			$(this).css('z-index',100);
							
										CandtHome.startAnimation();
										
							//		});
								});
							});
						});
					});
				});
//			});
//		});
	
	}
	else{
		
		$('#realheader').css('display','block');
		$('#fakeheader').css('display','none');
		$('#realheader').css('visibility','visible');
		$('#homeborder').css('visibility','visible');
		$('#homeborder').css('display','block');
		$('.coverDiv').animate({ opacity: 0 }, 500, '', function() { $(this).remove(); });
		$('#p1').css('z-index',100);
		$('#p1').animate({ opacity: .9999}, 01);
		$('#homeborder').animate({ opacity: .9999}, 01);
		$('#footer').css('z-index',100);
		$('#footer').animate({ opacity: .9999}, 01);
		
		
		totalNews=0;
		$('#news .newsrow').each(function(){ totalNews++ });
		//CandtHome.newsFade(0,1%totalNews,homecount);
		CandtHome.rotateSites();
		//l_xHomePlayer.write('hompage-fl');
		
	}
}


var g_sCurrentNews ='';

CandtHome.startAnimation = function(){	

//	$('#p1').animate({ opacity: .9999 }, 1000,'',function(){
//		$('#p1').animate({ opacity: .9999}, 500,'',function(){


	//$('#p1').animate({ opacity: .9999}, 1000,'', function(){
	//	$('#p1').animate({ opacity: .9999}, 500,'', function(){
			
	//		$('#p2').animate({ opacity: .9999 }, 1000,'', function(){
	//			$('#p2').animate({ opacity: .9999 }, 1000,'', function(){
					
			$('#homeborder').animate({ opacity: .9999 }, 1000);
//			$('#news').animate({ opacity: .9999 }, 1000);
			$('#footer').animate({ opacity: .9999 }, 1000);
			$('#home_content').animate({ opacity: .9999 }, 1000);
//			$('#icon_holder2').animate({ opacity: .9999 }, 1000);
			
			$('#fakeheader #header').animate({ opacity: .9999 }, 1000,'', function(){
																			   
			//					$('#fakeheader #header').animate({ opacity: .9999 }, 0500,'', function(){
										
				$('.coverDiv').animate({ opacity: 0 }, 500, '', function() { $(this).remove(); });
				$('#fakeheader').css('display','none');
				$('#realheader').css('display','block');
				$('#realheader').css('z-index',200);
				$('#news').css('z-index',1);
				$('#homeborder').css('z-index',1);
			//	CandtPlaylist.reinitialize();
				totalNews=0;
				$('#news .newsrow').each(function(){ totalNews++ });
				//CandtHome.newsFade(0,1%totalNews,homecount);
				CandtHome.rotateSites();
				CandtGlobal.setNavHovers();
				
				CandtHome.animating = false;
				//l_xHomePlayer.write('hompage-fl');
			});
//		});
//	});
	//});
	
	//				});
	//			});
	//		});
		//});
	//});
}

var l_nLinkCount = '';

CandtHome.rotateSites = function(){
	
	l_nLinkCount = $('#home_content .row1 .ajaxlink').length;
	
	if(l_nLinkCount > 1){
		
		setTimeout(function(){ CandtHome.rotateSitesCallback( 1,2, homecount ); },100);
		
	}
	
}


CandtHome.rotateSitesCallback = function(currentLink, nextLink, _homecount){
	//alert(currentLink+' '+nextLink);
	if( _homecount == homecount ){
		setTimeout(function(){
			if( _homecount == homecount ){
				
				$('#home_content .row1 .homelink_'+currentLink).animate({ opacity: 'hide' }, 0500);
				$('#home_content .row3 .homelink_'+currentLink).animate({ opacity: 'hide' }, 0500,'',function(){
					if( _homecount == homecount ){
						$('#home_content .row1 .homelink_'+nextLink).animate({ opacity: 'show' }, 0500);
						$('#home_content .row3 .homelink_'+nextLink).animate({ opacity: 'show' }, 0500,'',function(){
							if( _homecount == homecount )
								CandtHome.rotateSitesCallback(nextLink,((nextLink%l_nLinkCount)+1), _homecount);
						});
					}
					
				});
				
				
			}
		},9000);
	}
}

CandtHome.newsFade = function(currentNews, nextNews, _homecount){
	if( _homecount == homecount )
		$('#news'+currentNews).animate({ opacity: 1.0 }, 10000,'',function(){
			if( _homecount == homecount )
				$('#news'+currentNews).animate({ opacity: 'hide' }, 0500,'',function(){
					if( _homecount == homecount )															 
					$('#news'+nextNews).animate({ opacity: 'show' }, 0500,'',function(){
			
						if( _homecount == homecount )
							CandtHome.newsFade(nextNews,((nextNews+1)%totalNews), _homecount);
					});
					
				});
			
		});
	
}

CandtHome.redirect = function(fullUrl){
	if (charLoc = fullUrl.indexOf('#') ){
		
		theAnchor = fullUrl.slice(charLoc+1);
		
		var workTest = /work/;
		if (workTest.test(theAnchor)){
			workId = theAnchor.slice(5,8);
			
			if(!workId)
				window.location = '/work/';
	
			else
				window.location = '/work/'+workId;
		}
		var aboutTest = /about/;
		if (aboutTest.test(theAnchor))
			window.location = '/about/';
		
		var aboutTest = /careers/;
		if (aboutTest.test(theAnchor))
			window.location = '/careers/';
			
		var aboutTest = /contact/;
		if (aboutTest.test(theAnchor))
			window.location = '/contact/';
		
		//	alert (fullUrl.slice(charLoc+1));
	}
}

	
/**
 * Opacity function for jQuery
 *
 * @name   .opacity
 * @cat    Plugins/Effects
 * @author Woody Gilk/woody.gilk@gmail.com
 *
 * @example $(this).opacity(.2);
 */
$.fn.opacity = function(amount) {
	if (amount > 1) amount = 1;
	if (amount < 0) amount = 0;
	if ($.browser.msie) {
			amount = (parseFloat(amount) * 100);
			this.css('filter', 'alpha(opacity='+amount+')');
	} else {
			this.css('opacity', amount);
			this.css('-moz-opacity', amount);
	}
	return this;
}




function alignLeftRight() {


		$(".clients_cell").opacity(.5);
		$(".clients_cell").hover(function(){
			$(this).attr('rel','hover');
			$(this).opacity(1);

		}, function() {
			$(this).fadeTo("fast", .5, function(){
				if($(this).attr('rel')=='hover')
					$(this).opacity(1);
			});
			$(this).attr('rel','');
		});



	var checkLast = -1;
	
	$("#clients_table > div").each(function(i){
		
		var pixelNumber = $(this).css("width").substring(0,$(this).css("width").length-2);
		
		//alert(pixelNumber);
		
		if (i%4 == 0)	// left column
		{
			var marginChange = 38;
			$(this).css("background-position","left center");
			$(this).css("margin-left", marginChange);
			$(this).css("width", pixelNumber-marginChange);
			$(this).children("a").css("width", pixelNumber-marginChange);
			checkLast = i;
		}
		else
		{
			$(this).css("background-position","center center");
		}
		
		if (checkLast>-1)	// right column
		{
			//alert(1);
			if (i == checkLast+3) {
				var marginChange = 38;
				$(this).css("background-position","right center");
				$(this).css("margin-right", marginChange);
				$(this).css("width", pixelNumber-marginChange);
				$(this).children("a").css("width", pixelNumber-marginChange);
				$(this).after('<div class="clear"></div>')  ;
				checkLast = -1;
			}
		}
		
	});
	
	
	
	
	
}		
		