
/** effects.js **/
/*
* GWF (General Website Framework)
* Copyright (C) 2008 Dinu Florin
*
* GWF is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* GWF is distributed in the hope that it will be useful,* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with GWF. If not, see <http://www.gnu.org/licenses/>.
*/function setCookie(name, value, days)
{
 if(days)
 {
 var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires = "; expires="+date.toGMTString(); }
 else var expires = ""; document.cookie = name+"="+value+expires+"; path=/";}function getCookie(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 removeCookie(name)
{
 setCookie(name,"",-1);}function MovableGWFEffect(id, params)
{
 var element = $(id); var dragOpacity = 1; var persistent = false; var zIndex = false; if(MovableGWFEffect.zStack == null) MovableGWFEffect.zStack = new Array(); var paramLen = params.length; for(var i=0; i < paramLen; i++)
 {
 if(isFinite(params[i]))
 {
 dragOpacity = params[i]; }
 else if(params[i] == 'persistent')
 {
 persistent = true; }
 else if(params[i] == 'zindex')
 {
 zIndex = true; MovableGWFEfect.zStack.push(element); }
 }
 var cookieName = "GWFM" + id; if(!persistent)
 {
 removeCookie(cookieName); }
 this.onMouseUp = function(event)
 {
 if(persistent)
 {
 if(zIndex)
 {
 MovableGWFEffect.zStack.each(function(elem, index) {
 elem.style.zIndex = 1500 + index; var cookieName = "GWFM" + elem.id; setCookie(cookieName, elem.style.left + "," + elem.style.top + "," + elem.style.zIndex, 5000); }); }
 else
 {
 setCookie(cookieName, this.style.left + "," + this.style.top + "," + this.style.zIndex, 5000); }
 }
 this.canMove = false; this.setOpacity(1); event.stop(); }
 this.onMouseDown = function(event)
 {
 if(event.isLeftClick())
 {
 this.canMove = true; this.oX = parseInt(this.style.left); this.oY = parseInt(this.style.top); this.clickX = event.pointerX(); this.clickY = event.pointerY(); this.setOpacity(dragOpacity); if(zIndex)
 {
 MovableGWFEffect.zStack = MovableGWFEffect.zStack.without(this); MovableGWFEffect.zStack.push(this); MovableGWFEffect.zStack.each(function(elem, index) {elem.style.zIndex = 1500 + index;}); }
 }
 else this.canMove = false; event.stop(); }
 this.onMouseMove = function(event)
 {
 if(this.canMove)
 {
 var x = event.pointerX(); var y = event.pointerY(); this.style.left = x - this.clickX + this.oX + "px"; this.style.top = y - this.clickY + this.oY + "px"; }
 event.stop(); }
 element.absolutize(); if(persistent)
 {
 var pos = getCookie(cookieName); if(pos != null)
 {
 pos = pos.split(','); if(pos[0] != null && pos[1] != null && pos[2] != null)
 {
 element.style.left = pos[0]; element.style.top = pos[1]; element.style.zIndex = pos[2]; }
 }
 }
 element.observe('mouseup', this.onMouseUp); element.observe('mousedown', this.onMouseDown); element.observe('mousemove', this.onMouseMove); element.observe('mouseout', this.onMouseMove);}