if (typeof _hbPageView == "undefined" || !_hbPageView) {
    function _hbPageView(){ }    
}


/**
 * 
 * The HDSocial global namespace object.  If HDSocial is already defined, the
 * existing HDSocial object will not be overwritten so that defined
 * namespaces are preserved.
 *
 * @class HDSocial
 * @static
 */
var HDSocial = {
    hasAnalytics: function()
	{    
        return !!HD && !!HD.util && !!HD.util.Analytics;        
    },    
    pageLink: function(pageUrl, windowName, winProperties, swfId)
	{    
        var winNew = window.open(pageUrl, windowName, winProperties);        
        if (!winNew) 
		{        
            HDSocial.getSwf(swfId).openWindowFromSwf(pageUrl);            
        }        
        else {        
            winNew.focus();            
        }        
    },         
    getSwf: function(id)
	{
        if (navigator.appName.indexOf("Microsoft") != -1) 
		{        
            return window[id];            
        }        
        else 
		{        
            return document[id];            
        }        
    },
    hdSocialShare: function(target, shareUrl, title, description, thumbUrl, hbxContent, swfId, media)
	{    
        switch (target) 
		{       
            case 'facebook':               
                HDSocial.hdFbShare(shareUrl, title, hbxContent, swfId, media);                
                break;                
            case 'myspace':               
                HDSocial.hdMSShare(shareUrl, title, description, thumbUrl, hbxContent, swfId, media);                
                break;                
            case 'digg':                
                HDSocial.hdDiggShare(shareUrl, title, description, hbxContent, swfId, media);                
                break;                
            case 'wordpress':    
				HDSocial.hdBlogShare(shareUrl, title, description, thumbUrl, hbxContent, swfId, target, media);                
                break;   
            case 'blogger':                
                HDSocial.hdBlogShare(shareUrl, title, description, thumbUrl, hbxContent, swfId, target, media);                
                break;                
        }
        
    },
    hdFbShare: function(shareUrl, title, hbxContent, swfId, media){
    
        var metaArray = document.getElementsByTagName("meta").description;
        
        docContent = metaArray.content;
        
        //docContent = docContent.substr(0, 92) + "...";
        
        //alert(docContent);
        
        var u = shareUrl;
        
        var t = docContent;
        
        var finalURL = 'http://www.facebook.com/sharer.php?u=' + encodeURIComponent(u) + '&t=' + encodeURIComponent(t);
        
        var properties = 'toolbar=0,status=0,width=626,height=436';
        
        HDSocial.pageLink(finalURL, 'Facebook', properties, swfId);
        
        
        
        //hbx
        
        if (this.hasAnalytics()) {
        
            HD.util.Analytics.track(this.analyticsFacebookString(media));
            
        }
        
        else {
        
            _hbPageView('Facebook', hbxContent);
            
        }
        
    },
    
    
    
    //Share MySpace
    
    hdMSShare: function(shareUrl, title, description, thumbUrl, hbxContent, swfId, media){
    
    
    
        //localUrl = MY10.util.getRequestParam("locale");
        
        //localUrl = "fr_ca";
        
        
        
        var metaArray = document.getElementsByTagName("meta").description;
        
        docContent = metaArray.content;
        
        //docContent = docContent.substr(0, 92) + "...";
        
        //alert(docContent);
        
        
        
        
        
        
        
        var bor = '0';
        
        var ref = shareUrl;
        
        var tar = '_blank';
        
        var s = '8';
        
        var alt = docContent;
        
        var a = 'left';
        
        var p = thumbUrl;
        
        var i = '<a href=' + ref + '  target=' + tar + '><img src=' + p + ' align=' + a + ' alt=' + alt + ' hspace=' + s + ' border=' + bor + '/></a>';
        
        var T = docContent;
        
        var C = i + T + "<br/>Check it out at <a href='" + ref + "' target='" + tar + "'>" + ref + "</a>";
        
        var U = '';
        
        var finalURL = 'http://www.myspace.com/index.cfm?fuseaction=postto&' + 't=' + encodeURIComponent(T) + '&c=' + encodeURIComponent(C) + '&u=' + encodeURIComponent(U);
        
        var properties = 'width=1024,height=768,scrollbars=yes,resizable=yes,toolbar=no,location=no,menubar=no,directories=no,status=no';
        
        HDSocial.pageLink(finalURL, 'MySpace', properties, swfId);
        
        
        
        //hbx
        
        if (this.hasAnalytics()) {
        
            HD.util.Analytics.track(this.analyticsMyspaceString(media));
            
        }
        
        else {
        
            _hbPageView('MySpace', hbxContent);
            
        }
        
    },
    
    
    
    //Share Digg
    
    hdDiggShare: function(shareUrl, title, description, hbxContent, swfId, media){
    
        var finalURL = 'http://digg.com/submit/?url=' + shareUrl + '&title=' + title + '&bodytext=' + description;
        
        var properties = 'width=1024,height=768,scrollbars=yes,resizable=yes,toolbar=no,location=no,menubar=no,directories=no,status=no';
        
        HDSocial.pageLink(finalURL, 'Digg', properties, swfId);
        
        
        
        //hbx
        
        if (this.hasAnalytics()) {
        
            HD.util.Analytics.track(this.analyticsDiggString(media));
            
        }
        
        else {
        
            _hbPageView('Digg', hbxContent);
            
        }
        
    },
    
    
    
    //Share blog
    
    hdBlogShare: function(shareUrl, title, description, thumbUrl, hbxContent, swfId, target, media){
    
        var bor = '0';
        
        var ref = shareUrl;
        
        var tar = '_blank';
        
        var s = '8';
        
        var alt = title.replace(/['"]/g, '');
        
        var a = 'left';
        
        var p = thumbUrl;
        
        var U = '';
        
        var T = title;
        
        
        
        var i = '<div id="HDSocialBlogPost">';
        
        i += '<div class="dblRuleBtm">';
        
        i += '  <div class="head">POST TO YOUR BLOG</div>';
        
        i += '</div>';
        
        i += '<div class="hdwcMedPadBtm">';
        
        i += '<div id="hdwcInstructions">Copy and paste the embed code below and post it to your blog:</div>';
        
        i += '</div>';
        
        i += '<div id="hdwcBody" class="wrap">';
        
        i += '<div class="htmlEmbedCode hdwcSmlPadBtm">';
        
        i += '      <h2>Embed Code</h2>';
        
        i += '  <textarea name="copyText" id="copyText" >';
        
        i += '<a href="' + location.href + '"  target="' + tar + '"><img src="' + p + '" align="' + a + '" alt="' + alt + '" hspace="' + s + '" border="' + bor + '"/></a>';
        
        i += description + '<br/>Check it out at <a href="' + location.href + '" target="' + tar + '">' + T + '</a>';
        
        i += '</textarea>';
        
        i += '</div>';
        
        i += '<div class="btnOrange"><a href="javascript: void(0);" id="hdSocial-closebtn">Close</a></div>';
        
        i += '</div>';
        
        i += '</div>';
        
        
        
        HDSocial.showOverlay(i, T, 586, 254, false);
        
        
        
        //hbx
        
        if (this.hasAnalytics()) {
        
            if (target == 'wordpress') {
            
                HD.util.Analytics.track(this.analyticsWordpressString(media));
                
            }
            
            else 
                if (target == 'blogger') {
                
                    HD.util.Analytics.track(this.analyticsBloggerString(media));
                    
                }
            
        }
        
        else {
        
            _hbPageView(target || 'Blog', hbxContent);
            
        }
        
    },
    
    
    
    /**
     * Method for displaying page overlay.
     * @param body{String} the overlay source HTML as a string
     * @param title {String} the overlay title string (used in iframe)
     * @param width{int} (optional) the overlay width
     * @param height{int} (optional) the overlay height
     * @param iframe{Boolean} sets overlay to iframe instead of DOM display
     */
    showOverlay: function(body, title, width, height, iframe){
    
        var overlayEl = YAHOO.util.Dom.get("hdwcOverlay");
        
        
        
        // hide overlay instance if one already exists
        
        if (overlayEl) {
            this.hideOverlay();
        }
        
        
        
        // get viewport height              
        
        var isResizeViewPort = 540 > YAHOO.util.Dom.getViewportHeight() && parseInt(height, 10) > 450;
        
        
        
        // if the viewport it too small for the overlay we will resize the overlay
        
        if (isResizeViewPort) {
        
            height = YAHOO.util.Dom.getViewportHeight() - 40;
            
        }
        
        
        
        var posX = (YAHOO.util.Dom.getViewportWidth() / 2) - (width / 2);
        
        var sfs = YAHOO.util.Dom.getDocumentScrollTop();
        
        var posY = ((YAHOO.util.Dom.getViewportHeight() + sfs) / 2) - (height / 2);
        
        
        
        posX = Math.round(posX);
        
        posY = Math.round(posY);
        
        
        
        // configure overlay
        
        var overlayConfig = {
        
            constraintoviewport: true,
            
            close: true, // show close button
            draggable: true, // draggable
            zindex: 100000, // z index
            modal: true, // overlays other elements
            visible: false, // visible right away
            iframe: true, // useful in overlay certain elements
            underlay: "shadow", // show shadow,
            x: posX,
            
            y: posY,
            
            // set width and height if passed, append "px" if integers
            
            height: typeof height == 'number' ? height + 'px' : height || null,
            
            width: typeof width == 'number' ? width + 'px' : width || null
        
        };
        
        
        
        if (iframe == true) {
        
            //set iframe to import page body as overlay body. passes width, height and src string.
            
            body = "<iframe class='hdwcOverlayIframe' src='" + body + "' frameBorder='0' height='" + height + "' width='" + width + "' scrolling='no' allowTransparency='true'></iframe>";
            
        }
        
        
        
        var overlay = new YAHOO.widget.Panel("hdwcOverlay", overlayConfig);
        
        //overlay.setHeader(header);
        
        overlay.setBody(body);
        
        overlay.render(document.body);
        
        //show the overlay
        
        overlay.show();
        
        
        
        //IF IE check to position overlay in the middle of the screen
        
        if (YAHOO.env.ua.ie > 0) {
        
            YAHOO.util.Dom.setStyle("hdwcOverlay_c", 'top', posY);
            
            YAHOO.util.Dom.setStyle("hdwcOverlay_c", 'left', posX);
            
        }
        
        
        
        var closeClickCb = function(){
        
            HDSocial.hideOverlay();
            
        };
        
        
        
        // use our hideOverlay method for when use clicks close on overlay
        
        // this allows for different events to fire when closing was user initiated
        
        var closeEls = YAHOO.util.Dom.getElementsByClassName("container-close", "a", overlayEl);
        
        closeEls.push(document.getElementById("hdSocial-closebtn"));
        
        for (var i = 0, len = closeEls.length; i < len; i++) {
        
            (function(){
            
                closeEls[i].onclick = closeClickCb;
                
            })();
            
        }
        
        
        
        // if the viewport it too small for the overlay we will resize overlay content
        
        if (isResizeViewPort) {
        
            YAHOO.util.Event.onContentReady("hdwcBody", function(){
            
                var hdwcBodyEl = YAHOO.util.Dom.get("hdwcBody");
                
                var scrollableDivEl = YAHOO.util.Dom.get("scrollableDiv");
                
                
                
                if (hdwcBodyEl) {
                
                    hdwcBodyEl.style.height = (parseInt(height, 10) - 65) + "px";
                    
                }
                
                if (scrollableDivEl) {
                
                    scrollableDivEl.style.height = (parseInt(height, 10) - 90) + "px";
                    
                }
                
            });
            
            
            
        }
        
        
        
        this.overlay = overlay;
        
        
        
        return overlayEl;
        
    },
    
    
    
    hideOverlay: function(){
    
        //if there is an existent overlay, hide it                  
        
        if (this.overlay != null) {
        
            this.overlay.hide();
            
            this.overlay.destroy();
            
        }
        
    },
    
    
    
    analyticsFacebookString: function(){
    
        return "/Products/Motorcycles/2010s/Share/Facebook";
        
    },
    
    
    
    analyticsMyspaceString: function(){
    
        return "/Products/Motorcycles/2010s/Share/MySpace";
        
    },
    
    
    
    analyticsBloggerString: function(){
    
        return "/Products/Motorcycles/2010s/Share/Blogger";
        
    },
    
    
    
    analyticsWordpressString: function(){
    
        return "/Products/Motorcycles/2010s/Share/Wordpress";
        
    },
    
    
    
    analyticsDiggString: function(){
    
        return "default_analyticsDiggString";
        
    }
    
    
    
};

//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
