/*
FILE ARCHIVED ON 13:12:02 May 13, 2013 AND RETRIEVED FROM THE
INTERNET ARCHIVE ON 14:43:04 Sep 17, 2014.
JAVASCRIPT APPENDED BY WAYBACK MACHINE, COPYRIGHT INTERNET ARCHIVE.
ALL OTHER CONTENT MAY ALSO BE PROTECTED BY COPYRIGHT (17 U.S.C.
SECTION 108(a)(3)).
*/
/******************************************************
* Loads the pageimage administration iframe if
* the user is editing the bamcms page.
*
* Loads and activates the slideshow if it's required.
*
*/
/* Runtime */
function init_pageimage($pageid)
{
// load admin iframe if required
if( $('module-specific-admin') )
{
// alert($('module-specific-admin'));
Element.update('module-specific-admin', '
Manage images for this page
');
}
// load slideshow if required
if( $('pageimage-slideshow') )
{
var mySlideshow = null;
mySlideshow = new slideshow('pageimage-slideshow',5);
}
}
/* Helper Methods */
function slideshow( container, timeout )
{
this.slides = [];
var nl = $(container).getElementsByTagName('div');
for (var i = 0; i < nl.length; i++)
{
if (Element.hasClassName(nl[i], 'pageimage-slide'))
{
this.slides.push(nl[i]);
}
}
this.timeout = timeout;
this.current = 0;
for ( var i = 0; i < this.slides.length; i++ )
{
this.slides[i].style.zIndex = this.slides.length - i;
this.slides[i].style.display = 'block';
}
Element.show(container);
this.timer = setTimeout( ( function(){ this.next(); } ).bind( this ), this.timeout + '999');
}
slideshow.prototype = {
show: function($current)
{
clearTimeout( this.timer );
this.current = $current;
for ( var i = 0; i < this.slides.length; i++ )
{
var slide = this.slides[(this.current + i) % this.slides.length];
slide.style.zIndex = this.slides.length - i;
}
var $delay = ( parseFloat(this.timeout) + 4 ) + '999'; //add 4 secs to the timeout
this.timer = setTimeout((function(){this.next();}).bind(this), $delay);
},
next: function($current)
{
for (var i = 0; i < this.slides.length; i++)
{
var slide = this.slides[(this.current + i) % this.slides.length];
slide.style.zIndex = this.slides.length - i;
}
Effect.Fade(this.slides[this.current],
{
duration:1,
afterFinish: function(effect)
{
effect.element.style.zIndex = 0;
Element.show(effect.element);
Element.setOpacity(effect.element, 1);
}
});
this.current = (this.current + 1) % this.slides.length;
this.timer = setTimeout((function(){this.next();}).bind(this), this.timeout + '999');
}
};
/* Helper Methods */
function init_sortable(){
//init the pageimage-sorting functionality
Sortable.create("sortable", {
tag:'div',
overlap:'horizontal',
constraint: false,
onUpdate:function(){
//alert(Sortable.serialize("sortable"));
var myAjax = new Ajax.Request(
'/pageimages/reorder/index.html', {
method: 'post',
parameters: '&'+Sortable.serialize("sortable"),
onComplete: function(){
new Effect.Appear('autosaved');
new Effect.Fade('autosaved', { queue: 'end'});
}
}
);
}
});
// display the pageimage thumbnail
if($('pageimage_thumbnail').value != "") {
$('pageimage_thumbnail_image').innerHTML = "";
}
}
function launchImageManager() {
mcImageManager.open(
'pageimage',
'',
'',
'changeImage',
{}
);
}
function addNewPageImage() {
mcImageManager.open(
'pageimage',
'data[Pageimage][thumbnail]',
'',
'changeImageAndSubmit',
{}
);
}
function regexpMatch(regex,subject) {
var re = new RegExp(regex);
var m = re.exec(subject);
if (m == null) {
return("Untitled");
} else {
var s = "Match at position " + m.index + ":\n";
for (i = 0; i < m.length; i++) {
s = s + m[i] + "\n";
}
return m[1];
}
}
function changeImage(url) {
url = url.replace("http://" + window.location.hostname, "");
$('pageimage_thumbnail').value = url;
alert('');
$('pageimage_thumbnail_display').innerHTML = '';
return true;
}
function changeImageAndSubmit(url) {
url = url.replace("http://" + window.location.hostname, "");
$('pageimage_thumbnail').value = url;
$('pageimage_title').value = regexpMatch(/\/([^\/]+)\./,url); //automatically enters a title
document.forms['pageimage'].submit();
return true;
}