 var count = 0;
 var stop = false;
 var button_group;
 $(document).ready(function(){

     

      if (jQuery.browser.msie)
            $('img[src$=.png]').each(function() {
            this.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src="+this.src+",sizingMethod='scale')";
        });
      $('[class*="button-group"]').css('display','none');
       $('.ri-img.first').fadeIn('fast');
      $(window).load(
      function() {
           
	       $('.counter-dots').fadeIn('fast');
	       $('.button-group1').fadeIn('slow', function(){

      });

      $('.trigger-bg img').css('width','41px');
      $('.trigger img').css('width','36px');
     
      $('.ri-img').fadeIn('slow');
      $('.trigger-bg').effect("pulsate", { times:100 }, 2000);
     tbkSlider();
     $('.slideshow').css('background-color','#000000');
     $('.slideshow-container').fadeIn('slow');
     }
     );
    });

(function($){

  var zoomed = false;
  var popupShown = false;
  var thisImg="";
  var thisPopup ="";
  var animDone = true;
   tbkSlider = function() {
    $('.trigger').click(function () {
        //$('.button').css({opacity: 0.0});
	// $('.button').css({filter:(alpha="0")});

	  $('.arrow').fadeOut('fast');
          
	 if (!$(this).parent().children().is(':animated')) {
	 
	 thisImg = $(this).attr('id');
	 var last_char= thisImg.charAt(thisImg.length-1);
 	 var index = parseInt(last_char);
	 
	 //alert (last_char);
         thisPopup = '#' + thisImg + '.pu-mid';
	 //alert(thisPopup);
	 if(index<=6){
	   $(".counter-dots").fadeOut('fast');
	   $(".main-exit").fadeIn('fast');
	 }
        	if(zoomed == false){

		if(index<=6){
	          $('.button-group'+last_char).fadeOut('fast');
		}
		button_group = '.button-group'+last_char;
		$(this).fadeIn('slow');
		$('#first-set').css('display','block');
//		$('.popup').css('top','0');
                $("." + thisImg).animate({width: "694px"}, 'slow');
		//});
		
		     
	             
//         	  $(thisPopup).css('display','block');
//		  //alert(thisPopup);
//		  $(thisPopup).animate({
//		      top: '-=' + 10 + 'px',
//		      opacity: 1.0,
//		      filter:(alpha="100")
//		  },100);
//		   popupShown=true;
//                  zoomed = true;
  
		//});
	$(thisPopup).fadeIn('slow');
    	       

	}else{
                if(popupShown == false){
		  $(thisPopup).animate({
		      top: '-=' + 10 + 'px',
		      opacity: 1.0
		  },300);
		popupShown = true;
	    }else{
		$(thisPopup).animate({
		      top: '+=' + 10 + 'px',
		      opacity: 0.0
		  },300);
		popupShown = false;
	    }
	}
	}
	 
    });
     $(".pu-mid").hover(
	    function () {
		
	    }
	    );

   $(".trigger").hover(
	    function () {
		$('.arrow').css('display','none');
		if (!$(this).parent().children().is(':animated')) {
		 thisArrow = $(this).attr('id')+"-arrow";
		// alert(thisArrow);
		
		$(".arrow-text").fadeIn('fast', function() {
		    

		    //$('.arrow img').css('width','100%' );
		    $("#" +thisArrow).fadeIn('fast');
		});

		}
	    },
	    function () {
		if (!$(this).parent().children().is(':animated')) {
		  $("#" +thisArrow).fadeOut('fast');
		}
	    }

	);

   $('.pu-mid').click(function () {
       var thisId = jQuery(this).attr("id");
       var thisPopup = '#' + thisId + '.pu-mid';
       

	$(thisPopup).fadeOut('fast');
	popupShown = false;


   });

   $('.main-exit').click(close);

   function close() {
       $('.main-exit').fadeOut('fast');
       $('.arrow').fadeOut('fast');
        $(thisPopup).fadeOut('slow');
        $("." + thisImg).animate({width: "0px"}, 'slow',function(){
          $(button_group).fadeIn('slow');
          $('.counter-dots').fadeIn('fast');
       });
         
       zoomed = false;
   };

 $('.forward').click(function() {
     if (animDone == true) {
	 animDone = false;
     var last_char= thisImg.charAt(1);
     var lNum = parseInt(last_char);

     var nextNum = lNum +1;

     if(nextNum==6){nextNum=1;}
      $('.counter').html(nextNum +  ' of 5');
     var nextz = 'z' + nextNum;
     var nextImg = '.z' + nextNum;
     var nextPopup = '#' + nextz + '.popup';
     var nextTrigger = '#' + nextz + '.trigger';

     $(thisPopup).animate({
	              top: '+=' + 10 + 'px',
		      opacity: 0.0
		  },100);
       $('.trigger').fadeOut('fast');
       $("." + thisImg).animate({width: "0px"}, 'slow');
       $(nextImg).animate({width: "695px"}, 'slow',function(){

		  $(".popup").css('display','none');
		  $('.popup').css('top','0');
		  $(nextPopup).css('display','block');

		  $(nextPopup).animate({
		      top: '-=' + 10 + 'px',
		      opacity: 1.0
		  },100);
	        $(nextTrigger).fadeIn('slow');
		animDone = true;
		});


	thisImg = nextz;
	thisPopup = nextPopup;
	popupShown = true;
     }
 });
  $('.back').click(function() {
     var sw;
     if (animDone == true) {
	 animDone = false;
     var last_char= thisImg.charAt(1);
     var lNum = parseInt(last_char);

     var prevNum = lNum - 1;

     if(prevNum==0){prevNum=5;sw = true}
      $('.counter').html(prevNum +  ' of 5');
     var prevz = 'z' + prevNum;
     var prevImg = '.z' + prevNum;
     var prevPopup = '#' + prevz + '.popup';
     var prevTrigger = '#' + prevz + '.trigger';

     $(thisPopup).animate({
	              top: '+=' + 10 + 'px',
		      opacity: 0.0
		  },100);
       $('.trigger').fadeOut('slow');

       if (sw == true){
	      //$("." + thisImg).css('float', 'right');
              $("." + thisImg).animate({width: "0px"}, 'slow');
	      //$("." + thisImg).css('float', 'left');
       //$("." + thisImg).animate({width: "0px"}, 'slow');
       }else{
	   $("." + thisImg).animate({width: "0px"}, 'slow');
	   sw = false
       }
       $(prevImg).animate({width: "695px"}, 'slow',function(){

		  $(".popup").css('display','none');
		  $('.popup').css('top','0');
		  $(prevPopup).css('display','block');

		  $(prevPopup).animate({
		      top: '-=' + 10 + 'px',
		      opacity: 1.0
		  },100);
	        $(prevTrigger).fadeIn('fast');
		animDone = true;
		});


	thisImg = prevz;
	thisPopup = prevPopup;
	popupShown = true;
     }
 });

};
})(jQuery);

