var isLandingPage = false;
function checkCookie(cookieId, trueElementId, falseElementId){
  if($.cookies.get(cookieId)){
    $(falseElementId).hide();
    $(trueElementId).show();
  }
}

function getLocationParams(){
  var locationParams = "";
  if(window.location.search != "") {
    var deeplinkparameter = String(window.location).split("?");
    if(deeplinkparameter[1] != "") {
      var args = deeplinkparameter[1].split("&");
      for(i = 0; i<args.length; i++) {
        var a = args[i].split("=");
        if(a[0] == "PartnerID" | a[0] == "ref" | a[0] == "zanpid" ) {
          locationParams=locationParams+"PartnerID="+a[1]+"&";
        }
        else {
        	locationParams=locationParams+a[0]+"="+a[1]+"&";
        }
      }
      locationParams = locationParams.substr(0, locationParams.length-1);
    }
  }
  if(locationParams != ""){
   locationParams = "?" + locationParams;
  }
  return locationParams
}

$(document).ready(function(){
  // open account button
  $("a#buttonAccountOpen, a#buttonAccountOpen2, a#buttonAccountOpenLanding").click(function(){

    if(isLandingPage){
	  if(languageCode == "de"){
        var currentLocationParams = getLocationParams();
        var layerAccountLink = $(".contentOpenAccountDetails .detailsLeft a.buttonSmall");
        layerAccountLink.attr("href", layerAccountLink.attr("href") + currentLocationParams);
        this.href = this.href + currentLocationParams;
	  }
	  return true;
	}

	if(languageCode == "de"){
      var currentLocationParams = getLocationParams();
      var layerAccountLink = $(".contentOpenAccountDetails .detailsLeft a.buttonSmall");
      layerAccountLink.attr("href", layerAccountLink.attr("href") + currentLocationParams);
      this.href = this.href + currentLocationParams;
  	  var userLoginedIn = $.cookies.get("bankCustomer");
	  if(!userLoginedIn){
        tb_show("","TB_inline?height=flex&amp;width=617&amp;inlineId=openAccountDetails","");
        return false;
      }
	}
	if(languageCode == "nl"){
	  /*
      tb_show("","TB_inline?height=flex&amp;width=617&amp;inlineId=openAccountDetails","");
      return false;
      */
	}
	return true;
  });

// add mousover to info icon

  $("a img.contentInfoIcon").hover(function(){
    $(this).attr("src", basicImagePath + "/icon_info-a.gif");
  }, function(){
    $(this).attr("src", basicImagePath + "/icon_info.gif");
  });

  if(typeof jsAjaxBase == "undefined"){
	// init contact form
	    $("#kontaktForm").jForms();

	    $("#mainSubject_fake_list li").each(function(i,e){
	        $(e).click(function(){
	          $("#subject1Container, #subject2Container, #subject3Container").hide();
	          $("#subject" + i + "Container").show();
	          $("#subject1_fake_label, #subject2_fake_label, #subject3_fake_label").css("display", "none");
	          if(i!=0){
	            $("#subject" + i + "_fake_label").css("display", "block");
	          }
	        });
	      });

	// init content search
	    $("#contentSearchForm").jForms();
  }

  $(".searchInput").mouseover(function(){
      $(this).hide();
      $("#searchButton").show();
    }).click(function(){
    $("#contentSearchForm").submit();
  });
  $("#searchButton").mouseout(function(){
      $(this).hide();
      $(".searchInput").show();
    }).click(function(){
    $("#contentSearchForm").submit();
  });

  $("#contentSearchValue").click(function(){
     $(this).select(); 
  });

// build tab buttons
  $(".contentTabNavigation li a.active").before('<img src = "' + basicImagePath + '/tab_navi_left_active.gif" />').after('<img src = "' + basicImagePath + '/tab_navi_right_active.gif" />')
  $(".contentTabNavigation li a:not(.active)").before('<img src = "' + basicImagePath + '/tab_navi_left.gif" />').after('<img src = "' + basicImagePath + '/tab_navi_right.gif" />')
  $(".tabContent").after('<img class="tabBgBottom" src = "' + basicImagePath + '/tab_bg_bottom.gif" />')

// add corners to main navi
  $(".mainNavigation table").before('<div class="bgMainnavigationLeft"></div>').after('<div class="bgMainnavigationRight"></div>');
  
//add numbers to columns
  $("#contentTableLoginInfo .contentTableColumn img").each(function(i,e){
    $(this).before('<div class="contentTableColumnNumber' + (i+1) + '"></div>');
    if(i==3){
      $(this).parent().addClass("last");
    }
  });
  $("#table3Columns .contentTableColumn img.columnImage").each(function(i,e){
    $(this).before('<div class="contentTableColumnNumber' + (i+1) + '"></div>');
    if(i==3){
      $(this).parent().addClass("last");
    }
  });
  $(".contentTable4Columns .contentTableColumn img.columnImage").each(function(i,e){
    $(this).before('<div class="contentTableColumnNumber' + (i+1) + '"></div>');
    if(i==3){
      $(this).parent().addClass("last");
    }
  });

// add icon to pdf link
  $("#relatedContent p.standard a.pdf").append('<div class="iconpdf"></div>');
  
//show subnavigation
  var elementLeft = 18;
  $(".mainNavigation a").each(function(i,e){
    
    var elementWith = $(".mainNavigation table td:eq(" + i + ")").width();

    if(i == 0){
      $("#subNavigation" + i).css("left", elementLeft-6);
    }else if(i == $(".mainNavigation table td").size()-1){
      $("#subNavigation" + i).css("right", 237);
      $("#subNavigation" + i).css("left", "auto");
    }else{
      $("#subNavigation" + i).css("left", elementLeft);
    }
    elementLeft += elementWith;

    $("#subNavigation" + i).show();
    if($("#subNavigation" + i + " a").width() < elementWith){
      if(i == 0){
        $("#subNavigation" + i + " a").width(elementWith - 21 );
      }else if(i == $(".mainNavigation table td").size()-1){
        $("#subNavigation" + i + " a").width(elementWith - 23 );
      }else{
        $("#subNavigation" + i + " a").width(elementWith - 28 );
      }
    }else{
      $("#subNavigation" + i + " a").width($("#subNavigation" + i + " a").width());
    }
    $("#subNavigation" + i).hide();

    $(this).mouseover(function(){
      $("#subNavigation" + i).show();
      var tester = $("#subNavigation" + i).width();
      var tester2 = $("#subNavigation" + i).height();
      $("#subNavigation" + i).css("width", tester);
      $(".subNavigationBottomBG").css("width", tester-22);
      $(".subNavigationLeftBG").css("height", tester2);
      $(".subNavigationRightBG").css("height", tester2);
      if(i == 0){
        $(".bgMainnavigationLeft").addClass("bgMainnavigationLeftActive");
      }
      if(i == $(".mainNavigation table td").size()-1){
        $(".bgMainnavigationRight").addClass("bgMainnavigationRightActive");
      }
    }).mouseout(function(){
      $("#subNavigation" + i).hide();
      if(i == 0){
        $(".bgMainnavigationLeft").removeClass("bgMainnavigationLeftActive");
      }
      if(i == $(".mainNavigation table td").size()-1){
        $(".bgMainnavigationRight").removeClass("bgMainnavigationRightActive");
      }
    });
  });

  $(".subNavigation").mouseenter(function(){
    $(this).show();
    if(this.id == "subNavigation0"){
      $(".bgMainnavigationLeft").addClass("bgMainnavigationLeftActive");
    }
    if(this.id == "subNavigation" + ($(".mainNavigation table td").size()-1)){
      $(".bgMainnavigationRight").addClass("bgMainnavigationRightActive");
    }
  }).mouseleave(function(e){
    $(this).hide();
    if(this.id == "subNavigation0"){
      $(".bgMainnavigationLeft").removeClass("bgMainnavigationLeftActive");
    }
    if(this.id == "subNavigation" + ($(".mainNavigation table td").size()-1)){
      $(".bgMainnavigationRight").removeClass("bgMainnavigationRightActive");
    }
  });

}); // document.ready