/*
	NixBox.com JavaScript
 	Copyright (c) 2008 Jolyon Terwilliger 
*/

var current_page='solutions';
var current_pane='main';
					
//console.log();

$(document).ready( function () {

	// set the appropriate current_page and current_pane if a hash link
	if (document.location.hash) {
		pnp = document.location.hash.split('_');
		if (pnp[1]) {
			current_pane = pnp[1];
		}
		current_page = pnp[0].substr(1);
	}

	// break out of linear display mode and hide non-active pages and panes
	$('.pane').css('height','440px')
		.not('#'+current_page+'_div').hide();
	$('.pane_text').css('height','340px').css('overflow','auto')
		.not('#'+current_page+'_'+current_pane).hide();
	
	// to pass CSS validator and keep slide outs smooth
	$('#content').css('overflow-x','hidden');
	
	// set the 'active' class for appropriate navbar and submenus
	$("#navbar li a[href='#"+current_page+"']").addClass('active');
	$('#content .submenu a[href="#'+current_page+'_'+current_pane+'"]').addClass('active');
	
	// trick to keep mozilla/firefox from outlining links with a dashed box
	if ($.browser.mozilla) {
		$('a').click(function() {
			this.blur();
		});
	}
	
	// simulate link clicks for contact links embedded in text
	$('a.contact_link').click(function () {
		$('#navbar li a[href="#contact"]').click();
		return false;
	});

	// set sample images to use flyout plugin
	$('a.sample_image').flyout({loadingSrc:'/images/ajax-3d.gif'});

	// fixes copyright div position on IE browsers.
	// fixes cleartype issue on IE allowing smoother transitions for other browsers.
	if ($.browser.msie) {
		$('#copyright').css({position:'absolute'});
		$('.pane_text').css({'background-color':'#FFF'});
	}
	
	// doesn't look so hot on first visit because of no script compatibility, dern it.
	//setTimeout('pageFadeIn("solutions")',500);
	
	// add class 'active' to clicked links (remove the rest)
	$('#content .submenu a')
		.click(function() {
			$('#content .submenu a.active').removeClass('active');
			fadePane(this);
			$(this).addClass('active');
		})

	// sets up the main navbar animation
	// thanks Remy for this demo:  http://jqueryfordesigners.com/image-fade-revisited/
	
	// this works in IE 6 for me, so..
	// if ($.browser.msie && $.browser.version < 7) return;
	$('#navbar li')
		.removeClass('highlight')
		.find('a')
		.click(function() {
			// add class 'active' to clicked links (remove the rest)
			$('#navbar li a.active').removeClass('active');
			switchPage($(this).addClass('active').parent().get(0).id.replace( /_nav$/, ''));
		})
		.append('<span class="hover" />').each(function () {
				var $span = $('> span.hover', this).css('opacity', 0);
				$(this).hover(function () {
					// on hover
					$span.stop().fadeTo(500, 1);
				}, function () {
					// off hover
					$span.stop().fadeTo(500, 0);
				});
			});
	
});


function switchPage(page) {
	$('#'+page+'_main').stop().css('display','none');
	$('#'+page+'_div').stop().css('display','none');

	$('#'+current_page+'_div').fadeOut(1000, function() {
		$('#'+current_page+'_div').css('display','none');
		$('#'+current_page+'_'+current_pane).css('display','none');
		
		$('#'+page+'_div').fadeIn(1000, function () {
			$('#'+page+'_main').show('drop',{direction:'up'},1000);
		});
	
		current_page=page;
		current_pane='main';

		$('#content .submenu a.active').removeClass('active');
		$('#content .submenu a[href="#'+current_page+'_'+current_pane+'"]').addClass('active');

		_gaq.push(['_trackPageview','/'+page]);
		_gaq.push(['_trackEvent',page,'Viewed']);
	});
}

function fadePane(obj) {
	pane = obj.href.split('#')[1].split('_')[1];

	if (pane == current_pane) return false;

	$('#'+current_page+'_'+pane).css('display','none');
	
	$('#'+current_page+'_'+current_pane).hide('drop',{direction:'right'},777, function () {
		$('#'+current_page+'_'+current_pane).css('display','none');
		$('#'+current_page+'_'+pane).show('drop',{direction:'up'},1000);
	});

	current_pane=pane;

	_gaq.push(['_trackPageview','/'+current_page+'-'+pane]);
	_gaq.push(['_trackEvent',+current_page+'-'+pane,'Viewed']);
}