
namespacing={init:function(namespace){var spaces=[];namespace.split('.').each(function(space){var curSpace=window,i;spaces.push(space);for(i=0;i<spaces.length;i++){if(typeof curSpace[spaces[i]]==='undefined'){curSpace[spaces[i]]={};}
curSpace=curSpace[spaces[i]];}});}};namespacing.init('istock.tracking');istock.tracking.Omniture=Class.create({_firstSearch:true,_firstSearchEvent:null,initialize:function()
{this._observeLanguage();this._observeSisterSite();this._observeErrorBubble();this._observeNewsTicker();this._observePriceRange();this._observeDownload();this._observeSearch();this._observeLightbox();this._observeImage();},_trackLink:function(link,navType)
{s.linkTrackVars='events,prop7,prop8,eVar38';s.linkTrackEvents='event13';s.prop8=link;s.eVar8=link;s.events='event13';s.tl('trackLink',navType,link);},_trackPriceRange:function(priceRange)
{s.prop42=s.eVar42=priceRange;},_trackErrorBubble:function(errorMsg)
{s.linkTrackVars='prop19,eVar19,eVar38';s.prop19=errorMsg;s.eVar19=s.prop19;s.tl('trackError','o',errorMsg);},_trackLightbox:function(name,events,eventType)
{s.linkTrackVars='events,prop10,eVar10,eVar38';s.linkTrackEvents=events;s.events=events;s.eVar10=s.prop10=name;s.tl('trackLightbox','o',eventType);},_trackRowColumn:function(event)
{var item=Event.element(event).up('.srItem');var isListLayout=false;if(typeof item=='undefined'){item=event.element().up('.lsrRow');if(typeof item=='undefined'){return;}
isListLayout=true;}
var id=item.id.split('_')[1];var count=0;istock.search.resultsHandler.getResultSet(true).each(function(image){if(id==image.id){throw $break;}
count++;}.bind(this));if(isListLayout){var row=count+1;var col=1;}else{var numPerRow=Math.floor($('srchRslts').offsetWidth/item.offsetWidth);var row=(Math.floor(count/numPerRow))+1;var col=(count%numPerRow)+1;}
document.cookie="omnitureImage="+id+"|"+row+"|"+col+';path=/';},_observeImage:function()
{if($('srchRslts')!=null){$('srchRslts').observe('click',function(event){this._trackRowColumn(event);}.bind(this));if(!Prototype.Browser.WebKit){$('srchRslts').observe('mouseup',function(event){if((event.which&&event.which==2)||(event.buttons&&event.buttons==1)){this._trackRowColumn(event);}}.bind(this));}}},_observeLanguage:function()
{document.observe('omniture:language',function(event){$$('a.e_languageOpt').each(function(event){event.observe('click',function(event){this._trackLink('language selector: '+event.currentTarget.innerHTML,'o');}.bind(this));}.bind(this));}.bind(this));},_observeSisterSite:function()
{$$('a.trackSisterSite').each(function(event){event.observe('click',function(event){this._trackLink('sister site: '+event.currentTarget.innerHTML.stripTags(),'e');}.bind(this));}.bind(this));if(!Prototype.Browser.WebKit){$$('a.trackSisterSite').each(function(event){event.observe('mouseup',function(event){if((event.which&&event.which==2)||(event.buttons&&event.buttons==1)){this._trackLink('sister site: '+event.currentTarget.innerHTML.stripTags(),'e');}}.bind(this));}.bind(this));}
document.observe('omniture:gettyLink',function(event){$$('a.trackSisterSite').each(function(event){event.observe('click',function(event){this._trackLink('sister site: gettyimages.com','e');}.bind(this));}.bind(this));if(!Prototype.Browser.WebKit){$$('a.trackSisterSite').each(function(event){event.observe('mouseup',function(event){if((event.which&&event.which==2)||(event.buttons&&event.buttons==1)){this._trackLink('sister site: gettyimages.com','e');}}.bind(this));}.bind(this));}}.bind(this));},_observeNewsTicker:function()
{document.observe("omniture:newsTickerEvent",function(event){this._trackLink(event.memo,'o');}.bind(this));},_observePriceRange:function()
{document.observe("omniture:priceRangeEvent",function(event){this._trackPriceRange(event.memo);}.bind(this));},_observeErrorBubble:function()
{document.observe("omniture:errorBubble",function(event){this._trackErrorBubble(event.memo);event.stop();}.bind(this));},_observeDownload:function()
{document.observe("omniture:trackDownload",function(event){s.linkTrackVars='events,eVar4,prop4,eVar38';s.linkTrackEvents='event9';s.events='event9';s.tl('agreeBtn','o','Accept Agreement');var trackSplit=event.memo.split('~');s.linkTrackVars="products,events,eVar13,eVar38,prop4,eVar4,eVar58,eVar39,prop39";s.linkTrackEvents="event23,event4";s.events="event4,event23";s.products=';;;;event23='+trackSplit[1]+';';s.eVar13=trackSplit[0];s.eVar58=trackSplit[2];s.eVar39=trackSplit[3];s.prop39=trackSplit[3];if(trackSplit[4]==''){s.linkTrackEvents+=",event7";s.events+=",event7";if(trackSplit[5]=='0'){s.linkTrackVars+=',eVar20';s.eVar20='free';}}
s.tl("startDownload","o","trackDownloads");event.stop();}.bind(this));},_observeLightbox:function()
{if($('LightboxForm')!=null){$('LightboxForm').observe('submit',function(event){if($('ID')==null){this._trackLightbox($('Name').value,'event6','Create Lightbox');}}.bind(this));}
document.observe("omniture:lightboxCreate",function(event){this._trackLightbox(event.memo,'event5,event6','Create Lightbox');event.stop();}.bind(this));document.observe("omniture:lightboxAdd",function(event){this._trackLightbox(event.memo,'event5','Add File Lightbox');event.stop();}.bind(this));},_trackCollections:function(results){stats={'agency':0,'vetta':0,'exclusive+':0,'exclusive':0,'plus':0,'main':0,'dollarbin':0,'pump':0},$A(results.results).each(function(v){collection=v.collection;if(!v.collection){collection='main';}
stats[collection]++;}.bind(this));s.linkTrackVars+=',prop38';s.prop38=stats['main']+'|'+stats['vetta']+'|'+stats['dollarbin']+'|'+stats['exclusive']+'|'+
stats['exclusive+']+'|'+stats['agency']+'|'+stats['plus'];},_parseSearch:function(event)
{var breadBox=this._parseBreadBox();this._trackSearch(breadBox,event);if(breadBox.lightbox!=''){s.linkTrackVars='eVar10,prop10,eVar38';s.eVar10=s.prop10=breadBox.lightbox;s.tl('trackLightbox','o','Lightbox');}},_trackSearch:function(breadBox,event)
{s.linkTrackVars='prop11,prop12,prop13,prop14,prop15,prop16,prop31,prop32,prop39,'+'prop33,prop34,prop35,prop36,prop37,prop42,prop43,eVar11,eVar12,eVar13,eVar14,'+'eVar15,eVar16,eVar31,eVar32,eVar33,eVar34,eVar35,eVar36,eVar37,eVar53,eVar38,eVar39,eVar42,eVar43';var totalResults=istock.search.resultsHandler.getTotalResultCount();s.prop11=breadBox.keywords;if(totalResults==0){s.prop11='none:'+s.prop11;}
s.prop12=breadBox.portfolio;s.prop13=totalResults.toString();s.prop14=istock.search.resultsHandler.getCurrentPage().toString();s.prop15=SearchSortOptions[istock.search.preferences.get('order')];s.prop16=breadBox.fileTypes;s.prop31=breadBox.photoIllustration;s.prop32=$('colourSelectorInput').value;if(s.prop32=='HEX'){s.prop32='';}
s.prop33=breadBox.videoFilters;s.prop34=breadBox.audioFilters;s.prop35=breadBox.collections;s.prop36=breadBox.more;s.prop37=breadBox.categories;s.eVar53=istock.search.preferences.get('perPage');s.eVar11=s.prop11;s.eVar12=s.prop12;s.eVar14=s.prop14;s.eVar15=s.prop15;s.eVar16=s.prop16;s.eVar31=s.prop31;s.eVar32=s.prop32;s.eVar33=s.prop33;s.eVar34=s.prop34;s.eVar35=s.prop35;s.eVar36=s.prop36;s.eVar37=s.prop37;if(typeof s.eVar42==='undefined'){s.eVar42=s.prop42='none';}
s.eVar43=s.prop43=breadBox.license.toLowerCase()
this._trackCollections(event.memo);var ssCookie=istock.cookie.getCookie('SS_MIX');if(ssCookie==null){s.prop39=istock.search.resultsHandler.getUserSegmentId();s.eVar39=s.prop39;}else{s.prop39=ssCookie;s.eVar39=ssCookie;}
if(this._firstSearch){s.events="event2,event14";s.t();this._firstSearch=false;}else{s.tl('trackSearch','o','Search');}},_parseBreadBox:function()
{var data={keywords:'',portfolio:'keyword',categories:'',photoIllustration:'',fileTypes:'all files',license:'',videoFilters:'',audioFilters:'',collections:'',lightbox:'',more:''};var firstChild='';var breadBox=$('breadbox').childElements();for(var i=0;i<breadBox.length;i++){firstChild=breadBox[i].firstDescendant();switch(omnitureTranslation[firstChild.innerHTML.trim()]){case'Keywords':data.keywords=this._parseBreadBoxTerms(breadBox[i],false);break;case'Portfolio':data.portfolio='memberID';break;case'Categories':data.categories=this._parseBreadBoxTerms(breadBox[i],true);break;case'Photos &amp; Illustration Filters':data.photoIllustration=this._parseBreadBoxTerms(breadBox[i],true);break;case'File Types':data.fileTypes=this._parseBreadBoxTerms(breadBox[i],true);break;case'License':data.license=this._parseBreadBoxTerms(breadBox[i],true);break;case'Video Filters':data.videoFilters=this._parseBreadBoxTerms(breadBox[i],true);break;case'Audio Filters':data.audioFilters=this._parseBreadBoxTerms(breadBox[i],true);break;case'Collections':data.collections=this._parseBreadBoxTerms(breadBox[i],true);break;case'More Attributes':data.more=this._parseBreadBoxTerms(breadBox[i],true);break;case'Lightbox':data.lightbox=this._parseBreadBoxTerms(breadBox[i],false);break;default:break;}}
return data;},_parseBreadBoxTerms:function(element,translate)
{var facets=element.select('div.facetTitle');var facetString='';var rawFacetString='';for(var i=0;i<facets.length;i++){if(translate){rawFacetString=facets[i].innerHTML.replace(/(<([^>]+)>)/ig,"").replace(/&nbsp;/gi,'').trim();if(typeof omnitureTranslation[rawFacetString]=='undefined'){facetString+=rawFacetString;}else{facetString+=omnitureTranslation[rawFacetString];}}else{facetString+=facets[i].innerHTML.replace(/(<([^>]+)>)/ig,"").replace(/&nbsp;/gi,'');}
facetString+='|';}
facetString=facetString.truncate(facetString.length-1,'');return facetString;},_observeSearch:function()
{try{Event.observe(document,istock.search.event.NEW_RESULTS,function(event){if(!this._firstSearch){this._parseSearch(event);}else{this._firstSearchEvent=event;}}.bind(this));}catch(exception){}
document.observe('omniture:firstSearch',function(event){this._parseSearch(this._firstSearchEvent);event.stop();}.bind(this));}});document.observe('dom:loaded',function(ev){var omnitureTracking=new istock.tracking.Omniture();});
