// Slideshow Refresh for Ads and Omniture
// js/hdn/slideshow/refresh.js

if (!HDN) {
	var HDN={};
}

var _comscore = _comscore || []; // setup comScore object in global scope

HDN.iframeurl = "/tmpl/slideshow_iframe.php";
HDN.refresh = function(type,value) {
	if (HDN.doRefresh == 1) {
		// reload the iframe for ads
		var riframe = document.getElementById('galleryrefresher');
		riframe.setAttribute("src",HDN.iframeurl);
		// Omniture tracking for slideshows and article pages
		try {
            if ( type=='photo' ){
                track_slideshow(value);
            } else if ( type=='page' ){
                track_article_pages(value);
            }
        } catch(err) { // if there is a console (like in Firefox), note the error
            if ( window.console!=undefined ){
                console.log(err);
            }
        }
		//Visual Revenue, only ctpost at time of writing
		//if (HDN.visualRevenue){
		if ( typeof _vrtrack=='function' ) {
			_vrtrack();
		}
		// Google Analytics
		if ( typeof _gaq=='object' ) {
			if ( typeof _gaq.push=='function' ) {
				_gaq.push(['_trackPageview']);
			}
		}
		// Nielsen track event (defined below)
		nielsenEvent();
		// comScore track event (defined below)
		comScoreEvent();
        // Jump Time beacon (defined in analyticswcm.js)
        if ( typeof sendJumpTimeBeacon=='function' ) {
			sendJumpTimeBeacon();
		}
	}
}

// monkey patch showid to hook in ad/omniture refresh
hstrot.prototype.origshowid = hstrot.prototype.showid;
hstrot.prototype.showid = function(id) {
	HDN.refresh('photo',id);
	return this.origshowid(id);
};


function track_slideshow(photoNumber){
    objectClass = omni_className;
    objectID = omni_bizObjectId;
    objectName = omni_title;
    if ( s_account=='hearstconnecticutglobal' || s_account=='hearstadvocate' ||s_account=='hearstctgreenwichtime' ||s_account=='hearstconnpost' ||s_account=='hearstnewstimeslivecomnew' ||s_account=='hearstctweeklies'){
        if (objectClass=="article") {
            s_hdn.prop24="article slideshow";
            s_hdn.prop33="article slideshow photo:" + photoNumber;
        }
    } else {
        if (objectClass=="article") {
            s_hdn.prop24="article slideshow";
            s_hdn.eVar24="article slideshow";
            s_hdn.prop33="article slideshow photo:" + photoNumber;
            // omni_channelPath and omni_categorize may be defined in strange places 
            if(typeof(omni_channelPath)!="undefined"){
                // They will likely try to use "s", so make sure it's the object we expect
                if (s!==s_hdn){ s = s_hdn; }
                omni_categorize(omni_channelPath+' slideshow');
            }
        }	
    }
    if (objectClass=="slideshow") {
        s_hdn.prop33="slideshow photo:" + photoNumber;
    }
    var s_code = s_hdn.t();
    if (s_code) document.write(s_code);
    //alert('s.prop33: '+s.prop33+"\ns.prop24: "+s.prop24+"\nomni_channelPath: "+omni_channelPath);
}

function track_article_pages(pageN){
	objectClass = omni_className;
	if (objectClass=="article") {
		s_hdn.prop24="article";
		s_hdn.eVar24="article";
	}
	s.prop33="article page:" + pageN;
	var s_code = s_hdn.t();
	if (s_code) document.write(s_code);
	//alert('s.prop33: '+s.prop33+"\ns.prop24: "+s.prop24);
}

function nielsenEvent(){
	var d = new Image(1, 1);
	d.src = ["//secure-us.imrworldwide.com/cgi-bin/m?ci=us-202808h&cg=0&cc=1&si=",escape(window.location.href), "&rp=", escape(document.referrer),"&c0=usergen,1&rnd=", (new Date()).getTime()].join('');
}

function comScoreEvent(){
	//var _comscore = _comscore || [];
	_comscore.push({ c1: "2", c2: "6036097", c3: "", c4: "" }); // reset global object
	(function() {
		var s = document.createElement("script"), el = document.getElementsByTagName("script")[0]; s.async = true;
		s.src = (document.location.protocol == "https:" ? "https://sb" : "http://b") + ".scorecardresearch.com/beacon.js";
		el.parentNode.insertBefore(s, el);
	})();
}

// end js/hdn/slideshow/refresh.js

