jQuery(document).ready(function() {
  jQuery('#content_2').hide();
  jQuery('#mainim2').hide();

  jQuery('#tab1').click(function() {
    if (jQuery("#content_1").is(":hidden")) {
      jQuery("#content_1").slideToggle();
      jQuery("#content_2").slideToggle();
      jQuery('#tab1').toggleClass("tabon");
      jQuery('#tab2').toggleClass("tabon"); 
    }  
  });

  jQuery('#tab2').click(function() {
    if (jQuery("#content_2").is(":hidden")) {
      jQuery("#content_2").slideToggle();
      jQuery("#content_1").slideToggle();
      jQuery('#tab1').toggleClass("tabon");
      jQuery('#tab2').toggleClass("tabon"); 
    }  
  });
  
  
  jQuery('.thumbim').click(function() {
    jQuery.selim=parseInt(jQuery(this).attr('im'));
    var xo = jQuery(this).attr('id');
    jQuery('.thumbim').removeClass('imon');
    jQuery(this).addClass('imon');
    if (jQuery("#mainim2").is(":hidden")) {
      jQuery('#mainim2').css("background-image", 'url('+xo+')');
      jQuery('#mainim1').css("z-index", '55');
      jQuery('#mainim2').css("z-index", '2');
      jQuery('#mainim2').show();
      jQuery('#mainim1').fadeOut();
    }

    if (jQuery("#mainim1").is(":hidden")) {
      jQuery('#mainim1').css("background-image", 'url('+xo+')');
      jQuery('#mainim2').css("z-index", '55');
      jQuery('#mainim1').css("z-index", '2');
      jQuery('#mainim1').show();
      jQuery('#mainim2').fadeOut();
    }

  });


  jQuery('#ni').click(function() {
    jQuery.selim=jQuery.selim+1;
    if (jQuery.selim>=jQuery('#caseThumb > .image').size()) {
      jQuery.selim=0;
    }
    var xo = jQuery('#caseThumb > .image:eq('+jQuery.selim+') > img').attr('id');
    jQuery('.thumbim').removeClass('imon');
    jQuery('#caseThumb > .image:eq('+jQuery.selim+') > img').addClass('imon');

    if (jQuery("#mainim2").is(":hidden")) {
      jQuery('#mainim2').css("background-image", 'url('+xo+')');
      jQuery('#mainim1').css("z-index", '55');
      jQuery('#mainim2').css("z-index", '2');
      jQuery('#mainim2').show();
      jQuery('#mainim1').fadeOut();
    }

    if (jQuery("#mainim1").is(":hidden")) {
      jQuery('#mainim1').css("background-image", 'url('+xo+')');
      jQuery('#mainim2').css("z-index", '55');
      jQuery('#mainim1').css("z-index", '2');
      jQuery('#mainim1').show();
      jQuery('#mainim2').fadeOut();
    }  
  });

  jQuery('#pi').click(function() {
    jQuery.selim=jQuery.selim-1;
    if (jQuery.selim<0) {
      jQuery.selim=jQuery('#caseThumb > .image').size()-1;
    }
    var xo = jQuery('#caseThumb > .image:eq('+jQuery.selim+') > img').attr('id');
    jQuery('.thumbim').removeClass('imon');
    jQuery('#caseThumb > .image:eq('+jQuery.selim+') > img').addClass('imon');
    if (jQuery("#mainim2").is(":hidden")) {
      jQuery('#mainim2').css("background-image", 'url('+xo+')');
      jQuery('#mainim1').css("z-index", '55');
      jQuery('#mainim2').css("z-index", '2');
      jQuery('#mainim2').show();
      jQuery('#mainim1').fadeOut();
    }

    if (jQuery("#mainim1").is(":hidden")) {
      jQuery('#mainim1').css("background-image", 'url('+xo+')');
      jQuery('#mainim2').css("z-index", '55');
      jQuery('#mainim1').css("z-index", '2');
      jQuery('#mainim1').show();
      jQuery('#mainim2').fadeOut();
    }  
  });

  
  jQuery.selim=0;
});
