$(document).ready(function () {
  // create folio scroller	
  $(".folio_container").scrollable({
    next: ".scroll_right",
    prev: ".scroll_left",
    circular: false
  }).navigator();


  // create products scroller on home page
  $(".products_container").scrollable({
    next: ".scroll_right",
    prev: ".scroll_left",
    circular: false
  }).navigator();


  // add classes to the paging arrows
  $(".paging input:last-child").addClass('right');
  $(".paging input:first-child").addClass('left');

  $(".screenshot_overlay_scroller_cont").scrollable({
    next: ".scroll_right",
    prev: ".scroll_left",
    circular: false,
    onSeek: function () {
      var ind = this.getIndex();
      var ht = $(".screenshot_overlay_scroller img").eq(ind).height();
      $(".screenshot_overlay_scroller_cont").height(ht);
    }
  }).navigator();


  $('.screenshots a[rel]').overlay({
    mask: {
      color: '#3d464b',
      loadSpeed: 50,
      opacity: 0.9
    },
    onLoad: function () {
      //center the dots
      $('.navi').show();
      var wd = $('.navi').width();
      var parwd = $('.navi').parent().width();
      var lt = (parwd - wd) / 2;

      $('.navi').css({
        left: lt
      });
      // postion the arrows
      $('.screenshot_overlay .scroll_left').css({
        left: lt - 40
      });
      $('.screenshot_overlay .scroll_right').css({
        left: lt + wd + 40
      });
      // seek to item from trigger
      var trigId = parseInt(this.getTrigger().attr('href').slice(1)) - 1;
      var scroller = $(".screenshot_overlay_scroller_cont").data("scrollable");
      scroller.seekTo(trigId, 0);
      var ht = parseInt($(".screenshot_overlay_scroller img").eq(trigId).height());
      $(".screenshot_overlay_scroller_cont").height(ht);
      $('html, body').animate({ scrollTop: 0 }, 200);
    }
  });


  /*$('.img_holder a[rel]').overlay({
  mask: {
  color: '#3d464b',
  loadSpeed: 50,
  opacity: 0.9
  },
  onLoad: function () {
  var trigId = this.getTrigger().attr('href').slice(1);
  var scroller = $(".screenshot_overlay_scroller_cont").data("scrollable");
  scroller.seekTo(trigId - 1, 0);
  var ht = $(".screenshot_overlay_scroller img").eq(trigId).height();
  $(".screenshot_overlay_scroller_cont").height(ht);
  $('html, body').animate({ scrollTop: 0 }, 200);
  }
  });*/



  // make product links go to a new window
  $('.products_item a').each(function () {
    if ($(this).attr('href').substring(0, 4) == 'http') {
      $(this).attr('target', '_blank');
    }
  });


  // add class="fourth" to every fourth portfolio item
  $('ul.case_studies li').filter(function (index) {
    return index % 4 == 3;
  }).addClass('fourth');
  $('<div class="clear"></div>').insertBefore('.fourth');

  $('ul.case_studies li').hover(
		function () {
		  $(this).toggleClass('portfolio_bgrd');
		},
		function () {
		  $(this).toggleClass('portfolio_bgrd');
		}
	);

  //mouseclick event for masterpages navigator

  //    $('#btnWhoWeAre').click(function () {

  //               $('#btnWhoWeAre').addClass('active');
  //        
  //    });


  // center the folio and products navigator dots
  $('.navi').each(function () {
    var wd = $(this).width();
    var parwd = $(this).parent().width();

    $(this).css({
      left: (parwd - wd) / 2
    });
  });

  // fix css background pngs
  var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1);
  var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);
  if (jQuery.browser.msie && (ie55 || ie6)) {
    //IE6 safe way of loading script

    // select all img elements with pngs and add pngfix class
    $("img[src$=.png]").each(function () {
      $(this).addClass("pngfix");
    });
    // select all elements with png bg and add pngfix class
    $("*").each(function () {
      var bgIMG = jQuery(this).css('background-image');
      if (bgIMG.indexOf(".png") != -1) {
        $(this).addClass("pngfix");
      }
    });
    // run the png fix
    DD_belatedPNG.fix('.pngfix');
  }


});


