window.name = "RV_Main"; //added for interaction with fullscreen response viewer pages

$(function() {
    $.tabs.init('#tabs-selector div.tab-selector a.headline', '#tabs li', '#tabsContent .tabContent');
});


$.tabs = {
	init: function(tabsSelectors, tabs, tabsContent) {
		this.tabsSelectors = $(tabsSelectors);
		this.currentSet = 1;
		this.tabs = $(tabs);
		this.tabsContent = $(tabsContent);
		this.tabsContent.css('display', 'none');
		
		$(tabs + ':eq(0)').addClass('selected');
		$(tabsContent + ':eq(0)').css('display', 'block');
		
		this.tabsSelectors.each(function(index) {
			$(this).click(function(){
				if(!$(this).hasClass('on')) {
					if($('#tabs-selector').hasClass('flipped'))
						$('#tabs-selector').removeClass('flipped');
					else {
						$('#tabs-selector').addClass('flipped');
					}
				}
				$.tabs.tabsSelectors.removeClass('on');
				$('#tabs-selector .tab-selector').removeClass('selected');
				$(this).parents('.tab-selector').addClass('selected');
				$(this).addClass('on');	
				
				$.tabs.currentSet = index + 1;
				$(tabs + ':eq(0)').addClass('selected').siblings('li').removeClass('selected');
				var tabString = "#tab1-" + $.tabs.currentSet;
				$.tabs.collapse();
				$(tabString).css('display', 'block');
			});							 
		});
		
		this.tabs.click(function() {
			var tabID = $(this).attr('hook');
			tabID += "-" + $.tabs.currentSet;
			$(this).siblings('li').removeClass('selected');
			$(this).addClass('selected');
			$.tabs.collapse();
			$.tabs.tabsContent.each(function() {
				var thisID = $(this).attr('id');
				if(thisID == tabID) {
					$(this).css('display', 'block');
				}	
			});
		});
		
	},
	
	collapse: function() {
		this.tabsContent.each(function() {
			$(this).css('display', 'none');						  
		});
	}
}
