// -- textareas ------------------------------------------------------------------------------
jQuery(document).ready(function() {
  var j_ta = jQuery("textarea");

  var __fix_textarea = function() {
    j_ta.each(function() {
      if (this.scrollHeight > this.offsetHeight) {
        if (this.offsetHeight < 400) {
          if (this.scrollHeight < 400) {
            this.style.height = this.scrollHeight+"px";
          } else {
            this.style.height = "400px";
          }
        }
      }  
    });
    window.setTimeout(__fix_textarea, 100);
  }
  window.setTimeout(__fix_textarea, 100);
});
//*/

// -- search box -----------------------------------------------------------------------------
jQuery(document).ready(function() {
  jQuery("#div_search input")
    .bind("focus", function() {
      if (this.value == "Search this site") {
        this.value = "";
      }
    })
    .bind("blur", function() {
      if (this.value == "") {
        this.value = "Search this site";
      }
    });
});
//*/

// -- login box ------------------------------------------------------------------------------
function ui_login_toggle() {
  var j_img = jQuery("#div_login_button a img");
  var j_lb = jQuery("#div_login_box");
  if (j_lb.is(":visible")) {
    j_img.attr("src", "images/plus.gif");
    j_lb.hide();
    jQuery(".home .help-compare .right_col").css("margin-top", "110px");
  } else {
    j_img.attr("src", "images/minus.gif");
    j_lb.show();
    jQuery(".home .help-compare .right_col").css("margin-top", "220px");
  }
  return false;
}
jQuery(document).ready(function() {
  jQuery("#div_login_button a")
    .bind("click", ui_login_toggle);
});
//*/


// -- default page : blocks ------------------------------------------------------------------
jQuery(document).ready(function() {
  var timeout;
  jQuery("#div_blocks .block").hover(
    function() {
      var j_this = jQuery(this);
      if (timeout) {
        window.clearTimeout(timeout);
      }
      timeout = window.setTimeout(function() {
        j_this
          .addClass("block-hover")
          .siblings(".block-hover")
            .removeClass("block-hover")
        ; 
      }, 500);
    },
    function() { window.clearTimeout(timeout); }
  );
});
//*/

// -- default page : blocks ------------------------------------------------------------------
jQuery(document).ready(function() {
  /*
  var j_h_0 = jQuery("div#div_intros .slides #div_intro_start").height();
  var j_h_1 = jQuery("div#div_intros .slides #div_intro_banks").height();
  var j_h_2 = jQuery("div#div_intros .slides #div_intro_dealers").height();
  var j_h_3 = jQuery("div#div_intros .slides #div_intro_funds").height();
  var j_h_4 = jQuery("div#div_intros .slides #div_intro_brokers").height();
  var j_h_5 = jQuery("div#div_intros .slides #div_intro_traders").height();
  
  j_h =  j_h_0;
  if (j_h_1 > j_h) { j_h = j_h_1; }
  if (j_h_2 > j_h) { j_h = j_h_2; }
  if (j_h_3 > j_h) { j_h = j_h_3; }
  if (j_h_4 > j_h) { j_h = j_h_4; }
  if (j_h_5 > j_h) { j_h = j_h_5; }
  
  jQuery("div#div_intros .slides .intro_right table").css("height", j_h);
  */
  var j_h = jQuery("div#div_intros .slides").height();
  jQuery("div#div_intros .slides div.intro_right").each(function() {
    //var j_h_temp = jQuery(this).height();
    var j_h_temp = 327;
    if (j_h_temp > j_h) { j_h = j_h_temp };
  })
  jQuery("div#div_intros .slides .intro_right table").css("height", j_h);
});

jQuery(document).ready(function() {
  var j_block_h = 100;
  jQuery("div#div_blocks .block.slide_hrel .body .bg_body_middle").each(function() {
    var j_block_h_0 = jQuery(this).height();
    if (j_block_h_0 > j_block_h) { j_block_h = j_block_h_0; }
  });
  jQuery("div#div_blocks .block.slide_hrel .body .bg_body_middle").css("height", j_block_h);
});
//*/

// -- top & bottom menus ---------------------------------------------------------------------
jQuery(document).ready(function() {
  jQuery("#ul_top_menu li:first")
    .addClass("left");
  jQuery("#ul_top_menu li")
    .hover(
      function() { jQuery(this).addClass("hover"); },
      function() { jQuery(this).removeClass("hover"); }
    );
  jQuery("#ul_bottom_menu li:first")
    .addClass("left");
  jQuery("#ul_bottom_menu li:last")
    .addClass("right");
});
//*/

// -- POPUP WINDOWS --------------------------------------------------------------------------
function ui_reload_top_frame() {
  var href = top.location.href;
  top.location.replace(href);
}
function ui_popup_close() {
  function __do_close(doc) {
    var j_pw = jQuery("#popup_window", doc);
    var j_pw_title = jQuery("#div_pw_title", doc);
    var j_pw_frame = jQuery("#frame_pw", doc);
    
    j_pw_title.html("&nbsp;")
    j_pw_frame.attr("src", "about:blank");
    j_pw.attr("class", "nop");

    return false;
  }
  __do_close(window.top.document);
}

jQuery(document).ready(function() {
  var j_pw = jQuery("#popup_window");
  var j_pw_title = jQuery("#div_pw_title");
  var j_pw_frame = jQuery("#frame_pw");

  function open_popup(j_this, attr) {
    var p_classes = j_this.attr("class").split(' ');

    var p_type = "type_1";
    for (var index = 0; index < p_classes.length; index++) {
        var p_class = p_classes[index];
        if (p_class.indexOf("type_")==0) {
            p_type = p_class;
        } else if (p_class=="admin" || p_class=="admin_link") {
            p_type = p_class;
        }
    }

    var p_href = j_this.attr(attr);
    j_pw_title.html(j_this.attr("title"))
    j_pw.attr("class", "act " + p_type);
      if ($.browser.msie && $.browser.version == 6) {
        var __fix_popup_position_ie6 = function() {
          scroll_position = jQuery("html").scrollTop();
          html_height = jQuery("html").height() - 4;
          //alert(scroll_position);
          jQuery("#popup_window").css("top", scroll_position).css("height", html_height);
          window.setTimeout(__fix_popup_position_ie6, 100);
        }
        window.setTimeout(__fix_popup_position_ie6, 100);
      }
    if (p_href.indexOf("?") > 0) {
      j_pw_frame.attr("src", p_href+"&type="+p_type);
    } else {
      j_pw_frame.attr("src", p_href+"?type="+p_type);
    }
    return false;
  };

  jQuery("a.popup")
    .bind("click", function() {
      open_popup(jQuery(this), "href");
      return false;
    });

  jQuery("li.category_terms_and_conditions a, li.category_privacy_statement a")
    .bind("click", function() {
      open_popup(jQuery(this), "href");
      return false;
    });


  jQuery("div.div_popup")
    .bind("click", function() {
      open_popup(jQuery(this), "rel");
    });

  jQuery(".iframe a.admin")
    .bind("click", function() {



      function __do_open(doc) {
        var j_pw = jQuery("#popup_window", doc);
        j_pw.attr("class", "act admin");

        return false;
      }
      __do_open(window.top.document);



    });

  jQuery("#a_pw_close")
    .bind("click", ui_popup_close)
    .hover(
      function(){
        jQuery(this).addClass("close_popup_act");
      },
      function() {
        jQuery(this).removeClass("close_popup_act");
      }
    );

});
//*/

// -- solutions left block -------------------------------------------------------------------
jQuery(document).ready(function() {
  var j_head   = jQuery("#div_solutions_block .head_block");
  var j_middle = jQuery("#div_solutions_block .middle");

  var j_chead = null;

  function __animate_block(j_h, j_m) {
    j_head.removeClass("body_block");
    j_middle.slideUp(300);

    j_h.addClass("body_block");
    j_m.slideDown(300);
  }
  function __animate_page() {
    if (j_chead) {
      j_cmiddle = j_chead.next(".middle");
      if (!j_cmiddle.is(":visible")) {
        if (!j_middle.is(":animated")) {
          __animate_block(j_chead, j_cmiddle);
        }
      }
    }
    window.setTimeout(__animate_page, 150);
  }
  window.setTimeout(__animate_page, 150);

  jQuery("#div_solutions_block .head_block")
    .hover(function() {
      j_chead = jQuery(this);
    });

  jQuery("#div_solutions_block .head_block:first").addClass("body_block");
  jQuery("#div_solutions_block .middle:first").show();
});
//*/

// -- links left block -----------------------------------------------------------------------
jQuery(document).ready(function() {
  var j_title   = jQuery("#div_block_links li.outli");
  var j_body = jQuery("#div_block_links div.body");

  var j_chead = null;

  function __animate_block(j_h, j_m) {
    j_title.removeClass("act");
    j_body.slideUp(300);

    j_h.addClass("act");
    j_m.slideDown(300);
  }
  function __animate_page() {
    if (j_chead) {
      j_cmiddle = j_chead.children(".body");
      if (!j_cmiddle.is(":visible")) {
        if (!j_body.is(":animated")) {
          __animate_block(j_chead, j_cmiddle);
        }
      }
    }
    window.setTimeout(__animate_page, 150);
  }
  window.setTimeout(__animate_page, 150);

  jQuery("#div_block_links li.outli")
    .hover(function() {
      j_chead = jQuery(this);
    });

  jQuery("#div_block_links li.outli:first").addClass("act");
  jQuery("#div_block_links div.body:first").show();
});
jQuery(document).ready(function() {
  jQuery("#div_block_links a.klappe")
    .click(function() {
      jQuery(this)
        .toggleClass("act")
        .next("span.klappe")
          .toggleClass("act")
        .parent("div.body")
          .css("height", "auto")
      ;
    })
});
//*/

// -- SLIDER -----------------------------------------------------------------------------------
var ui_slider_scroll_rel = null;

jQuery(document).ready(function() {
  var i_width = jQuery("div.slides div:first").width();
  var s_width = jQuery("div.slides > div").length * i_width + 50;

  var j_slider = jQuery("div.slides");
  j_slider
    .css("width", s_width+"px")
    .css("left", "0px")
  ;

  var j_a_left = jQuery("div.arrow_left a");
  var j_a_right = jQuery("div.arrow_right a");

  ui_slider_scroll_rel = function(rel_id) {
    var j_rel = jQuery("#"+rel_id);
    var rel_left = -j_rel.position().left;

    var j_prev = j_rel.prev();
    if (j_prev.length <= 0) {
        j_prev = j_rel.siblings(":last");
    }

    j_a_left.attr("href", "javascript: ui_slider_scroll_rel('"+j_prev.attr("id")+"');");

    var j_next = j_rel.next();
    if (j_next.length <= 0) {
        j_next = j_rel.siblings(":first");
    }

    j_a_right.attr("href", "javascript: ui_slider_scroll_rel('"+j_next.attr("id")+"');");

    if (j_slider.is(":animated")) {
      j_slider.stop();
    }

    j_slider.animate({ left: rel_left }, 500, "swing", function() {
      var j_a = jQuery("a.slide_trel[rel='"+rel_id+"']");
      var j_li = j_a.closest("li");
      j_li.siblings("li").removeClass("act");
      j_li.addClass("act");

      jQuery("div.slide_hrel").removeClass("block-hover");

      var j_h = jQuery("div.slide_hrel[rel='"+rel_id+"']");
      j_h.addClass("block-hover");
    });
  }

  jQuery("a.slide_trel")
    .bind("click", function() {
      var j_a = jQuery(this);
      ui_slider_scroll_rel(j_a.attr("rel"));
    });

  var timeout;
  
  jQuery("div.slide_hrel")
    .hover(
      function() {
        var j_div = jQuery(this);
        if (timeout) {
          window.clearTimeout(timeout);
        }
        timeout = window.setTimeout(function() {
          ui_slider_scroll_rel(j_div.attr("rel"));
        }, 500);
      }, 
      function() { window.clearTimeout(timeout); }
    );
});
//*/

// -- SPLASH SCREENS ---------------------------------------------------------------------
jQuery(document).ready(function() {
  var j_slider = jQuery("#div_intro_start .slider");

  jQuery("#div_intro_start .arrows .button:first").addClass("act");
  
  jQuery("#div_intro_start .arrows .button a")
    .bind("click", function() {
      var rel = jQuery(this).attr("rel");
      var j_rel = jQuery("#"+rel);

      /*
      var j_next = j_rel.next(".item");
      if (j_next.length <= 0) {
          j_next = j_rel.siblings(".item:first");
      }

      jQuery("#div_intro_start .arrows .next a").attr("rel", j_next.attr("id"));
      */

      if (j_slider.is(":animated")) {
        j_slider.stop();
      }

      j_slider.animate({ left: -j_rel.position().left }, 500, "swing", function() {
        var j_div = jQuery("#div_intro_start .arrows .num a[rel='"+rel+"']").closest("div");
        j_div.siblings("div").removeClass("act");
        j_div.addClass("act");
      });
    });
});
//*/

// -- COMPARE ----------------------------------------------------------------------------
jQuery(document).ready(function() {
  jQuery("#div_compare .plus a")
    .bind("click", function() {
      var j_a = jQuery(this);
      var rel_id = j_a.attr("rel");
      var j_rel = jQuery("#"+rel_id);
      if (j_rel.is(":visible")) {
          j_rel.hide();
          j_a.html("<img src=\"images/iplus.gif\" />");
      } else {
          j_rel.show();
          j_a.html("<img src=\"images/iminus.gif\" />");
      }
    });

  jQuery("#div_compare a.expand")
    .bind("click", function() {
      jQuery("#div_compare .plus a").html("<img src=\"images/iminus.gif\" />");
      jQuery("#div_compare .feature_details").show();
    }),
  
  jQuery("#div_compare a.collapse")
    .bind("click", function() {
      jQuery("#div_compare .plus a").html("<img src=\"images/iplus.gif\" />");
      jQuery("#div_compare .feature_details").hide();
    })
});
//*/


// -- PRODUCTS ----------------------------------------------------------------------------
jQuery(document).ready(function() {
  var j_block_h = 20;
  jQuery("div.intro_right_cc .border_middle .centermiddle .hd").each(function() {
    var j_block_h_0 = jQuery(this).height();
    if (j_block_h_0 > j_block_h) { j_block_h = j_block_h_0; }
  });
  jQuery("div.intro_right_cc .border_middle .centermiddle .hd").css("height", j_block_h);
  j_block_h = 150;
  jQuery("div.intro_right_cc .border_middle .centermiddle .img").each(function() {
    var j_block_h_0 = jQuery(this).height();
    if (j_block_h_0 > j_block_h) { j_block_h = j_block_h_0; }
  });
  jQuery("div.intro_right_cc .border_middle .centermiddle .img").css("height", j_block_h);
  j_block_h = 150;
  jQuery("div.intro_right_cc .border_middle .centermiddle .text").each(function() {
    var j_block_h_0 = jQuery(this).height();
    if (j_block_h_0 > j_block_h) { j_block_h = j_block_h_0; }
  });
  jQuery("div.intro_right_cc .border_middle .centermiddle .text").css("height", j_block_h);
});
//*/


// -- WHY CHOOSE --------------------------------------------------------------------------
jQuery(document).ready(function() {
  var j_reason_h = 200;
  jQuery("#div_reasons .slides_content .reason_block table").each(function() {
    var j_h_temp = jQuery(this).height();
    if (j_h_temp > j_reason_h) {
      j_reason_h = j_h_temp;
    }
  })
  jQuery("#div_reasons .slides_content .reason_block table").css("height", j_reason_h);
});
jQuery(document).ready(function() {
  var j_reason_h = 80;
  jQuery("#div_reasons .slides_content .head table").each(function() {
    var j_h_temp = jQuery(this).height();
    if (j_h_temp > j_reason_h) {
      j_reason_h = j_h_temp;
    }
  })
  jQuery("#div_reasons .slides_content .head table").css("height", j_reason_h);
});
//*/

// -- ABOUT US ---------------------------------------------------------------------------
/*
jQuery(document).ready(function() {
  jQuery("div.intro_right div.about_us_container div.container").each(function() {
    j_h_about_container = jQuery(this).find("div.about_us_center").height() + 20;
    jQuery(this).css("height", j_h_about_container);
  })

  jQuery("div.intro_right div.about_us_container").hover(
    function() { jQuery(this).addClass("abs_container"); },
    function() { jQuery(this).removeClass("abs_container"); }
  )
});

  jQuery("div.intro_right .about_us_str .about_us_container .body").each(function() {
    var text = jQuery(this).html();
    var text_length = text.length;
    var span = "<span class=\"spots\"> ... &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>";
    var text_limit = 50;
    
    if (text_length > text_limit) {
      text_position = text.lastIndexOf(' ', text_limit);
      var text_0 = text.substring(0, text_position);
      var text_1 = text.substring((text_position+1));
      new_text = text_0 + span + text_1;
      alert(new_text);
    }
  })

  jQuery("div.intro_right .about_us_str .about_us_container").bind("click", function() {
    if (!jQuery(this).hasClass(".abs_container")) {
      jQuery(".about_us_container").removeClass("abs_container");
      jQuery("div.intro_right .about_us_str").css("z-index", "0");
      jQuery(this).find("div.body").find("span.spots").hide();
      jQuery(this).addClass("abs_container");
      jQuery(this).parent().css("z-index", "5");
    } else {
      jQuery(".about_us_container").removeClass("abs_container");
      jQuery("div.intro_right .about_us_str").css("z-index", "0");
      jQuery(this).find("div.body").find("span.spots").show();
    }
  })
});
*/

//*/
