// Public names for tagging functions, and passive tagging where it is universally applicable
// Requires Prototype.

// Google Analytics configuration and stuff

var _gaq = _gaq || [];

(function() {

    var GA_locale_cookie = '<Not Set>';
    var GA_is_ld = 'No';

    var locale_cookie_found = document.cookie.match(/(^|;\s*)locale=([^;]*)/);
    if(locale_cookie_found) {
        GA_locale_cookie = locale_cookie_found[2];
    }

    if(document.cookie.match(/(^|;\s*)ldinfo=./)) {
        GA_is_ld = 'Yes';
    }

    _gaq.push(['_setAccount', 'UA-17614433-2']);
    _gaq.push(['_setDomainName', 'none']);
    _gaq.push(['_setAllowLinker', true]);

    _gaq.push(['_setCustomVar', 1, 'Using Livescribe Desktop', GA_is_ld, 3 ]);
    _gaq.push(['_setCustomVar', 2, 'User Locale Cookie', GA_locale_cookie, 3 ]);

    _gaq.push(['_trackPageview']);

    
    Event.observe(document, 'dom:loaded', function() {
        var ga = document.createElement('script');
        ga.type = 'text/javascript';
        ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0];
        s.parentNode.insertBefore(ga, s);

        if($$("div.download_widget a[class]").length == 2) {
            var downloadLinks = $$("div.download_widget a[class]");
            downloadLinks.each(function(element, index) {
                element.observe('click', function(event) {
                    event.stop();
                    window.recordOutboundLink(this, 'LD Downloads', this.href);
                    return false;
                }) 
            });
        }

    });
    
    /* Function to record outbound links */

    window.recordOutboundLink = function(link, category, action) {
        _gat._getTrackerByName()._trackEvent(category, action);
        setTimeout('document.location = "' + link.href + '"', 100);
    }
    
})();

// Doubleclick/DART/Various ad networks configuration
(function() {

    var loadlist = [];
    var load_happened = false;

    Event.observe(window, 'load', function() {
        loadlist.each(function(f) {
            f()
            });
        load_happened = true;
    });

    var afterLoad = function(fn) {
        if(load_happened) {
            fn();
        }
        else {
            loadlist.push(fn);
        }
    };

	//FlashTalking - Julie (100711)		
	var flashtalking_tags = {
		'Echo Homepage' :  {  
			'http' : "http://cdn.flashtalking.com/container/6273/6273.js?EchoHomepage&cachebuster="
		},
		
		'Livescribe - About Pencasts' : { 
			'http' : "http://cdn.flashtalking.com/container/6271/6271.js?Livescribe-AboutPencasts&cachebuster="
		},
		
		'Livescribe - Community' : { 
            'http' : "http://cdn.flashtalking.com/container/6269/6269.js?Livescribe-Community&cachebuster=",
			'https' : "https://secure.flashtalking.com/container/6269/6269.js?Livescribe-Community&cachebuster="
        },
		
		'Livescribe - Community Search Results' : {
            'http' : "http://cdn.flashtalking.com/container/6270/6270.js?Livescribe-CommunitySearchResults&cachebuster=",
			'https' : "https://secure.flashtalking.com/container/6270/6270.js?Livescribe-CommunitySearchResults&cachebuster="
        },

		'Livescribe - Getting Started' : {
            'http' : "http://cdn.flashtalking.com/container/6279/6279.js?Livescribe-GettingStarted&cachebuster="
        },
		
		'Livescribe Home' : {
            'http' : 'http://cdn.flashtalking.com/container/6253/6253.js?LivescribeHome&cachebuster='
        },
		
		'Livescribe Home - Smartpen' : {
            'http' : 'http://cdn.flashtalking.com/container/6274/6274.js?LivescribeHome-Smartpen&cachebuster='
        },
		
		'Livescribe Home - Homepage Store Module (Buy Now)' : {
            'http' : 'http://cdn.flashtalking.com/container/6258/6258.js?HomepageStoreModule-BuyNow&cachebuster='
        },
		
		'Livescribe Home - Learn More (Main image click through)' : {  
            'http' : 'http://cdn.flashtalking.com/container/6254/6254.js?LivescribeHome-LearnMoreMainimage&cachebuster='
        },
		
		'Livescribe Home - Retailers (Amazon)' : {
            'http' : "http://cdn.flashtalking.com/container/6259/6259.js?LivescribeHome-RetailersAmazon&cachebuster="
        },

        'Livescribe Home - Retailers (Apple Store)' : {
            'http' : "http://cdn.flashtalking.com/container/6261/6261.js?LivescribeHome-RetailersAppleStore&cachebuster="
        },

        'Livescribe Home - Retailers (BestBuy)' : {
            'http' : "http://cdn.flashtalking.com/container/6256/6256.js?LivescribeHome-RetailersBestBuy&cachebuster="
        },
		
        'Livescribe Home - Retailers (Brookstone)' : {
            'http' : "http://cdn.flashtalking.com/container/6263/6263.js?LivescribeHome-RetailersBrookstone&cachebuster="
        },

        'Livescribe Home - Retailers (Staples)' : {
            'http' : "http://cdn.flashtalking.com/container/6262/6262.js?LivescribeHome-RetailersStaples&cachebuster="
        },

        'Livescribe Home - Retailers (Target)' : {
			'http' : "http://cdn.flashtalking.com/container/6260/6260.js?LivescribeHome-RetailersTarget&cachebuster="
        },
		

        'Livescribe Home - Video (How can a Smartpen Help You?)' : {
            'http' : 'http://cdn.flashtalking.com/container/6257/6257.js?VideoHowcanaSmartpenHelpYou&cachebuster='
        },
		
		'Livescribe Store - Where to Buy' : {
            'http' : "http://cdn.flashtalking.com/container/6280/6280.js?LivescribeStore-WheretoBuy&cachebuster=",
			'https' : "https://secure.flashtalking.com/container/6280/6280.js?LivescribeStore-WheretoBuy&cachebuster="
        },

        'Livescribe Platform - Smartpen - Apps' : {
            'http' : "http://cdn.flashtalking.com/container/6277/6277.js?LivescribePlatform-Smartpen-Apps&cachebuster="
        },

        'Livescribe Platform - Smartpen - Customer Stories' : {
            'http' : "http://cdn.flashtalking.com/container/6278/6278.js?LSPlatform-Smartpen-CustomerStories&cachebuster="
        },

        'Livescribe Platform - Smartpen - Save & Search' : {
            'http' : "http://cdn.flashtalking.com/container/6275/6275.js?LSPlatform-Smartpen-SaveandSearch&cachebuster="
        },

        'Livescribe Platform - Smartpen - Send & Share' : {
            'http' : "http://cdn.flashtalking.com/container/6276/6276.js?LSPlatform-Smartpen-SendandShare&cachebuster="
        },
		
		'Livescribe Store' : {
            'http' : "http://cdn.flashtalking.com/container/6264/6264.js?LivescribeStore&cachebuster=",
			'https' : "https://secure.flashtalking.com/container/6264/6264.js?LivescribeStore&cachebuster="
        },

        'Livescribe Store - Step 1 (Item List)' : {
            'http' : "http://cdn.flashtalking.com/container/6265/6265.js?LivescribeStore-Step1ItemList&cachebuster="
        },

        'Livescribe Store - Step 2 (Your Info)' : {
            'https' : "https://secure.flashtalking.com/container/6266/6266_HTTPS.js?LivescribeStore-Step2YourInfo&cachebuster="
        },

        'Livescribe Store - Step 3 (Confirmation)' : { 
            'https' : "https://secure.flashtalking.com/container/6267/6267_HTTPS.js?LivescribeStore-Step3Confirmation&cachebuster="
        },
		
		'Pulse Homepage' : {
            'http' : "http://cdn.flashtalking.com/container/6272/6272.js?PulseHomepage&cachebuster="
        },
		
        'Student Solution' : {
            'http' : "http://cdn.flashtalking.com/container/6282/6282.js?Livescribe-StudentsPage&cachebuster="
        },
		
        'Learning Solution' : {
            'http' : "http://cdn.flashtalking.com/container/6281/6281.js?Livescribe-LDPage&cachebuster="
        }

	};
	
	//Media6 - Julie (100711)
	var media6_tags = {
		'Echo Homepage' :  {  
			'http' : 'http://action.media6degrees.com/orbserv/hbjs?pixId=7210&pcv=36',
			'https' : 'https://secure.media6degrees.com/orbserv/hbjs?pixId=7210&pcv=36'
		},
		
		'Livescribe Home' : {
            'http' : 'http://action.media6degrees.com/orbserv/hbjs?pixId=7206&pcv=40',
			'https' : 'https://secure.media6degrees.com/orbserv/hbjs?pixId=7206&pcv=40'
        },
		
		'Livescribe Store' : {
            'http' : 'http://action.media6degrees.com/orbserv/hbjs?pixId=7207&pcv=41',
			'https' : 'https://secure.media6degrees.com/orbserv/hbjs?pixId=7207&pcv=41'	
        },
		
		'Livescribe Store - Where to Buy' : {
            'http' : 'http://action.media6degrees.com/orbserv/hbjs?pixId=7209&pcv=43',
			'https' : 'https://secure.media6degrees.com/orbserv/hbjs?pixId=7209&pcv=43'
        },
		
		'Pulse Homepage' : {
            'http' : 'http://action.media6degrees.com/orbserv/hbjs?pixId=7211&pcv=37',
			'https' : 'https://secure.media6degrees.com/orbserv/hbjs?pixId=7211&pcv=37'		
        }

	};
	
	media6 = function(media6_query) {
		if(document.cookie.match(/(^|;\s*)ldinfo=./)) {
            return; // GO NO FURTHER in LD
        }
		// ELSE IF we're NOT in LD
		
		var mediatag={
            add:function(a,b,c,d){
                d=d||false;
                if(a.addEventListener){
                    a.addEventListener(b,c,d)
                    }else if(a.attachEvent){
                    a.attachEvent("on"+b,c)
                    }
                },
			load:function(){
				var a;
				
				var tagprotocol = ('https:' == document.location.protocol ? 'https' : 'http');
				var b=document.createElement('script');
				var c=media6_tags[ media6_query ][ tagprotocol ];
				b.type='text/javascript';
				b.src= c;
				var d=document.getElementsByTagName('script');
				var e=Number(d.length)-1;
				var f=document.getElementsByTagName('script')[e];
				f.parentNode.insertBefore(b,f);
			}
    	};
		
		afterLoad(function() {
			mediatag.load();
		});
		
	};
	
	flashtalking = function(flashtalking_query) {
		if(document.cookie.match(/(^|;\s*)ldinfo=./)) {
            return; // GO NO FURTHER in LD
        }
		// ELSE IF we're NOT in LD
		
		var ft={
            add:function(a,b,c,d){
                d=d||false;
                if(a.addEventListener){
                    a.addEventListener(b,c,d)
                    }else if(a.attachEvent){
                    a.attachEvent("on"+b,c)
                    }
                },
			load:function(){
				var a;
				if(typeof a=='undefined'){
					a=Math.random()*1000000;
					};
				var tagprotocol = ('https:' == document.location.protocol ? 'https' : 'http');
				var b=document.createElement('script');
				var c=flashtalking_tags[ flashtalking_query ][ tagprotocol ];
				b.type='text/javascript';
				b.src= c+a;
				var d=document.getElementsByTagName('script');
				var e=Number(d.length)-1;
				var f=document.getElementsByTagName('script')[e];
				f.parentNode.insertBefore(b,f);
			}
    	};
		
		afterLoad(function() {
			ft.load();
		});
		
	};

    // To be called ONLY ON THE HOME PAGE (but for all locales)
    /* global*/  analytics_home = function() {};


    var steelhouse_media = function() {

        //////////////////////////////////////////
        // Steel House Media

        var aid='9204';
        var additional='';

        var steelhouse={
            add:function(a,b,c,d){
                d=d||false;
                if(a.addEventListener){
                    a.addEventListener(b,c,d)
                    }else if(a.attachEvent){
                    a.attachEvent("on"+b,c)
                    }
                },
        load:function(){
            var a;
            if(typeof a=='undefined'){
                a=Math.random()*10000000000000000
                };
            var b=document.createElement('script');
            var c='px.steelhousemedia.com/st?aid='+aid+'&cb='+a+additional;
            b.type='text/javascript';
            b.src=('https:'==document.location.protocol?'https://':'http://')+c;
            var d=document.getElementsByTagName('script');
            var e=Number(d.length)-1;
            var f=document.getElementsByTagName('script')[e];
            f.parentNode.insertBefore(b,f);
        }
    };

    afterLoad(function() {
        steelhouse.load();
    });
	
	
	//add CNET and Turn Tracking Beacon Code (Julie 100711)
	function loadGLobalTrackingImg(url){
		
		var image = '<img src="' + url + '" width="1" height="1" border="0"/>';
		
		afterLoad(function() {
		   $$('body')[0].insert({
			   bottom: image
		   });
		});
	}
	
	//CNET Tracking Pixel
	loadGLobalTrackingImg("https://dw.com.com/clear/c.gif?sId=17&ctype=partner;loc&cval=livescribe;landing");
	//Turn Tracking Beacon Code
	loadGLobalTrackingImg("https://r.turn.com/r/beacon?b2=5STagz6Q5aMry01N36JT86V09ia17Mj4RKID8UIDncak2xkDAUtgpuXLcFWDWjiQ_Ay-xUB06bTaBzOe6bp2BQ&cid=");
        
}


if(document.cookie.match(/(^|;\s*)ldinfo=./)) {
    // pass
    }
    else {
        steelhouse_media();
    }

})();


// Global Analytics tools
window.promo = function(destination, info) {
    /** CALL WITH:
      <a onclick="promo('/store/', { 
                                   floodlight: 'fls.doubleclick.net/activityi;src=12345;type=type123;cat=cat123',
                                   eyewonder: 'Livescribe Home - Save a Bunch!',
								   flashtalking: 'Livescribe Home - Save a Bunch!',
                                   gaLogicalPage: '/~PROMO~/homepage/right/saveABunch'
                                   }">Save A Bunch!</a>

      WHERE
      destination, the first argument, = where the browser should end up after the click
      info = ALL OPTIONAL arguments
           floodlight: if present, used as a query to floodlight()
           eyewonder: if present, used as a query to eyewonder()
		   flashtalking: if present, used as a query to flashtalking()
           gaLogicalPage: if present, sent to google analytics as a dummy page view associated with this promo

    **/

    if(info) {
        if("undefined" != typeof info['gaLogicalPage']) {
            _gaq.push(['_trackPageview', info['gaLogicalPage'] ]);
        }

        if("undefined" != typeof info['floodlight']) {
            floodlight(info['floodlight']);
        }

        if("undefined" != typeof info['eyewonder']) {
            eyewonder(info['eyewonder']);
        }
		
		if("undefined" != typeof info['flashtalking']) {
            flashtalking(info['flashtalking']);
        }
		
		if("undefined" != typeof info['media6']) {
            media6(info['media6']);
        }

    }

    window.setTimeout(function() {
        document.location = destination;
    }, 100);

    return void(0);
}

function loadScript(url, callback)
{
    // adding the script tag to the head as suggested before
    var head= document.getElementsByTagName('head')[0];
    var script= document.createElement('script');
    script.type= 'text/javascript';
    script.src= url;

    // then bind the event to the callback function 
    // there are several events for cross browser compatibility
    script.onreadystatechange = callback;
    script.onload = callback;

    // fire the loading
    head.appendChild(script);
}

var loc = window.location.href;

if(loc.indexOf("https://") != -1 )
{	
	
} else {
	loadScript("http://include.reinvigorate.net/re_.js", reinvigorateInit);
	//Adnetik (Julie 100711)
	loadScript("http://www.wtp101.com/pixel?id=4198", reinvigorateInit);
}

function reinvigorateInit() {
    try {
	reinvigorate.url_filter = function (url) { return url; }
        reinvigorate.track("fkujo-11sz25xhsl");
    } catch(err) {
        
    }
}

