/**
 * We use the initCallback callback
 * to assign functionality to the controls
 */
function mycarousel_initCallback(carousel) {
    jQuery('.jcarousel-control a').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        return false;
    });
};


function showFullImage(url) {
  nw=window.open(url, '','width='+720+',height='+760+',resizable=yes,locations=no,status=no,scrollbars=yes,toolbar=no,directories=no,menubar=no,fullscreen=no');
  // nw.document.open();
  // nw.document.writeln("<html><head></head>");
  // nw.document.writeln("<body style=\"font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 12px; background-color:#ffffff; margin: 0\">");
  // nw.document.writeln("<table width=\"100%\" height=\"100%\">");
  // nw.document.writeln("<tr><td valign=\"center\" align=\"center\"><a href=\"javascript:window.close();\"><img src="+url+" border=\"0\"></a></td></tr>");
  // nw.document.writeln("<tr><td align=\"center\" style=\"font-family:Arial, Helvetica, sans-serif; font-size:11pt; background-color:#ffffff\"><a href=\"javascript:window.close();\">Zamknij okno</a></td></tr>");
  // nw.document.writeln("</table></body></html>");
  // nw.document.close();
  // nw.focus();
}

$(function(){
  
  // Tabs
  var $tabs = $('#tabs').tabs();

  //hover states on the static widgets
  $('#dialog_link, ul#icons li').hover(
    function() { $(this).addClass('ui-state-hover'); }, 
    function() { $(this).removeClass('ui-state-hover'); }
  );

  // $('a[rel*=facebox]').facebox();
  $('a[rel*=facebox]').click(function(e) {
    showFullImage($(this).attr('href'));
    // alert($(this).attr('href'));
    e.preventDefault();
  });

  jQuery('#banner-carousel').cycle({
   fx: 'fade',
   pager: '#banner-control',
   timeout: 5000
  });

  // if ($('#banner_carousel').length > 0) {
  //   $('#banner_carousel').jcarousel({
  //     initCallback: mycarousel_initCallback,
  //     vertical: true,
  //     visible: 1,
  //     auto: 10,
  //     // scroll: 1,
  //     // animation: 0,
  //     wrap: "both",
  //     buttonNextHTML: null,
  //     buttonPrevHTML: null
  //   });
  // }
    

  $("#q").labelify();
  

  // Ukrywanie/wyświetlanie pól formularza zaawansowanego
  $('input#switch_extended').click(function() {
    var on = $(this).attr('checked');
    if (on)
      $('form p.extended').show();
    else
      $('form p.extended').hide();
  });
  $('form p.extended').hide();

  // Wybór opcji "other" z selecta
  $('select').change(function() {
    var name = $(this).attr('name');
    if ($(this).val() == 'other')
      $('input[name=' + name + '_other]').show();
    else
      $('input[name=' + name + '_other]').hide();
  });

  $('select#product-select').change(function() {
    window.location = $(this).val();
  });

  if ($("#side-menu li").size() > 0) {
    var active_item = $('#side-menu').attr("class").substr(7);
    $('.item-' + active_item).addClass('open');
  }

  // Klasy dla ikonek z plikami
  $('#files-box a[href$=pdf]').addClass('pdf');
  $('#files-box a[href$=zip]').addClass('zip');
  $('#files-box a[href$=rar]').addClass('rar');
  $('#files-box a[href$=swf]').addClass('swf');
  $('#files-box a[href$=doc]').addClass('doc');
  $('#files-box a[href$=ppt]').addClass('ppt');


  // SWFObject
  // var flashBanners = $('.flash-banner');
  // $.each(flashBanners, function() {
  //   var bannerId = $(this).attr('id');
  //   swfobject.registerObject(bannerId, "9.0.0");
  // });
  // swfobject.registerObject("myFlashContent", "9.0.0");

  // Bloki z linkami na stronie głównej
  $('.halfbox ul li').hover(
    function() {
      $(this).closest('.halfbox').find('.default').hide();
      $(this).siblings().removeClass('active');
      $(this).addClass('active');
    },
    function() {
      // $(this).parent().toggleClass('active');
    }
  );
  
  // Ikonka "Promocja" otwiera zakładkę
  $('.promotions-link').click(function() {
    $tabs.tabs('select', '#tabs-4');
  });

})
