/**
 * @author John
 */
var timeout = 500;
var timer = null;
var openItem = null;
$(document).ready(function()
{
	$("#postit").pngFix(); 
	$(".delta_root").mouseover(function(){
		
		if(timer)
		{
			close();
			clearTimeout(timer);
			timer = null;
		}
		
		openItem = $(this).find("ul");
		openItem.show();
	}).mouseout(function(){
		timer = window.setTimeout(close, timeout);
	});
	$(document).click(close);
	
	var startSlide = get_cookie('ssIndex') || 0;
	$('#slideshow').cycle({
		fx: 'fade',
		timeout: 4500,
		startingSlide:startSlide,
		before:function(pCurr,pNext,pOptions,pForward){
			var imgId =	pNext.id;
			var index = getIndex(imgId);
			set_cookie('ssIndex',index);
		}
	});
});
function getIndex(pId)
{
	var index = 0;
	try{
		index = parseInt(pId.substring(pId.indexOf("_")+1));
	}
	catch(pex)
	{
		index = 0;
	}
	return index;
}
function set_cookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure )
{
  var cookie_string = name + "=" + escape ( value );
  if ( exp_y )
  {
    var expires = new Date ( exp_y, exp_m, exp_d );
    cookie_string += "; expires=" + expires.toGMTString();
  }
  if ( path )
        cookie_string += "; path=" + escape ( path );

  if ( domain )
        cookie_string += "; domain=" + escape ( domain );
  
  if ( secure )
        cookie_string += "; secure";
  
  document.cookie = cookie_string;
}

function get_cookie ( cookie_name )
{
  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );

  if ( results )
    return ( unescape ( results[2] ) );
  else
    return null;
}


function close()
{
	
	if(openItem)
	{
		openItem.hide();
	}
}

