function set_cookie(name, value) {
	document.cookie = name+'='+value+';';
}

//-----------------------------------------------------------------------------------

function get_cookie(name) {
	if(document.cookie) {
		var cookies = document.cookie.split(';');
		for(i=0;i<cookies.length;i++) {
			var data = cookies[i].split('=');
			if( data[0].replace(' ', '') == name ) {
				var obj = {'name':data[0].replace(' ', ''), 'value':data[1]};
				return obj;
			}
		}
		return false;
	} else {
		return false;
	}
}

//-----------------------------------------------------------------------------------

function set_postitFx() {
	var postit;
	if( postit = $('postit') ) {
		postit.onmouseover = function() {
			postit.set('morph',{duration:250});
			postit.morph({top:-203});
		}
		postit.onmouseout = function() {
			postit.set('morph',{duration:250});
			postit.morph({top:-390});
		}
	}
}

//-----------------------------------------------------------------------------------

function set_postit() {

	var postit;
	if( postit = $('postit') ) {

		var postit_cookie = get_cookie('tellyourfriends_postit');
		var persistentLogin = get_cookie('tellyourfriends');
		if( postit_cookie !== false || persistentLogin !== false) {
			if(FB_APP) {
				postit.style.left = '-600px';
				postit.style.top = '-390px';
				set_postitFx();
			} else {
				postit.style.left = '0px';
				postit.style.top = '0px';
			}
			postit.style.visibility = 'visible';
			postit.style.display = 'block';
		} else {
			postit.style.left = '-430px';
			postit.style.top = '80px';
			postit.style.visibility = 'visible';
			if(FB_APP) {
				$('content_right').style.display = 'block';
				setTimeout(function() {
					postit.style.display = 'block';
					postit.set('morph',{duration:500,onComplete:function(){
						set_postitFx();
					}});
					postit.morph({top:-390,left:-600});
				},2000);
			} else {
				setTimeout(function(){
					postit.set('morph',{duration:500,onComplete:function(){
						/*
						var img = document.createElement('img');
						img.id = 'fb_tooltip';
						img.src = '/img/fb_tooltip.png';
						img.onclick = function() {
							this.style.display = 'none';
							fb_login();
						}
						setTimeout(function(){
							$(img).setOpacity(0.001);
							document.getElementById('content_right').appendChild(img);
							var duration = (Browser.Engine.trident) ? 1 : 500;
							img.set('morph',{duration:duration});
							img.morph({opacity:1});
							setTimeout(function(){img.style.display='none';} ,4000);
						},1200);
						*/
					}});

					postit.morph({top:0,left:0});
				},1000);
			}
			set_cookie('tellyourfriends_postit', '1');
		}
	}
}

window.addEvent('load', function() {
	set_postit();

});
