<!-- Template ID = 18449 Template Name = MediaBrix SocialFlex 1.4 MP4/FLV [JAVASCRIPT]  -->

<script type="text/javascript">
var mb_type = "i";
var mb_payload = {
     "euui" : "6371979", //populated from mediabrix metrics server
     "myfbuserid" : null, // From publisher
     "orderName" : "Sandro's v1.4 test order", //manually entered in DFP
     "adid" : "253944826", //ad id from DFP macro
     "crid" : "47019004", //creative id from DFP macro
     "siteName" : "mbrix.testsocialflexv1_4", //site name from DFP
     "zoneName" : "mediabrix", //manually entered in DFP template as zone.
     "postUrl" : "http://mediabrix-metrics-us.cloudapp.net/", //Domain of the metrics server
     "host" : document.domain,
     "session" : null,
     "product_type" : "socialFlex"
}

function addMetrics(){
     var ad_page;
     if(mb_type=="j"){
          ad_page = parent.document.getElementById('socialFlexHolder').parentNode;
     }else{
          ad_page = document.body;
}
     var metrics_script = document.createElement('script');
     metrics_script.id = "mb_metrics";
     metrics_script.src = "https://mediabrix.hs.llnwd.net/o38/v1_4/metrics.js"
     ad_page.appendChild(metrics_script);
}


//Populate missing optional values in socialVars with the corresponding var from mbDefaults.
function compareSocialWithDefault(){
     var options = ["confirmText","autoplay","automute","iconURL","backgroundURL","share", "youtube", "twitter", "tweet","facebook","linkedin","feedback", "data_capture"];

     for (var i=0;i<options.length;i++)     {
          if(typeof(socialVars[options[i]]) === 'undefined'){
               socialVars[options[i]] = mbDefaults[options[i]];
          }
     }
    
}

// **** start feedback engine **** //

function mb_feedback_message(){
     var mb_message = "<h3>Thank you for your feedback</h3>";
     document.getElementById('mb_feedback_form').innerHTML = mb_message;
     document.getElementById('mb_feedback_form').style.textAlign = "center";
     document.getElementById('mb_feedback_form').style.top = "210px";
     setTimeout('mb_kill_message()', 1500);
}

// ** Fetch forms from limelight ** //

function mb_fetch_form(form_id){
     var new_script = document.createElement('script');
     new_script.id = "preview_form_script";
     new_script.src = "https://mediabrix.hs.llnwd.net/o38/data_capture/form_" +form_id+ ".js";
     document.body.appendChild(new_script);
}

function mb_kill_message(){
     document.getElementById('mb_feedback_form').style.display = "none";
}

function mb_cancel_feedback(){
     document.getElementById('mb_feedback_form').style.display = "none";
     document.getElementById('mb_click_pop1').style.display = "block";
     document.getElementById('mb_click_pop2').style.display = "block";
     document.getElementById('mb_click_pop3').style.display = "block";

}

function mb_show_feedback(form_id){
     mb_fetch_form(form_id);
    
     document.getElementById('mb_feedback_form').style.display = "block";
     document.getElementById('mb_click_pop1').style.display = "none";
     document.getElementById('mb_click_pop2').style.display = "none";
     document.getElementById('mb_click_pop3').style.display = "none";
}

function mb_show_data_cap(){
     if(mb_vars.dc){mb_fetch_form(mb_vars.dc);}
     document.getElementById('mb_data_cap').style.display = "block";
    
}

function mb_submit_data_cap(){
     document.getElementById('mb_data_cap').style.display = "none";
}

// **** end feedback engine **** //



// **** Start Sharing Options  **** //    

// ** Sharing data

var mbDefaults ={
          "youtube" : "mediabrix",
          "twitter" : "mediabrix",
          "tweet" : "mediabrix",
          "facebook" : "mediabrix",
          "linkedin" : "mediabrix",          
          "autoplay" : "true",
          "automute" : "false",
          "feedback" : 30,
          "data_capture" : 27,
          "share" : []
     }

var options = ["youtube", "twitter", "tweet","facebook","linkedin"];

for (var i=0;i<options.length;i++)     {
     if(typeof(mbDefaults[options[i]]) !== 'undefined' && mbDefaults[options[i]] != ""){
          mbDefaults.share.push(options[i]);
     }
}
    


//Toggle visibility of share buttons
function toggleShareIcons(){
    
     //Loop through socialVars.share and display those elements
     if(typeof(socialVars.share) != 'undefined'){
          shares = socialVars.share;
          }else if(typeof(socialVars.share) != 'undefined'){
          shares = socialVars.share;
          }
//Hide all share icons unless shares = all
     if(shares === "all"){return false;}
     var icons = document.getElementsByClassName('mb_share_icon');
          for (var i=0;i<icons.length;i++)     {
          icons[i].style.display = "none";    
     }

//Loop through socialVars.share and display those elements; reuse var i                   
     for (var i=0;i<shares.length;i++)     {
          //window["mb_"+shares[i]+"_share"](document.getElementById('mb_confirm_'+shares[i]));
          window["mb_"+shares[i]+"_share"](document.getElementById('mb_share_'+shares[i]));
     }

}

// *** Display share icons and attach click events ***// 
//Facebook buttons
function mb_facebook_share(button){
     button.onclick = function(){
          window.open('http://www.facebook.com/sharer/sharer.php?u='+socialVars.facebook +'/','_blank','width=640,height=400, toolbar=no');
          mb_metrics.logEvent('share', 'facebook');
          return false;
     };
     button.style.display = "block";
}

//LinkedIn buttons
function mb_linkedin_share(button){
     button.onclick = function(){
          window.open('http://www.linkedin.com/cws/share?url='+socialVars.linkedin+'&original_referer=&token=&isFramed=false&_ts=','_blank','width=600,height=400, toolbar=no');
          mb_metrics.logEvent('share', 'linkedin');
          return false;
     };
     button.style.display = "block";
}

//Tweet buttons
function mb_tweet_share(button){
     button.onclick = function(){                         
          window.open('https://twitter.com/intent/tweet?original_referer='+document.location.href+'&source=tweetbutton&text=&url='+socialVars.tweet+'/' ,'_blank','width=640,height=400, toolbar=no');
          mb_metrics.logEvent('share', 'tweet');
          return false;
     };
     button.style.display = "block";
}

//Twitter buttons
function mb_twitter_share(button){
     button.onclick = function(){
          window.open('https://twitter.com/'+socialVars.twitter +'/','_blank');
          mb_metrics.logEvent('share', 'twitter');
          return false;
     };
     button.style.display = "block";
}

//Youtube buttons
function mb_youtube_share(button){
     button.onclick = function(){
          window.open('http://www.youtube.com/user/'+socialVars.youtube +'/','_blank');
          mb_metrics.logEvent('share', 'youtube');
          return false;
     };
     button.style.display = "block";
}


// **** End Sharing Options  **** //


// **** Start Countdown Timer **** //

var time_to = "";
var timer_count = 5;

function sf_start_Timer(){
if(mb_type == "i")return false;

     if(time_to == ""){
         time_to = window.setInterval("sf_countDown()", 1000);
     }else{
          sf_stop_Timer();
    }
}

function sf_stop_Timer(){
     if(time_to != ""){
          window.clearInterval(time_to);
          time_to = "";
          document.getElementById('mb_divForTimer').innerHTML = "";
         
          document.getElementById('mb_close').style.display = "block";

         
     }
}

function sf_countDown(){
     document.getElementById('mb_divForTimer').innerHTML = timer_count;
     timer_count--;
     if(timer_count == -1){
          sf_stop_Timer();
     }
}

// **** End Countdown Timer **** //


//Apply publisher settings to the unit 
function initSocialVars(){
     if(typeof(socialVars) == 'undefined'){socialVars={}};

//Compare socialVars with mbDefaults.
     compareSocialWithDefault();
         
     attachSocialFlex();
//Toggle Share buttons
     toggleShareIcons();         
}

// **** Start Removal of SocialFlex Instance **** // 

function closeSocialFlex(){
     var t_div = document.getElementById('socialFlexHolder');
     var d_div = document.getElementById('mb_canvas');
     t_div.style.width = '1px';
     t_div.style.height = '1px';
     t_div.removeChild(d_div);
     //Send termination message to publisher 
     if(typeof(socialVars.callback) != 'undefined') fireCallBack();
    
}

// **** End Removal of SocialFlex Instance **** //

function attachSocialFlex(){

strVar
 =
'          <style type="text/css">\n#socialFlexHolder { po'
+ 'sition:absolute: z-index:400000; width:100%; overflow:hi'
+ 'dden; left:0px; top:0px; }\n#mb_canvas { font-family:Luci'
+ 'da Grande, Arial; overflow:hidden; width:644px; height:5'
+ '00px; border:3px solid pink; margin:0 auto; }\n'
+ '#mb_canvas.jstag{border-radius:10px; -moz-border-radius:10px; -webkit-border-radius:10px; box-shadow:0px 0px 5px #000; -moz-box-shadow:0px 0px 5px #000; -webkit-box-shadow:0px 0px 5px #000; }\n'
+ '#mb_branded_bg { float:left; width:644px; height:'
+ '453px; overflow:hidden; background:url(\'https://mediabrix.hs.llnwd.net/o38/brands/tmobile/bg.jpg\') #ccc; text-align:center; }\n#mb_close { margin:3px'
+ ' 3px 0 0; display:none; float:right; width:33px; height:'
+ '32px; background:url(\'https://mediabrix.hs.llnwd.net/o38'
+ '/socialflex/images/share/mb_close.png\'); cursor:pointer;'
+ ' }\n#mb_video_holder { margin:182px 0 '
+ '0 242px; width:360px; he'
+ 'ight:203px; overflow:hidden; background:#ff'
+ 'f; }\n\n#mb_social_share_links { float:left; width:634px; '
+ 'padding:5px; overflow:hidden; background:#fff; }\n#mb_log'
+ 'o { overflow:hidden; float:left; margin:0 80px 0 0; widt'
+ 'h:100px; height:36px; background:url(\'https://mediabrix.'
+ 'hs.llnwd.net/o38/socialflex/images/share/mb_logo.png\'); '
+ '}\n.mb_share_icon { float:left; height:36px; padding:0 8p'
+ 'x 0 8px; margin:0 0 0 0; cursor:pointer; }\n#mb_feedback '
+ '{ overflow:hidden; float:right; width:75px; height:19px;'
+ ' cursor:pointer; background:url(\'https://mediabrix.hs.ll'
+ 'nwd.net/o38/socialflex/images/share/feedback.png\'); }\n\n#'
+ 'mb_feedback_form { display:none; line-height:3.0em; floa'
+ 't:left; width:644px; height:494px; color:#252525; overfl'
+ 'ow:hidden; background:#fff; text-align:center; font-fami'
+ 'ly:Lucida Grande, Arial; }\n\n</style>\n<div id="mb_canvas"'
+ '>\n                                   \n     \n     <div id="mb_feedback_form">\n          \n          <div id="m'
+ 'b_data_form"></div>\n          \n\n     </div>\n     \n     <div id="mb_branded_b'
+ 'g">\n     \n          <div id="mb_click_pop1" class="clicker" onclick='
+ '"window.open(\'http://ad.doubleclick.net/click%3Bh%3Dv8/3c30/3/0/%2a/y%3B253944826%3B0-0%3B1%3B77658484%3B13126-650/500%3B47019004/47035253/1%3B%3B%7Esscs%3D%3fhttp://www.mediabrix.com\');"><img src="http://www.google.com" border="0" width="1" height="1" /></d'
+ 'iv>\n          <div id="mb_click_pop2" class="clicker" onclick="w'
+ 'indow.open(\'http://ad.doubleclick.net/click%3Bh%3Dv8/3c30/3/0/%2a/y%3B253944826%3B0-0%3B1%3B77658484%3B13126-650/500%3B47019004/47035253/1%3B%3B%7Esscs%3D%3fhttp://www.mediabrix.com\');"></div>\n          \n          <div id="mb_click_pop3"'
+ ' class="clicker" onclick="window.open(\'http://ad.doubleclick.net/click%3Bh%3Dv8/3c30/3/0/%2a/y%3B253944826%3B0-0%3B1%3B77658484%3B13126-650/500%3B47019004/47035253/1%3B%3B%7Esscs%3D%3fhttp://www.mediabrix.com\');"></div>\n\n'
+ '          \n          <div id="mb_close" onclick="closeSocialFlex(); mb_m'
+ 'etrics.logEvent(\'close\', true);"></div>\n\n          <div id="mb_d'
+ 'ivForTimer" style="margin:9px 3px 0 0; float:right; widt'
+ 'h:33px; height:32px; line-height:1.8em; color:#000; font'
+ '-weight:bold; font-size:0.7em; font-family:arial;"></div'
+ '>\n          \n          <div id="mb_video_holder">\n               <object type="appli'
+ 'cation/x-shockwave-flash" data="http://mediabrix.vo.llnw'
+ 'd.net/o38/socialflex/jwplayer/player.swf" width="360" height="203">\n\n                    <param name="m'
+ 'ovie" value="http://mediabrix.vo.llnwd.net/o38/socialfle'
+ 'x/jwplayer/player.swf" />\n                    <param name="allowfullscre'
+ 'en" value="true" />\n                    <param name="allowscriptaccess" '
+ 'value="always" />\n                    <param name="flashvars" value="fil'
+ 'e=http://mediabrix.vo.llnwd.net/o38/brands/tmobile/tmobile.mp4&autostart='
+ socialVars.autoplay +'&controlbar.position=over'
+ '&mute='+socialVars.automute+'&provider=video" />\n               </object>\n          </div>\n\n     </'
+ 'div>\n\n     \n     <div id="mb_social_share_links">\n     \n          <div id="m'
+ 'b_logo"></div>\n          \n          <div id="mb_share_txt" style="overfl'
+ 'ow:hidden; float:left; width:43px; height:36px; backgrou'
+ 'nd:url(\'https://mediabrix.hs.llnwd.net/o38/socialflex/im'
+ 'ages/share/share.png\')"></div>\n          \n          <div class="mb_share'
+ '_icon" id="mb_share_facebook">\n               <img src="https://medi'
+ 'abrix.hs.llnwd.net/o38/socialflex/images/share/facebook.'
+ 'png" border="0" alt="like us facebook" />\n          </div>\n          \n          '
+ '<div class="mb_share_icon" id="mb_share_linkedin">\n               <i'
+ 'mg src="https://mediabrix.hs.llnwd.net/o38/socialflex/im'
+ 'ages/share/linkedin.png" border="0" alt="like us faceboo'
+ 'k" />\n          </div>\n\n          \n          <div class="mb_share_icon" id="mb_s'
+ 'hare_tweet">\n               <img src="https://mediabrix.hs.llnwd.net'
+ '/o38/socialflex/images/share/tweet.png" border="0" alt="'
+ 'Tweet!" />\n          </div>\n\n          <div class="mb_share_icon" id="mb'
+ '_share_twitter">\n               <img src="https://mediabrix.hs.llnwd'
+ '.net/o38/socialflex/images/share/twitter.png" border="0"'
+ ' alt="Follow us on Twitter" />\n          </div>\n\n          <div class="m'
+ 'b_share_icon" id="mb_share_youtube">\n               <img src="https:'
+ '//mediabrix.hs.llnwd.net/o38/socialflex/images/share/you'
+ 'tube.png" border="0" alt="Follow us on YouTube" />\n\n          </'
+ 'div>\n\n          <div id="mb_feedback" onclick="mb_show_feedback('
+ '\'30\'); return false;"></div>\n     \n     </div>'
+ '\n\n                              \n\n</div>';

// end_var_declaration
     if(mb_type == "j"){
          document.getElementById('socialFlexHolder').innerHTML = strVar;
          document.getElementbyId('mb_canvas').className = 'jstag';
     } else {
          document.write(strVar);
     }
}


initSocialVars();
addMetrics();
sf_start_Timer();

</script>