$(document).ready(function(){
  if($('meta[name=language]').attr("content") == "de"){
   $(".responseToolHeaderRight p").html("<p>1 Punkt = stimme weniger zu<br>5 Punkte = stimme voll zu</p>");
   $(".responseToolHeaderRight a").attr("href", "mailto:tcm-service@tchibo.de?subject=Kommentar an Tchibo");
  }else{
   $(".responseToolHeaderRight p").html("<p>1 point = don't really agree<br>5 points = completely agree </p>");
   $(".responseToolHeaderRight a").attr("href", "mailto:tcm-service@tchibo.de?subject=Message to Tchibo");
   $(".responseToolHeaderRight a").html("Message to Tchibo");
  }
  $("#headSearchSubmit").mouseover(function(){
    $(this).attr("base", $(this).attr("src"));
    $(this).attr("src", $(this).attr("active") );
  }).mouseout(function(){
    $(this).attr("src", $(this).attr("base") );
  });
  $("#contentNavigationSelect").fdd2div({AnimationSpeed: "fast", GenerateHyperlinks:1, OpenStatus:0, maxHeight:5});
  $('form#contactSubjectForm').jForms({listSize:10});
// select "Suche" on click
  $("#searchValue").focus(function (e) {
    $(this).select();
  });
// tag cloud
  $(".tagCloud li").each(function(i,e){
    switch (i) {
      case 0:
        $(e).addClass("tagCloud11");
        break;
      case 1:
        $(e).addClass("tagCloud13");
        $(e).css("marginLeft", "10px");
        break;
      case 2:
        $(e).addClass("tagCloud15");
        $(e).css("textAlign", "center");
        break;
      case 3:
        $(e).addClass("tagCloud17");
        break;
      case 4:
        $(e).addClass("tagCloud15");
        $(e).css("textAlign", "right");
        $(e).css("marginRight", "10px");
        break;
      case 5:
        $(e).addClass("tagCloud13");
        $(e).css("marginLeft", "28px");
        break;
      case 6:
        $(e).addClass("tagCloud11");
        break;
    }
  });
   
   
// add rounded corners ti images with the class "roundedCorners"
  htmlStr  = "<div class='imageCornerBR'></div>";
  htmlStr += "<div class='imageCornerBL'></div>";
  $("img.roundedCorners").after(htmlStr);
  $("#largeStageTeaserAnimation").after(htmlStr);
// image gallery
  htmlStr = "<a href='javascript:void(0)' class='imageGalleryThunbnailsBG'><div></div></a>";
  $(".imageGalleryThunbnails img").wrap(htmlStr).click(function(){
    $(".imageGalleryImage img").attr("src", $(this).attr("zoomLargeUrl"));
    $(".imageGalleryImage img").attr("zoomParam", $(this).attr("zoomGalleryParam"));
    $(".imageGalleryImage img").attr("zoomurl", $(this).attr("zoomGalleryUrl"));
    $(".imageGalleryThunbnailsBG div").css("backgroundImage", "none");
    $(this).parent().css("height", "56px");
    $(this).parent().css("backgroundImage", "url(/cb/314284/data/-/galerie_thumb_bg-a.jpg.jpg)");
  });
// iconBookmark
  if($('meta[name=language]').attr("content") == "en"){
    $("a.iconBookmark").html("Bookmark this page");
  }
  // Response Tool
  // load results
  $(".responseToolEntry .ratingTool").each(updateResult);
  // add values to img
  $(".responseToolEntry .ratingTool img").each(function(i, e){
    $(e).attr("question",$(e).parent().attr("id"));
    $(e).attr("value", imageValue++);
    if(imageValue == 6){
      imageValue = 1;
    }
  });
  // add hover and click to img
  $(".responseToolEntry .ratingTool img").each(function(i, e){
    $(e).hover(function(){
      for(var j=1; j <= $(this).attr("value"); j++){
        $("#" + $(e).attr("question") + " img[value='" + j + "']").attr("oldSrc", $("#" + $(e).attr("question") + " img[value='" + j + "']").attr("src"));
        $("#" + $(e).attr("question") + " img[value='" + j + "']").attr("src", ratingUserSrc);
      }
    }, function(){
      for(var j=1; j <= 5; j++){
        $("#" + $(e).attr("question") + " img[value='" + j + "']").attr("src", $("#" + $(e).attr("question") + " img[value='" + j + "']").attr("oldSrc"));
      }
    }).click(function(){
//alert($(this).attr("question") + $(this).attr("value") + voteDate);
      var formValue = "action=setRatings&id=" + $(this).attr("question") + "&value=" + $(this).attr("value") + "&checksum=" + MD5($(this).attr("question") + $(this).attr("value") + voteDate);
      var currentQuestion = $(this).attr("question");
     /* cookie ---> */
      var cookieName = "tchibo_vote" + $(this).attr("question");
      var cookieOptions = {path: '/', expires: 1460};
      if($.cookie(cookieName) != "true"){
        $.cookie(cookieName, 'true', cookieOptions);
      }else{
storedResultText = $("#" + currentQuestion + " .ratingText").html();
        setResultText(currentQuestion, voteAlreadyText);
        //setTimeout("setResultText('" + currentQuestion + "', '" + storedResultText + "')", 2000);
        setTimeout('setResultText("' + currentQuestion + '", "' + storedResultText + '")', 2000);
        return;
      }
      /* <--- cookie */
      $.ajax({
        type:"GET",
        url:"/ratings/index.php",
        data:formValue,
        dataType:"json",
        success:function(msg){
          storedResultText = $("#" + currentQuestion + " .ratingText").html();
          $(".responseToolEntry .ratingTool").each(updateResult);
          setResultText(currentQuestion, voteCountText);
          setTimeout('setResultText("' + currentQuestion + '", "' + storedResultText + '")', 2000);
        },
        error:function(msg){
        }
      });//ajax
    })
  })
}); // document.ready
// Response Tool
var ratingSrc = "/cb/314352/data/-/gray.png.png";
var ratingActiveSrc = "/cb/314354/data/-/star.png.png";
var ratingUserSrc = "/cb/314356/data/-/user.png.png";
var ratingHalfSrc = "/cb/314358/data/-/star-half.png.png";
var imageValue = 1;
var voteDate = "SECRET";

var voteResultText = " haben abgestimmt.";
var voteCountText = "Stimme wurde gez&auml;hlt.";
var voteAlreadyText = "Bereits abgestimmt.";
var storedResultText = "";
var currentQuestion = "";
if($('meta[name=language]').attr("content") == "en"){
  voteResultText = " people have voted.";
  voteCountText = "Your vote has been counted.";
  voteAlreadyText = 'You\'ve already voted.';
}
function setResultText(resultId, resultText){
  $("#" + resultId + " .ratingText").html(resultText);
}
function updateResult(i, e){
var zeit = new Date();
var ms = zeit.getMilliseconds();
    var formValue = "action=getRatings&id=" + $(e).attr("id") + "&dummyNoCache="+ms;
    $.ajax({
      type: "GET",
      url: "/ratings/index.php",
      data: formValue,
      dataType:"json",
      success: function(msg){
        if(msg != null){
          for(var j=1; j <= 5; j++){
            if(j <= msg.average){
              $("#" + msg.id + " img[value='" + j + "']").attr("src", ratingActiveSrc);
            }else{
              if((j-msg.average)== 0.5){
                $("#" + msg.id + " img[value='" + j + "']").attr("src", ratingHalfSrc)
              }else{
                $("#" + msg.id + " img[value='" + j + "']").attr("src", ratingSrc)
              }
            }
          }
          if($("#" + msg.id + " .ratingText").html() == "" ){
            setResultText(msg.id, msg.ratings + voteResultText);
          }
        }
      },
      error: function(msg){
      }
    });//ajax
}
var flashvars = {};
var attributes = {};
var params = {
  wmode: "transparent",
  menu: "false",
  quality: "high",
  allowscale: "false",
  allowScriptAccess: "always"
};
$.fn.wait = function(time, type) {
    time = time || 1000;
    type = type || "fx";
    return this.queue(type, function() {
        var self = this;
        setTimeout(function() {
            $(self).dequeue();
        }, time);
    });
};
