﻿function process(){
   set_cookie ( "video", "played", 2012, 12, 12 );
}

function set_cookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure )

{
  var cookie_string = name + "=" + escape ( value );

  if ( exp_y )
  {
    var expires = new Date ( exp_y, exp_m, exp_d );
    cookie_string += "; expires=" + expires.toGMTString();
  }

  if ( path )
        cookie_string += "; path=" + escape ( path );

  if ( domain )
        cookie_string += "; domain=" + escape ( domain );
  
  if ( secure )
        cookie_string += "; secure";
  
  document.cookie = cookie_string;
  
}

function get_cookie ( cookie_name )
{
  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );

  if ( results )
    return ( unescape ( results[2] ) );
  else
    return null;
}

function video(cookie_name) {
	var p= get_cookie(cookie_name);
	if(p != null){
		return p;
	}else if (p == null){
		p="firsttime";
		return p;
	}
}

jQuery.extend(jQuery.expr[':'], {
external: function(a, i, m) 
{
    if (!a.href) 
    { 
        return false; 
    }
    if (a.hostname && a.hostname !== window.location.hostname) 
    {
        var fixedHostname = a.hostname.replace(/^\s+|\s+$/g, '').toLowerCase().replace('qa.', '').replace('stage.','').replace('www.', '');
        
        if (jQuery.inArray(fixedHostname, safeList) >= 0) {
            return false;
        }
        if (fixedHostname.indexOf('javascript') > 0 || fixedHostname.indexOf('(') > 0 )
        {
            return false;
        }
        else 
        {
            return true;
        }
    }
    else 
    {
        return false;
    }
}
});

$(document).ready(function() {
    var v = video("video");
    process();

	var currentTime = new Date()
	var date = (currentTime.getMonth()+1+'-'+currentTime.getDate()+'-'+currentTime.getFullYear());

    var flashvars = { played:v};
    flashvars.xmlfile = "/xml/homepage-playlist.xml?v=1"+date; //the path to the playlist
    flashvars.xmlfiletype = "Default";
    swfobject.embedSWF("/flash/homeVideoPlayer.swf", "bfl_homepage_video", "510", "310", "9.0.0", "/flash/expressInstall.swf", flashvars);
          
    $("div#callouts div.callout:first").css("padding-left", "0px");
    $("div#callouts div.callout:last").css("padding-right", "0px");
        
    $("h2.homepage_featured_title").corners("4px transparent top-left top-right");
    
    SetMinimumPageHeight();            
    
    $("img").ifixpng();
    $("div").ifixpng();
    
    $('a:external').addClass("external_link");
    
    $('a.socialmedia').removeClass("external_link");

    $('a').click(function(){
        if($(this).hasClass('external_link'))
        {
            if(!warn_on_leave($(this)[0].href))
            {
                return false;
            }
        }
    });
    
    $('div#bfl_homepage_video').click(function(){
        _gaq.push(['_trackEvent','Unstoppable-Tour', 'Click', 'BFL.com Flash Promo']);
        s.tl(this,'o','Unstoppable BFL Flash Promo');
    });
    
    $('a#facebook_easbrand').click(function(){
        _gaq.push(['_trackEvent','Unstoppable-Tour', 'Click', 'BFL.com Promo Box']);
        s.tl(this,'o','Unstoppable BFL Promo Box');
    });

});


