/**
 * general site setup
 * 
 */

var site = Site.getInstance();


function preloadImages(srcs){
	var preloaded_images = new Asset.images(srcs);
}


// make standards compliant external links
site.addLoadEvent(Ah.ExternalLink.parseLinks);

// set up any collapsable lists
site.addLoadEvent(Ah.CollapsableList.parseLists);




// will clear a text input or textarea of any default value on the first click
function setupInteligentInputs(){
    
    $$('input[type=text]', 'textarea').each(function(input){
        if(!input.form || (input.form && $(input.form).hasClass('inteligent_inputs')) ){
            input.addEvent('focus', function(e){ 
				if(!e.target.clicked){ 
					e.target.value = ''; 
					e.target.clicked = true;
				} 
				}.bindWithEvent() 
			);
        }
    });
    
    function submitClick(e){ 
        $(e.target.form).getElements('input[type=text], textarea').each(function(input){
            if(!input.clicked){ 
                input.value = ''; 
                input.clicked = true;
            }
        });
    }
        
    $$('form.inteligent_inputs input[type=submit]').each(function(submit){
        submit.addEvent('click', submitClick.bindWithEvent(submit));
    });
}

site.addLoadEvent(setupInteligentInputs);







//// map
function setupLocationMap(){
    if(!$('map')) return;
    
    // set up the toggle
    //$('map_toggler').addEvent('click', toggleMap.bindWithEvent($('map_toggler')));
    
    var point = new LatLonPoint('53.842111640261216', '-0.6326043605804443');
    
    //make the map
    $('map').mapstract = new Mapstraction( 'map', 'google');
    $('map').mapstract.setCenterAndZoom( point , 13);
    // add controls
    $('map').mapstract.addControls({
        zoom: 'small',
        map_type: true
    });
    // marker and bubble
    var marker = new Marker(point);
    marker.setInfoBubble(
        '<div class="bubble">' + 'The Star @ Sancton' + '</div>'
    );
    $('map').mapstract.addMarker(marker);
    
    //$('map').hide();
    
    //Ah.Storage.map_slider = new Ah.Effects.Mover( $('map_container'), { morphStart: '.map_morph_start', morphEnd: '.map_morph_end'});
    function toggleMap(e){
        /*if($('map').getStyle('display') == 'none'){
           $('map').show();
        }else{
           $('map').hide();
        }*/
        e.stop();
        Ah.Storage.map_slider.toggle();
    }
}

site.addLoadEvent(setupLocationMap);










function initSlideShow(){
	if(!$('slideShow')) return;
	Ah.Storage.slideshow = new Ah.Effects.FadeSlideshow( $('slideShow'), Ah.Storage.ss_srcs, {  random: false,
																											   duration: 10000,
																											    effectOptions: {
																																duration: 1500, 
																															    transition: Fx.Transitions.Quad.easeOut
																																}
																										     });    
}
site.addLoadEvent( initSlideShow );






function initGallery(){
	if(!$('gallery')) return;
  
	Ah.Storage.gallery = new Ah.Effects.FadeSlideshow( $('gallery'), Ah.Storage.g_srcs, {  random: true,
																											   duration: 10000,
																											    effectOptions: {
																																duration: 1500, 
																															    transition: Fx.Transitions.Quad.easeOut
																																},
                                                                descriptions: Ah.Storage.g_alts
																										     });    
                                                         
 $('gallery_previous').addEvent('click', Ah.Storage.gallery.previous.bind(Ah.Storage.gallery) );
 $('gallery_start').addEvent('click', Ah.Storage.gallery.play.bind(Ah.Storage.gallery) );
 $('gallery_stop').addEvent('click', Ah.Storage.gallery.stop.bind(Ah.Storage.gallery) );
 $('gallery_next').addEvent('click', Ah.Storage.gallery.next.bind(Ah.Storage.gallery) );
}
site.addLoadEvent( initGallery );
















function initStripyTables(){
    var tables = $$('table');
    tables.each( function(table){
        if( !table.hasClass('no_stripes') ) new Ah.StripyTable( table );
    });
}

site.addLoadEvent( initStripyTables );







// google analytics ///////////////////////////////////////////////////////////

if(URCHIN != ''){
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); 
    document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
    function trackPage(){
        var pageTracker = _gat._getTracker(URCHIN); 
        pageTracker._initData(); 
        pageTracker._trackPageview();
    }
    Site.getInstance().addLoadEvent(trackPage);
}
