


// Generate a random number 0-6 
var randy = Math.round(Math.random()*6);

var FFN_NS = {};
FFN_NS.im_banner = {
                        size : 'thumb',
                     skinIDX : 2,
                      domain : 'http://asiafriendfinder.com',
              domain_cobrand : '',
             graphics_domain : 'http://graphics2.asiafriendfinder.com',
                        site : 'ffz',
                         pid : 'g793249-pct',
                       toPid : '',
                      toSite : 'HASH(0x8e27dd8)',
                     pageVal : 'gallery',
                    siteType : 'dating',
                     freqCap : 0,
                    creative : '',
                   extraArgs : '',                   
                 modExtraAgs : '',
                         del : '',
                        cams : {
                                     thumb : { width : '235', height : '116', bg_dir : 'cams/',       img_width : '82px',  img_height : '62px', down_pos : '-120', pic_size : 1  },
                                  bigthumb : { width : '293', height : '160', bg_dir : 'cams/large/', img_width : '140px', img_height : '106',  down_pos : '-164' }
                               },
                      dating : {
                                     thumb : { width : '201', height : '116', bg_dir : '',       img_width : '47', img_height : '62',  down_pos : '-120' },
                                  bigthumb : { width : '233', height : '160', bg_dir : 'large/', img_width : '80', img_height : '106', down_pos : '-164' }
                                },
                        skin : [
                                  { header_font_color : '#666666',  body_font_color : '#000000', handle_pos : '25px' },
                                  { header_font_color : '#666666',  body_font_color : '#000000', handle_pos : '10px' },
                                  { header_font_color : '#FFFFFF',  body_font_color : '#000000', handle_pos : '10px' },
                                  { header_font_color : '#CCCCCC',  body_font_color : '#000000', handle_pos : '10px' },
                                  { header_font_color : '#666666',  body_font_color : '#000000', handle_pos : '10px' },
                                  { header_font_color : '#FFFFCC',  body_font_color : '#FFFFCC', handle_pos : '10px' },
                                  { header_font_color : '#FFFFCC',  body_font_color : '#FFFFCC', handle_pos : '10px' }
                               ],
                          re : {
                                 toDomain : /[^\.\/]+\.com/,
                                 toPid    : /(a|b|f|g|p)\d+c?(\-(all|brk|cpct|cpm|lp|npct|pct|pmb|pmem|pmo|po|ppc))?(\+reg)?[^&?]+/ 
                               },
                      update : true,
                               
                   buildArgs : function(name,val){
                                 if(val.length === 0){ 
                                   return ''; 
                                 }

                                 val        = val.split(',');
                                 var result = '';        
                                 var valLen = val.length;
                        
                                 for( var i = 0; i < valLen; i++){    
                                   result += '&' + name + '=' + val[i];
                                 }                    
                                 return result;            
                               }
                   };
                        
// Global variables
var gCookieName = 'FFN_im_' + FFN_NS.im_banner.pid;
var gDivID      = 'FFN_imBox';
var gDelay      = 5;
var banSizeObj  = FFN_NS.im_banner[FFN_NS.im_banner.siteType][FFN_NS.im_banner.size];

// User data
var udCity      = 'Jakarta';

// Get data for members.
var userInfo  = new Array();


 
userInfo[1] = new userData('','$5 USD Free','','','','Indonesia','<img style="border: 0 transparent none;" src="http://4.bp.blogspot.com/-o-EqsZIwbTk/TiqxBjyllkI/AAAAAAAAAJg/qKjv80vCo0U/s1600/marketiva.gif" width="180" height="70" alt="$5 USD Free" title="$5 USD Free" />','http://www.eforexs.com/download/forex.php');



  // Check is we need to use a default image
  if(userInfo[1].img.indexOf('[NO PHOTO]') > 1){
    userInfo[1].img = '<img src="' + FFN_NS.im_banner.graphics_domain + '/banners/imchat/no_image_f_4.jpg" width="' + banSizeObj.img_width + '" height="' + banSizeObj.img_height + '" alt="' + userInfo[1].handle + '" title="' + userInfo[1].handle + '" style="border:0 transparent none;"/>';
  }
  userInfo[1].href += '' + FFN_NS.im_banner.creative;



if(FFN_NS.im_banner.extraArgs.length !== 0){
  FFN_NS.im_banner.del         = '?';
  FFN_NS.im_banner.modExtraAgs = FFN_NS.im_banner.extraArgs.substr(1,FFN_NS.im_banner.extraArgs.length);
}

if(FFN_NS.im_banner.domain_cobrand.length > 0){
  FFN_NS.im_banner.domain = 'http://' + FFN_NS.im_banner.domain_cobrand;
}

FFN_NS.im_banner.page        = {
                                        cover : FFN_NS.im_banner.domain + '/go/' + FFN_NS.im_banner.pid + FFN_NS.im_banner.del + FFN_NS.im_banner.modExtraAgs + '&' + FFN_NS.im_banner.creative,
                                 registration : FFN_NS.im_banner.domain + '/go/' + FFN_NS.im_banner.pid + '+reg' + '?' + FFN_NS.im_banner.creative,
                                      gallery : FFN_NS.im_banner.domain + '/go/page/gallery_landing_page?pid=' + FFN_NS.im_banner.pid  + FFN_NS.im_banner.extraArgs + '&' + FFN_NS.im_banner.creative,
                                        model : FFN_NS.im_banner.domain + '/p/cams/view.cgi?&action=bio&stream=' + userInfo[1].handle + '&pid=' + FFN_NS.im_banner.pid + '&' + FFN_NS.im_banner.creative,
                                         view : FFN_NS.im_banner.domain + '/p/cams/view.cgi?&action=view&stream=' + userInfo[1].handle + '&pid=' + FFN_NS.im_banner.pid + '&' + FFN_NS.im_banner.creative
                                };

if(FFN_NS.im_banner.siteType === 'cams'){

  if(typeof FFN_NS.im_banner.page[FFN_NS.im_banner.pageVal] === 'undefined'){
    FFN_NS.im_banner.pageVal = 'model';
  }

  userInfo[1].href = FFN_NS.im_banner.page[FFN_NS.im_banner.pageVal];
}

var msg = new Array();


      msg[0] = '';
  

if(FFN_NS.im_banner.pageVal === ''){
  FFN_NS.im_banner.pageVal = 'registration';
}


if(FFN_NS.im_banner.toSite.indexOf('HASH(') !== 0){
  userInfo[1].href = userInfo[1].href.replace(FFN_NS.im_banner.re.toDomain,FFN_NS.im_banner.toSite);
}


if(FFN_NS.im_banner.toPid.length > 0){
  if(FFN_NS.im_banner.pageVal === 'registration'){
    FFN_NS.im_banner.toPid += '+reg';
  }     
  userInfo[1].href = userInfo[1].href.replace(FFN_NS.im_banner.re.toPid,FFN_NS.im_banner.toPid);
}

var randIDX   = Math.floor( Math.random() * msg.length );
var css       = 'position:fixed;';
var html_code = '';

// Build banner

if(document.all && window.XMLHttpRequest && !window.opera){

  
  if( ( window.document.childNodes[0].text == undefined ) || ( window.document.childNodes[0].text.search(/DOCTYPE\s+HTML\s+PUBLIC.+\.dtd/i) == -1) ){
    css = 'position:absolute; top:expression( eval( document.compatMode && document.compatMode == \'CSS1Compat\' ) ? documentElement.scrollTop + (documentElement.clientHeight-this.clientHeight) : document.body.scrollTop + ( document.body.clientHeight-this.clientHeight ) ); ';
  }

}


if(document.all && !window.XMLHttpRequest){
  css = 'position:absolute; top:expression( eval( document.compatMode && document.compatMode == \'CSS1Compat\' ) ? documentElement.scrollTop + (documentElement.clientHeight-this.clientHeight) : document.body.scrollTop + ( document.body.clientHeight-this.clientHeight ) ); ';
}

html_code += '<div id="FFN_imBox_Container" style="' + css + ' display:none; z-index:99999; bottom:0px; width:' + banSizeObj.width + 'px; height:' + banSizeObj.height +'px; right:5px; overflow:hidden; background-color:transparent; border-width:0px;">';
html_code += '<div id="' + gDivID + '" style="position:relative; top:' + banSizeObj.height +'px; z-index:99998; width:' + banSizeObj.width + 'px; height:' + banSizeObj.height + 'px; font-family:Arial, Helvetica, sans-serif; font-size:12px; padding:0px; background:transparent url(http://graphics2.asiafriendfinder.com/banners/imchat/' + banSizeObj.bg_dir + 'im_bg_' + FFN_NS.im_banner.skinIDX + '.gif);">';
html_code += '<div style="position:absolute; top:5px; right:5px;"><a id="FFN_btn_close" href="#" onclick="phmg_move(\'' + gDivID + '\',\'down\'); return false;" style="color:#666666; font-size:12px; text-decoration:none;"><img src="http://graphics2.asiafriendfinder.com/common/others/spacer.gif" height="15" width="15" border="0" style="border-width:0px;" /></a></div>';
html_code += '<div style="padding:6px 6px 6px ' + FFN_NS.im_banner.skin[FFN_NS.im_banner.skinIDX].handle_pos + '; text-align:left; font-family:verdana; font-size:10px; color:' + FFN_NS.im_banner.skin[FFN_NS.im_banner.skinIDX].header_font_color + ';"><b>' + userInfo[1].handle + ' ' + userInfo[1].sex + '/' + userInfo[1].age +'</b></div>';
html_code += '<div id="userImg" style="position:absolute; top:33px; left:9px; width:' + banSizeObj.img_width + 'px; height:' + banSizeObj.img_height + 'px;"><a href="' + userInfo[1].href + '" target="_blank" style="color:' + FFN_NS.im_banner.skin[FFN_NS.im_banner.skinIDX].body_font_color + '; text-decoration:none;">' +  userInfo[1].img + '</a></div>';
html_code += '<div style="position:absolute; top:30px; right:5px; text-align:left; width:125px;"><a href="' + userInfo[1].href + '" target="_blank" style="font-family:verdana; font-size:11px; font-weight:normal; color:' + FFN_NS.im_banner.skin[FFN_NS.im_banner.skinIDX].body_font_color + '; text-decoration:none;">' + msg[randIDX] +'</a></div>';
html_code += '<div style="clear:both;"></div>';
html_code += '</div>';
html_code += '</div>';

document.write(html_code);

phmg_delay(gDelay);

//--[Functions]-----------------------------------------------------------------//
var phmg_timer;
var phmg_btn_elm = document.getElementById('FFN_btn_close');

phmg_btn_elm.onclick = function (){
  phmg_move(gDivID,'down');
  if(FFN_NS.im_banner.freqCap != 0){
    phmg_setCookie(gCookieName,1,FFN_NS.im_banner.freqCap,'/');
  }
  return false;
}

function phmg_delay(sec){
  sec = sec || 0;
  phmg_timer = setTimeout('phmg_checkCookie()',1000 * sec);
}

function phmg_checkCookie(){
  var ck = phmg_getCookie(gCookieName);

  if(!ck){    
    phmg_move(gDivID);    
  }else{
    clearTimeout(phmg_timer);
  }
}

function phmg_move(elmID,direction){
  var supported = (document.getElementById);
  if (!supported){
    return;
  }
  var x;
  var divPath = document.getElementById(elmID);
  var currPos = parseInt(divPath.style.top);
  var holderDisplay = document.getElementById('FFN_imBox_Container');
  holderDisplay.style.display = ''; 
  if(direction === 'down'){
    x = divPath.offsetHeight;
    if(currPos <= x){

      currPos += (currPos + 5) > x? ( (x - currPos) +1 ):5;
      divPath.style.top = currPos + 'px';
      phmg_timer = setTimeout("phmg_move('" + elmID + "','down')",30);
    }else{
      // Antimation completed clear timeout
      clearTimeout(phmg_timer);
      holderDisplay.style.display = 'none';       
    }
  }else{
    x = 0;
    if(currPos > x){
      currPos -= currPos < 5? currPos:5;
      divPath.style.top = currPos + 'px';                                              
      phmg_timer = setTimeout("phmg_move('" + elmID + "','')",30);
    }else{
      // Antimation completed clear timeout
      clearTimeout(phmg_timer);
    }
  }
}

function phmg_setCookie(name,value,expires,path,domain,secure){
  var expStr = '';
  var type   = 'H';
  var ms     = {
     Y : 31557600000,
     W : 604800000,
     D : 86400000,
     H : 3600000,
     M : 60000,
     S : 1000
         };           
  if(expires){
    var expDte = new Date();
    var expMS  = expDte.valueOf() + (ms[type] * expires);
    expDte.setTime(expMS);
    expStr     = '; expires=' + expDte.toGMTString();
  }
  
  pathStr   = ( (path   === undefined ) ? '' : ('; path=' + path) );
  domainStr = ( (domain === undefined ) ? '' : ('; domain=' + domain) ); 
  secureStr = ( (secure === undefined ) ? '' : ('; secure') ); 

  document.cookie = name + '=' + escape(value) + expStr + pathStr + domainStr + secureStr;
}

function phmg_getCookie(name){
  var output   = null;
  var cks      = ' ' + document.cookie + ';';
  var matchCk  = ' ' + name + '=';
  var startPos = cks.indexOf(matchCk);  
  var endPos;
  if(startPos != -1){
    startPos += matchCk.length;
    endPos    = cks.indexOf(';', startPos);
    output    = unescape(cks.substring(startPos, endPos));
  }
  return output;
}

// Build userData object
function userData(handle,age,sex,city,state,country,img,href){
  this.handle  = handle;
  this.age     = age;
  this.sex     = sex;
  this.city    = city;
  this.state   = state;
  this.country = country;
  this.img     = img;
  this.href    = href;
}
//--End--//
