$(function(){


  //menünün altındaki cycle---------------
  $('#cycle').cycle({
    pager: '#cycle-thumbnails',
    pagerAnchorBuilder: function(idx, el) {
      image = $(el).find('img').attr('src');
      return '<span class="cycle-thumb"><img src="'+ image +'" /></span>';
    },
    containerResize: 0,
    timeout: 6000,
    speed: 500
  });

  //yonetim kurulu-------------------------
  $('.isim').hover(function(){
    id = $(this).attr('id');
    $('#isim-'+id).show();
  },function(){
    id = $(this).attr('id');
    $('#isim-'+id).hide();
  });


  //haberler kısmındaki cycle--------------
  $('#haber-container').cycle({
    pager: '#haberler-pager',
    pagerAnchorBuilder: function(idx, el){
      return '<span class="haber-page"></span>'
    },
    containerResize: 0,
    timeout: 6000,
    speed: 500
  });
  //butonları------------------------------
  $('.haber-button-sol').click(function(){
    $('#haber-container').cycle('prev');
  });
  $('.haber-button-sag').click(function(){
    $('#haber-container').cycle('next');
  });


  //ürün fotoğrafının ortalanması------------
  $('#urun-resim img').load(function(){
    height = $('#urun-resim').find('img').height();
    width = $('#urun-resim').find('img').width();
    if(height > 340){
      $('#urun-resim img').css('height','310px');
      $('#urun-resim img').css('margin-top','15px');
    }
    if(width > 350){
      $('#urun-resim img').css('width','350px');
      $('#urun-resim img').css('margin-top','10px');
    }
  });


  //sertifika listesinin carouseli--------------
  $('.urunler .row .row').jcarousel({ scroll: 1, wrap:'circular', visible:9 });


  //ürünlerin carouseli--------------
  $('.urunler2 .row .row').jcarousel({ scroll: 1, wrap:'circular', visible:6 });



  //anamenunun üstüne gelince altmenülerin çıkması-------
  $('#menu li').hover(function(){
    $(this).find('.altmenu:first').css('display','inline');
  },function(){
    $(this).find('.altmenu:first').css('display','none');
  });


  //anamenu elemanlarının linksizlerinde cursoru ayarla------
  $('#menu li a:not([href*="/"])').css('cursor','default');

  //sayfa içi cycle-----------------
  $('.do-cycle').cycle({
    pager: $('.do-cycle-pager'),
    pagerAnchorBuilder: function(idx, el) {
      return '<span class="do-cycle-thumb"></span>';
    }
  });

  //sidebar üstüne gelince altmenülerin çıkması-------
  $('#side-bar li').hover(function(){
    $(this).find('.alt-menu:first').css('display','inline');
  },function(){
    $(this).find('.alt-menu:first').css('display','none');
  });
});





// ============================================================
// TAB'lı Cycle Galeriler
// ============================================================


$(function(){

  var item_tpl  = '<div class="igrp-item"/>';
  var title_tpl = '<div class="igrp-title"/>';
  var nav_tpl   = '<div class="prev"/><div class="next"/>';

  var cycle_before = function(curr, next, opt, ff) {
    if ( ! opt['_init'] ) {
      opt['_init'] = true;
      opt['prev'].hide();
      return 0;
    }

    var n = opt['next'];
    var p = opt['prev'];

    if (opt.nextSlide > 0)  { p.show() } else { p.hide() }
    if (opt.nextSlide == opt.slideCount -1) { n.hide() } else { n.show() }

  };

  var cycle_props = { timeout:0, nowrap: true, before: cycle_before};

  $('.igrp img').each(function(){
    var img = $(this);
    var title = $(title_tpl).html( img.attr('title').replace(' | ', '<br />') );
    img.wrap(item_tpl).parent().append(title, nav_tpl);
  });

  $('.igrp').each(function(){
    var me = $(this);
    var p = cycle_props;
    p.prev = me.find('.prev');
    p.next = me.find('.next');

    me.cycle(p);
  });

  var tab_click = function(){
    $('#itabs a').removeClass('active');
    $(this).addClass('active');
    $('.igrp').hide();
    $(this).data('igrp').show();
  };

  $('.itab').each(function(){
    var tab = $(this);
    var grp = tab.siblings('.igrp');
    var anchor = $('<a href="javascript:;" />').html( tab.html() ).data('igrp', grp).click(tab_click);
    tab.remove();
    $('#itabs').append(anchor);
    $('#igrps').append(grp);

  });

  $('#itabs a:first').click();

});


