/*----------------------------------------------------------------------------
    Title: puder_consortio  
   Author: MARIO GRUSCHETZKI // MEDIENDESIGN
     Date: 18-06-2008
  Project: puder-consotio.de

  (c) Copyright 2008 Mario Gruschetzki. All Rights Reserved. 
----------------------------------------------------------------------------*/

function init_application() {

//  dev('page');
  if ($('slideshow-home')){ 
    
    var slideshow_home = new Slideshow;
    
    slideshow_home.config_progress('content-main','div',{'id': 'loading','class': 'progress'});
    slideshow_home.start('slideshow-home','li', 3)  
    
  };
  if($$('div.slideshow')){
    var slideshows = $$('div.slideshow');
    slideshows.each(function(slideshow){
      slideshow.addClassName('enable');
      var show = new SlideShow($(slideshow).readAttribute('id'));
      
    });
  }
  // call_if_condition_is_true($('content-main',test_func));
  link_set_target_blank($$('body')[0],'a.external');
  position_helper();
}

function position_helper(){

  var viewport      = document.viewport.getDimensions();
  var content_main  = $('content-main').getDimensions();
  var max_height    = '';
  var mh_vp         = viewport.height -95;
  var branding_info = $('branding-info');
  
  if(content_main.height > mh_vp){
    max_height  = content_main.height;
    position    = max_height + 102;
    branding_info.setStyle({  top: position+'px' });
  }
  else
  {
    max_height  = viewport.height;
    position    = max_height - 25;
    branding_info.setStyle({  top: position+'px'});
  }
}
  
function dev(condition) {
  var body = $(condition);
  if(body){
    var grid  = new Element('div', { 'id': 'grid'});
    var dev   = new Element('div', { 'id': 'development'});
    body.insert(grid);
    body.insert(dev);

    $('grid').onclick=function(){
      $('development').toggleClassName('show_grid');
    }   
  }

};

function link_set_target_blank(region,selector){

  var external_links = $(region).select(selector);
  $A(external_links).each(function(link){
    $(link).setAttribute('target','_blank');
  });
}

function call_if_condition_is_true(condition, call_function){
  if(condition){
    call_function;
  }else{
    return null;
  }
}
function test_func(){
  alert("funktioniert!");
}
// Call this function when the page has been loaded
// function map_initialize() {
//   var map = new google.maps.Map2(document.getElementById("map"));
//   map.setCenter(new google.maps.LatLng(37.4419, -122.1419), 13);
// }
// Event.observe(window, 'load',init_application);

document.observe('dom:loaded', function () { init_application(); });