/**
 * content.js - insert headline here
 *
 * COPYRIGHT: All  title   and  proprietary  rights,  including  trade
 * secrets,   in   the   Software   and   any   copies thereof and the
 * accompanying  written   materials,   are  owned  by   schukai  GmbH
 * and  are  protected  by  German  copyright  laws,  other applicable
 * copyright   laws  and  international  treaty  provisions.
 *
 * @package    alvine
 * @author     schukai GmbH <info@schukai.de>
 * @copyright  Copyright (C) 2002, 2003, 2004, 2005, 2006 schukai GmbH
 * @license    http://www.alvine.de/license/
 * @version    20061114
 * @link       http://www.alvine.de/
 */

if(typeof alvine == 'undefined') var alvine = new Object();
 
function content_js_init(boxID, options){

  if(typeof alvine['session'] == 'undefined') alvine['session'] = new Object();
  if(typeof alvine['plugin']  == 'undefined') alvine['plugin'] = new Object();
  if(typeof alvine['content'] == 'undefined') alvine['content'] = new Object();
  if(typeof alvine['page']    == 'undefined') alvine['page'] = new Object();
  if(typeof alvine['content']['imagePreloader'] == 'undefined') alvine['content']['imagePreloader'] = new Object();
  
  if(typeof options.useImagePreloader != 'undefined'){
    if(options.useImagePreloader){
      page_onLoad(content_js_imagePreloader_preloadImages);      
    }
  }  
  
  content_js_importSettings();
  
}

function content_js_imagePreloader_registerImage(imageUrl, key){
  
  if(typeof imageUrl == 'undefined') return false;
  key = (typeof key == 'undefined')?imageUrl:key;
  
  if(typeof alvine['content']['imagePreloader'][key] == 'undefined') alvine['content']['imagePreloader'][key] = new Object();
  alvine.content.imagePreloader[key]['url'] = imageUrl;
  
  return true;  
}

function content_js_imagePreloader_getStoredImageObject(key){
  if(typeof key == 'undefined') return false;
  if(typeof alvine.content.imagePreloader[key]['object'] == 'undefined') return false;
  
  return alvine.content.imagePreloader[key]['object'];  
}

function content_js_imagePreloader_preloadImages(ev){
  
  if(!ev) ev = window.event;
  
  for(var i in alvine.content.imagePreloader){

    if(typeof alvine.content.imagePreloader[i]['url']    == 'undefined') continue;
    if(typeof alvine.content.imagePreloader[i]['object'] != 'undefined') continue;
    
    alvine.content.imagePreloader[i]['object'] = new Image();    
    alvine.content.imagePreloader[i]['object'].src = alvine.content.imagePreloader[i]['url'];  
  }
  
}


function content_js_cutWindow() {  
  document.body.style.overflow="hidden";
  if(document.getElementsByTagName("html")[0]) {
    document.getElementsByTagName("html")[0].style.overflow="hidden";
  };
  
  return true;
};


function content_js_releaseCuttedWindow() {  
  document.body.style.overflow="visible";
  if(document.getElementsByTagName("html")[0]) {
    document.getElementsByTagName("html")[0].style.overflow="";
  };
  
  return true;
};

function content_js_scrollWindow(left, top, absolutePositioning) {  
  absolutePositioning = (absolutePositioning==false)?false:true;
  
  if(absolutePositioning){  
    left = (isNaN(left))?0:left;
    top = (isNaN(top))?0:top;
    
    window.scroll(left, top);
  }
  
  return true;
};

function content_js_setHover(obj, hoverKey, onEventName, offEventName){
  obj = element_isObject(obj);
  
  if(!obj) return false;

  var staticHoverString = 'js_hover';
  
  var newHoverKey = (hoverKey)?staticHoverString+'_'+hoverKey:staticHoverString;
  
  if(typeof obj.alvine_hoverKey != 'undefined') return true;
  
  element_addClassName(obj, 'islink');
  element_addClassName(obj, newHoverKey);  
  obj.alvine_hoverKey = newHoverKey;
  
  onEventName = (onEventName)?onEventName:'mouseover';
  offEventName = (offEventName)?offEventName:'mouseout';
  
  event_add(obj, onEventName, content_js_addHover);
  event_add(obj, offEventName, content_js_removeHover);
  
  return true;
}

function content_js_addHover(ev){
  if(!ev)  ev = window.event;
  
  if(typeof this.alvine_hoverKey == 'undefined') return true;  
  element_addClassName(this, this.alvine_hoverKey);      
  
  return true;
}

function content_js_removeHover(ev){
  if(!ev)  ev = window.event;
  
  if(typeof this.alvine_hoverKey == 'undefined') return true;  
  element_removeClassName(this, ' '+this.alvine_hoverKey);      
  
  return true;
}
