 var $j = jQuery.noConflict();

 
 $j(document).ready(function(){
   $j("#usanextmatch").click(function(e){
       e.preventDefault();
        var fxid=$j("#fxid").attr("value");

        $j.getJSON("/_scripts/ajax/usa.php?mode=nextmatch", {fxid:fxid, isusa: window.micro_usa? 1 : 0},
            function(data){
                setNextLast(data);
            });
   });

   $j("#usaprevmatch").click(function(e){
       e.preventDefault();
        var fxid=$j("#fxid").attr("value");

        $j.getJSON("/_scripts/ajax/usa.php?mode=prevmatch", {fxid:fxid, isusa: window.micro_usa? 1 : 0},
            function(data){
                setNextLast(data);
            });
   });

 });


function setNextLast(data){
    var crestpath = '/assets/images/crests/';
    $j("#usacomp").html(data.competition_venue);
    $j("#usamnulnk2").html(data.lineup);
    $j("#fxid").val(data.pa_id);
    $j("#usadt").html(data.fixture_date);
    $j("#usahcrest").attr("src", crestpath + data.home_crest);
    $j("#usaacrest").attr("src", crestpath + data.away_crest);
    $j("#usaccrest").attr("src", data.competition_crest);
    $j("#usamnulnk").attr("href", data.menu_link);
    $j("#usamnulnk2").attr("href", data.menu_link);

    if (data.tv_channel == null)
    {
       $j("#usatvchanwrap").hide();
       $j("#usafixdt").addClass('bottom');
    }else{
       $j("#usatvchanwrap").show().addClass('bottom');
       $j("#usafixdt").removeClass('bottom');
       $j("#usatvchan").html(data.tv_channel);
    }
}


 $j(document).ready(function(){
					$j("a.tooltip-link").bind("mouseenter",function(event){

						var offset = $j(this).offset();
						var aWidth = $j(this).width();
						aWidth = aWidth + offset.left - 2;

						var aHeight = $j("a.tooltip-link").height();
						aHeight = (offset.top - aHeight) - 12;

						var tipTitle = $j(this).attr("name");
						var tipContent = $j(this).attr("rel");

						var brokenstring = tipContent.split(' ');
						var words = 15;
						var string = '';
                        var concatme = '';

						var i = 0

						for (i=0;i<=words;i++)
						{
                            if (!brokenstring[i]) break;
							string += brokenstring[i] + ' ';
						}

                        if (brokenstring.length >= words)
                        {
                           concatme = '&hellip; <span class="toggle">More >></span>';
                        }

						$j(this).append(
							'<div class="tooltip-box"><div class="tooltip-content"><h4>' + tipTitle + '</h4><p class="truncated">' + string + concatme + '</p><p class="full-text">' + tipContent + '</p></div><div class="tooltip-bottom"></div></div>'
						);

						$j("div.tooltip-box").css({
							left:aWidth,
							top:aHeight
						});

						$j("p.full-text").hide().stop();

						$j(".toggle").bind("click",function(event){
							$j("p.truncated").hide().stop();
							$j("p.full-text").show().stop();
						});

					});

					$j("a.tooltip-link").bind("mouseleave",function(event){
						$j("div.tooltip-box").hide();
					});
 });
