//cortexture.js
//jason blatt
//01-21-2009


menuToggle = false;
helpToggle = false;
currentActiveMenu = 'homeNav';
currentActiveSkin = 'default';
delayItem = '';

$(document).ready(function() {
	
    resizeAll();
    
    //Active home nav item
    select($("#homeNav"));
    growH($("#homeNav"));

    //Set event handlers for skins
    $(".skin").click( function() {
	var which = $(this).attr('id');
	if(which != currentActiveSkin) {
	    var newCSS = 'cortexture';
	    if(which == 'default') newCSS += '.css';
	    else newCSS += '_' + which + '.css';
	    currentActiveSkin = which;
	    $("#mainCSS").attr('href','css/' + newCSS);
	    resizeAll();
	}
    });

    //Set event handlers for left navigation items
    $("ul#leftNav li a").each( function() {

	$(this)
	
	//Expand and colorize nav bar on hover
	    .mouseover( function() {
		if(this.getAttribute('id') != currentActiveMenu) {
		    growH(this)			  
		    highlight(this);
		}
	    })
	
	//Revert nav bar to normal on mouse leave        
	    .mouseout( function()  {
		if(this.getAttribute('id') != currentActiveMenu) {
		    shrinkH(this); 
		    unhighlight(this);
		}
	    })

	    .click( function() {
		
		var which = this;
		var oldMenu = currentActiveMenu;
		
		if(which.getAttribute('id') != oldMenu) {
		    $('#' + oldMenu.substring(0,oldMenu.length-3)).fadeOut(300, function() {
			$('#' + which.getAttribute('id').substring(0,which.getAttribute('id').length-3)).fadeIn(300);
		    });
		    
		    if(helpToggle) {
			$('#help_' + oldMenu).fadeOut(100, function() {
			    $('#help_' + which.getAttribute('id')).fadeIn(100);
			});
		    }
		    
		    currentActiveMenu = which.getAttribute('id');	
		    
		    delayItem = $("#" + oldMenu);
		    shrinkH($("#" + oldMenu));
		    unhighlight($("#" + oldMenu));
		    
		    growH(which);
		    select(which);
		}
		
	    }); //end on click
	
	
    }); //end nav event handlers
    
    
    //Set event handler for help menu
    $("#helpIcon")
    
	.mouseover( function() {
	    $(this).removeClass().addClass('help_active');

	    if(!helpToggle) $('#helpArrows').html('(more info) &raquo;').show();
	    else $('#helpArrows').html('&laquo;').show();
	})
    
    
	.mouseout( function() {
	    $(this).removeClass().addClass('help_normal');
	    $('#helpArrows').html('&raquo;').hide();
	})
    
    //Toggle display on click
	.click( function() {
	    if(!helpToggle) {
		$('#helpArrows').html('&laquo;');
		helpToggle = !helpToggle;
		$('#help_' + currentActiveMenu).fadeIn(100);
	    }
	    
	    else {
		$('#helpArrows').html('(more info) &raquo;');
		helpToggle = !helpToggle;
		$('#help_' + currentActiveMenu).fadeOut(100);
	    }
	});		
    
        
    //Setup lightbox links
    $('.lbLink').lightBox();
    
    //Check cookie and show info if first time or after 10 days
    if($.cookie('showHelp') != 'false') {
	$('#helpArrows').html('');
	helpToggle = !helpToggle;
	$('#help_' + currentActiveMenu).fadeIn(100);
	$.cookie('showHelp', 'false', { expires: 10 });
    }
    
}); //end ready function


$(window).resize(function(){
    resizeAll();
});

function resizeAll() {
    //Resize title shot image
    var homeHeight = $("#home").height();
    var homeWidth = $("#home").width();
    $("#home").css({ top: parseInt((getY() - homeHeight) / 2) ,  left: parseInt((getX() + 260 - homeWidth)/2) });
    if(currentActiveMenu == 'homeNav') $("#home").show();

    //Resize contact image
    var contactHeight = $("#contact").height();
    var contactWidth = $("#contact").width();
    $("#contact").css({ top: parseInt((getY() - contactHeight) / 2) , right: 0 });
    if(currentActiveMenu == 'contactNav') $("#contact").show();
}


function select(el) {
    $(el).removeClass().addClass('selected');
}

function highlight(el) {
    $(el).removeClass().addClass('highlighted');
}

function unhighlight(el) {
    $(el).removeClass().addClass('normal');
}

function shrinkH(el) {
    $(el).animate({ width:		'180px' , 
		    paddingLeft:	'25px' }, 160);
}

function growH(el) {
    $(el).animate({	width:		'230px' , 
			paddingLeft:	'35px' }, 160);
}

function randInt(maxV)
{
    return randomnumber=Math.floor(Math.random()*maxV)
}

function getX()
{
    if($.browser.msie) return document.body.clientWidth;
    else return window.innerWidth;
}

function getY()
{
    if($.browser.msie) return document.body.clientHeight;
    else return window.innerHeight;
}

