/* Eat your heart out. */

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
  //alert('created a cookie : '+ document.cookie);
}

function deleteCookie( name, path, domain ) {
if ( readCookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

function styleTime(){
	var currentTime = new Date();
	var hours = currentTime.getHours();
	if(hours < 6 || hours > 18){
		return 'night';
	}
	else{
		return 'day';
	}
}

jQuery(document).ready(function(){
	var time = styleTime();
	var cookie = readCookie('style');
	//alert(time);
	var stylesheet = cookie ? cookie : time;
	if(stylesheet == 'day'){
		jQuery('a#lights').html("AAH, IT'S TOO<br /> BRIGHT IN HERE");
	}else{
		jQuery('a#lights').html("DO YOU GUYS<br /> WANT THE LIGHTS ON?");
	}
	jQuery('body').addClass(stylesheet);
	jQuery('#lights').click(function(){
		if(jQuery('body').hasClass('day')){
			jQuery('body').removeClass('day');
			jQuery('body').addClass('night');
			jQuery(this).html("DO YOU GUYS<br /> WANT THE LIGHTS ON?");
			deleteCookie('style', '/', 'playground.mindutopia.com/mindutopia');
			createCookie('style','night', 0.2);
			
		}
		else if(jQuery('body').hasClass('night')){
			jQuery('body').removeClass('night');
			jQuery('body').addClass('day');
			jQuery(this).html("AAH, IT'S TOO<br /> BRIGHT IN HERE");
			deleteCookie('style', '/', 'playground.mindutopia.com/mindutopia');
			createCookie('style','day', 0.2);
			
		}
		Cufon.refresh();
		return false;
	});
	
	jQuery('.staff-info').hide();
	jQuery('.staff-box').hover(function(){
		jQuery(this).find('.staff-info').animate({height: 'toggle'}, 100);
	}
	, function(){
		jQuery(this).find('.staff-info').animate({height: 'toggle'}, 100);
	});
	
	jQuery('a.client').hover(function(){
			/*jQuery(this).animate({
				backgroundPositionY: '0px'
			}, 500);*/
			//jQuery(this).css('background-position-y','0px');
			jQuery(this).css('backgroundPosition','center 0px');
			/*jQuery(this).fadeIn('slow').addClass('client-over');*/
		}, 
		function(){
			/*jQuery(this).animate({
				backgroundPositionY: '-96px'
			}, 500);
			*/
			//jQuery(this).css('background-position-y','-96px');
			jQuery(this).css('backgroundPosition','center -96px');
			/*jQuery(this).removeClass('client-over').fadeIn('slow');*/
		});
		
	
});
