

var BOOST = {};
BOOST.setUpMapClicks = function(){
		// map overlay things
  
    var url = document.location.href;
    if (url.match(/coverage/)){
      	viewNationalMap();
    }
  
		
		//$('.coverageMapLink').click( function(){  viewNationalMap(); setOmnitureForMapPage();  return false; } );
		$('a.coverageMapLinkUnlimited,div.buttons .coverageMap').click( function(){  
		  if ($(this).attr('href').indexOf('javascript') != -1) return true;  // if there is a javasript call in the a.href then do it instead.
		  viewRegionalMap();  return false; 
		} );
		$('#btnCloseNationalMap,#btnCloseUnlimitedMap,#btnCloseStateMap').click( function(){ 		  $('div.zipOverlay').hide(); 		} );
		$('#btnNationalMap img').click( viewNationalMap );
		
		$('#unlimitedDetail div.coverageMap').click (viewRegionalMap );
		$('#unlimitedDetail div.coverageMap').click (viewRegionalMap );
		$('div.coverageMap_pp').click ( function(){  viewRegionalMap();  setOmnitureForMapPage(); document.location.href="#"; } );
}




BOOST.init = function(){
    
    //tablecloth();

    
    //zebra stripes
	  $('table tbody tr:odd').addClass('odd');  

    	// set up collapseable definitions
		$('dd').hide();
	    
		$('dt').click(function(){
			if ($(this).hasClass('expanded')) {
				$(this).removeClass('expanded').next().slideUp('fast');
			}
			else{
				$(this).addClass('expanded').next().slideDown('fast');	
			}
		});
		
		
		$('div.planTiles > div').fitted();
		
		//view plan details
		$('a.closeDetailsLink').hide();
		$('a.viewDetailsLink').click( function(){
			
		        $('a.viewDetailsLink').addClass('on');
		        $('div#planDetails').slideDown("fast",function(){
		            $('a.viewDetailsLink').hide();
		            $('a.closeDetailsLink').show();
		        });
		        setOmnitureForDetailPage();
			    window.unlimitedOverlayReplaces();
			    window.paygoOverlayReplaces();
			    
			return false; // dont follow # link
		});
		$('a.closeDetailsLink').click( function(){
		    $('a.viewDetailsLink').removeClass('on');
		    $('div#planDetails').slideUp("fast",function(){
		        $('a.closeDetailsLink').hide();
		        $('a.viewDetailsLink').show();
		    });
			return false; // dont follow # link
		});
		
		
		$('div#planDetails a.close').click( function(){
			$('div#planDetails').slideUp(); 
			$('a.viewDetailsLink').removeClass('on');
			$('a.closeDetailsLink').hide();
		    $('a.viewDetailsLink').show();
			return false;
		});
		
		
		
		// phone info toggles
		$('.also-available.swapc290-on img').click( function(){ $('.swapc290-on').hide(); $('.swapc290-off').show();      });
		$('.also-available.swapc290-off img').click( function(){ $('.swapc290-off').hide(); $('.swapc290-on').show();      });
		
     BOOST.setUpMapClicks();
	
	    $('.color-white-boxes dt').hover( function(){  $(this).addClass('hovered'); }, function(){ $(this).removeClass('hovered');  });
	    $('dt').hover( function(){  $(this).addClass('hovered'); }, function(){ $(this).removeClass('hovered');  });
	    $('#planNav a').hover( function(){  $(this).addClass('hover'); }, function(){ $(this).removeClass('hover');  });
	    
	    
	    //start rollovers
	    $(".viewDetailsLink").hover(function(){ 
		    $(this).addClass("hover"); 
		    },function(){ 
		      $(this).removeClass("hover"); 
	    });
	    $(".closeDetailsLink").hover(function(){ 
		    $(this).addClass("hover"); 
		    },function(){ 
		      $(this).removeClass("hover"); 
	    });
	    $(".coverageMapLink").hover(function(){ 
		    $(this).addClass("hover"); 
		    },function(){ 
		      $(this).removeClass("hover"); 
	    });
	    
	    
      $('a.findAStore,a.storeLocatorLink').click(function(){
        var url = document.location.href;
        if (url.match(/unlimited/)){
          $('#unlimitedreboost,#unlimitedphones').val('Yes');
        } else if (url.match(/(chat)|(paygo)|(premium)|(walkie)/)){
          $('#paygo10reboost,#paygoreboost,#paygophones').val('Yes');
        }
        $('#locatorForm input.zipcode').val(session.zipCode); //set the zipcode
        $('#locatorForm').submit();
        return false;
      });
  
      
      
      
      $('a.learnMore,div.buttons a').bind('mousedown',function(){
  
        if ($(this).css('position') == 'absolute'){
          try{
              $(this).css({
                top: (parseInt( $(this).css('top') , 10) + 1) + 'px !important',
                left: (parseInt( $(this).css('left') , 10) + 1) + 'px !important' 
              });
          }catch(e){}
          
        } else {
          $(this).css({position:'relative',top:'1px',left:'1px'});
        }
      
      }).bind('mouseup',function(){
        $(this).css({
            top: '',
            left: ''
          });
      });
	  
	  //setup pulldowns for user guides and videos
	$('.pulldowns a.collapsed').click(function(){
		$(this).next('div.container').slideDown('fast'); 
		return false;
	});
	$('.pulldowns a.expanded').click(function(){
		$(this).parent('div.container').slideUp('fast'); 
		return false;
	});

} // end of init()	
		




/******************/
/* image toogle */
/******************/

  startmenu = menu0func = menu1func = menu2func = menu3func = menu4func = menu5func = function(){};
  

$(function(){

  $('div.also-available a').click (function(e){
    $('div.featured-phone div.phone').hide().filter( $(this).attr('href') ).show();
    $('div.also-available div.phone').show().filter(':has([href='+ $(this).attr('href')+'])' ).hide();
  }).filter(':contains(i9)').add('#selectedphone').filter(':last').click();

});


/*****
* Ajax Methods
*/




function getPlans(){
    var zipCode = $get('zipCode').value;
   //set the cookie if it already does not exits
   //check if the cookie exits and has the same value
   var cookieValue = getCookie("ZipCode");
   if(cookieValue == zipCode){
    //cookie is already there dont do anything
   }else{
    //set cookie
    setCookie( "ZipCode" ,zipCode, 365); 
   }
   ZipCodeWebService.GetPlans(zipCode, onSuccess);
}

function onSuccess(result){
   $('#loader').remove();
   resultPlan = result;
   Sys.Debug.trace(result);
   showPlans(result);
}

/*
* This is the email notification stub call the function with zipcode and email
*/
function saveEmail(){
    EmailWebService.SaveEmail(zipcode, email);
}

function showPlans(result){
    var zipcode = $get('zipCode').value;
    $('#locatorForm input[type="hidden"][name="zipcode"]').val(zipcode); // set the zip on landing pages..
    var regionName;
    if(result.length>0){
        
        
        for(var x=0; x<3; x++){
          
         
          if ($("#planPrice_"+x).is('.sIFR-replaced')){ // we've been sifred replaced.
             $("#planPrice_"+x).removeClass('sIFR-replaced').empty().html("$"+result[x].Cost);
             unlimitedOverlayReplaces();
          } else {
            $("#planPrice_"+x).html("$"+result[x].Cost);
          }
          
          
            //$("planPrice_"+x+"_Desc").innerHTML = result[x].Plan.Description;
            $("#Table_Plan_"+x+"_Price").removeClass('sIFR-replaced').html("$"+result[x].Cost);
            
            
            if (result[x].ExtendedHomeCallingCost == 0){
                $get("Plan_"+x+"_ExtendedCalling").innerHTML ="N/A";
            }
            else{
                $("#Plan_"+x+"_ExtendedCalling").html("$"+ result[x].ExtendedHomeCallingCost+"/Month");
            }
            
            if ( $('#vmtd'+x).length == 0 ) continue; // dont continue if we're not on the unlimited page.
            
              
              if (result[x].HasVoiceMail) {
                $('#vmtd'+x).html('Included');
              }
              else if (result[x].HasVoiceMail === 'false') { 
                $('#vmtd'+x).html('Not Included'); 
              }
              else { 
                $('#vmtd'+x).html('N/A'); 
              }
              
              
              
        }
        
        
        session.zipCode = zipcode;
        session.mapImg = result[0].CoverageArea.ImageCode;
        session.regionName = result[0].CoverageArea.CoverageAreaName;
        if(result[0].CoverageArea.ExtendedCoverageArea != null){
            session.mapExtendedImg = result[0].CoverageArea.ExtendedCoverageArea.ImageCode;
         }else{
            $get('btnExtendedMap').style.display="none";
         }
        
        $('#ZipCodeContainer').hide();
        $('#coverageArea').html(result[0].CoverageArea.CoverageAreaName);
        $('#priceContainer').show();
        
        regionName = result[0].CoverageArea.CoverageAreaName;
        
        //if valid zip is provided, then we need to show the Home Calling Area links
        showHomeCallingAreaLinks();
       
        $(".priceInfo").show();
        
        if (typeof unlimitedReplaces == 'function'){
          unlimitedReplaces(); // defined in sifr-config;
          unlimitedPriceReplaces();
          unlimitedOverlayReplaces();
        }
        
        if (typeof landingpageSifr == 'function'){
          landingpageSifr(); // defined in landing-sifr-config;
        }
        
              
    }else{
        //show the email textbox and call the emailnotificationweb service
        
            //var pos = $('#Plan_0_Compare').offset();
            //if (pos.left && pos.top)
            //  $('#emailContainer').css({ left: pos.left, top: pos.top  });
            $('#emailContainer').show();
            
            $get('ZipCodeContainer').style.display = "none";
            for(var x=0; x<3; x++){
                 //$get("Table_Plan_"+x+"_Desc").innerHTML = "Zipcode Needed";
                 $("#Table_Plan_"+x+"_Price").html('');
                 $("#Plan_"+x+"_ExtendedCalling").html('');
            }
            regionName = "Region Unavailable";
             $('#planDetails div.priceInfo').hide();
           
        //if invalid zip is provided, then we need to hide w the Home Calling Area links
        hideHomeCallingAreaLinks();
    }
    
    //Omniture implementation
    
     setOmnitureForZip(zipcode, regionName);
    
}



function changeZip(){
    $('#priceContainer').hide();  
    $('#ZipCodeContainer').show();
    $('#emailContainer').hide();
    $('#ThankYouDiv').hide();
    
    $('div.content:first p.disclaimer').hide();
    
    setCookie( "ZipCode" ,'', 365); 
}
    
 /*
 * function to create a javascript cookie
 * source:http://www.w3schools.com/js/js_cookies.asp
 */
 function setCookie(c_name,value,expiredays)
{
    var exdate=new Date()
    exdate.setDate(exdate.getDate()+expiredays)
    document.cookie=c_name+ "=" +escape(value)+
    ((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
}
 
 /*
 *function to retrive a cookie
 * source: http://www.w3schools.com/js/js_cookies.asp 
 */
function getCookie(c_name)
{
    if (document.cookie.length>0)
      {
          c_start=document.cookie.indexOf(c_name + "=")
          if (c_start!=-1)
            { 
                c_start=c_start + c_name.length+1 
                c_end=document.cookie.indexOf(";",c_start)
                if (c_end==-1) c_end=document.cookie.length
                return unescape(document.cookie.substring(c_start,c_end))
            } 
      }
    return ""
}

/*
* checks for cookies and zipcode if the user had entered it in last one year
* if yes sets the cookie value else does nothing
*/

function unLimitedOnLoad(){
   
	    $(".coverageMapLinkUnlimited").hover(function(){ 
		    $(this).addClass("hover"); 
		    },function(){ 
		      $(this).removeClass("hover"); 
	    });
	    
    var zipCode = $get('zipCode');
  
   /*
   * Check of the cookie exists,
   * If yes read from the cookie and make the ajax call
   * 
   */
    var cookieValue = getCookie("ZipCode");
    //check if the cookie value exists
    if(cookieValue){
        zipCode.value = cookieValue;
        //ZipCodeWebService.GetPlans(zipCode, onSuccess);
        getPlans();
        
   }else{
        $(".priceInfo").hide();
        
        //if no zip, then we need to hide the Home Calling Area links
        hideHomeCallingAreaLinks();
        
        setOmnitureForNoZip();
   }
    
}

function hideHomeCallingAreaLinks(){  //if no zip, then we need to hide the Home Calling Area links
    $('#hcaNoLink').show();
    $('#hcaWithLink').hide();
}
function showHomeCallingAreaLinks(){
    $('#hcaNoLink').hide();
    $('#hcaWithLink').show();
}

function setOmnitureForZip(zipcode, regionName){
    
    //clear the variables
       void(s.t());
    s.pageName = "Unlimited with Zip - Plan Detail";
    s.channel ="Shop";
    s.prop2 = "Browse Plans Section";
    s.events = "event13";
    s.prop5 =  zipcode;
    s.evar18 = regionName;

    var s_code=s.t();
    if(s_code)document.write(s_code); 
    
    Sys.Debug.trace(s);
}

function setOmnitureForNoZip(){
 /*SiteCatalyst Variables */
    //clear the variables
    void(s.t());
    //set the values
    s.pageName = "Unlimited Plan";
    s.channel ="Shop";
    s.prop2 = "Browse Plans Section";
    s.events = "event13";

    var s_code=s.t();
    if(s_code)document.write(s_code);

    //Sys.Debug.trace(s);

}



function compareOnLoad(){
    var cookieValue = getCookie("ZipCode");
    
    if(cookieValue){
       //$('#ZipCodeContainer').html('Loading...');
        ZipCodeWebService.GetPlans(cookieValue, onCompareSuccess);   
    }else{
        var pos = $('#Plan_0_Compare').offset();
        $('#enter-zip').css({ left: pos.left, top: pos.top  });
        $('#enter-zip').show();
        $('#emailContainer').hide();
        
        //Omniture code
        s.pageName = "Compare All Plans";
        s.channel = "Shop";
        s.prop2 = "Browse Plans Section";
        s.events = "event13";
        
        //Omniture code do not alter
        var s_code=s.t();
        if(s_code)document.write(s_code);

    }

}

function submitEmail(){
    var emailValue = $get('email').value;
    var zipCode = $get('zipCode').value;
    EmailNotificationWebService.SaveEmail(emailValue, zipCode, emailSubmitSuccess);  
}

function emailSubmitSuccess(result){
   if(result){
    $get('ThankYouDiv').style.display ="";
    $get('emailContainer').style.display = "none";
    $get('ZipCodeContainer').style.display="none";
   }
}

function onCompareSuccess(result){
    if(result.length>0){
        for(var x=0; x<3; x++){
            $get("Plan_"+x+"_Compare").innerHTML = "<div>" + result[x].Plan.Description+"</div><span>"+ "$"+ result[x].Cost+"/</span>month";
            
            if (result[x].ExtendedHomeCallingCost == 0){
                $get("Plan_"+x+"_ExtendedCalling").innerHTML ="N/A";
            }
            else{
                $get("Plan_"+x+"_ExtendedCalling").innerHTML ="$"+ result[x].ExtendedHomeCallingCost+" month";
            }
        } 
          $get('enter-zip').style.display= "none";
    }else{
        //$get('enter-zip').style.display= "";
        //Show the Email Div
        
        var pos = $('#Plan_0_Compare').offset(); // we want to position Email Container on top of Plan 0
        if (pos.left && pos.top)
            $('#emailContainer').css({ left: pos.left, top: pos.top  });
            
        $get('emailContainer').style.display = "";
    }
    
     //Omniture code
            
            //clear the variables
            
            void(s.t());
            
            s.pageName = "Compare All Plans with zip";
            s.channel = "Shop";
            s.prop2 = "Browse Plans Section";
            s.events = "event13";
            s.prop5 =  zipcode;
            s.evar18 = regionName;
            
            //Omniture code do not alter
            var s_code=s.t();
            if(s_code)document.write(s_code);
  }

function compareSubmitZipCode(){
    var zipCode = $get('zip-code').value;
    
    if (zipCode=='Enter Zip') {
        alert('Please enter a valid Zip code');
    }
    else {
        //make the Ajax Call
        ZipCodeWebService.GetPlans(zipCode, onCompareSuccess);
    }    
}

function compareSubmitEmail(){
    var zipCode = $get('zip-code').value;
    var email = $get('email').value;
    
    if (email=='Email') {
        alert('Please enter a valid email address');
    }
    else {
        EmailWebService.SaveEmail(zipCode, email, comeback);
    }
}



function planHubOnLoad(){
    
	$(".learnMore").hover(function(){ 
		$(this).addClass("hover"); 
		},function(){ 
		  $(this).removeClass("hover"); 
	});
	
	
    //read from the cookie and put the value in the textbox
    var zipCode = $get('ZipCode');
     var cookieValue = getCookie("ZipCode");
    //check if the cookie value exists
    if(cookieValue){
        zipCode.value = cookieValue;
   }
}

function unlimitedSubmit(){
    
    // add a loading spinner
    $('#ZipCodeContainer')
      .find('input[type=image],a.submitzip')
      .after('<div id="loader"></div>');
    
    var zipCode = $get('zipCode').value
    //var cookieValue = getCookie("ZipCode");
    
    if (!isValidZipCode(zipCode)) {
        alert('Please enter a valid Zip code');
        $('#loader').remove();
    }
    else {
         getPlans();
    }
   
}
function planHubSubmit(){
    var zipCode = $get('ZipCode').value
    //var cookieValue = getCookie("ZipCode");
    
    if (!isValidZipCode(zipCode)) {
        alert('Please enter a valid Zip code');
    }
    else {
        //rewrite the cookie
        setCookie( "ZipCode" ,zipCode, 365);    
        document.location.href = "unlimited.aspx";
    }
}
function isValidZipCode(submittedZip){
    if(submittedZip=='Enter Zip'){
        return false;
    }
    //if it's less or more than 5 characters
    /*if(submittedZip.length>5 || submittedZip.length<5){
        return false;
    }*/
    //check if 5 numbers long
    var re = /^\d{5}?$/;
    return (re.test(submittedZip));
}




// map viewing script from boostmobile.com

function viewNationalMap(){
	//$('#headerFlash').css({visibility,'hidden'});
	$('#stateMap').hide();
	$('#nationalMap').show();
	//	doc.tracking.sendSClickHit('viewNationalMap');
	window.scrollTo(0,0);
}

function viewStateMap( state, stateName ){
	var img = $('#stateMapImg').attr('src','http://plans.boostmobile.com/images/maps/BSMB_' + state + '_WEB.gif');
	$('span#stateName').html(stateName);
	//$('#headerFlash').css({visibility,'hidden'});
	$('#stateMap').show();
	$('#nationalMap').hide();
	window.scrollTo(0,0);
}




    // temporary variable.
		var session = {mapImg: '', regionName : '', mapExtendedImg: '', zipCode: '' }
		
		
function viewRegionalMap(evt){

	//if(! session.zip)	$('zipChecker2').show();
	
	
	// after zip check in submitZip;
	  /*
		if(session.mapImg == null) {
			// if zip set on page 2 and then return to page 1 to view map
			// get mapImg and regionName from ajax call
			session.checkAvailability(session.zip,1);
			return;
		}		
		*/
		
		
		var img = document.getElementById('unlMapImg');
		img.width  = '696';
		img.height = '761';
		img.style.backgroundImage = "url('http://plans.boostmobile.com/images/maps/unl_regional/BSMB_" + session.mapImg + "_WEB.gif')";
		img.src = 'http://plans.boostmobile.com/images/maps/unl_regional/BSMB_' + session.mapImg + '_WEB.gif';


		var regionName = $('#unlRegionName').html(session.regionName);
		//displayUnlimitedPrice();
		$('#zipChecker2').hide();
		//doc.dhtml.toggleVisibilityById('headerFlash','hidden');
		$('#unlimitedMap').show();
		$('#emailSubmitWrap').hide();
		//$('#btnViewNationalMap').css({visibility:'visible'});


		//doc.tracking.sendSClickHit('viewRegionalMap');
window.scrollTo(0,0);
}

function viewRegionalNationalMap(){
    //$('#btnViewNationalMap').css({visibility:'hidden'});
		var img = document.getElementById('unlMapImg');
		img.width  = '696';
		img.height = '461';
		img.style.backgroundImage = "url('http://plans.boostmobile.com/images/maps/unl_national/BSMB_NAT_" + session.mapImg + "_WEB.png')";
		img.src = 'http://plans.boostmobile.com/images/maps/unl_national/BSMB_NAT_' + session.mapImg + '_WEB.gif';
		//img.src = doc.utils.baseURL +'images/maps/unl_regional/BSMB_NAT_WEB.gif';
		//img.style.backgroundImage = "url('" + doc.utils.baseURL +"images/maps/unl_regional/BSMB_NAT_WEB.gif')";
		$('#unlRegionName').html(session.regionName);
		//regionName.innerHTML = 'National';
		window.scrollTo(0,0);
}



function viewExtendedMap(){
    //$('#btnViewNationalMap').css({visibility:'hidden'});
		var img = document.getElementById('unlMapImg');
		img.width  = '696';
		img.height = '761';
		img.style.backgroundImage = "url('http://plans.boostmobile.com/images/maps/unl_extended/BSMB_EXT_" + session.mapExtendedImg + "_WEB.png')";
		img.src = 'http://plans.boostmobile.com/images/maps/unl_extended/BSMB_EXT_' + session.mapExtendedImg + '_WEB.gif';
		//img.src = doc.utils.baseURL +'images/maps/unl_regional/BSMB_NAT_WEB.gif';
		//img.style.backgroundImage = "url('" + doc.utils.baseURL +"images/maps/unl_regional/BSMB_NAT_WEB.gif')";
		$('#unlRegionName').html(session.regionName);
		//regionName.innerHTML = 'National';
		window.scrollTo(0,0);
}



function closeMap( evt ){
	var btn = doc.dhtml.getTargetId(evt);	
	btn = btn.toLowerCase();
	var openedMap = ((btn.indexOf('national') > -1) ? 'national' : (btn.indexOf('state') > -1) ? 'state' : 'unlimited') + 'Map';
	doc.dhtml.toggleDisplayById(openedMap,'none');

}


function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=430,height=450,left = 745,top = 420');");
}


// cache background images!
try {
  document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}



BOOST.landinginit = function(){ 
  
  $('#planDetails div.priceInfo').hide();
  
  $('#planDetails table tr:odd').addClass('odd');  
  
  $('#ZipCodeContainer a.submitzip').click(function(){
    
    unlimitedSubmit(); return false;
  });
  
  BOOST.zipInputText = $('#zipCode').val();
  $('#zipCode')
    .focus(function(){
      if ($(this).val() == BOOST.zipInputText) $(this).val('');
    })
    .blur(function(){
      if ($(this).val() == '') $(this).val(BOOST.zipInputText);
    })
    .keydown(function(e){
        if (e.keyCode == 13) {  // on enter.. submit it!
            $(this).next().click(); // assumes sumbit button is following in the dom.
        }
    });
    
  BOOST.setUpMapClicks();  
  
  $('#locpaygo,#locunltd').val('');
  
  // find a store links submit the form too.
  $('a.findAStore,a.storeLocatorLink').click(function(){
  
    var url = document.location.href;
    if (url.match(/unlimited/)){
      $('#locpaygo').val('Yes');
    } else if (url.match(/(chat)|(paygo)|(premium)|(walkie)/)){
      $('#locunltd').val('Yes');
    }
    $('#locatorForm').submit();
    return false;

  });
  
  
  
  
  
}





//image preload
var preload = new Image();
preload.src = "../img08/landing/ajax-loader.gif";   





/**
* Fitted: a jQuery Plugin
* @author: Trevor Morris (trovster)
* @url: http://www.trovster.com/lab/code/plugins/jquery.fitted.js
* @documentation: http://www.trovster.com/lab/plugins/fitted/
* @published: 11/09/2008
* @updated: 29/09/2008
* @requires: jQuery v.1.2.6 or above
* 
* @notes: 
* Also see BigTarget by Leevi Graham - http://newism.com.au/blog/post/58/bigtarget-js-increasing-the-size-of-clickable-targets/ 

// usage: $('div.withLinkInsideIt).fitted();
*/
if (typeof jQuery != 'undefined') {
    jQuery(function($) {
        $.fn.extend({
            fitted: function(options) {
                var settings = $.extend({},
                $.fn.fitted.defaults, options);
                return this.each(function() {
                    if ($.fn.jquery < '1.2.1') {
                        return
                    }
                    if ($(this).find('a').length == 0) return this;
                    var $t = $(this);
                    var o = $.metadata ? $.extend({},
                    settings, $t.metadata()) : settings;
                    if ($('a',$t).length) {
                        var $a = $t.find('a:first');
                        var href = $a.attr('href');
                        var title = $a.attr('title');
                        if (typeof o['title'] != 'undefined' && o['title'] === true) {
                            $t.attr('title', 'Go to "' + href + '"')
                        }
                        $t.addClass(o['class']['container']).hover(function() {
                            $h = $(this);
                            $h.addClass(o['class']['hover'])
                        },
                        function() {
                            $h = $(this);
                            $h.removeClass(o['class']['hover'])
                        }).click(function(evt) {
                            if ($a.is('[rel*=external]')) {
                                window.open($a.attr('href'));
                                return false
                            } else if ($a.data && $a.data('offToEng')) { 
                              // this is an espanol modal
                              // if they clicked on the A tag proper, let it go
                              if ($(evt.target).data('offToEng') || $(evt.target).parent().data('offToEng')){
                                return true;
                              } else{
                                // they clicked on another part of the fitted box
                                $a.click();
                              }
                                
                            } else {
                                window.location = href
                            }
                        })
                    }
                })
            }
        });
        $.fn.fitted.defaults = {
            'class': {
                'container': 'fitted',
                'hover': 'hovered'
            },
            'title': true,
            'status': false
        }
    })
}

