var approva = {};

var TabNavigatorOLD = Class.create({
	init: function(container,arr) {
		// arr = [{tab:'blog_feed',content:'blog-items'},{tab:news_feed,content:'news-items'}];
		var _this = this;
		var tabID;
		var i;
		_this.group = container;
		_this.tabs = arr;
		
		for (i = 0; i < _this.tabs.length; i++) {
			tabID = _this.tabs[i].content;
			$('#' + _this.tabs[i].tab + ' a').click(function(){
				if ($(this).closest('li').hasClass('selected') == false) {
					$('#'+ _this.group + ' li').removeClass('selected');
					$(this).closest('li').addClass('selected');
					
					$('#' + $(this).closest('div').attr('id') + ' div').removeClass('focused');
					$('#' + $(this).closest('li').attr('id').substring(0,4) + '-items').addClass('focused');
				}
				return false;
			});
		}
	},
	group: '',
	tabs: []
});

function enableTabNavigation(group,tabs) {
	var i;
	var tabID;
	
	for (i = 0; i < tabs.length; i++) {
		tabID = tabs[i].content;
		$('#' + tabs[i].tab + ' a').click(function() {
			if ($(this).closest('li').hasClass('selected') == false) {
				$('#' + group + ' li').removeClass('selected');
				$(this).closest('li').addClass('selected');
				
				$('#' + $(this).closest('div').attr('id') + ' div').removeClass('focused');
				$('#' + $(this).closest('li').attr('id').substring(0,4) + '-items').addClass('focused');
			}
			return false;
		});
	}
}

function enableExternalLinks() {
	var href;
	var d = 'approva.net';
	$("a").each(function(index, element) {
		href = $(this).attr('href');
		if (href.indexOf('http://') != -1 || href.indexOf('https://') != -1) {
			if (href.indexOf(d) == -1) {
				$(this).attr('target','_blank');
			}
		}
	});
}

function updateTicker() {
	var curItem = '#ticker ul li.focused';
	var nextItem;
	if ($(curItem).hasClass('last')) {
		$(curItem).fadeOut('fast', function() {
			$('#ticker ul li').first().fadeIn('fast', function() {
				$(this).addClass('focused');
			});
			$(curItem).removeClass('focused');
		});
	} else {
		$(curItem).fadeOut('fast', function() {
			$(this).next().fadeIn('fast', function() {
				$(this).addClass('focused');
			});
			$(curItem).removeClass('focused');
		});
	}
}

function init_one_details_ui(){
	$('ul#platform a').mouseover(function(){
		//console.log($(this).next('ul.detail').children('li').attr('id'));
		$(this).next('ul.detail').children('li').fadeIn('fast');
	}).mouseout(function(){
		$(this).next('ul.detail').children('li').hide(0);
	});
	
	$('ul#activities a').mouseover(function(){
		//console.log($(this).next('ul.detail').children('li').attr('id'));
		$(this).next('ul.detail').children('li').fadeIn('fast');
	}).mouseout(function(){
		$(this).next('ul.detail').children('li').hide(0);
	});
	$('ul#activities li a').click(function(){
		return false;
	});
}

function init_platform_details_ui(){
	$('ul#segments a').mouseover(function(){
		$(this).next('ul.detail').children('li').fadeIn('fast');
	}).mouseout(function(){
		$(this).next('ul.detail').children('li').hide(0);
	});
}

function play_before_after(){
	$('#after_image').animate({width:356},1500);
	$('#graphic-slider').animate({left:366},1460, function(){
		$('#stamp').fadeIn('fast',function(){
			$('#replay-button').fadeIn('slow');	
		});
	});
}

function init_scroll_event(){
	$('#graphic-slider').click(function(){
		play_before_after();
		$(window).unbind('scroll');
		$('#graphic-slider').unbind('click');
		return false;
	});
	$(window).bind('scroll',function(){
		if ($(window).scrollTop() > 150) {
			play_before_after();
			$(window).unbind('scroll');
		}
	});
	$('#replay-button').click(function(){
		$('#replay-button').fadeOut('fast');
		$('#before_image').css('display','none');
		$('#after_image').css('display','none');
		$('#after_image').css('width', '1px');
		$('#stamp').fadeOut('fast');
		$('#graphic-slider').fadeOut('fast',function(){
			$('#graphic-slider').css('left','15px');
			$('#before_image').fadeIn('fast', function() {
				$('#graphic-slider').fadeIn('fast', function (){
					$('#after_image').css('display', 'block');
					play_before_after();
				});
			});
		});
		return false;
	});
}
