/* UFC FIGHT CLUB */
/* JAVASCRIPT
----------------------------------------------------------------------------- */


/* READY FUNCTION
----------------------------------------------------------------------------- */


	$(document).ready(function() {


		// Referral Lock Link
		$('#upcoming td.date strong').each(function() {
		
			if ($(this).text() == "10/18/08") {
			
				$(this).parent().parent().children('td:last').addClass('action tickets ticketfactory');
				$('a#ticketfactory').clone().appendTo('td.ticketfactory');
				$('#content > a#ticketfactory').remove();
				$('a#ticketfactory').show();
			
			}
		
		});


		$('div.widget-advertising.overlay').wrap('<div id="overlay"></div>');
		$('#overlay div.widget-advertising').append('<a class="close" href="#">&times; Close</a>');
		$('#overlay a.close').click(hideOverlay);
	

/* MEMBERSHIP UPGRADE ALERT
----------------------------------------------------------------------------- */

		if (page == "account") {
		
			var $upgrade = $('ul.subscriptions h4:contains("UFC Fight Club Y5 Ultimate Membership Upgrade")').parent('li').hide();
/*			$upgrade.addClass('upgrade');
			$upgrade.find('a.upgrade').text('Add New Items to Your Ultimate Package');
			$upgrade.find('p').text("We're excited to announce the recent addition of new items to this year's Fight Club package which includes a DVD and dog tag. In order to add these items to your package, please click on the button below. You will simply be charged for the additional shipping cost.");*/
		
		}

			
/* FLASH: SPLASH PAGE
----------------------------------------------------------------------------- */	

		if (page == "login") {
		
			// VIDEO PLAYER
			var so = new SWFObject(asset_host + "/flash/intro-ufc.swf?xmlUrl=http://modules.ufc.com/index.cfm?fa=videoPlayer.xml4VideoPlayerFightClub", "photos", "220", "124", "8", "#000000", true);
			so.addParam("wmode", "transparent");
			so.addParam("allowScriptAccess", "always");
			so.write("splash-intro");
		
			// PHOTOS
			var so = new SWFObject("http://cdn.sparkart.net/ufcfightclub/flash/photos.swf", "photos", "220", "130", "8", "#000000", true);
			so.addParam("wmode", "transparent");
			so.addParam("allowScriptAccess", "always");
			so.write("splash-photos");
			
		}
	
	
/* FLASH: VIDEO PLAYER
----------------------------------------------------------------------------- */
	

		if (page == "index") {
		
			var so = new SWFObject(asset_host + "/flash/tv.swf", "tvplayer", "540", "360", "8", "#000000", true);
			so.addParam("wmode", "transparent");
			so.addParam("allowScriptAccess", "always");
			so.write("tv");
		
		}
		
		if (page == "video") {

			var so = new SWFObject(asset_host + "/flash/videos.swf", "video", "900", "350", "8", "#000000", true);
			so.addParam("wmode", "transparent");
			so.addParam("allowScriptAccess", "always");
			so.write("videos");
			
		}
	
	
/* FUNCTION: ITEM CYCLE
----------------------------------------------------------------------------- */	

	if (page == "login") {

		$('#swap').cycle({ 
		    fx:    'fade', 
		    speed:  2000,
		    timeout:  8000
		 });
		
		};
		
/* END READY FUNCTION
----------------------------------------------------------------------------- */

	});


/* LOAD FUNCTION
----------------------------------------------------------------------------- */


	$(window).load(function() {


		setTimeout("showOverlay()", 1000);
	

/* PRE-SALE CODE
----------------------------------------------------------------------------- */


	if ($('div.widget-event.display dt:contains(Password)').length > 0) {
		$('<p class="code"><em>Your Pre-sale Code:</em><strong>' + $('div.widget-event.display dt:contains(Password)').next().text() + '</strong></p>').insertAfter('div.widget-event.display div.venue');
		$('div.widget-event.display dt:contains(Password)').next().remove();
		$('div.widget-event.display dt:contains(Password)').remove();
	}


/* POPUP EXTERNAL LINKS
----------------------------------------------------------------------------- */


		$('a[rel=external]').click(function(){
		
			link = $(this).attr('href');
			window.open(link);
			return false;
	
		});


/* TABS
----------------------------------------------------------------------------- */

	
		if (page == "chat") {
		
			if ($('#panel-player > ul.tabs').length == 0) {
		
				cameraTwo();
			
			}
	
			$('#panel-player > ul.tabs').tabs({ 
			
				fxFade: true, 
				load: function(ui) {
	
					if ( $('li.selected').children('a').attr('id') == "tab-cam-one") {
					
					$('#player_two embed').remove();
	
					}
					
					if ( $('li.selected').children('a').attr('id') == "tab-cam-two") {
					
					$('#player_one embed').remove();
					
					}	
			
				},
				show: function(ui) {
	
					if ( $('li.selected').children('a').attr('id') == "tab-cam-one") {
					
					cameraOne();
					
					}
					
					if ( $('li.selected').children('a').attr('id') == "tab-cam-two") {
					
					cameraTwo();
					
					}		
			
				}
			
			});
	
		}
		

/* CHAT WINDOW
--------------------------------------------------------------------------- */


	$('a.launchchat').click(function(){

		$('div#chat').addClass('dim');
		$('div#chat').prepend('<a class="reembed" href="#">Re-embed Chat Here</a>');
		$('div#chat table').hide();
		
		window.open( site_host + '/chat-popup','Chat','width=600,height=450,resizable=0,scrollbars=0,toolbar=0,location=0,directories=0,status=0,menubar=0');
		
		$('a.reembed').click(function(){

			$('div#chat table').show();
			$('a.reembed').remove();
			return false
			
		});
		
		return false;
		

	});
	
	$('a.closechat').click(function(){

		window.close();
			
	});


/* END LOAD FUNCTION
----------------------------------------------------------------------------- */


	});


/* OVERLAY TOGGLE FUNCTIONS
----------------------------------------------------------------------------- */
	
	
	function showOverlay() {
	
		$('#overlay').show();
		$('#overlay').animate({top: 0}, 'slow');
	
	}

	function hideOverlay() {
	
		$('#overlay').slideUp('fast');
		$('div.flash').css('visibility','visible');
		return false;
	
	}


/* CHAT CAM FUNCTIONS
----------------------------------------------------------------------------- */
	
	
/*

	function cameraOne()  {
	
		var cam_one = new SWFObject( "http://www.ustream.tv/flash/live/1/334010", "instance_one", "400", "320", "9", "#000000" );
		cam_one.addParam( "allowScriptAccess", "always" );
		cam_one.addParam( "allowFullScreen" , "true" );
		cam_one.addVariable( "playerID", "instance_one" );
		cam_one.addVariable( "brand", "embed" );
		cam_one.addVariable( "autoPlay", "false" );
		cam_one.write( "player_one" );
					
	}

*/

	function cameraTwo() {

		//var cam_two = new SWFObject( "http://www.ustream.tv/flash/live/1/606106", "instance_two", "400", "320", "9", "#000000" );
		//var cam_two = new SWFObject( asset_host + "/flash/ufc_ustream.swf", "instance_two", "400", "345", "9", "#000000" );
		var cam_two = new SWFObject( asset_host + "/flash/ufc_stream.swf?v=2", "instance_two", "400", "345", "9", "#000000" );
		cam_two.addParam( "allowScriptAccess", "always" );
		cam_two.addParam( "allowFullScreen" , "true" );
		cam_two.addParam("menu", "false");
		//cam_two.addVariable( "playerID", "instance_two" );
		//cam_two.addVariable( "brand", "embed" );
		//cam_two.addVariable( "autoPlay", "false" );
		cam_two.write( "player_two" );
		
	}
	
	function openChat() {
	
		$('div#chat').removeClass('dim');
		$('div#chat table').show();

	}
