$(document).ready(function() {

    // TABS
    $(".tabs").each(function(arr1) {
        
        var tTab = $(this);
        tTab.append('<div class="tablinks"></div>');
        tTab.append('<div class="tabcontentholder"></div>');
        tTab.append('<div class="tabfooter"></div>');
        
        var tLinks = tTab.children(".tablinks");
        var tContent = tTab.children(".tabcontentholder");
        var numTabs = tTab.children(".tabcontent").length;
        
        tTab.children(".tabcontent").each(function(idx) {
            var linkName = arr1 + '-' + (idx+1);
            
            tLinks.append('<a class="tab" href="#' + linkName + '" class="crosslink">' + $(this).attr("title") + '</a>');
            
			tLinks.bind("click", function() {
							if (typeof(stopFlashPlayers) != "undefined") {
            						stopFlashPlayers();
									startFlashPlayers(); 
							};
										  });

			
            var aLink = tLinks.children("a").eq(idx);
            
            aLink.addClass("tab-"+(idx+1));
            
            aLink.bind("click", function() {
                tLinks.children("a.active").removeClass("active");
				
                $(this).addClass("active");
                tTab.find(".tabcontent.active").removeClass("active");
                tTab.find(".tabcontent").eq(idx).addClass("active");
                $(this).blur();
            });
            
            if (idx == 0) {
                aLink.addClass("start");
            }
            else if (idx == numTabs-1)
                aLink.addClass("end");
            
            $(this).remove().appendTo(tContent);
            
            $(this).attr("title", "");
        });
    
    });
    
    var myAnc = document.location.toString().split(',')[1]; 
    var myFile = document.location.toString().split(',')[0];
    
    $('.tabs .tablinks a.start').click();
    
    if (myFile.match('#')) {
        var myAnchor = myFile.split('#')[1];
        var myTabs = myAnchor.split("-")[0];
        var myTab = myAnchor.split("-")[1] - 1;
        
        $('.tabs').eq(myTabs).find(".tablinks a").eq(myTab).click();
    }
    
    if (myAnc != undefined) {
        location.href = "#" + myAnc;
        location.href = "#" + myAnchor + "," + myAnc;
    }
    
    $("a.crosslink").bind("click", function() {
        var file = document.location.toString().split("#")[0];
        var newFile = $(this).attr("href").split("#")[0];
		
        
        if (file.substring(file.lastIndexOf("/")+1) == newFile.substring(newFile.lastIndexOf("/")+1)) {
            var myAnchor = $(this).attr("href").split('#')[1];
            var myTabs = myAnchor.split("-")[0];
            var myTab = myAnchor.split("-")[1] - 1;
        
            $('.tabs').eq(myTabs).find(".tablinks a").eq(myTab).click();
        }
    });
    
    $(".tabs .tabcontent .tabcontentitem").hover(function() {
        $(this).addClass("active");
    }, function() {
        $(this).removeClass("active");
    });
    // / TABS
    
    // MENU
    $("#nav ul.main li").hover(function() {
        $(this).addClass("hover");
        $(this).children("ul").show();
    }, function() {
        $(this).removeClass("hover");
        $(this).children("ul").hide();
    });
	
	
	 $("#nav ul.main li").bind("click", function() {
					if (typeof(stopFlashPlayers) != "undefined") {
            						stopFlashPlayers();
									startFlashPlayers(); 
					};
	 });							
   
    // / MENU

    $("ul.blueinline li a").hover(function() {
    
        $("ul.blueinline li.hover").removeClass("hover");
        $(this).parent().addClass("hover");
    
    }, function() {
    
        $(this).parent().removeClass("hover");
        
    });
    
    $.ifixpng('img/blank.gif');
    $('img[@src$=.png]').ifixpng();
    //$('.png').ifixpng();
    
    $("#dauclose, #daubackground").bind("click", function() {
        $("#dauswf").remove();
        //$("#wrapper").show();
        $("#dau").hide();
        
        if (typeof(startFlashPlayers) != "undefined")
            startFlashPlayers();
    });
    
    $("a#experience").bind("click", function() {
        //$("#daubackground").css("opacity", 0.85);
        
        //$("#mainflashplayer").remove();
        if (typeof(stopFlashPlayers) != "undefined")
            stopFlashPlayers();
        
        $("#dau").height($(document).height());
        $("#dau").width($(document).width());
        
        $("#dau").show();
        
        $("#dauflash").css("left",($(document).width()/2) - ($("#dauflash").outerWidth({margin:true})/2));
        $("#dauflash").css("top",($(window).height()/2) - ($("#dauflash").outerHeight({margin:true})/2));

        var so = new SWFObject('swf/DAU_Interactive.swf','dauswf','720','533','8');
        so.addParam('menu','false');
        so.addParam('wmode','transparent');
        so.write("dauflashholder");
        
        //$("#wrapper").hide();
    });
    
	//old drop list to video player
    $("#sportsdd_old ul.advert a, .background100lt_old a.video").bind("click", function() {
        if (typeof(stopFlashPlayers) != "undefined")
            stopFlashPlayers();
        
        var str = "<div id='sportsvids'><div class='holder'><iframe frameborder='0' width='100%' height='100%' src=\"" + $(this).attr("href") + "\"></iframe></div></div>";
        $("body").prepend(str);
        
        var vids = $("#sportsvids");
        var hold = $("#sportsvids .holder");
        
        vids.height($(document).height());
        vids.width($(document).width());
        
        vids.show();
        
        hold.height($(window).height() - 40);
        hold.width(630);
        
        hold.css("left",($(document).width()/2) - (hold.outerWidth({margin:true})/2));
        hold.css("top",($(window).height()/2) - (hold.outerHeight({margin:true})/2));
        
        vids.click(function() { $(this).remove(); });
        
        $("#sportsvidlist").hide();
        
        return false;
    });
	
	$("#sportsdd ul.advert a, .background100lt a.video").bind("click", function() {
        if (typeof(stopFlashPlayers) != "undefined")
            stopFlashPlayers();        
        $("#sportsvidlist").hide();
		var ssvidurl = $(this).attr("href");
		window.open(ssvidurl,'mywindow','width=1184,height=540,left=0,top=20,screenX=0,screenY=20,resizable=no,resizable=no,toolbar=no,location=no,directories=no,status=no,menubar=no') 
        
        return false;
    });

	
	// -- hack for calling sports sponsor page from what's hot.	
	    $(".tabcontentitem end, a.video_spon2").bind("click", function() {
        if (typeof(stopFlashPlayers) != "undefined")
            stopFlashPlayers(); 
        
        var str = "<div id='sportsvids'><div class='holder'><iframe frameborder='0' width='100%' height='100%' src=\"" + $(this).attr("href") + "\"></iframe></div></div>";
        $("body").prepend(str);
        
        var vids = $("#sportsvids");
        var hold = $("#sportsvids .holder");
        
        vids.height($(document).height());
        vids.width($(document).width());
        
        vids.show();
        
        hold.height($(window).height() - 40);
        hold.width(630);
        
        hold.css("left",($(document).width()/2) - (hold.outerWidth({margin:true})/2));
        hold.css("top",($(window).height()/2) - (hold.outerHeight({margin:true})/2));
        
        vids.click(function() { $(this).remove(); });
        
        $("#sportsvidlist").hide();
        
        return false;
    });
	
	
	// ---- Copy Com page
    $("#commcopydd ul.advert a").bind("click", function() {
        if (typeof(stopFlashPlayers) != "undefined")
            stopFlashPlayers();
        
        var comstr = "<div id='commcopypage'><div class='holder'><iframe frameborder='0' scrolling='no' width='100%' height='100%' src=\"" + $(this).attr("href") + "\"></iframe></div></div>";
        $("body").prepend(comstr);
        
        var comvids = $("#commcopypage");
        var comhold = $("#commcopypage .holder");
        
        comvids.height($(document).height());
        comvids.width($(document).width());
        
        comvids.show();
        
        comhold.height(1600);
        comhold.width($(window).width());
        
        comhold.css("left",($(document).width()/2) - (comhold.outerWidth({margin:true})/2));
        comhold.css("top",($(document).height()/2) - (comhold.outerHeight({margin:true})/2));
        
        comvids.click(function() { $(this).remove(); });
        
        $("#commcopylist").hide();
        
        return false;
    });


});

	
/*		$(document).ready(function(){ 
			bgImageTotal=8; 
			randomNumber = Math.round(Math.random()*(bgImageTotal-1))+1; 
			imgPath=('img/background/'+randomNumber+'.jpg'); 
			$('body').css('background-image', ('url("'+imgPath+'")'));
			$('body').css('backgroundRepeat', ('no-repeat'));
		
		 
		});
*/
		$(document).ready(function() {
			$('.kwicks').kwicks({
				min : 30,
				spacing : 0,
				sticky : true,
				defaultKwick : 0
			});
				$('.kwicks3').kwicks({
				min : 30,
				spacing : 0,
				sticky : true,
				defaultKwick : 0
			});
		
		});



function setupMainPlayer() {
    var so = new SWFObject('swf/largeplayer.swf','mainflashplayer','480','270','9');
    so.addParam('flashvars','&xml=xml/mainplayer.xml');
    so.addParam("wmode","transparent");
    so.write("flashcontent");
}
