// JavaScript Document

$(document).ready(function(){


  /*** IE8 button fix ***/
  if ($.browser.msie && $.browser.version.substr(0,1)==8){
    $(".form-submit").mousedown(function(){
        $(this).removeClass("form-submit-unclick").addClass("form-submit-click");
        $(this).mouseout(function(){$(this).removeClass("form-submit-click").addClass("form-submit-unclick");});
    }).mouseup(function(){$(this).removeClass("form-submit-click").addClass("form-submit-unclick");});
  }
  /*** END ***/

  uiFirstLast();
  //imageGallery();
  scrollcontent();
  scrollpost();

$("#myController").jFlow({
			controller: ".jFlowControl", // must be class, use . sign
			slideWrapper : "#jFlowSlide", // must be id, use # sign
			slides: "#mySlides",  // the div where all your sliding divs are nested in
			selectedWrapper: "jFlowSelected",  // just pure text, no sign
			width: "800px",  // this is the width for the content-slider
			height: "438px",  // this is the height for the content-slider
			duration: 1000,  // time in miliseconds to transition one slide
			prev: ".jFlowPrev", // must be class, use . sign
			next: ".jFlowNext", // must be class, use . sign
			auto: true // true or false
		});

/*var pox;
$("div.block-caroesel").everyTime(6000, pox, function() {
    imageGallery();
},0);*/


});

function uiFirstLast(){
  $("ul").each(function(){
    $("li:first", this).addClass("first");
    $("li:last", this).addClass("last")
  });
}

function imageGallery(){
    var time = 3000;
    var images = $("div.p.current div.block-caroesel img");
    $(images).css({opacity: 0});
   // $(images).eq(0).addClass("current");
    $(images).animate({opacity: 1}, time);
    $(images).each(function(){
 
        //$('div.p.current div.block-caroesel img.current').removeClass('current');
        $(images).animate({opacity: 0}, time);
       $(this).animate({opacity: 1}, time);
       
    });
    $(images).animate({opacity: 0}, time);
    return true;
}


function scrollcontent(){
  $("div.block-table-content").each(function(){
    var $this = $(this);
    var content = $("table", this);
    var height =  parseFloat($("table.current", this).height());
    var pager = $("div.pager li span", this);
    var time = 1000;

    $this.height(height + "px");
    $("div.pager li:first span", this).addClass("active");
    
    pager.click(function(){
      pager.removeClass("active");
      $(this).addClass("active");
      index = $(pager).index(this);
      height = parseFloat($(content).eq(index).height());
      $this.animate({height: height - "px"}, time);
      $current = $(content).eq(index).stop().css({top:  height + "px"}).animate({top: 0}, time).addClass("current");
      $(content).not($current).stop().animate({top: - 1.5 * height + "px"}, time);
    });
  });
}


function scrollpost(){
  $("div.block-post-caroesel").each(function(){
    var $this = $(this);
    var content = $("div.p", this);
    var height =  parseFloat($("div.p.current", this).height());
    var pager = $("div.pager-p li span", this);
    var time = 1000;

    $this.height(height + "px");
    $("div.pager-p li:first span", this).addClass("active");


      pager.click(function(){
          pager.removeClass("active");
          $(this).addClass("active");
          index = $(pager).index(this);
          height = parseFloat($(content).eq(index).height());
          $this.animate({height: height - "px"}, time);
          $this.find('.current').removeClass('current');
          $current = $(content).eq(index).stop().css({top:  height + "px"}).animate({top: 0}, time).addClass("current");
          $(content).not($current).stop().animate({top: - 1.5 * height + "px"}, time);
        });

  
  });
}


