
//Extend the scal library to add draggable calendar support.
//This script block can be added to the scal.js file.
Object.extend(scal.prototype,
{
	toggleCalendar: function()
	{
		var element = $(this.options.wrapper) || this.element;
		this.options[element.visible() ? 'onclose' : 'onopen'](element);
		this.options[element.visible() ? 'closeeffect' : 'openeffect'](element, {duration: 0.5});
	},

	isOpen: function()
	{ 
		return ( $(this.options.wrapper) || this.element).visible();
	}
});


document.observe('dom:loaded', function() {
	/*
	 * If a link has the rel "external" the target will be setted to blank.
	 */
	$$('a[rel="external"]').each(function(link){
		if(link.readAttribute('href') != '' && link.readAttribute('href') != '#'){
			link.writeAttribute('target', '_blank');
		}
	});

    new Protofade('protofade', { Random: true, Duration: 2.0, Delay: 4.0 });

	if($('PersonOldpassword')) {
		$('PersonOldpassword').setAttribute('autocomplete', 'off');
		$('PersonOldpassword').setValue('');
	}

	if($('PersonNewpassword')) {
		$('PersonNewpassword').setValue('');
	}
	
	if($('PersonNew2password')) {
		$('PersonNew2password').setValue('');
	}
});

	Shadowbox.init({
	   players:  ['img', 'html', 'iframe', 'qt', 'wmp', 'swf', 'flv']

	});

//this is a global variable to have only one instance of the calendar
var calendar = null;

//@element	 => is the <div> where the calender will be rendered by Scal.
//@input	 => is the <input> where the date will be updated.
//@container => is the <div> for dragging.
//@source	 => is the img/button which raises up the calender, the script will locate the calenar over this control.
function showCalendar(element, input, container, source)			
{
	if (!calendar)
	{
		container = $(container);
		//the Draggable handle is hard coded to "rtop" to avoid other parameter.
		new Draggable(container, {handle: "rtop", starteffect: Prototype.emptyFunction, endeffect: Prototype.emptyFunction});

		//The singleton calendar is created.
		calendar = new scal(element, $(input), 
		{
			updateformat: 'dd/mm/yyyy', 
			closebutton: '&nbsp;', 
			wrapper: container
		}); 
	}
	else
	{
		calendar.updateelement = $(input);
	}

	var date = new Date($F(input));
	calendar.setCurrentDate(isNaN(date) ? new Date() : date);

	//Locates the calendar over the calling control  (in this example the "img").
	if (source = $(source))
	{
		Position.clone($(source), container, {setWidth: false, setHeight: false, offsetLeft: source.getWidth() + 2});
	}

	//finally show the calendar =)
	calendar.openCalendar();
};

var imageArray = new Array(	"../../img/new/header_image.jpg",
							"../../img/new/header_image2.jpg",
							"../../img/new/header_image3.jpg", 
							"../../img/new/header_image4.jpg");


