function getLatest(type){
var params = "config=" + configURL;

if(type && type!='all'){
params += "&filter=" + type;
}

loadP2(params, type);

return false;
}

function getLatestPage(pageNo, type){
var params = "config=" + configURL + "&pageNo=" + pageNo;

if(type && type!='all'){
params += "&filter=" + type;
}

$j('html, body').animate({scrollTop: $j('#p2').offset().top}, 200);
loadP2(params, type);

return false;
}

function loadP2(params, type){
$j('#latest-nav a').removeClass('selected');
if(type) $j('#latest-nav .' + type.toLowerCase() + ' a').addClass('selected');

$j('#p2 .ajax-loader').show();

$j('#ajax-p2').slideUp(700, function(){
$j.ajax({
url: "/global/music/franchises/posted/ajax/latest.jhtml",
data: params,
success: function(data){
$j("#ajax-p2").replaceWith(data);
//Hide p2 again... otherwise slide down won't work
$j("#ajax-p2").hide();
$j('#ajax-p2').slideDown(700);
$j('#p2 .ajax-loader').hide();

meteorFShare();	
FB.Share.renderAll();
meteorRetweet();
addHoverEffects();	
}
});
});
}

function addHoverEffects(){
$j("li.p2_promo").hover(function(){
if(($j(this).hasClass('twitter') == false) && ($j(this).hasClass('facebook') == false)){
$j('.share', this).css('visibility', 'visible');
$j('.callToAction', this).css('visibility', 'visible');
$j(".promoArea", this).stop().animate({bottom:"0px"},{queue:false,duration:180});
$j(this).addClass('hover');	

$j(".promoAction", this).stop().animate({bottom:'120px', opacity:'1'},{queue:false,duration:200});
$j(".fb, .retweet", this).stop().animate({bottom:"165px"},{queue:false,duration:200});

$j(".fade", this).fadeOut("fast");
$j(".p2-overlay", this).stop().animate({opacity:"0.6"},{queue:false,duration:200});
}
}, function() {
if($j(this).hasClass('twitter') == false && $j(this).hasClass('facebook') == false){
$j('.share', this).css('visibility', 'hidden');
$j('.callToAction', this).css('visibility', 'hidden');
$j(".promoArea", this).stop().animate({bottom:"-10px"},{queue:false,duration:200});
$j(this).removeClass('hover');
$j(".promoAction", this).stop().animate({bottom:'0px', opacity:'0'},{queue:false,duration:200});
$j(".fb, .retweet", this).stop().animate({bottom:"0px"},{queue:false,duration:200});
$j(".fade", this).fadeIn("fast");
$j(".p2-overlay", this).stop().animate({opacity:"0"},{queue:false,duration:200});
}
});	
}

function meteorFShare(){

$j('a[name=fb_share]').each(function(){
var share = $j(this).attr('share_url') || '';
var href = $j(this).attr('href') || '';
var newShare = "";

if(href){
if(href.indexOf('?') != -1){
newShare = href + '&fbid=' + $j('#fbid').val();
}else{
newShare = href + '?fbid=' + $j('#fbid').val();
}

$j(this).attr('href', newShare);

} else if(share){

if(share.indexOf('?') != -1 || href.indexOf('#') != -1){
newShare = share + '&fbid=' + $j('#fbid').val();
}else{
newShare = share + '?fbid=' + $j('#fbid').val();
}

$j(this).attr('share_url', newShare);	

}

$j(this).click(function(){
meteor.tracking.track_conversion(meteor_key,{'name':'fb:'+share});	
});

});

}

function meteorRetweet(){

//Add click events
$j('.retweet').click(function(event){
//Don't let the link go anywhere!
event.preventDefault();

var href = this.href || '';
var newShare = "";

if(href.indexOf('?') != -1 || href.indexOf('#') != -1){
newShare = href + '&fbid=' + $j('#fbid').val();
}else{
newShare = href + '?fbid=' + $j('#fbid').val();
}

//Shorten link
BitlyClient.shorten(encodeURIComponent(newShare), 'shortenResponse');

meteor.tracking.track_conversion(meteor_key,{'name':href});	
});

$j.ajax({
url: "/global/music/franchises/posted/includes/meteor_counter.jhtml",
dataType: 'json',
success: function(data){
$j('.retweet').each(function(){
var url = $j(this).attr('href');
var count = data[url];

if(count)
{
$j(this).prepend('<strong class="vert">' + count + '</strong>');
}
});
}
});
}

var shortenResponse = function(data) {
for ( var url in data.results ) {
var hash = data.results[url].userHash;
var fbidIndex = url.indexOf('fbid');
var origUrl = url.substring(0,fbidIndex-1);
var elems = $j('.share').find('.retweet[href=' + origUrl + ']');

for ( var i = 0; i < elems.length; i++ ) {
var title = elems.parent().parent().find('.promoArea .title').text();
var href = "http://twitter.com/home?status=" + encodeURIComponent(title + " http://bit.ly/") + hash;

window.open(href,"_blank");
}
}
};

$j(document).ready(function($) {	
meteorFShare();
addHoverEffects();
meteorRetweet();

if(jQuery.browser.msie){
MTVN.resetPageTitle();
}
});

var com_mtvi_attpostedflag = true;

try{
if (typeof(MTVN.Ads.additionalValues != 'undefined'))
MTVN.Ads.additionalValues += 'event=att10';
}catch(e){
//console.log(e);
}

try{
if (typeof(dispatcher.setAttribute) == 'function')
dispatcher.setAttribute('prop44', 'att10');	
} catch(e){
//console.log(e);
}


