function Set_Cookie( name, value, expires, path, domain, secure )
{
var today = new Date();
today.setTime( today.getTime() );


if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}
	
function Get_Cookie( check_name ) {
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		
		a_temp_cookie = a_all_cookies[i].split( '=' );


		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}
		
// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
if ( Get_Cookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function boardInfo(id,height){
	var biwh = height+10;
	var bih = height;
	var biwd = 'boardinfowrapper'+id;
	var bid = 'boardinfo'+id;
	
	
	if(!Get_Cookie('board'+id)){
	
		Delete_Cookie('board'+id, '/', '');
		Set_Cookie( 'board'+id, '1', '', '/', '', '' );
	
		$(biwd).tween('height', [0, biwh]); 
	
		$(bid).tween('height', [0, bih]);
		
		$(biwd).setStyle('borderBottom','1px solid #e0e0e0');
	
		}else{
		
	
		Delete_Cookie('board'+id, '/', '');
	
		$(bid).tween('height', [bih, 0])
	
		$(biwd).tween('height', [biwh, 0]); 
	
		$(biwd).setStyle('borderBottom','0');
	
		}


}


function inArray(myValue,myArray)
{
    function equals(a,b)
    {
        return (a === b);
    }

    for (var i in myArray)
    {
        if (equals(myArray[i],myValue))
            return true;
    }

    return false;
}



function favBoard(id){
	
	
	
	if(Get_Cookie('klf'))
	{
		var favCookie = Get_Cookie('klf');
		var favArray = favCookie.split('.');
		var arrayCount = favArray.length;
	}
	else
	{
	var arrayCount = 0;
	var favArray = new Array();
	}
	

	
	if (!inArray(id,favArray))
	{
	favArray[arrayCount] = id;
	newCookie = favArray.join('.');
 	newCookie=newCookie.replace(".0", "");
	Set_Cookie( 'klf', newCookie, '', '/', '', '' );
	var imgSrc = document.getElementById('heart'+id).src;
	imgSrc=imgSrc.replace("On", "Off");
	imgSrc=imgSrc.replace("Off", "On");
	document.getElementById('heart'+id).src = imgSrc;
	if(arrayCount==0)
		alert('This board has been added to your favorites.');
	}
	
	else
	
	{
	 var x;	 
 		for(x in favArray)
 		{
 		 	if(favArray[x]==id)
 		 		favArray[x] = 0;
 		}
 	
 	newCookie = favArray.join('.'); 
 	newCookie=newCookie.replace(".0", "");
	Set_Cookie( 'klf', newCookie, '', '/', '', '' );
	var imgSrc = document.getElementById('heart'+id).src;
	imgSrc=imgSrc.replace("Off", "On");
	imgSrc=imgSrc.replace("On", "Off");
	document.getElementById('heart'+id).src = imgSrc;
	
	}	


}


	
	