function toggleBtns(obj,nextObj)
{
	var btnIdx = $(nextObj).attr('class');
	$('#bottomControl').children("ul").children("li").attr('class','');
	$('#bottomControl').children("ul").children("li").eq(btnIdx).attr('class','active');
}

function stopSlider(curr, next)
{
   var id = next.id;
   if(id == 'slideTwo') { $('#slider').cycle('pause'); }	
}

function init() {

	$('#leftScreenshots').cycle({ 
	    fx:     'fade',
	    speed: 1000,
	    after: toggleBtns,
            timeout: 7000
	});

	$('#slider').cycle({ 
            cleartypeNoBg: true,
	    fx:     'scrollHorz', 
	    prev:   '#prev', 
	    next:   '#next', 
	    timeout: 9000,
	    startingSlide: 0,
	    after : stopSlider
	});
}

$(document).ready(function() {

    try
    {
      $.get("twitter.php", function(data){
        $('#twitterClient').html(data);
      });    
    }catch(err) {}


    $("#bottomControl div, li")
      .bind("click.homepage", function(e){
        var 
          $obj = $(e.target),
          $ul  = $obj.closest("ul"),
          btnIndex = $ul.children("li").index($obj)
        ;
        
        if(btnIndex > -1) {
          $('#leftScreenshots').cycle(btnIndex);
          $('#leftScreenshots').cycle('pause');
          $('#playpause').attr('class','play');
        }
        else {
          var tp = $obj.attr('class');
          if(tp == 'play') {
             $('#playpause').attr('class','');	
             $('#leftScreenshots').cycle('resume');
          }	
          else {
             $('#playpause').attr('class','play');	
             $('#leftScreenshots').cycle('pause');          	
          }
        }
    });


  
    $('#bottomBoxes .bottomBox').bind('click.homepage', function(e) {
       var
         $obj = $(e.target),
         $div = $obj.parent('div'),
         index = $div.children('div').index($obj)
         ;
         
         switch(index) {
           case 0 : location = 'https://www.hotboxvapors.com/store/product.php?productid=16185&cat=262&page=1'; break;
           case 1 : location = 'https://www.hotboxvapors.com/store/product.php?productid=16166&cat=261&page=1'; break;
           case 2 : location = 'https://www.hotboxvapors.com/store/product.php?productid=16170&cat=261&page=1'; break;
           case 3 : location = 'https://www.hotboxvapors.com/store/product.php?productid=16151&cat=3&page=1'; break;
           case 4 : location = 'https://www.hotboxvapors.com/store/product.php?productid=16149&cat=3&page=1'; break;
           case 5 : location = 'https://www.hotboxvapors.com/store/product.php?productid=16178&cat=262&page=1'; break;
           case 6 : location = 'https://www.hotboxvapors.com/store/product.php?productid=16172&cat=262&page=1'; break;
           case 7 : location = 'https://www.hotboxvapors.com/store/product.php?productid=16160&cat=103&page=1'; break;
         }
       
    });


});
