Cufon.replace('.cufon', { fontFamily: 'Century Gothic' });

function scrollFirstPageImages() {
  var imagesCount = $("#slide-images li").size();    
  var currentImage = $("#slide-images li:visible").attr('id');  
  if(imagesCount > 1) {  
    var nextimage = 1+parseFloat(currentImage);    
    if(nextimage > imagesCount) {
      var nextimage = 1;
    } 
    $("#slide-images li#"+currentImage).fadeOut(1000, '', function() {
      $("#slide-images li#"+nextimage).fadeIn(1000);
    });                   
  }  
}

$(document).ready(function() {
    
    $("#dialog").dialog({
      width: 400,
      modal: true
    });
    
    $('#subscribe').click(function(){
      $('#subscribe_form').submit();
    });
    
    $('#submit_contact').click(function(){
      $('#contact_us_form').submit();
    });

    $('.footer_input').focus(function() {
      var oldval = $(this).val();
      $(this).val('');
      $(this).blur (function() {
        if($(this).val() == '') {
          $(this).val(oldval);
        }
      })
    });
    
    $('.searchinput').focus(function() {
      var oldval = $(this).val();
      $(this).val('');
      $(this).blur (function() {
        if($(this).val() == '') {
          $(this).val(oldval);
        }
      })
    });

    $('a[rel*=lightbox]').lightBox();

    $('.sf-menu').superfish({
      autoArrows: false,
      animation:   {opacity:'show',height:'show'},
      speed:       'fast',
      delay:      100
    }); 
    
    $(".product_image").hover(function() {
        var id = $(this).attr('id');
        $('#buy_'+id).show();
    }, function() {
        var id = $(this).attr('id');
        $('#buy_'+id).hide();
    });

    $('.spinner_content_item img').each(function() {            
        var parent_height = $(this).parent().height();
        var image_height = $(this).height();
    });
    
    $('.partners_item a img').each(function() {            
        var parent_height = $(this).closest('div').height();
        var image_height = $(this).height();
    });
    
    $('.imprint_item img').each(function() {            
        var parent_height = $(this).closest('div').height();
        var image_height = $(this).height();
    });
    
    var size = $(".spinner_content_inner > div").size()-1;
    var width = (size)*220;
    $(".spinner_content_inner").css({'width':width});
    
    $(".arrow_right").click(function() {            
      var left_pos = $(".spinner_content_inner").css('left');
      var maxpos = $(".spinner_content_inner").width();
      //alert(parseInt(maxpos));
      if(parseInt(left_pos) > -maxpos+880){
        $(".spinner_content_inner").stop();
        var oldpos = $(".spinner_content_inner").css('left');
        var oldpos = oldpos.replace('px', '');
        var newpos = oldpos-220;
        
        if(newpos <= -maxpos ) {
            $(".spinner_content_inner").css({'left': 890});
            $(".spinner_content_inner").animate({'left': 660});
        }else{                         
            $(".spinner_content_inner").animate({'left': newpos});
        }
      }
    });
    
    $(".arrow_left").click(function() {
        //alert($(".spinner_content_inner").css('left'));
        var left_pos = $(".spinner_content_inner").css('left');
        if(parseInt(left_pos) < 0){
          $(".spinner_content_inner").stop();
          var oldpos = $(".spinner_content_inner").css('left');
          var oldpos = oldpos.replace('px', '');            
          var newpos = parseFloat(oldpos)+220;
          var maxpos = $(".spinner_content_inner").width();
          if(oldpos >= maxpos ) {                
              $(".spinner_content_inner").css({'left': -maxpos});
              $(".spinner_content_inner").animate({'left': -maxpos+220});
          }else{                         
              $(".spinner_content_inner").animate({'left': newpos});
          }
        }
    });
    
    $(".sub_filter_element").change(function() {
      $("#sub_filter").submit();
    });
    
    $("#logo1").click(function(){
      if($("#impr_logo1").val() == 1){
        $("#impr_logo1").val('0');
        $("#logo1").removeClass('filled');
      }else{
        $("#impr_logo1").val('1');
        $("#logo1").addClass('filled');
      }
    });
    
    $("#number2").click(function(){
      if($("#impr_number2").val() == 1){
        $("#impr_number2").val('0');
        $("#number2").removeClass('filled');
      }else{
        $("#impr_number2").val('1');
        $("#number2").addClass('filled');
      }
    });
    
    $("#name3").click(function(){
      if($("#impr_name3").val() == 1){
        $("#impr_name3").val('0');
        $("#name3").removeClass('filled');
      }else{
        $("#impr_name3").val('1');
        $("#name3").addClass('filled');
      }
    });
    
    $("#number4").click(function(){
      if($("#impr_number4").val() == 1){
        $("#impr_number4").val('0');
        $("#number4").removeClass('filled');
      }else{
        $("#impr_number4").val('1');
        $("#number4").addClass('filled');
      }
    });
    
    $("#logo5").click(function(){
      if($("#impr_logo5").val() == 1){
        $("#impr_logo5").val('0');
        $("#logo5").removeClass('filled');
      }else{
        $("#impr_logo5").val('1');
        $("#logo5").addClass('filled');
      }
    });
    
    $("#number6").click(function(){
      if($("#impr_number6").val() == 1){
        $("#impr_number6").val('0');
        $("#number6").removeClass('filled');
      }else{
        $("#impr_number6").val('1');
        $("#number6").addClass('filled');
      }
    });
    
    $("#impr_send").click(function(){
      $("#imprinting_form").submit();
    });
});
