// JavaScript Document


function load_feature_block() {

	$.fn.initTabs();
	$.fn.initPromos.options = {
		slide_interval: 8000  
	};
    $('#promos').initPromos();

    //$('#container').append('<object id="board_intro" data="/swf/boardintro.swf" type="application/x-shockwave-flash" width="280" height="440"><param value="true" name="allowfullscreen"><param name="wmode" value="transparent"></object>');

   
    
}

(function($){
	
	// initiate tabs
	$.fn.initTabs = function() {
        // featured tabs
		var tabContainers = $('#feature_wrap > div');

		$('ul#feature_tabs a').click(function () {
			
			tabContainers.hide().filter(this.hash).show();		
			$('ul#feature_tabs a').removeClass('active');
			$(this).addClass('active');        
			return false;
			
		}).filter(':first').click();
		
        // news feed tabs
		var tabContainers2 = $('#home_news_box_body > .news_box_content');
    
		$('#home_news_box_tabs a').click(function () {
			
			tabContainers2.hide().filter(this.hash).show();		
			$('#home_news_box_tabs a').removeClass('active');
			$(this).addClass('active');        
			return false;
			
		}).filter(':first').click();
		
	};
	
})(jQuery);


(function($){

	// initiate promos
	$.fn.initPromos = function() {
	
		var options = $.extend($.fn.initPromos.defaults, $.fn.initPromos.options);
		var promos_array = new Array();
		var current = 0;
		var firstRun = true;
		var num_of_promos = $("ul.slideshow li").length;
		var mouseIsOverImage = false;	
		var mouseIsOverCopy = false;	
		var mouseIsOverButton = false;

		// create array of promos		
		$("#promos .promo").each(function(initIndex) {
			
			initTextAnim();
			promos_array.push($(this));

		});
		
		function initTextAnim() {

			$('.feature_media').hover( function() {
				mouseIsOverImage = true;
			},
			function() {
				mouseIsOverImage = false;
			});
			
			$('.feature_copy').hover( function() {
				mouseIsOverCopy = true;
			},
			function() {
				mouseIsOverCopy = false;
			});
            
		}
		
		$("ul.slideshow li").filter(':first').addClass("current");
		
		$('#promo'+(current+1)+' .feature_copy').css("left", "-670px");
		promos_array[0].show();
		$('#promo'+(current+1)+' .feature_copy').animate({left: 0}, 300);
		
		if(num_of_promos > 1) slideshow_interval = setInterval(nextSlide, options.slide_interval);		
			
		function nextSlide() {
						
			if(isMouseOverPromo() == false){

				$('#promo'+(current+1)+' .feature_copy').animate({left: '-670px'}, 300, function(){
					
					var tempCur = $(".current");	
					tempCur.next().addClass("current");
					tempCur.removeClass("current");
					
					if (current+1 < num_of_promos) {
						
						promos_array[current].hide();						
						current++;		
						promos_array[current].show();
						
					} else {
						
						promos_array[current].hide();
						promos_array[0].show();
						current = 0;
						$("ul.slideshow li:first-child").addClass("current");
						
					}	
					
					$('#promo'+(current+1)+' .feature_copy').css("left", "-670px");
					$('#promo'+(current+1)+' .feature_copy').animate({left: 0}, 300);
				
				});
							
			}
			
		}
		
		function isMouseOverPromo(){			
			if (mouseIsOverCopy == false && mouseIsOverImage == false && mouseIsOverButton == false)
				return false;
			else
				return true;			
		}
        
		$("ul.slideshow a").click( function() {
			
			if(num_of_promos > 1) {
			
				mouseIsOverButton = true;
				
				var num = $(this).text() - 1;
				$("ul.slideshow li").removeClass("current");
				$("ul.slideshow li:nth-child("+(num+1)+")").addClass("current");
				
				promos_array[current].hide();
				current = num;			
				$('#promo'+(current+1)+' .feature_copy').css("left", "-670px");
				$('#promo'+(current+1)+' .feature_copy').animate({left: 0}, 300);			
				promos_array[current].show();
				
				clearInterval(slideshow_interval);			
				slideshow_interval = setInterval(nextSlide, options.slide_interval);		
				
				$(this).mouseout(function() {
					mouseIsOverButton = false;
					$(this).unbind("mouseout");
					//if(isMouseOverPromo() == false) $('.feature_copy').animate({left: '-670px'}, 300);
				});
			
			}
			
			return false;
			
		});
		
	};

})(jQuery);



/* YouTube functions */

function loadVideo(playerUrl, autoplay) {
	swfobject.embedSWF(
	playerUrl + '&rel=0&color1=0x2b405b&color2=0x6b8ab6&fs=1&autoplay=' + 
	(autoplay?1:0), 'player', '450', '350', '9.0.0', false, 
	false, {allowfullscreen: 'true', allownetworking: 'internal', wmode: 'transparent'});
}

function showMyVideos(data) {
	var feed = data.feed;
	var entries = feed.entry || [];
	var html = ['<ul>'];
    for (var i = 0; i < entries.length; i++) {
        var list_class = ((i % 2 == 0) ? 'stripe' : '');
        var entry = entries[i];
        var title = entry.title.$t;
        var thumbnailUrl = entries[i].media$group.media$thumbnail[0].url;
        var playerUrl = entries[i].media$group.media$content[0].url;
        html.push('<li class="', list_class, '" onclick="loadVideo(\'', playerUrl, '\', true)">',
        '<span class="title" title="',title,'">', title, '</span><img title="', title ,'" src="',
        thumbnailUrl, '" width="80" height="70"/><br class="clear" />', '</li>');
    }

	html.push('</ul>');
	document.getElementById('list_videos').innerHTML = html.join('');
	  if (entries.length > 0) {
		loadVideo(entries[0].media$group.media$content[0].url, false);
	}
}


/* Facebook functions */

$(".tab3").click( function() {
/*
  window.fbAsyncInit = function() {
    FB.init({appId: 'your app id', status: true, cookie: true,
             xfbml: true});
  };
  (function() {
    var e = document.createElement('script'); e.async = true;
    e.src = 'http://connect.facebook.net/en_US/all.js';
    document.getElementById('fb-root').appendChild(e);
  }());
*/
alert('load facebook');

});



