  jQuery(document).ready(function($) {
    initSenses($);    
  });
  did=0;
function initSenses($){ 


    jQuery('.senses_center_box_content_images img').each(function(i) {
       jQuery(this).click(function(){
        jQuery(this).parent('dt').children('a').click();
       });
    });

    $('.sensespageritem').each(function(i){
       $(this).click(function(){ 
         var id= this.id.split('_');   
         sensescall(id[1]); 
       });
    });

    $('.senses_arrow_right_box span').each(function(i){
       $(this).click(function(){   
         sensescall(sensesright); 
       });
       $(this).mouseover(function(){   
         $(this).addClass('hover');
       });
       $(this).mouseout(function(){   
         $(this).removeClass('hover');
       });
    });

    $('.senses_arrow_left_box span').each(function(i){
       $(this).click(function(){ 
         var id= this.id.split('_');   
         sensescall(sensesleft); 
       });
       $(this).mouseover(function(){   
         $(this).addClass('hover');
       });
       $(this).mouseout(function(){   
         $(this).removeClass('hover');
       });
    });
  }
  
  function handleResponse(data){ 
    images= [];
    images.push(jQuery(data.images.head.html+" img").attr('src'));

    jQuery('.senses_center_box_content_images')[0].innerHTML="";
    jQuery(data.images.content).each(function(){
      jQuery('.senses_center_box_content_images')[0].innerHTML=jQuery('.senses_center_box_content_images')[0].innerHTML+this;
    });
    jQuery('.senses_center_box_content_images img').each(function(){
      images.push(jQuery(this).attr('src'));
    });
    
    jQuery('.senses_dot_pager')[0].innerHTML=data.pager;
    jQuery('.senses_center_box_content_text_text')[0].innerHTML=data.text;
    jQuery('.senses_center_box_content_text_headimage')[0].innerHTML=data.title;
    images.push(jQuery(jQuery('.senses_center_box_content_text_headimage img')[0]).attr('src'));
    jQuery('.headerimagewrapper').hide();
    jQuery('.headerimagewrapper').append(data.images.head.html);
    jQuery(jQuery('.headerimagewrapper img')[1]).hide();
    jQuery('.headerimagewrapper').show();
    sensesleft=data.left;
    sensesright=data.right;
    jQuery('.sensespageritem').each(function(i){
       jQuery(this).click(function(){ 
         var id= this.id.split('_');   
         sensescall(id[1]); 
       });
    });
    imagecount=0;
    jQuery(images).each(function(){
      var img = new Image();
      jQuery(img).load(function(){
        imagecount++;
        if(imagecount==images.length)
          setData(data)
      });
      jQuery(img).attr('src', this);
    });
    
    jQuery('.senses_center_box_content_images img').each(function(i) {
       jQuery(this).click(function(){
        jQuery(this).parent('dt').children('a').click();
       });
    });
   }
   
  function setData(data){
    setLightboxForImages();
    jQuery(jQuery('.headerimagewrapper img')[1]).fadeIn(500,function(){
      jQuery(jQuery('.headerimagewrapper img')[0]).remove();
      jQuery(jQuery('.senses_center_box_content_images')[0]).fadeIn(300);
      jQuery('.senses_dot_pager').fadeIn(300);
      jQuery('#senses_center_box_content_wrapper').fadeIn(300);
    }); 
  }

  function sensescall(id){
    did=id;
    jQuery(jQuery('.senses_center_box_content_images')[0]).hide();
    jQuery('.senses_dot_pager').fadeOut(300);
    jQuery('#senses_center_box_content_wrapper').fadeOut(300,function(){senddata()});
  }
    
  
  function senddata(){
    jQuery.getJSON("/?eID=sensescall&entry="+did+"&container="+containerID+"&L="+languagecode,
      function(data){
        handleResponse(data);
      });
  }