
/*   ************************************************************   */
/*   Image prelaoder - http://stackoverflow.com/questions/476679/preloading-images-with-jquery   */
/*   ************************************************************   */

function preload(arrayOfImages) {
    $(arrayOfImages).each(function(){
        $('<img/>')[0].src = this;
        // Alternatively you could use:
        // (new Image()).src = this;
    });
}

/*   ************************************************************   */
/*   jquery protect email address - http://plugins.jquery.com/project/Mailme   */
/*   ************************************************************   */
jQuery.fn.mailme = function() {
    var at = / at /;
    var dot = / dot /g;
    this.each( function() {
        var addr = jQuery(this).text().replace(at,"@").replace(dot,".");
        var title = jQuery(this).attr('title')
        $(this)
            .after('<a href="mailto:'+addr+'" title="'+title+'">'+ addr +'</a>')
            .remove();
    });
};

/*   ************************************************************   */
/*	Correct pathing between local and live servesr	*/
/*   ************************************************************   */

var pathname = window.location.pathname;
if (strstr(pathname,'/theyoungturks.com/www/')) { var host = "http://localhost/theyoungturks.com/www"; }
else{ var host = "http://dev.theyoungturks.com"; }

//alert(host);

/*   ************************************************************   */
/*   jquery protect email address - http://plugins.jquery.com/project/Mailme   */
/*   ************************************************************   */

$('span.mailme').mailme();


function jumpToAnchor(anchor){
     location.href = location.href+"#"+ anchor;
}

function scollToId(id){
   window.scrollTo(0,$("#"+id).offset().top);
}

function CurrencyFormatted(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}

/*   http://stereointeractive.com/blog/2008/11/21/javascript-get-window-hashanchor-get-link-target/   */
function getHash() {
  var hash = window.location.hash;
  return hash.substring(1); // remove #
}
 
function getLinkTarget(link) {
  return link.href.substring(link.href.indexOf('#')+1);
}

// {{{ explode
function explode( delimiter, string, limit ) {
    // Split a string by string
    // 
    // +    discuss at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_explode/
    // +       version: 809.522
    // +     original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     improved by: kenneth
    // +     improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     improved by: d3x
    // +     bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: explode(' ', 'Kevin van Zonneveld');
    // *     returns 1: {0: 'Kevin', 1: 'van', 2: 'Zonneveld'}
    // *     example 2: explode('=', 'a=bc=d', 2);
    // *     returns 2: ['a', 'bc=d']
 
    var emptyArray = { 0: '' };
    
    // third argument is not required
    if ( arguments.length < 2
        || typeof arguments[0] == 'undefined'
        || typeof arguments[1] == 'undefined' )
    {
        return null;
    }
 
    if ( delimiter === ''
        || delimiter === false
        || delimiter === null )
    {
        return false;
    }
 
    if ( typeof delimiter == 'function'
        || typeof delimiter == 'object'
        || typeof string == 'function'
        || typeof string == 'object' )
    {
        return emptyArray;
    }
 
    if ( delimiter === true ) {
        delimiter = '1';
    }
    
    if (!limit) {
        return string.toString().split(delimiter.toString());
    } else {
        // support for limit argument
        var splitted = string.toString().split(delimiter.toString());
        var partA = splitted.splice(0, limit - 1);
        var partB = splitted.join(delimiter.toString());
        partA.push(partB);
        return partA;
    }
}// }}}


