/*
 * Skafield JS
 * Copyright: anti-design.com GmbH & Co. KG, 2010
 * Author: Lars Lorenz
 * Version: $Id: common.js,v 1.11 2010/04/15 20:44:04 lars Exp $
 */

function lightBoxHelper() {
  if ($("a.lightbox").length > 0) {
    $(".contentBox").each(function(i) {
      if (this.id) {
        $("#"+this.id+" a.lightbox").lightBox({
          imageLoading: '/img/lightbox/lightbox-ico-loading.gif',
          imageBtnClose: '/img/lightbox/lightbox-btn-close.gif',
          imageBtnPrev: '/img/lightbox/lightbox-btn-prev.gif',
          imageBtnNext: '/img/lightbox/lightbox-btn-next.gif'
        });
      }
    });
  }
}

function playerController() {
  if ($("#title").length > 0) {
    $("ul.player li a#play",window.parent.frames['main'].document).hide();
    $("ul.player li a#stop",window.parent.frames['main'].document).show();
    var image = $("#title").html();
    $("#playtitle",window.parent.frames['main'].document).css('background-image','url('+image+')');
    $("#playtitle",window.parent.frames['main'].document).show();
  }
  else {
    $("ul.player li a#play",window.parent.frames['main'].document).show();
    $("ul.player li a#stop",window.parent.frames['main'].document).hide();
    $("#playtitle",window.parent.frames['main'].document).hide();
  }
}

function iframeController(params) {
  if (top.frames.length == 0) {
    var query = '';
    if (params) {
      query = location.href;
      if (query.indexOf('?')!=-1) {
        query = query.split('?');
        query = '?'+query[1];
      }
      else {
        query = '';
      }
    }
    window.location.href = '/index.php'+query;
  }
}

function heightManager() {
  var pageHeight = $(document).height();
  $("iframe#main").height(pageHeight);
}

function newsLinkHelper() {
  if ($(".contentBox a").length > 0) {
    $(".contentBox a").each(function(i) {
      if (this.href.indexOf('skafield.de')==-1) {
        this.target = '_blank';
      }
    });
  }
}


$(window).load(function() {
  if ($("body.index").length > 0) {
    heightManager();
  }
});

$(window).resize(function() {
  if ($("body.index").length > 0
      && !$.browser.msie) {
    heightManager();
  }
});

$(document).ready(function(){
  if ($("body.index").length > 0) {
    heightManager();
  }
  if ($("body.main").length > 0) {
    iframeController(true);
    lightBoxHelper();
    newsLinkHelper();
  }
  if ($("body.player").length > 0) {
    iframeController(false);
    playerController();
  }
});