$(document).ready(function(){

	//REMOVE TO PREVENT CSS FALLBACKS
	$('body').removeClass('noJS');

	//01 NEWS ACCORDION
    $('#news-overview-page .article-entry').accordionView();
	$('#news-overview-page h1 + .article-entry').accordionView('expand');
	// END 01

	// 02 FADE ON HOVER BUTTONS
    var hoverFadeSpeed = 300;
	if(!($('body').is('.ie7,.ie8'))){
		$('a.hover-fade').bind("mouseover",function(){
			if(!$(this).hasClass('active')){
				$(this).children('span.hover-fade').stop(1,1).fadeTo(hoverFadeSpeed, 1)
			}
		});
		$('a.hover-fade').bind('mouseout',function(){
			if(!$(this).hasClass('active')){
				$(this).children('span.hover-fade').stop(1,1).fadeTo(hoverFadeSpeed, 0)
			}
		});
	}
	// END 02

	// 03 FRONT PAGE BANNER
	$('#fp #header-img-container').panZoom();
	// END 03

	// 04 FRONT PAGE TAB FUNCTIONALITY
	$('#fp-tabs a').click(function(){
        if(!$(this).hasClass('active')){
            $('#fp-tabs a.active').removeClass('active').mouseout();
            $(this).addClass('active');
        }
	});
	$('#fp-tabs li.blog a').click(function(e){
		e.preventDefault();
		$('#fp #twoCol-left .tab-content-news').hide();
		$('#fp #twoCol-left .tab-content-blog').show();
	});
	$('#fp-tabs li.news a').click(function(e){
		e.preventDefault();
		$('#fp #twoCol-left .tab-content-blog').hide();
		$('#fp #twoCol-left .tab-content-news').show();
	});
	// END 04
    
    // 05 ABOUT PAGE EMPLOYEE SCROLLER
    $('#employee-viewer').scrollFocus();
    $('#employee-viewer').bind('focus', function(e, label, blurb ){
        $('#employee-viewer .employee-caption').html(label);
        $('#employee-viewer .employee-info').html(blurb);
    });
    // END 05
	
    //06 MEDIA VELOCITY SCROLLER
    $('#media-scroller').veloScroll();

    $('#media-scroller-slider').slider();
    $('#media-scroller-slider').bind('sliding',function(e, value){
        $('#media-scroller').veloScroll('animEngine', value );
    })
    $('#media-scroller-slider').bind('stop',function(e, value){
        $('#media-scroller').veloScroll('animEngine',  0 );
    });
	
	/* Firefox reflections */
	var velocityScrollerCount = 0;
	$('#media-scroller #carousel ul li.carousel-item').each(function(){
		var reflectThis = $(this).children('div.reflect-this');
		var idString = 'velocity-li-' + velocityScrollerCount;
		var bgString = '-moz-element(#' + idString + ')';
		$(this).children('div.reflect-this').attr('id', idString);
		$(this).children('div.reflection').css({'background-image':bgString});
		//document.mozSetImageElement("bar", reflectThis);
		velocityScrollerCount++;
	});
	
	/* Show download links on hover */
	if(!($('body').is('.ie7,.ie8'))){
		//Not IE7 or IE8
		$('#media-scroller #carousel ul li.carousel-item').hover(
			function(){$(this).find('.download-links').stop(1,1).fadeIn(300);},
			function(){$(this).find('.download-links').stop(1,1).fadeOut(300)}
		);
	} else {
		//IE7 and IE8
		$('#media-scroller #carousel ul li.carousel-item').hover(
			function(){$(this).addClass('hover');},
			function(){$(this).removeClass('hover')}
		);
	}
    //END 06
	
    //07 FANCYBOX
    $('a.fancybox').fancybox({
        'transitionIn'	: 'elastic',
        'transitionOut'	: 'elastic'	
    });
    //END 07
    
   //08 APPLY / EMAIL TO FRIEND
   $('#taleo-forward' ).taleoForward();
   // taleo forward
   $('#btn-confirm-site-exit').lightBox({
      translucentLayer: '#light-box-translucent-layer',
      content: '#taleo-forward',
      lightBoxFrame: '#light-box-frame'
   });
   $('#taleo-forward').bind('close', function(){
      $('#btn-confirm-site-exit').lightBox("close")
   })
   // email friend
   $('#email-friend' ).emailFriend();
   $('#btn-email-friend').lightBox({
      translucentLayer: '#light-box-translucent-layer',
      content: '#email-friend',
      lightBoxFrame: '#light-box-frame'
   });
   // bind form close event to close lightBox
   $('#email-friend').bind('close', function(){
      $('#btn-confirm-site-exit').lightBox("close")
   })
   // bind light box 'show' event to open emailFriendForm
   $('#btn-email-friend' ).bind('show', function(){
      $('#email-friend' ).emailFriend("show");
   })  

   //END 08

	//09 SHOW MORE BUTTONS ON HOME PAGE
    $("body#fp .tab-content-blog .article-list").artlistloader({
		button: $("body#fp .tab-content-blog .btn-show-more"),
		showAuthorInfo: true,
		showAvatar: false,
		serviceUrl:'/global/includes/php/ajaxJson.php?feedType=blog',
		feedType: 'blog'
	});
    $("body#fp .tab-content-news .article-list").artlistloader({
		button: $("body#fp .tab-content-news .btn-show-more"),
		showAuthorInfo: false,
		showAvatar: false,
		serviceUrl:'/global/includes/php/ajaxJson.php?feedType=news',
		feedType: 'news' 
	});
	//END 09
	
	//10 TWITTER BUCKET
    $("#bucket-tweets .bucket-content").tweet({
		username: ["Carbine_Studios"],	
		count: 3,
		fetch: 5,
		refresh_interval: 60,	
		join_text:"auto",
		template: "{text}<span class='date'>{tweet_relative_time}</span>",
		loading_text: "Loading Tweets..."
	});
	//END 10
	
	//11 JPLAYER
	$.each($('.jp-jplayer'), function(i,v){
		var playerName = '';
		var interfaceName = '';
		playerName = $(this).attr('id');
		interfaceName = playerName.replace(/jplayer/, 'jinterface' )
		$('#'+playerName).jPlayer({
			ready: function () {
				 $(this).jPlayer("setMedia", {
					mp3: $(this).data('mp3'),
					oga: $(this).data('oga')
				 });
			},
		  swfPath: "/global/includes/swf",
		  supplied: "mp3, oga",
		  volume: 1,
		  cssSelectorAncestor: '#'+interfaceName
		})
		.bind($.jPlayer.event.play, function() { // Using a jPlayer event to avoid both jPlayers playing together.
		  $(this).jPlayer("pauseOthers");
		});
	});
	//END 11
	
	//12 MIN HEIGHT BASED ON VIEWPORT SIZE
	$('.content-container').css('min-height',function(i){return ($(window).height() - 400)});
	//END 12
    
});
