 $(document).ready(function(){

 
    $("#start").click(function(){
      $("#start").animate({ 
        top: "-103px"
      }, 150, 'linear', show_move );

    });
    $("#tomove").click(function(){
      $("#tomove").animate({ 
        top: "-724px"
      }, 500, 'linear', show_start );
    });
    
    $(function() {
		  $("#accordion").accordion({ autoHeight: false });
      $("#accordion2").accordion({ autoHeight: false });
      $("#accordion3").accordion({ autoHeight: false });
	  });
 
    $(".emblem_low").mouseover(function(){
    
      var act_id = this.id;
      
      var id_parts = act_id.split('_');
      
      var row = id_parts[0];
      var rating = id_parts[1];
      
      for (var i=1; i<=rating; i++) {
        $("#"+row+"_"+i).addClass('emblem_high');
      }
    
	  });
    
    $(".emblem_low").mouseout(function(){
    
      var act_id = this.id;
      
      var id_parts = act_id.split('_');
      
      var row = id_parts[0];
      var rating = id_parts[1];
      
      for (var i=1; i<=rating; i++) {
        $("#"+row+"_"+i).removeClass('emblem_high');
      }
    
	  });
    
    
    $(".single").colorbox();
    $("a[rel='multi']").colorbox({transition:"fade"});
    $(".colorbox").colorbox();
    $(".iframe").colorbox({width:"800px", height:"500px", iframe:true});



    $(".actresses").click(function(){
    
      var act_id = this.id;

      var id_parts = act_id.split('_');
      var id = id_parts[1];

      $("#actresses").css('left', -1 * (70*(id-1))+'px');
      $(".actresses").removeClass('acthigh');
      $("#actresses_"+id).addClass('acthigh');
      
      $('#arrow2_prev').show();
      $('#arrow2_next').show();
      
      if (id == 1) {
        $('#arrow2_prev').hide();
      }
      
      if (id == 10) {
        $('#arrow2_next').hide();
      }
      
    });
    
    $(".actors").click(function(){
    
      var act_id = this.id;

      var id_parts = act_id.split('_');
      var id = id_parts[1];

      $("#actors").css('left', -1 * (70*(id-1))+'px');
      $(".actors").removeClass('acthigh');
      $("#actors_"+id).addClass('acthigh');
      
      $('#arrow3_prev').show();
      $('#arrow3_next').show();
      
      if (id == 1) {
        $('#arrow3_prev').hide();
      }
      
      if (id == 10) {
        $('#arrow3_next').hide();
      }
      
    });
    
    $("#tabrightlow").click(function() {
    
      $("#tabrightlow").hide();
      $("#tabrighthigh").show();
      $("#tableftlow").show();
      $("#tablefthigh").hide();
      
      $("#chart2").show();
      $("#chart1").hide();
    
    });
    
    $("#tableftlow").click(function() {
    
      $("#tabrightlow").show();
      $("#tabrighthigh").hide();
      $("#tableftlow").hide();
      $("#tablefthigh").show();
    
      $("#chart2").hide();
      $("#chart1").show();
    
    });
    
    
    $(".dropdown_button").click(function() {
    
      var id = this.id;
      
      var cont = id + '_cont';
      var mask = id + '_mask';

      $('#'+mask).show();

      var height = $('#'+cont).css('height');
      
      if ($('#'+cont).css('top') == '0px') {
        $('#'+cont).animate( { top:'-'+height}, 500, function() { $('#'+mask).hide(); });
      }
    
      if ($('#'+cont).css('top') == '-'+height) {
        $('#'+cont).animate( { top:'0px'}, 500);
      }
    
    });
    
    
    $('#faq .question a').attr('onfocus', 'blur()');
    $('#faq .question a').click(function() {
    
      //alert($(this).parent());
    
      $('#faq .answer').hide();
      $('#faq .question_active').removeClass('question_active');
      
      $(this).parent().addClass('question_active');
      $(this).parent().next('.answer').show();
      
    });
    
 });


 
function saveCCRating(cc_id, film_id, user_id, rating) {

  var dataString = 'cc_id=' + cc_id + '&film_id=' + film_id + '&user_id=' + user_id + '&rating=' + rating;

  //alert(dataString);
  
  $.ajax({
    type:     "POST",
    url:      "/ajax/ccrating",
    data:     dataString,
    dataType: "json",
    success: function(data) {

      if (data.status == 'success') {

        var newhtml = '';
        
        for (var i=1; i<=rating; i++) {
          newhtml += '<p class="emblem_small emblem_high"></p>'
        }
        
        $('#cc_'+cc_id).html(newhtml);
      
          
      } else {
      
        //$('#code_error_content').html('<h4>Fehler</h4><p>Dieser Code kann nicht verarbeitet werden.<p>')
        //$('#code_error').hide().fadeIn(1000);          
      
      }
    
    },
    error: function(obj, msg1, msg2) {
      alert('error' + msg1 + ' ' + msg2);
    }
    
  });
  
  return false;

}  
 
 
function saveFilmVote(film_id, user_id) {

  var dataString = 'film_id=' + film_id + '&user_id=' + user_id;

  //alert(dataString);
  
  $.ajax({
    type:     "POST",
    url:      "/ajax/filmvote",
    data:     dataString,
    dataType: "json",
    success: function(data) {

      if (data.status == 'success') {
        
        $('#emblem').addClass('high');
        $('#votebutton').html('<p>I like it!</p>');
          
      } else {
      }
    
    },
    error: function(obj, msg1, msg2) {
      alert('error' + msg1 + ' ' + msg2);
    }
    
  });
  
  return false;

}  
 

var ismoving; 

function hor_slide(id, width, rows, arrowname, listname) {

  if (!ismoving) {

    var elem = $('#'+id);
    var position = elem.position();

    var new_pos = (position.left + 1*width);

    //alert(new_pos);
    $('#'+arrowname+'_prev').show();
    $('#'+arrowname+'_next').show();
    
    if (new_pos == 0) {
      $('#'+arrowname+'_prev').hide();
    }
    
    if ( (width < 0) && (new_pos <= ((rows-1) * width))) {
      $('#'+arrowname+'_next').hide();
    }
    
    if (new_pos > 0) {
      return;
    }

/*
    if ( (width < 0) && (new_pos < ((rows-1) * width))) {
      return;
    }
*/

    var new_pos_str = new_pos + 'px';
    
    ismoving = true;
    
    $('#'+id).animate( { left:new_pos_str}, 1000, function() { 
      ismoving = false; 

      if (listname != null) {
        var list_id = (Math.abs(new_pos) / Math.abs(width)) + 1;
        
        //alert(new_pos + ' ' + width);
        
        $("."+listname).removeClass('acthigh');
        $("#"+listname+"_"+list_id).addClass('acthigh');
      
      }
  
    });
    
  }
  
}


function toggleTab(id, selector, content) {

  //$('#'+content + ' > div:visible').fadeOut('fast');
  $('#'+content + ' > div:visible').hide();

  $('#'+selector+' a').removeClass('high');
  $('#'+id).addClass('high');  

  $('#'+id+'_content').fadeIn('slow');
  
  $('#faq .answer').hide();
  $('#faq .question_active').removeClass('question_active');
  $('#faq .question_first').addClass('question_active');
  $('#faq .answer_first').show();

}


 function show_start() {
       $("#start").animate({ 
        top: "0px"
      }, 150 );
 }

 function show_move() {
      $("#tomove").animate({ 
        top: "0px"
      }, 500 );
 }
 

 function showPrevQaPage(id) {

   var nextid = id-1;
   
   $('#page'+id).hide();
   $('#page'+nextid).show();

 }  
 
 function showNextQaPage(id) {

   var nextid = id+1;
   
   $('#page'+id).hide();
   $('#page'+nextid).show();
/* 
   var all_answered = true;
   for (var i=0; i<qs.length; i++) {
     if (!$('#answer_'+qs[i]+':checked').val()) {
       all_answered = false;
     }
   }
 
   if (!all_answered) {
     if (confirm('Sie haben nicht alle Fragen beantwortet. Wirklich fortfahren?')) {
      $('#page'+id).hide();
      $('#page'+(id+1)).show();     
     }
   } else {
    $('#page'+id).hide();
    $('#page'+(id+1)).show();     
   
   }
 
*/

 }
 
 
 function showLargeFlash(value) {
 
   $('<a />').colorbox({width:"800px", height:"500px", iframe:true, href:"/dvd/trailer/id/"+value, bgOpacity:0, open:true}); return false; 
 
 }

