$(document).ready(function()
{

	var content = "hidden";
	var	cycled = "no";
	var faded = "in";

	var prevsection = "";		
	var section = "home";
	var browser = ($.browser.msie && $.browser.version=="6.0")? 'ie6' : '';

	$("#sample").click(function(event)
	{
		
		event.preventDefault();
		$(this).blur();
	
		if (section=="sample") return false;
	
		if (faded=="in"){
		
			prevsection = section;

			section = "sample";

		if( browser!="ie6" ) faderout();		
			
			sectionChange(section);
						 
		};
	
	});
	
	$("#about").click(function(event){

		event.preventDefault();

		if (section=="about") return false;

		if (section=="sample" && browser!="ie6") faderin();
		
		prevsection = section;

		section = "about";
		
		sectionChange(section);

	});
	
	$("#contact").click(function(event){

		event.preventDefault();
	
		if (section=="contact") return false;

		if (section=="sample" && browser!="ie6") faderin();

		prevsection = section;		

		section = "contact";
		
		sectionChange(section);
	
	});
	
	function faderin(){
	
	
		$('ul#nav li a').css({"background-image" : "url(img/nav.png)"});

		$("#bg").fadeIn(1000);
		
		$("#logo-white").fadeOut(1000);
		$("#logo-black").fadeIn(1000);
		
		faded="in";
	
	};

	function faderout(){

		$('ul#nav li a').css({"background-image" : "url(img/nav_dark.png)"});
		
		$("#bg").fadeOut(1000);
		
		$("#logo-black").fadeOut(1000);
		$("#logo-white").fadeIn(1000);
		
		faded="out";
	
	};

	function sectionChange(section){
	
		$("ul#nav li a").removeClass("current");
		$("ul#nav li#"+section+" a").addClass("current");
	
		if(prevsection=='home'){$("#content").fadeIn(500, function(){ $('#content-'+section).fadeIn(); if(section=="sample") docycle();});  return false;};
		
		$('#content-'+prevsection).fadeOut(500, function(){
		
			$('#content-'+section).fadeIn(500, function(){if(section=="sample") docycle();});
		
		});
	
	};
	

	
function docycle(){		
	if(cycled=='no') {startcycle()} ;
};

function startcycle(){		
	$("#box-sample1").cycle({next:'#next2',prev:'#prev2', delay:400});
	$("#box-sample2").cycle({next:'#next2',prev:'#prev2', delay:400});
	$("#box-sample3").cycle({next:'#next2',prev:'#prev2', delay:400});
	$("#box-sample4").cycle({next:'#next2',prev:'#prev2', delay:400});
	$("#box-sample5").cycle({next:'#next2',prev:'#prev2', delay:400});		
	$("#description").cycle({next:'#next2',prev:'#prev2', delay:400});
	cycled = 'yes';
};

});
