/*  modified from script @ http://webfreak.no/wp/2007/09/05/get-for-mootools-a-way-to-read-get-variables-with-javascript-in-mootools/ */
    
    function $get(key,url){
        if(arguments.length < 2) url =location.href;
        if(arguments.length > 0 && key != ""){
            if(key == "#"){
                var regex = new RegExp("[#]([^$]*)");
            } else if(key == "?"){
                var regex = new RegExp("[?]([^#$]*)");
            } else {
                var regex = new RegExp("[?@]"+key+"=([^@#]*)");
            }
            var results = regex.exec(url);
            return (results == null )? "" : results[1];
        } else {
            url = url.split("?");
            var results = {};
            if(url.length > 1){
                url = url[1].split("#");
                if(url.length > 1) results["hash"] = url[1];
                url[0].split("@").each(function(item,index){
                    item = item.split("=");
                    results[item[0]] = item[1];
                });
            }
            return results;
        }
    } 

function urlencode(str) {
    return escape(str).replace('+', '%2B').replace('%20', '+').replace('*', '%2A').replace('/', '%2F').replace('@', '%40');
}

function window_size(mode) {
    window_w = getWidth();
    window_h = getHeight();
    window_s_h = getScrollHeight();
    window_scroll = getScroll();
    if( Browser.Engine.webkit && getHeight() != getScrollHeight() ) window_w -= 16;
    
    if( mode == 1 ) {
        $(document.body).adopt( new Element( 'div' , { 'id':'fade_bg' } ).setStyles({'height':window_s_h , 'width':window_w  }) );
        $('fade_bg').setOpacity(0.8);
        $('fade_bg').addEvent( 'click' , function() {
            if( $('production_stills_canvas') ) $('production_stills_canvas').destroy();
            if( $('player_canvas') ) {
                if( $('hero_player') ) {
                    hero_play_time = $('hero_player').getPlayheadTime();
                    hero_full_time = $('hero_player').getVideoDuration();
                }
                $('player_canvas').destroy();
            }
            $('fade_bg').destroy();
        });
    }
    
}


window.addEvents({
    
    'domready' : function() {
    
    if( $("search_n_js") ) $('search_n_js').destroy();
    
    Cookie.dispose('js_active');
    Cookie.write('js_active', 1 , { path: '/' } );

    base_url = $('base_').getProperty( 'href' );
    base_style = base_url + 'static/styles/1/';
    
    /* NOTE SLIDE */
    
    if( $('note') ) {
        slide_note = new Fx.Slide( 'note' , { wait:false , duration:1000  } ).hide();
        scroll_note = new Fx.Scroll(document.body);
        $('note').removeClass('hide');
    }
    
    function add_note( txt ) {
        if( $('note') ) {
            $('note').set( 'html' , txt );
            slide_note.slideIn();
            ( function() { slide_note.slideOut() }).delay(8000);
        }
    }
    
    /* SMOOTH SCROLL */
    new SmoothScroll();

    /* NAVIGATION MENU DROPDOWN */
    
    var navigation_main = $$('#menu li a');
    
    navigation_main.each( function( el, i ) {
    
        if( el.rel && $('menu_'+el.rel) ) {

            var oc = ''
            var x = ''
            var y = ''

            
            navigation_main[i].addEvents({
            
                'mouseover': function() {
                    xy = navigation_main[i].getCoordinates();
                    x =  xy.left;
                    Browser.Engine.trident ?  y = xy.top+xy.height-2 : y =  xy.top+xy.height;
                    if( x < 0 ) {x = -x}  
                    if( y < 0 ) {y = -y}  
                    
                    if( Browser.Engine.presto ) Browser.Platform.mac ? y = y+55 : y = y+60;
                    if( Browser.Engine.gecko ) y = y-1
                    
                    oc = el.getAttribute('class');
                    $('menu_'+el.rel).setStyles({ 'visibility' : 'visible' , 'left' : x , 'top':y  });
                    el.setProperty( 'class' , 'menu_tab' );
                },
                
                'mouseout': function() {
                    $('menu_'+el.rel).setStyle( 'visibility' , 'hidden' );
                    el.setProperty( 'class' , oc );
                }
                
            });
            
            $('menu_'+el.rel).addEvents({
            
                'mouseover': function() {
                    $('menu_'+el.rel).setStyles({ 'visibility' : 'visible'  });
                    el.setProperty( 'class' , 'menu_tab' );
                },
            
                'mouseout': function() {
                    $('menu_'+el.rel).setStyle( 'visibility' , 'hidden' );
                    el.setProperty( 'class' , oc );
                }
            
            });
        }
        
    });

    
    /* IMAGE SELECT */
    
    var img_array = $$('.thumb_select');
    var img_array_src = new Array;
    var img_delete = new Array;

    if( img_array.length > 0 ) {
    
        for( var i = 0 ; i < img_array.length ; i++ ) {
        
            img_array[i].setProperty( 'id' , i );
            img_array_src[i] = img_array[i].getProperty( 'title' );
        
            img_array[i].addEvent( 'click' , function(e) {
            
                e = new Event(e).stop();
                
                if( img_array[e.target.id] ) {
                
                    if( img_delete.contains(e.target.id) ) {
                        img_array[e.target.id].setProperty( 'class' , 'thumb_select' );
                        img_delete.remove(e.target.id);
                    } else {
                        img_array[e.target.id].setProperty( 'class' , 'thumb_select_on' );
                        img_delete.include(e.target.id);
                    }
                    
                    $('delete_hidden').empty();
                
                    for( var c = 0 ; c < img_delete.length ; c++ ) {
                        $('delete_hidden').adopt( new Element( 'input' , { 'type' : 'hidden' , 'name' : 'delete_img[]' , 'value' : img_array_src[img_delete[c]] } ) );
                    }
                
                }
                
            })
        
        }
    
    }
    
    if( $('img_change') ) {
    
        $('img_change').addEvent( 'change' , function() {
        
            $('micon').setProperty( 'src' , $('img_change').value );
        
        });
    
    }
    
    
    /* WORD COUNT */
    
    if( $('count') && $('current_count') && $('total_count') ) {
    
        var words = '';
    
        $('count').addEvent( 'keyup' , function() {
        
            words = $('count').value.clean();
            
            if( words != '' ) {
                words = words.split(/\s/);
                $('current_count').setHTML( words.length );
            } else $('current_count').setHTML( '0' );
            
            if( words.length >= $('total_count').innerHTML ) {
                $('current_count').setStyle( 'color' , 'red' );
            } else $('current_count').setStyle( 'color' , '' );
        
        });
    
    }
    
    /* IMAGE CALL */
    
    function image_call( mode , id ) {

        new Request.HTML({url:base_url+'dynamic/image_call.php?go='+mode+'&id='+id , onComplete:function(tree, el, html, js) {
        
            if( html ) {
            
                imgs = html.split( '|' );
                $('display_stills').empty();
                for( i = 0 ; i < imgs.length ; i++ ) {
                    $('display_stills').adopt( new Element( 'img' , { 'src':base_url+'static/images/shows_production_stills/'+id+'/sm/'+imgs[i] , 'alt':'thumbnail' , 'class':'thumbnail' } ) );
                }
            
                forms[0].adopt( new Element( 'input' , { 'type':'hidden' , 'name':'img_delete', 'id':'img_delete' } ) );
                 
                $$('.thumbnail').addEvent( 'click' , function() {
                    this.hasClass( 'thumbnail_on' ) ? this.setProperty( 'class' , 'thumbnail' ) : this.setProperty( 'class' , 'thumbnail_on' );
                    $('img_delete').value = '';
                    if( $$('.thumbnail_on').length > 0 ) {
                        img_info = [];
                        $$('.thumbnail_on').each( function( el, i ) {
                            img_info[i] = el.getProperty('src');
                        });
                        img_info = img_info.join('|');
                        $('img_delete').value = img_info;
                    }
                });
            
            } else $('display_stills').set('html', "You have no images uploaded" );
 
        }}).get();
    
    }
    
    if( $('display_stills' ) ) image_call( 'display_stills' , $get("id") );

    /* SEARCH */
    
    if( $('search_go' ) ) {
    
        $('search_find').setProperty( 'autocomplete' , 'off' );
    
        function update_search_suggest(sugg) {
            var search_res = ''
            if( k_status == 1 ) $clear(search_now)
            k_status = 0;
            for( i = 0 ; i < sugg.length ; i++ ) {
                if( sugg[i]['stitle'].toLowerCase().substr(0,find_val.length) == find_val.toLowerCase() && sugg[i]['stitle'] != '' ) {
                    sugg[i]['stitle'] = sugg[i]['stitle'].replace('\\', '');
                    search_res += '<a href="'+base_url+'show/'+sugg[i]['sname']+'">'+sugg[i]['stitle']+'</a>'
                }
            }
            if( search_res != '' ) {
                $('search_suggest_content').set('html', search_res );
                $('search_suggest').removeClass('hide');
                sugg_shows = $$('#search_suggest_content a');
                sugg_shows.addEvents({
                    'mouseenter': function() {
                        sugg_shows.removeClass('on');
                        this.addClass('on');
                        this.focus();
                    },
                    'mouseleave': function() {
                        sugg_shows.removeClass('on');
                    },
                    'keydown': function(e) {
                        sugg_shows.removeClass('on');     
                        if( e.key == 'down' ) {
                            sugg_go = sugg_on.getNext();
                            if( !sugg_go ) sugg_go = sugg_shows[0];
                            sugg_go.addClass('on');
                            sugg_on = sugg_go;
                        }
                        if( e.key == 'up' ) {                   
                            sugg_go = sugg_on.getPrevious();
                            if( !sugg_go ) sugg_go = sugg_shows[sugg_shows.length-1];
                            sugg_go.addClass('on');
                            sugg_on = sugg_go;
                        }
                        if( e.key == 'enter' ) {
                            e = new Event(e).stop();
                            location.href = sugg_on.getProperty('href');
                        }
                    }
                });
            }
        }
    
        k_status = 0;
        sugg_on = 0;
        k_fetch = [];
        
        $('search_find').addEvents({
        
            'keyup': function() {
                
                if( sugg_on == 0 ) {
                    k_status = 1;
                    find_val = $('search_find').getProperty('value').clean();
                    if( find_val.substr(0,4).toLowerCase() == 'the ' ) find_val = find_val.substr(4);
                    if( find_val != '' ) {
                        $('search_suggest_content').set('html', '' );
                        $('search_suggest').addClass('hide');
                        if( !k_fetch[find_val.substr(0,1)] ) {
                            search_now = ( function() { new Request.JSON({url: base_url+'dynamic/search.php', onComplete: function(shows){
                                k_fetch[find_val.substr(0,1)] = shows;
                                update_search_suggest(shows);
                                k_status = 0;
                                $clear(search_now)
                            }}).post({'find': find_val}); } ).delay(500); // only make the search if they stopped typing for a half second
                        } else update_search_suggest(k_fetch[find_val.substr(0,1)]);
                    }
                }    
            },
                
            'keydown': function(e){
                if( e.key == 'down' && $('search_suggest_content').get('html') != '' ) {
                    sugg_shows[0].addClass('on');
                    sugg_on = sugg_shows[0];
                    sugg_on.focus();
                }
                
                if( k_status == 1 ) $clear(search_now);
            },
            
            'click': function() {
                sugg_on = 0;
            }
            
        })
        
        $('search_go').addEvent( 'click' , function() {
        
            if( $('search_find').getProperty('value').clean() != '' ) {
                new_url = urlencode( $('search_find').getProperty('value').clean() )
                
                location.href = base_url+'search/'+new_url
            }
        });

    }

    
    /* FORM PROCESSER */


    /* -- First, find your forms ... and grab the crypt if we're bringing content in with AJAX -- */
    
    function forms_proc() {
    
        forms = $$('form');
        
        if( forms.length > 0 ) {
    
            des_load = 0;
            submit_buttons = [];
            
            forms.each( function( el , i ) {
                el.setProperty( 'id' , 'form_'+i );
                submit_buttons[i] = $$('#form_'+i+' input[type=submit]');
                if( el.getProperty( 'rel' ) == 'follow' ) {
                    des_load = 1;
                    submit_buttons[i].setProperty('disabled' , true );
                }
                
            });

            if( des_load == 1 ) {
                new Request.HTML({url:base_url+'fetch.inc' , onComplete:function(tree, el, html, js) {
                    kk = html
                    new Asset.javascript(base_url+'static/javascript/libs/webtoolkit.base64.js', { onload: function() { 
                        new Asset.javascript(base_url+'static/javascript/libs/des.lib.js', { onload: forms_load } );
                    }});
                }}).get();
            } else forms_load();
            
        }
        
    }
    
    function forms_load() {

        if( $$('.wysiwyg').length > 0 ) {
            new Asset.javascript(base_url+'static/javascript/libs/fckeditor/fckeditor.js', {onload:
                function(){
                    oEditor = [];
                    $$('.wysiwyg').each( function( el , i ) {
                        var oEditor = new FCKeditor(el.getProperty('name')) ;
                        oEditor.BasePath = base_url+"static/javascript/libs/fckeditor/" ;
                        oEditor.Config["CustomConfigurationsPath"] = base_url+"static/javascript/libs/fckeditor/stv_config.js?" + ( new Date() * 1 ) ;
                        oEditor.ReplaceTextarea() ;
                    });
                }
            });
        } 
        
        url_ext = ''
        
        forms.each( function( el , i ) {
            
            el.addEvent( 'submit' , function(e) {
            
                e = new Event(e).stop();

                form_no = i;
                
                if( $$('.wysiwyg').length > 0 ) {
                    oEditor = [];
                    $$('.wysiwyg').each( function( el , i ) {
                        oEditor[i] = FCKeditorAPI.GetInstance(el.getProperty('name'))
                        if( $('wysiwyg_'+i) ) $('wysiwyg_'+i).destroy();
                        forms[form_no].adopt( new Element( 'input' , { 'id':'wysiwyg_'+i , 'type':'hidden' , 'name':el.getProperty('name')+'_overwrite' , 'value':oEditor[i].GetXHTML() } ) );
                    });
                }

                $get('act') != '' ? url_ext = '?act='+$get("act")+'&id='+$get("id") : url_ext = '';

                new Request.HTML({url:base_url+'dynamic/'+el.getProperty('name')+'.php'+url_ext , onComplete:function(tree, el, html, js) {

                    if( html ) {
                        
                        var pieces = html.split("^");
                        var ret = pieces[0].split("|");
                        
                        if( pieces.length < 2 ) pieces[1] = ''
                        
                        if( pieces[2] ) {
                            forms[form_no].setProperties({ 'target':'upload_target' , 'enctype':'multipart/form-data' , 'method':'post' , 'action':base_url+'dynamic/image_upload.php'});
                            forms[form_no].adopt( new Element( 'input' , { 'name':'image_info', 'id':'image_info', 'type':'hidden' , 'value':pieces[2] } ) );
                            forms[form_no].adopt( new Element( 'iframe' , { 'id':'upload_target', 'name':'upload_target', 'src':'' } ).setStyles({'width':0, 'height':0, 'border':0 }) );
                            forms[form_no].submit();
                            
                            $('upload_target').addEvent( 'load' , function() {
                                if( pieces[2].contains('stills') ) image_call( 'display_stills' , $get("id") );
                                forms[form_no].removeProperties('target', 'enctype', 'action');
                                $('image_info').destroy();
                                $('upload_target').destroy();
                                add_note('The image(s) have been uploaded');
                            });
                        }

                        if( ret[0] == "cookie" ) {
                        
                            Cookie.write('stvuser', ret[1] , { path: '/' } );
                            if( $get('remember') ) {
                                type_r = $get('remember').split('_');
                                if( type_r[0] == 'show' ) {
                                    location.href = base_url+'show/'+type_r[1]+'/'
                                    return;
                                }
                            }
                            location.href = base_url+'members/profile/'
                            
                        } else if( ret[0] == "cookie_admin" ) {
                        
                            Cookie.write('ccadmin', ret[1] , {path: '/'} );
                            location.href = base_url+'administration/'

                        } else if( ret[0] == "blog_comment" ) {
                        
                            new Element( 'div' , {'class':'blog_comments' , 'html':ret[1] } ).injectBefore( $('add_comment') );
                            
                        } else if( ret[0] == "forward" ) {
                    
                            location.href = ret[1];
                    
                        } else if( pieces[1] == "comment" ) {
                            
                            location.href = location.href
                            
                        } else if( pieces[1].contains('directions:') ) {
                        
                            map_info = pieces[1].split(':');
                            load_map_dir(map_info[1])
                            
                        } else if ( pieces[0] == 'booking_calc' ) {
                        
                            pay = pieces[1].split('|');
                        
                            $('pay_total').set('html', pay[0] );
                            $('pay_deposit').set('html', pay[1] );
                            
                        } else if ( pieces[0] == 'pay_form' ) {
                        
                            $('content').set('html',pieces[1] );
                            $('VSPForm').submit();
                            return;
                            
                        } else if( pieces[0] ) {

                            var error_ret = ret.map( function( item, index ){ return item * 1 } );
                            var error_msg = $$('#form_'+form_no+' b.error');
                            var input_f = $$('.right input');
                            
                            error_msg.setStyles({'visibility':'hidden', 'display':'none'});
                            
                            for( var i = 0 ; i < error_msg.length ; i++ ) {
                                if( error_ret.contains( i ) ) error_msg[i].setStyles({ 'visibility':'visible', 'display':'inline'});
                            }
                            
                            error_msg.addEvent( 'click' , function() { this.setStyles({'visibility':'hidden', 'display':'none'}); } );
                            
                            scroll_note.toElement('note');
                
                        } else if( pieces[1] ) {
                            add_note( pieces[1] );
                            scroll_note.toElement('note');
                        }
                
                    } else if( $('success') ) $('content').set('html', $('success').get('html') );

                    restore_sub_button();
                
                }}).post(forms[i])
        
            });
        
        });
        
    }

    forms_proc();

    sub_button_val = ''
    function restore_sub_button() {
        if( sub_button_val != '' ) {
            sub_button.setProperty( 'value' , sub_button_val );
        }
    }
    
    $$('input[type=submit]').addEvent( 'click' , function() {
        sub_button = this;
        sub_button_val = this.getProperty('value');
        this.setProperty( 'value' , 'Sending...' );
    });
    

    /* DELETE */
    
     if( $$('.delete').length > 0 ) {
    
        $$('.delete').addEvent( 'click', function(e) {
 
            e = new Event(e).stop();
            e.stopPropagation();
            
            cell = this.getParent();
            row = cell.getParent();

            if( confirm( "Are you sure?" ) ) {

                new Request.HTML({url:this.getProperty('href') , onComplete:function(tree, el, html, js) {
                    row.addClass( 'hide' );
                    if( $$('tr.hide').length == $$('.delete').length ) location.href = location.href
                    if( html ) add_note( html );
                }}).post({'id':this.getProperty('rel')})
            
            }
        });
    
    }   
    
    /* LOG IN REPLACE */
    
    if( $('log_in_container') ) {
    
        var log_in_orig = $('log_in_container').get('html');
    
        function login_click( e ) {
    
            e = new Event(e).stop();
        
            $('log_in_container').set( 'html', $('log_in_hidden').get('html') );
            
            forms_proc();
            
            $('log_in_password').addEvent( 'focus' , function() { $('log_in_password').setProperties({ 'type' : 'password' , 'value' : '' }) });
            $('log_in_name').addEvent( 'click' , function() { $('log_in_name').setProperty( 'value' , '' ) });
            $('log_in_reset').addEvent( 'click' , function() { 
                $('log_in_container').set( 'html', log_in_orig );
                $('log_in').addEvent( 'click' , login_click );
            });

        }
    
        $('log_in').addEvent( 'click' , login_click );
    
    }
    
    /* CLICK SHOW */

    if( $$('.click_show').length > 0 ) {
    
        $$('.click_show').each( function( el , i ) {
    
            el.addEvent( 'click' , function() {
                $$('.click_target').addClass( 'hide' );
                $$('tr[rel='+el.getProperty('id')+']').removeClass( 'hide' );
            });
    
        }) 
        
        $$('.click_target').addClass( 'hide' );
    
    }
    


        /* -- performs search while user typing in textarea -- */

        if( $('search_txt') ) {
    
            k_status = 0;
        
            $('search_txt').addEvents({
            
                'keyup': function() {
                    k_status = 1;
                    $('search_results').set('html', '' );
                    search_now = ( function() { new Request.HTML({url:base_url+'dynamic/'+$('search_txt').getProperty('rel')+'.php' , onComplete:function(tree, el, html, js) {
                        $('search_results').removeClass('loading');
                        $('search_results').set('html', html );
                        k_status = 0;
                        $clear(search_now)
                    }}).post({'name':$('search_txt').value}); } ).delay(2000); // only make the search if they stopped typing for 2 seconds
                },
                'keydown': function(){
                    k_status == 1 ? $clear(search_now) : $('search_results').addClass('loading');
                }
            })
        
        }    
    
        /* -- alernate colours on table rows -- */
    
        if( $$('table.alternate' ).length > 0 ) {
            $$('table.alternate tr:even').setProperty( 'class' , 'dark' );
            $$('table.alternate tr:odd').setProperty( 'class' , 'light' );
        }
        
        /* -- column spacing -- */
        
        if( $$('.column').length > 0 ) {
            $$('.columns .column:even').setStyle( 'float' , 'left' );
            $$('.columns .column:odd').setStyle( 'float' , 'right' );
        }
        
        if( $('map') ) {
            
            var localSearch = new GlocalSearch();
            
        
function usePointFromPostcode(postcode, callbackFunction) {
	
	localSearch.setSearchCompleteCallback(null, 
		function() {
			
			if (localSearch.results[0])
			{		
				var resultLat = localSearch.results[0].lat;
				var resultLng = localSearch.results[0].lng;
				var point = new GLatLng(resultLat,resultLng);
				callbackFunction(point);
			}else{
				alert("Postcode not found!");
			}
		});	
		
	localSearch.execute(postcode + ", UK");
}

            

            function load_map() {
                if (GBrowserIsCompatible()) {
                    
                    map_ = new GMap2( $('map') );
                    
                    map_.setCenter( new GLatLng( 50.492823383934635,-4.319794178009033 ) , 13 )
                    map_.openInfoWindowHtml( map_.getCenter() ,'<div class=\'small\'><b>Coombe Cottage</b><br />Liskeard Road<br />Callington<br />Cornwall<br />PL17 7HJ</div>' )
                    map_.setMapType( G_HYBRID_MAP )
                    map_.addControl(new GSmallMapControl());
                    map_.setZoom( 16 )
                    map_.enableScrollWheelZoom()
                    var locationicon = new GIcon();
                    locationicon.image = 'mapmarker.png';
                    locationicon.iconSize = new GSize(157, 69);
                    locationicon.iconAnchor = new GPoint(107, 0);
                }
            }
        
            load_map();
            
            $('get_car_dir').addEvent( 'click' , function(e) {
                e.stop();
                usePointFromPostcode($('get_car_dir_pc').getProperty('value'), function(point){
                    load_map_dir(point.lat() + ',' + point.lng());
                });
                
            });
            
            function load_map_dir(latlng) {
                map_.setCenter( new GLatLng(latlng  ) , 13 )
                map_.addControl(new GSmallMapControl());
                map_.setZoom( 10 )
                gdir = new GDirections(map_, $('route'));
                gdir.load('from: ' + latlng + ' to:  ' + '50.492823383934635,-4.319794178009033' );
                
                $('map').setStyles({'height':'500px'});
            }
        
        }     

        $$('.currency img').addEvent( 'click' , function() {
            Cookie.write( 'cccurrency' , this.getProperty('alt') , {'path':'/'} );
            location.href = location.href;
        });
    
        if( $('slide_show') ) {

            new Request.JSON({url:base_url+'dynamic/slide_show.php?folders='+$('slide_show').getProperty('rel') , onComplete:function(img_list) {
        
                if( img_list ) {
                   
                    ss_imgs = new Asset.images(img_list, {
                        onProgress: function(c,i) {
                            $('slide_show').set('html','<p style="padding:10px ; font-weight:bold">Loading image ' + (c+1) + ' of ' + ss_imgs.length + '</p>' );
                            if( (c+1) == ss_imgs.length ) $('slide_show').set('html', '');
                        },
                        onComplete: function() {
                            data = {};
                            
                            function sort_r() { return ( Math.round(Math.random())-0.5 ); }
                            ss_imgs.sort(sort_r);
                            
                            ss_imgs.each( function( el, i ) {
                                this[el.getProperty('src')] = {'caption':el.getProperty('alt')};
                            },data);
	  
  		                    new Slideshow.KenBurns('slide_show', data, { captions: true, controller: true, delay: 2000, duration: 2000, height: 420, width: 400 });
                        }
                    });

                } else $('slide_show').set('html', "There are no images to view for this slideshow" );
 
            }}).get(); 

        }
        
        if( $('gallery') ) {

            new Request.JSON({url:base_url+'dynamic/slide_show.php?folders='+$('gallery').getProperty('rel') , onComplete:function(img_list) {
        
                if( img_list ) {
                   
                    ss_imgs = new Asset.images(img_list, {
                        onProgress: function(c,i) {
                            $('gallery').set('html','<p style="padding:10px ; font-weight:bold">Loading image ' + (c+1) + ' of ' + ss_imgs.length + '</p>' );
                            if( (c+1) == ss_imgs.length ) $('gallery').set('html', '');
                        },
                        onComplete: function() {
                            data = {};

                            ss_imgs.each( function( el, i ) {
                                this[el.getProperty('src')] = {'caption':'Image ' + (i+1) + ' of ' + ss_imgs.length };
                            },data);

  		                    new Slideshow.KenBurns('gallery', data, { controller: true, captions:true, height: 480, duration:3000 ,  thumbnails: true, width: 640 });
                        }
                    });

                } else $('gallery').set('html', "There are no images to view for this slideshow" );
 
            }}).get(); 

        }

    },
    
    'unload': function() {
        
        if( $('map') ) {
            GUnload();
        }
    
    },
    
    'load': function() {
    

        if( $('date_arrive') )  {
            book_cal = new Calendar({
                'date_arrive':'d/m/Y',
                'date_depart':'d/m/Y'
            }, {pad:1, direction:1});
        }





        /* -- panel toggling -- */
    
        if( $$('#panel_tabs li').length > 0 ){
    
            nav_inner_link = $$('#panel_tabs li a');  
            nav_inner_span = $$('.panel');
            nav_fx = [];
            s_l = '-1';

            nav_inner_link.each( function( el, i ) {
                nav_fx[i] = new Fx.Slide( nav_inner_span[i] , { wait:false ,  duration:250  , transition:Fx.Transitions.Quad.easeInOut } );
                nav_fx[i].hide();     
                el.setProperty( 'rel' , i );
            });
            
            nav_inner_link.addEvent( 'click' , function(e) {
                e = new Event(e).stop();
                setpanel(this.getProperty('rel'));
            })     

            function setpanel( p ) {

                if( p != s_l ) {
        
                    if( s_l != -1 ) {
                        Cookie.write( 'panel' , p );
                        nav_fx[s_l].slideOut().chain(function() { nav_fx[p].slideIn() });
                        nav_inner_link.removeClass( 'on' );
                    } else nav_fx[p].show();

                    nav_inner_link[p].addClass( 'on' );                    
                    s_l = p;
            
                }
            
            }
        
            var p = Cookie.read( 'panel' );
            if( p == '' || !nav_inner_link[p] ) p = 0;
       
            setpanel(p);

        }
        
        size_col_to = 0;
        if( $$('.column').length > 0 ) { 
            $$('.column').each( function( el, i ) {
            if( el.getHeight() > size_col_to ) size_col_to = el.getHeight();
            }) 
            $$('.column').setStyle('height',size_col_to);
        }
        
        /* -- if we have a blank content page, fill it -- */
        
        ( function() { if( $('mainwrap').get('html') == '' ) {
            $('mainwrap').load(base_url+'static/404.html');
            if( $$('#menu li a[class=tab_on]').length  > 1 )  $$('#menu li a').removeClass('tab_on');
        } } ).delay(50); // slight delay or Safari cries like a girl

    }
    
    
    

});
