var currentpath = Array();
var patharray = Array();
var title = document.title;
var elheight=0;
scGlobal = {};

scGlobal.setNavHovers = function() {
	$('#contentholder .mainnav .nav').hover(function(){
		if($(this).css('color') != 'rgb(184,184,184)' && $(this).css('color') != 'rgb(184, 184, 184)' && $(this).css('color') != '#b8b8b8') {
			$(this).attr('name','animating');
			$(this).attr('rev',9);
			$(this).parent().attr('class','color9');
		}
	},function(){
		if($(this).attr('name')){
			$(this).attr('name','');
			scGlobal.colorMe ($(this));
		}
	});
}

scGlobal.colorMe = function(element){
	currentColor = $(element).attr('rev');
	
	if (currentColor < 1 ) return;
	if ( $(element).attr('name') == 'animating') {
		$(element).parent().attr( 'class','color9');
		$(element).attr('rev',9);
	} else {
		$(element).parent().attr( 'class','color'+(currentColor - 1) );
		$(element).attr('rev',currentColor - 1);
	}
	window.setTimeout(function() { scGlobal.colorMe( $(element) ); },050);
}




scControl = {};
scControl._xArgs = {};


scControl.loadNow = function(path){
	$('#'+path+'_loader').html('<img src="images/ajax-loader.gif">');
	var thisel = $(scControl._xArgs.returnDiv).find("div#control");
	if($('div.isOpen')){
		$('div.isOpen').animate({ "height": "0px" }, 200,function(){
			$(this).removeClass('isOpen').hide().find('#control').empty();
		});
		
		thisel.oneTime(300,function(){
			thisel.load(path+'.php',function(){
				$('#'+path+'_loader').html('');
				thisel.parent().addClass('isOpen').height(1).animate({ "height": elheight+"px" }, 500);			
			});
		});
	}
	else{
		thisel.load(path+'.php',function(){			
			$('#'+path+'_loader').html('');
			thisel.parent().addClass('isOpen').height(1).animate({ "height": elheight+"px" }, 500);			
		});
	}

}

scControl.closeAll = function(){
	if($('div.isOpen')){
		$('div.isOpen').animate({ "height": "0px" }, 200,function(){
			$(this).hide().removeClass('isOpen').find('#control').empty();
		});
	}
}



$('.ajaxlink').live("click", function(){
	$.address.value(this.rel); 
	return false;
});


scHome = {};
scHome.init = function(){
	scGlobal.setNavHovers();

	if (net_browser == 11){			
	    $("div#titleholder").removeAttribute('filter');
		$("div#contentholder").removeAttribute('filter');
	}
		
	$("div#titleholder").css('opacity','0').oneTime(300,function(){$(this).animate({ opacity: 1}, 1000);}); 
	$("div#contentholder").css('opacity','0').oneTime(700,function(){$(this).animate({ opacity: 1}, 1000); });
}

$.address.change(function(event) {   
	patharray = event.path.split('/');
	$('#contentholder .mainnav').attr('class','mainnav').addClass(patharray[1]);
	ajaxcontrolswitch(patharray[1]);		
});





function ajaxcontrolswitch(switchon){
		switch(switchon){
			case '':
				$.address.title("Stephanie Chai");
				scControl.closeAll();								
			break;
			
			case 'news':
				$.address.title("Stephanie Chai | News");
				elheight = 250;				
				scControl._xArgs.returnDiv = '#news_container';
				scControl.loadNow('news');								
			break;
			
			case 'bio':
				$.address.title("Stephanie Chai | Biography");
				elheight = 350;				
				scControl._xArgs.returnDiv = '#bio_container';
				scControl.loadNow('bio');								
			break;

			case 'gallery':
				$.address.title("Stephanie Chai | Gallery");
				elheight = 190;
				scControl._xArgs.returnDiv = '#gallery_container';
				scControl.loadNow('gallery');								
			break;

			case 'videos':
				$.address.title("Stephanie Chai | Videos");
				elheight = 190;
				scControl._xArgs.returnDiv = '#videos_container';
				scControl.loadNow('videos');								
			break;

			case 'articles':
				$.address.title("Stephanie Chai | Articles");
				elheight = 310;
				scControl._xArgs.returnDiv = '#articles_container';
				scControl.loadNow('articles');								
			break;

			case 'contact':
				$.address.title("Stephanie Chai | Contact");
				elheight = 270;
				scControl._xArgs.returnDiv = '#contact_container';
				scControl.loadNow('contact');								
			break;
			
			default:
				window.location = "/";
			break;
		}
		currentpath = patharray;
}
